/* 
	moo.rd - A lightweight Mootools extension  

	Author: Riccardo Degni, <http://www.riccardodegni.it/> and the moo.rd Team 

	License: GNU GPL License 

	Copyright: copyright 2007 Riccardo Degni 

	[Credits] 
		[li] moo.rd is based on the MooTools framework <http://mootools.net/>, and uses the MooTools syntax 
		[li] moo.rd constructors extends some of the MooTools Classes 
		[li] moo.rd Documentation is written by Riccardo Degni 
	[/Credits] 

*/ 

var Moo = {};

Moo.Rd = {
	version: '1.3.2',
	author: 'Riccardo Degni',
	members: [
		'Cristiano Fino',
		'Moocha'
	]
};

var Table = new Class({	
	initialize: function(element) {
		this.element = $(element);
		this.rows = this.element.getElements('tr');
		this.cells = this.element.getElements('tr').getElements('td');
	}
});

var Make = new Class({
	Implements: [Options],
	options: {
		content: 'text'
	}
});

function $dump(obj, result) {
	var r = '(' + '<br />';
	var tinyspaces = '&nbsp;&nbsp;';
	r += tinyspaces + 'Value: ' + obj.toString() + '<br />';
	r += tinyspaces + 'Type: ' + $type(obj) + '<br />';
	r += ')';
	return (result) ? $(result).set('html', r) : r;
}

function $string(obj) {
	return $type(obj) == 'string';
}

function $int(obj) {
	return $type(obj) == 'number';
}

function $array(obj) {
	return $type(obj) == 'array';
}

function $object(obj) {
	return $type(obj) == 'object';
}

function $function(obj) {
	return $type(obj) == 'function';
}

function $date(obj) {
	return $type(obj) == 'date';
}

function $class(obj) {
	return $type(obj) == 'class';
}

function $element(obj) {
	return $type(obj) == 'element';
}

function $collection(obj) {
	return $type(obj) == 'collection';
}

function $arguments(obj) {
	return $type(obj) == 'arguments';
}

function $textnode(obj) {
	return $type(obj) == 'textnode';
}

function $whitespace(obj) {
	return $type(obj) == 'whitespace';
}

function $window(obj) {
	return $type(obj) == 'window';
}

function $document(obj) {
	return $type(obj) == 'document';
}

Browser.ie = Browser.Engine.trident;
Browser.ie6 = Browser.Engine.trident4;
Browser.ie7 = Browser.Engine.trident5;
Browser.firefox = Browser.Engine.gecko;
Browser.safari = Browser.Engine.webkit;
Browser.safari2 = Browser.Engine.webkit419;
Browser.safari3 = Browser.Engine.webkit420;
Browser.opera = Browser.Engine.presto;
Browser.opera925 = Browser.Engine.presto925;
Browser.opera950 = Browser.Engine.presto950;

var Overlay = new Class({
						
	createOverlay: function(id, light) {
		this.overlay = new Element('div', {
			'id': id || 'overlay',
			'styles': {
				'position': (Browser.ie6) ? 'absolute' : 'fixed',
				'top': '0px',
				'left': '0px',
				'width': (Browser.ie6) ? window.getWidth() : '100%',
				'height': '100%',
				'background-image':'url(g.gif)',
				'z-index': 800
			}
		});
		
		if(Browser.Engine.presto) this.overlay.setStyle('overflow', 'hidden');  
	
		this.setLight(light);
		
		return this;
	},
	
	createFullPage: function(id) {
		this.fullpage = new Element('div', {
			'id': id || 'fullpage',
			'styles': {
				'position': (Browser.ie6) ? 'absolute' : 'fixed',
				'top': '0px',
				'left': '0px',
				'width': (Browser.ie6) ? window.getWidth() : '100%',
				'height': '100%',
				'background-image':'url(g.gif)',
				'z-index': 900
			}
		});
		
		if(Browser.Engine.presto) this.fullpage.setStyle('overflow', 'hidden');  
		
		return this;
	},
	
	setLight: function(light, opacity) {
		switch(light) {
			case 'darken': 
				var color = '#333333';
				break;
			case 'lighten':
				var color = '#FFFFFF';
				break;
			case false:
				var color = 'transparent';
				break;
			default: 
				var color = light;
				break;
		};
		this.overlay.setStyles({
			'background-color': color,
			'opacity': opacity || '0.8'			   
		});
		
		return this;
	},
	
	injectOverlay: function(fullpage) {
		this.overlay.inject(document.body);
		if(fullpage) this.fullpage.inject(document.body);
		this.overlayActive = true;
		this.fixOverlay();
		return this;
	},
	
	removeOverlay: function() {
		this.overlay.dispose();
		this.fullpage.dispose();
		if(Browser.ie6) {
			document.body.setStyles({'height': this.bodyHeightTrident4, 'overflow': this.bodyOverflowTrident4});
		}
		this.overlayActive = false;
		return this;
	},
	
	fixOverlay: function() {
		if(Browser.ie6) {
			if(!this.bodyHeightTrident4) this.bodyHeightTrident4 = $(document.body).getStyle('height');
			this.bodyOverflowTrident4 = $(document.body).getStyle('overflow');
			
			$$(this.overlay, this.fullpage).setStyle('overflow', 'hidden');
			
			$$(window, document.body).setStyles({
				'height': '100%',
				'overflow': 'auto',
				'margin': 0,
				'padding': 0
			});
		}
		return this;
	}
});

String.implement({
	
	upper: function() {
 		return this.toUpperCase();
 	},
	
 	lower: function() {
 		return this.toLowerCase();
 	},
	
	firstChar: function (n) {	
		return (this.charAt(0)==n) ? true : false;
	},
	
	hasChar: function (n) {
		for(var i=0; i<=this.length; i++)
			if(this.charAt(i)==n) return true;
		return false;
	},
	
	lastChar: function (n) {	
		return (this.charAt(this.length-1)==n) ? true : false;
	},
	
	stripPhp: function() {
		return this.replace(/<\?php|\?>/gi, '');
	},
	
	stripJs: function() {
		return this.replace(/<script[^>]{0,}>|<\/script>/gi, '');
	},
	
	globalReplace: function(val, repl, regexAttr) {
		return this.replace(new RegExp(val, regexAttr || 'gi'), repl);
	},
	
	contains: function (phrase) {
		return (this.indexOf(phrase) != -1) ? true : false;
	},
	
	posOf: function (n) {
		var positions = new Array();
			for (var i=0; i<this.length; i++)
				if(this.charAt(i)==n)
					positions.push(i);
			if(positions.length==0)
				return false;
			else
				return positions;
	},
	
	getFirst: function() {
		return this.charAt(0);
	},
	
	getLast: function() {
		return this.charAt(this.length-1);
	},
	
	camelize: function() {
		var s = '';
		for(var i=0; i<this.length; i++) {
			if(i%2 == 0) s+= this.charAt(i).upper();
			else s+= this.charAt(i).lower();
		}
		
		return s;
	},
	
	upperFirst: function() {
		return this.replace(this.charAt(0), this.charAt(0).upper());	
	}
			  
});

String.implement({
	
	stripTags: function () {
		return this.replace(/<([^>]+)>/g,'');
	},

	addslashes: function() {
		return this.replace(/['"]/g, function(match){
			return ('\\' + match.charAt(0) + match.charAt(1));
		});
	},
	
	nl2br: function() {
		return this.replace(/\\n/g, '<br />');
	},
	
	br2nl: function() {
		return this.replace(/<br>|<br\/>|<br \/>/g, '\n');
	},
	
	stripslashes: function() {
		return this.replace(/\\['"]{1,}/g, function(match){
			return (match.charAt(1));
		});
	},
	
	htmlEntities: function () {
		return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
	},
	
	html_entity_decode: function() {
	  var txt = new Element("textarea");
	  txt.set('html', this.replace(/</g,"&lt;").replace(/>/g,"&gt;"));
	  return txt.get('value');
	},
	
	trim: function() {
		return this.replace(/^\s+|\s+$/g,'');
	},
	
	ltrim: function() {
		return this.replace(/^\s+/g,'');
	},
	
	rtrim: function() {
		return this.replace(/\s+$/g,'');
	}
});

Array.implement({
	
	print_r: function(results) {
		var r = 'Array ( ' + '<br />';
		var spaces = '&nbsp;&nbsp;&nbsp;&nbsp;';
		var tinyspaces = '&nbsp;&nbsp;';
		
		var _obj = function(r, el, index) {
			var r = '';
			var el = el;
			var index = index;
			r += spaces + '[' + index + ']' + ' => ';
			r += 'Object { ' + '<br />';
			for(var p in el) {
				if($string(p))
					r += spaces + tinyspaces + '[' + p + ']' + ' => \'' + el[p] + '\'<br />';
				else if($int(p))
					r += spaces + tinyspaces + '[' + p + ']' + ' => ' + el[p] + '<br />';
			};
			r += spaces + '}' + '<br />';
			return r;
		};
		
		this.each(function(el, index) {
			if($array(el)){ 
				r += tinyspaces + '[' + index + ']' + ' => ';
				r += 'Array ( ' + '<br />';
				el.each(function(e, i) {
					if($string(e))
						r += spaces + '[' + i + ']' + ' => \'' + e + '\'<br />';
					else if($int(e))
						r += spaces + '[' + i + ']' + ' => ' + e + '<br />';
					else if($object(e))
						r += _obj(r, e, i);
				});
				r += tinyspaces + ')' + '<br />';
			}
			else {
				if($string(el))
					r += tinyspaces + '[' + index + ']' + ' => \'' + el + '\'<br />';
				else if($int(el))
					r += tinyspaces + '[' + index + ']' + ' => ' + el + '<br />';
				else if($object(el))
					r += _obj(r, el, index);
			}
		});
		r += ')';
		return (results) ? $(results).set('html', r) : r;
	},
	
	numSort: function() {
		return this.sort(function(a, b) {return a-b;});
	},
	
	rNumSort: function() {
		return this.sort(function(a, b) {return b-a;});
	},
	
	getFirst: function() {
		return this[0];
	},
			
	getLast: function() {
		return this[this.length-1];
	},
	
	asItem: function(item) {
		var a = new Array();
		for(var z=0; z<this.length; z++)
			if(this[z] == item) return true;
		return false;
	},
	
	asItems: function() {
		var a = new Array();
				
		for(var i=0; i<arguments.length; i++)
			if(this.asItem(arguments[i]))
				a.push(arguments[i]);
				
		return (a.length >= arguments.length);
	},
	
	stripItem: function() {
		var a = new Array();
		for(var z=0; z<this.length; z++)
			for(var i=0; i<arguments.length; i++)
				if(this[z] != arguments[i])
					a.push(this[z]);
		return a;	
	},
	
	stripItems: function() {
		var a = new Array();
		for(var w=0; w<this.length; w++) a.push(this[w]);
				
		for(var z=0; z<this.length; z++) {
			for(var i=0; i<arguments.length; i++)
				if(this[z] == arguments[i])
					a = a.stripItem(arguments[i]);
		}	
		return a;	
	},
	
	posOf: function(item) {
		var a = new Array();
				
		for(var z=0; z<this.length; z++)
			if(this[z] == item)
				a.push(z);
		return a;
	}
});

function print_r(v, results) {
	if($array(v)) v.print_r(results);
}

Table.implement({

	zebra: function(color1, color2, firstLine) {
		if(this.element.get('tag') != 'table')  return false;
		
		this.cells.each(function(cell, index) {
			if(firstLine && index == 0)	return;		
			(index%2 == 0) ? cell.setStyle('background-color', color1) : cell.setStyle('background-color', color2);
		});
	},
	
	overClickRows: function(overcolor, clickcolor) {
		this.rows.each(function(row, index) {
			row.addEvent('mouseover', function() {
				if(!this.init) this.init = row.getElement('td').getStyle('background-color');
				if(row.getElement('td').getStyle('background-color').toUpperCase() != clickcolor)
					row.getElements('td').setStyle('background-color', overcolor);
			});
			
			row.addEvent('mouseout', function() {
				if(row.getElement('td').getStyle('background-color').toUpperCase() != clickcolor)
					row.getElements('td').setStyle('background-color', this.init);
			});
			
			row.addEvent('click', function() {
				if(row.getElement('td').getStyle('background-color').toUpperCase() != clickcolor)
					row.getElements('td').setStyle('background-color', clickcolor);
				else
					row.getElements('td').setStyle('background-color', this.init);
			});
		});
	},
	
	overRows: function(color) {
		this.rows.each(function(row, index) {
			row.addEvent('mouseover', function() {
				this.init = row.getElement('td').getStyle('background-color');
				row.getElements('td').setStyle('background-color', color);
			});
			
			row.addEvent('mouseout', function() {
				row.getElements('td').setStyle('background-color', this.init);
			});
		});
	},
	
	clickRows: function(color) {
		this.rows.each(function(row, index) {
			row.addEvent('click', function() {
				if(!this.initBc) this.initBc = row.getElement('td').getStyle('background-color').toUpperCase();
				if(row.getElement('td').getStyle('background-color').toUpperCase() != this.initBc)
					row.getElements('td').setStyle('background-color', this.initBc);
				else
					row.getElements('td').setStyle('background-color', color);	
			});
		});
	}
});

Table.implement({
	
	zebraCells: function(color1, color2, firstLine) {
		this.rows.each(function(row, index) {
			if(firstLine && index==0) return;
			row.getElements('td').each(function(td, i) {
				if(i%2 == 0)
					(index%2 == 0) ? td.setStyle('background-color', color1) : td.setStyle('background-color', color2);
				else
					(index%2 == 0) ? td.setStyle('background-color', color2) : td.setStyle('background-color', color1);
			});
		});
	},
	
	overClickCells: function(color, clickcolor) {
		this.rows.each(function(row, index) {
			row.getElements('td').each(function(td,index) {
				td.addEvent('mouseover', function() {
					if(!this.init) this.init = td.getStyle('background-color');
					if(td.getStyle('background-color').toUpperCase() != clickcolor)
						td.setStyle('background-color', color);
				});
				
				td.addEvent('mouseout', function() {
					if(td.getStyle('background-color').toUpperCase() != clickcolor)
						td.setStyle('background-color', this.init);
				});
				
				td.addEvent('click', function() {
					if(td.getStyle('background-color').toUpperCase() != clickcolor)
						td.setStyle('background-color', clickcolor);
					else
						td.setStyle('background-color', this.init);
				});
			});
		});
	},
	
	overCells: function(color) {
		this.rows.each(function(row, index) {
			row.getElements('td').each(function(td,index) {
				td.addEvent('mouseover', function() {
					this.init = td.getStyle('background-color');
					td.setStyle('background-color', color);
				});
				
				td.addEvent('mouseout', function() {
					td.setStyle('background-color', this.init);
				});
			});
		});
	},
	
	clickCells: function(color) {
		this.rows.each(function(row, index) {
			row.getElements('td').each(function(td,index) {
				td.addEvent('click', function() {
					if(!this.initC) this.initC = row.getElement('td').getStyle('background-color').toUpperCase();
					if(td.getStyle('background-color').toUpperCase() != this.initC)
						td.setStyle('background-color', this.initC);
					else
						td.setStyle('background-color', color);
				});
			});
		});
	}
});

Table.implement({	
	
	zebraCols: function(color1, color2, firstLine) {
		this.rows.each(function(row, index) {
			if(firstLine && index==0) return;
			row.getElements('td').each(function(td, i) {
				if(i%2 == 0)
					td.setStyle('background-color', color1);
				else
					td.setStyle('background-color', color2);
			});
		});
	},
				
	overClickCols: function(color, clickcolor, firstLine) {
		this.colors = [];
		this.rows.each(function(row, indexRow) {
			
		  row.getElements('td').each(function(td, indexTd) {
			 
			var i = indexTd;
			
			if(!this.colors[indexRow]) { 
				this.colors[indexRow] = []; 
			}
			this.colors[indexRow][indexTd] = td.getStyle('background-color').toUpperCase();
			td.store('color', this.colors[indexRow][indexTd]);
			
			
			td.addEvent('mouseover', function() {
				td.getParent().getParent().getElements('tr').each(function(r, indexR) {
					r.getElements('td').each(function(c, indexC) {
						if(indexC == i)
							if((firstLine) && (indexR==0))
								c.setStyle('background-color', c.retrieve('color'));
							else if(c.getStyle('background-color').toUpperCase() != clickcolor)
								c.setStyle('background-color', color);
							else
								c.setStyle('background-color', clickcolor);
					}, this);
				}, this);
			}.bind(this));
			
			td.addEvent('mouseout', function() {
				td.getParent().getParent().getElements('tr').each(function(r, indexR) {
					r.getElements('td').each(function(c, indexC) {
						if(indexC == i)
							if(c.getStyle('background-color').toUpperCase() == color)
								c.setStyle('background-color', c.retrieve('color'));
					}, this);
				}, this);
			}.bind(this));
				
			td.addEvent('click', function() {
				td.getParent().getParent().getElements('tr').each(function(r, indexR) {
					r.getElements('td').each(function(c, indexC) {
						if(indexC == i)
							if((firstLine) && (indexR!=0))
							  if(c.getStyle('background-color').toUpperCase() != clickcolor)
								  c.setStyle('background-color', clickcolor);
							  else
								  c.setStyle('background-color', c.retrieve('color'));
							else if((!firstLine))
								 if(c.getStyle('background-color').toUpperCase() != clickcolor)
								  c.setStyle('background-color', clickcolor);
							  else
								  c.setStyle('background-color', c.retrieve('color'));
					}, this);
				}, this);
			}.bind(this));
				
		  }, this);		
		}, this);
	},
	
	overCols: function(color, firstLine) {
		this.colors = [];
		this.rows = this.element.getElements('tr');
		this.rows.each(function(row, indexRow) {
			
			  row.getElements('td').each(function(td, indexTd) {
				 
				var i = indexTd;
				if(!this.colors[indexRow]) { 
					this.colors[indexRow] = []; 
				}
				this.colors[indexRow][indexTd] = td.getStyle('background-color').toUpperCase();
				td.store('color', this.colors[indexRow][indexTd]);
				
				td.addEvent('mouseover', function() {
					td.getParent().getParent().getElements('tr').each(function(r, indexR) {
						r.getElements('td').each(function(c, indexC) {
							if(indexC == i)
								if((firstLine) && (indexR==0))
									c.setStyle('background-color', c.retrieve('color'));
								else if(c.getStyle('background-color').toUpperCase() != color)
									c.setStyle('background-color', color);
								else
									c.setStyle('background-color', c.retrieve('color'));
						}, this);
					}, this);
				}.bind(this));
				
				td.addEvent('mouseout', function() {
					td.getParent().getParent().getElements('tr').each(function(r, indexR) {
						r.getElements('td').each(function(c, indexC) {
							if(indexC == i)
								if(c.getStyle('background-color').toUpperCase() == color)
									c.setStyle('background-color', c.retrieve('color'));
						}, this);
					}, this);
				}.bind(this));
			  
			}, this);		
		}, this);
	},
	
	clickCols: function(color, firstLine) {
		this.colors = [];
		this.rows = this.element.getElements('tr');
		this.rows.each(function(row, indexRow) {
			
		  row.getElements('td').each(function(td, indexTd) {
			 
			var i = indexTd;
			if(!this.colors[indexRow]) { 
				this.colors[indexRow] = []; 
			}
			this.colors[indexRow][indexTd] = td.getStyle('background-color').toUpperCase();
			td.store('color', this.colors[indexRow][indexTd]);
			
			td.addEvent('click', function() {
				td.getParent().getParent().getElements('tr').each(function(r, indexR) {
					r.getElements('td').each(function(c, indexC) {
						if(indexC == i)
							if((firstLine) && (indexR==0))
								c.setStyle('background-color', c.retrieve('color'));
							else if(c.getStyle('background-color').toUpperCase() != color)
								c.setStyle('background-color', color);
							else
								c.setStyle('background-color', c.retrieve('color'));
					}, this);
				}, this);
			}.bind(this));
		  
		  }, this);		
		}, this);
	}
});

Make.Table = new Class({
					   
	Extends: Make,
			
	initialize: function(id, rows, options) {
		this.idKey = id;
		this.setOptions(options);
		this.rows = rows;
	},
	
	make: function() {
		if(!$(this.idKey)) {
			this.table = new Element('table', {
				'id': this.idKey
			});
			
			var table = this.table;
			var tbody = new Element('tbody').inject(table);
			var first = this.first;
			var l = this.rows.length-1;
			
			this.rows.each(function(row, index) {
				var tr = new Element('tr').inject(tbody);
				row.each(function(cell) {
					if($object(cell)) {
						if(cell.styles) tr.setStyles(cell.styles);
						if(cell.properties) tr.setProperties(cell.properties);
					}
					else new Element('td').set(this.options.content, cell).inject(tr);	
				}, this);
			}, this);
			
			return this.table;
		}
		else return;
	}
});

Array.implement({
	makeTable: function(id, options) {
		return new Make.Table(id, this, options).make();
	}
});

function make_table(id, rows, options) {
	return new Make.Table(id, rows, options).make();
}

Make.List = new Class({
					  
	Extends: Make,
					  
	options: {
		type: 'ul',
		listOptions: {}
	},
	
	initialize: function(id, items, options) {
		this.idKey = id;
		this.items = items;
		this.setOptions(options);
	},
	
	make: function() {
		if(!$(this.idKey)) {
			
			if(this.options.type != 'ul' && this.options.type != 'ol') this.options.type = 'ul';
			
			this.ul = new Element(this.options.type, $merge(this.options.listOptions, {'id': this.idKey}));
			
			this.items.each(function(li) {
				if($array(li)) {
					li.each(function(item, i) {
						var mul = new Element('ul');
						if($object(item)) {
							var a = new Element('a', $merge(item.linkOptions, {
								'href': item.href
							})).set(this.options.content, item.text);
							var lis = new Element('li');
							a.inject(lis);
							lis.inject(mul);
							mul.inject(this.ul);
						}			 
						else {
							var mli = new Element('li').set(this.options.content, item).inject(mul);
							mul.inject(this.ul);
						}
					}, this);
				}
				else if($object(li)) {
					var a = new Element('a', $merge(li.linkOptions, {
						'href': li.href
					})).set(this.options.content, li.text);
					var li = new Element('li');
					a.inject(li);
					li.inject(this.ul);
				}
				else {
					var li = new Element('li').set(this.options.content, li);
					li.inject(this.ul);
				}
			}, this);
			
			return this.ul;
		}
		else return;
	}
});

Array.implement({
		
		makeList: function(id, options) {
			return new Make.List(id, this, options).make();
		}
});

function make_list(id, items, options) {
		return new Make.List(id, items, options).make();
}

Make.Select = new Class({
						
	Extends: Make,
	
	options: {
		properties: {}
	},
			
	initialize: function(id, items, options) {
		this.idKey = id;
		this.items = items;
		this.setOptions(options);
	},
	
	make: function() {
		if(!$(this.idKey)) {
			this.select = new Element('select', $extend({'id': this.idKey}, this.options.properties));
			
			this.items.each(function(item) {
				if($array(item)) {
					item.each(function(i, index) {
						if(index == 0) {
							this.group = new Element('optgroup', { 'label': i });
							this.select.adopt(this.group);
						}
						else {
							var opt = new Element('option', {
								'label': i,
								'value': i
							}).set(this.options.content, i);
							opt.inject(this.group);	
						}
					}, this);	
				}					 
				else {
					var option = new Element('option', {
						'label': item,
						'value': item
					}).set(this.options.content, item);
					option.inject(this.select);
				}
			}, this);
			
			return this.select;
		}
		else return;
	}
});

Array.implement({
	makeSelect: function(id, options) {
		return new Make.Select(id, this, options).make();
	}
});

function make_select(id, items, options) {
	return new Make.Select(id, items, options).make();
}

var Custom = new Class({
		
	Implements: [Options, Events, Overlay],
		
	options: {
		height: 'auto',
		width: '300px',
		overlay: false,
		opacify: true,
		draggable: true,
		dragOpacity: false,
		adjustStyles: true,
		promptType: {
			box: 'single',
			lines: 1,
			startValue: '',
			search: false,
			target: 'new'
		},
		content: 'text',
		enable: {
			closeButton: true,
			confirmButton: true,
			cancelButton: true,
			onConfirm: true,
			onCancel: true,
			textBox: false
		},
		text: {
			confirmButtonText: 'OK',
			closeButtonText: 'X',
			cancelButtonText: 'Cancel'
		},
		zones: {
			box: null,
			head: null,
			body: null,
			buttonBox: '',
			promptBox: ''
		},
		buttons: {
			closeButton: '',
			confirmButton: '',
			cancelButton: ''
		},
		onConfirm: $empty,
		onCancel: $empty
	},
	
	initialize: function(title, text, options) {
		this.title = title;
		this.text = text;
		this.setOptions(options);
		this.box = new Element('div', {
			'id': 'customBox',
			'styles': {
				'position': (!Browser.Engine.trident4) ? 'fixed' : 'absolute',
				'top': '50%',
				'left': '50%',
				'z-index': 1000,
				'height': this.options.height,
				'width': this.options.width
			}
		});
		this.createOverlay('customBoxOverlay', this.options.overlay);
		this.createFullPage('customBoxfullpage');
		this.mechanize();
		this.box.set('tween', {duration: 1000});
		this.dragOptions = {container: this.fullpage};
		if(this.options.dragOpacity) 
			this.dragOptions = $merge(this.dragOptions, {
				onDrag: function(element) {
					element.set('opacity', 0.6);
				},
				onComplete: function(element) {
					element.set('opacity', 1);
				}
			});
	},
	
	create: function() {
		this.customize();
	},
	
	mechanize: function() {
		if(this.options.zones['box']) this.box.addClass(this.options.zones['box']);
		
		this.head = new Element('div').injectInside(this.box);
		if(this.options.zones.head) this.head.addClass(this.options.zones['head']);
		this.head.set(this.options.content, this.title);
		
		if(this.options.enable.closeButton) {
			this.closebutton = new Element('a', {'id': 'customCloseButton', 'class': this.options.buttons.closeButton}).injectInside(this.head);
			this.closebutton.setProperty('href', '#');
			this.closebutton.set(this.options.content, this.options.text.closeButtonText);
			this.closebutton.addEvent('click', function(event) {
				event.preventDefault();
			});
			this.closebutton.addEvent('click', this.cancelRemove.bind(this));
		}
		
		this.content = new Element('div').injectInside(this.box);
		if(this.options.zones.body) this.content.addClass(this.options.zones['body']);
		this.content.set(this.options.content, this.text);
		
		if(this.options.enable.textBox) {	
			this.promptbox = new Element('div', {
				'id': 'customPromptTextBox', 'class': this.options.zones.promptBox}).inject(this.box);
			this.form = new Element('form', {'id': 'customPromptTextForm', 'action': '#'}).inject(this.promptbox);
			
			switch(this.options.promptType.box) {
				case 'single':  this.input = new Element('input', {'type': 'text', 'value': this.options.promptType.startValue}).inject(this.form);
								break;
				case 'multi':	this.input = new Element('textarea', {'value': this.options.promptType.startValue}).inject(this.form).inject(this.form).setProperty('rows', this.options.promptType.lines);
								break;
			}
			
			switch(this.options.promptType.search) {
				case 'google':
					this.addEvent('onConfirm', function(event) {
						if(this.options.promptType.target == 'same')
							location.href = 'http://www.google.it/search?q=' + this.input.get('value');
						else if(this.options.promptType.target == 'new')
							window.open('http://www.google.it/search?q=' + this.input.get('value'));
					});
					break;
				case 'yahoo':
					this.addEvent('onConfirm', function(event) {
						if(this.options.promptType.target == 'same')
							location.href = 'http://search.yahoo.com/search?p=' + this.input.get('value');
						else if(this.options.promptType.target == 'new')
							window.open('http://search.yahoo.com/search?p=' + this.input.get('value'));
					});
					break;
				case 'wikipedia':
					this.addEvent('onConfirm', function(event) {
						if(this.options.promptType.target == 'same')
							location.href = 'http://en.wikipedia.org/wiki/' + this.input.get('value');
						else if(this.options.promptType.target == 'new')
							window.open('http://en.wikipedia.org/wiki/' + this.input.get('value'));
					});
					break;
			}
		}
	
		this.closebox = new Element('div', {'id': 'customButtonBox', 'class': this.options.zones.buttonBox}).injectInside(this.box);
	
		if(this.options.enable.confirmButton) {
			this.button = new Element('a', {'id': 'customButton', 'class': this.options.buttons.confirmButton}).injectInside(this.closebox);
			this.button.setProperty('href', '#');
			this.button.set(this.options.content, this.options.text.confirmButtonText);
			this.button.addEvent('click', function(event) {
				event.preventDefault();
			});
			
			this.button.addEvent('click', this.confirmRemove.bind(this));
		}
		
		if(this.options.enable.cancelButton) {
			this.cancelButton = new Element('a', {'id': 'customCancelButton', 'class': this.options.buttons.cancelButton}).injectInside(this.closebox);
			this.cancelButton.setProperty('href', '#');
			this.cancelButton.set(this.options.content, this.options.text.cancelButtonText);
			this.cancelButton.addEvent('click', function(event) {
				event.preventDefault();
			});
			
			this.cancelButton.addEvent('click', this.cancelRemove.bind(this));
		}
	},
	
	customize: function() {
		if($(this.box.get('id')))  return;
		
		if(this.options.opacify)	this.box.set('opacity', 0);
		
		this.box.injectInside(this.fullpage);
		this.injectOverlay(true);
		
		var dimensions = this.dimensions = { 
			top: this.box.getSize().y/2,
			left: this.box.getSize().x/2,
			fullTop: this.fullpage.getSize().y.toInt()/2,
			fullLeft: this.fullpage.getSize().x.toInt()/2
		};
		
		this.box.setStyles({
			'margin-left': -dimensions.left,
			'margin-top': -dimensions.top,
			'top': dimensions.fullTop,
			'left': dimensions.fullLeft 
		});
		
		if(this.options.opacify)	this.box.fade('in');
		
		if(this.options.draggable) this.drag = new Drag.Move(this.box, this.dragOptions);
		
		if(this.options.adjustStyles) {
			this.newsizes = function() {
				this.box.setStyles({
					'top': window.getSize().y.toInt()/2,
					'left': window.getSize().x.toInt()/2
				});
				if(this.options.draggable) this.drag = new Drag.Move(this.box, this.dragOptions);
			};
			this.boundsizes = this.newsizes.bind(this);
			window.addEvent('resize', this.boundsizes);
		}
	},
	
	remove: function() {
		this.box.dispose();
		this.fullpage.dispose();
		this.removeOverlay();
		window.removeEvent('resize', this.boundsizes);
	},
	
	checkremove: function() {
		if(this.options.opacify) {
			this.box.fade('out');
			this.remove.delay(this.box.get('tween').options.duration.toInt(), this);
		}
		else {
			this.remove();
		}
	},
	
	confirmRemove: function() {
		if(this.options.enable.onConfirm) (this.input) ? this.fireEvent('onConfirm', this.input.get('value')) : this.fireEvent('onConfirm');
		this.checkremove();
	},
	
	cancelRemove: function() {
		if(this.options.enable.onCancel) this.fireEvent('onCancel');
		this.checkremove();
	},
	
	setText: function(text) {
		this.text = text;
		this.content.set(this.options.content, this.text);
		return this;
	},
	
	setTitle: function(title) {
		this.title = title;	
		this.head.set(this.options.content, this.title);
		return this;
	},
	
	setIDs: function(box, overlay, fullpage) {
		this.box.set('id', box);
		this.overlay.set('id', overlay);
		this.fullpage.set('id', fullpage);
	}
});

Custom.Alert = new Class({
						   
	Extends: Custom,
						   
	options: {
		enable: {
			closeButton: true,
			confirmButton: true,
			cancelButton: false,
			onConfirm: false,
			onCancel: false
		}
	},
	
	initialize: function(title, text, options) {
		this.parent(title, text, options);
		this.setIDs('customAlertBox', 'customAlertOverlay', 'customAlertFullpage');
	}
});

Custom.Confirm = new Class({
						   
	Extends: Custom,
						   
	options: {
		enable: {
			closeButton: true,
			confirmButton: true,
			cancelButton: true,
			onConfirm: true,
			onCancel: true
		}
	},
	
	initialize: function(title, text, options) {
		this.parent(title, text, options);
		this.setIDs('customConfirmBox', 'customConfirmOverlay', 'customConfirmFullpage');
	}
});

Custom.Prompt = new Class({
						   
	Extends: Custom,
						   
	options: {
		enable: {
			closeButton: true,
			confirmButton: true,
			cancelButton: true,
			onConfirm: true,
			onCancel: true,
			textBox: true
		}
	},
	
	initialize: function(title, text, options) {
		this.parent(title, text, options);
		this.setIDs('customPromptBox', 'customPromptOverlay', 'customPromptFullpage');
	}
});


var SmoothScrolling = new Class ({
								 
	Extends: Fx.Scroll,
	
	options: {
		links: 'a',
		preventDefault: false
	},
	   
	initialize: function(options) {
		this.parent(window, options);
		if(this.options.initialize) this.options.intialize.call(this);
	},
    
    create: function() {
	 var targets = new Array();
	 var anchors = new Array();
	
	 $$('a').each(function(lnk, index) {
		if(lnk.name) targets.push(lnk);
	 });
				
	 $$(this.options.links).each(function(lnk, index) {
	 	if(lnk.href.test(/#\w+/)) {
			anchors.push(lnk);
			for(var i=0; i<targets.length; i++) {
				if(lnk.href.split('#')[1] == targets[i].name)
					lnk.targetName = targets[i].name;
					lnk.addEvent('click', this.makeScroll.bind(this, lnk));
					if(this.options.preventDefault) lnk.addEvent('click', function(event) { event.preventDefault(); });
			}
		}
	  }, this);
	},
	
	makeScroll: function(lnk) {
		this.start(0, $(document.body).getElement('a[name=' + lnk.targetName + ']').getTop());
	}
	
});

Fx.implement({
	
	initStyles: function() {
		this.init = {};
		$A(arguments).each(function(a) {
			if(a == 'opacity') this.init['opacity'] = this.element.get('opacity');
			else (this.element.getStyle(a).test('px')) ? this.init[a] = this.element.getStyle(a).toInt() : this.init[a] = this.element.getStyle(a);
		}, this);
		return this;
	},
	
	removeAuto: function() {
		if(!this.init) this.init = {};
		$A(arguments).each(function(a) {
			if(this.element.getStyle(a) == 'auto') { 
				this.element.setStyle(a, '0px');
				this.init[a] = 0;
			}
		}, this);
		return this;
	},
	
	setPosition: function() {
		if(this.element.getStyle('position') == 'static') this.element.setStyle('position', 'relative');	
		return this;
	}
});

Element.implement({
	
	fx: function(eff, options) {
		if(!this.retrieve(eff)) this.store(eff, new Fx[eff.upperFirst()](this, options));
		return this.retrieve(eff);
	},
	
	effect: function(fx) {
		this.get(fx).start.pass(Array.slice(arguments, 1), this.get(fx))();
		return this;
	},
	
	removeAuto: function() {
		$A(arguments).each(function(a) {
			if(this.element.getStyle(a) == 'auto') this.element.setStyle(a, '0px');
		}, this);
		return this;
	}
});

var fxToHash = function(hash, effects) {
	Array.each(effects, function(fx, i) {
		var fx = fx.toString();
		var props = {
			set: function(options) {
				var tween = this.retrieve(fx);
				if (tween) tween.cancel();
				return this.eliminate(fx).store(fx + ':options', options);
			},
			
			get: function(options){
				if (options || !this.retrieve(fx)){
					if (options || !this.retrieve(fx + ':options')) this.set(fx, options);
					this.store(fx, new Fx[fx.upperFirst()](this, this.retrieve(fx + ':options')));
				}
				return this.retrieve(fx);
			}
		};
		hash.set(fx, props);
	});
};

Fx.Fold = new Class({
					
	Extends: Fx.Morph,
	
	options: {
		mode: 'vertical'
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.element.setStyle('overflow', 'hidden');
	},
	
	start: function(mode) {
		var mode = mode || this.options.mode;
		switch(mode) {
			case 'vertical':  var styles = { first: {'height':0}, last: {'width': 0}};
					   break;
			case 'horizontal':  var styles = { first: {'width':0}, last: {'height': 0}};
					   break;
		};
		
		var superMethod = arguments.callee;
		this.parent(styles.first).chain(
			function() { this.parentOf(superMethod, styles.last); }
		);
	}		
});

Fx.Shrink = new Class({
					  
	Extends: Fx.Morph,
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.initStyles('fontSize');
		this.element.setStyles({overflow: 'hidden'});
	},
	
	start: function() {
		this.parent({
			'height': 0,
			'width': 0,
			'font-size': [this.init.fontSize, 0]
		});
	}		
});

Fx.Grow = new Class({
					
	Extends: Fx.Morph,
	
	initialize: function(element, options, values) {
		this.parent(element, options);
		this.values = values || {height: 200, width: 200, fontsize: 10};
		this.element.setStyle('overflow', 'hidden');
	},
	
	start: function(values) {
		var values = values || this.values;
		this.parent({
			'height': [0, values.height || this.values.height],
			'width': [0, values.width || this.values.width],
			'font-size': [0, values.fontsize || this.values.fontsize]
		});
	}	
});

Fx.Scale = new Class({
					
	Extends: Fx.Morph,
	
	options: {
		scale: 1.3
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.element.setStyle('overflow', 'hidden');
	},
	
	start: function(properties, scale) {
		var scale = scale || this.options.scale;
		if($type(properties)=='array') {
			var obj = {};
			properties.each(function(p, i) {
				obj[p] = [this.element.getStyle(p).toInt(), this.element.getStyle(p).toInt()*scale];
			}, this);
			this.parent(obj);
		}
	}	
});

Element.implement({
	
	fold: function(options) {
		return new Fx.Fold(this, options);	
	},
	
	shrink: function(options) {
		return new Fx.Shrink(this, options);	
	},
	
	grow: function(options, values) {
		return new Fx.Grow(this, options, values);	
	},
	
	scale: function(options) {
		return new Fx.Scale(this, options);	
	}
});

fxToHash(Element.Properties, ['fold', 'shrink', 'grow', 'scale']);

Fx.Bubble = new Class({
					   
	Extends: Fx.Morph,
	
	options: {
		mode: 'vertical',
		duration: 3000
	},
					   
	initialize: function(element, options) {
		this.parent(element, $merge(this.options, options));
		this.element.setStyle('overflow', 'hidden');
	},
	
	start: function(mode) {
		var mode = mode || this.options.mode;
		var styles = {'font-size': 0, 'opacity': 0};
		switch(mode) {
			case 'vertical':
				this.parent($merge({'height': 0}, styles));
				break;
			case 'horizontal':
				this.parent($merge({'width': 0}, styles));
				break;
		}
	}
});

Fx.Fade = new Class({
					
	Extends: Fx.Tween,
	
	initialize: function(element, options) {
		this.parent(element, options);
	},
	
	start: function(where) {
		switch(where) {
			case 'in': this.parent('opacity', 1); 
					   break;
			case 'out': this.parent('opacity', 0); 
					   break;
			case 'toggle': 
			default: this.parent('opacity', (this.element.get('opacity') == 0) ? 1 : 0); 
					   break;
		}
	}
});

Fx.DropOut = new Class({
					   
	Extends: Fx.Morph,
	
	options: {
		size: 40,
		where: 'down'
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.setPosition().initStyles('top').removeAuto('top');
	},
	
	start: function(where) {
		var where = where || this.options.where;
		switch(where) {
			case 'down':
				var fullTop = this.init.top + this.options.size;
				break;
			case 'up':
				var fullTop = this.init.top - this.options.size;
				break;
		}
		this.parent({
			'top': fullTop,
			'opacity': 0
		});
	}
});

Fx.Squish = new Class({
					  
	Extends: Fx.Morph,
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.initStyles('fontSize').setPosition();
		this.element.setStyles({overflow: 'hidden'});
	},
	
	start: function() {
		this.parent({
			'height': 0,
			'width': 0,
			'opacity': 0,
			'font-size': [this.init.fontSize, 0]
		});
	}		
});

Fx.Puff = new Class({
					
	Extends: Fx.Morph,
	
	options: {
		increase: 1.3
	},
					
	initialize: function(element, options) {
		this.parent(element, options);
		this.initStyles('height', 'width', 'fontSize').setPosition();
		this.element.setStyles({overflow: 'hidden'});
	},
	
	start: function(increase) {
		var increase = increase || this.options.increase;
		this.parent({
			'height': [this.init.height*increase],
			'width': [this.init.width*increase],
			'font-size': [this.init.fontSize*increase],
			'opacity': 0
		}).chain(function() { this.element.setStyle('display', 'none'); });
	}			
});

Element.implement({
	
	bubble: function(options) {
		return new Fx.Bubble(this, options);	
	},
	
	fading: function(options) {
		return new Fx.Fade(this, options);	
	},
	
	dropOut: function(options) {
		return new Fx.DropOut(this, options);	
	},
	
	squish: function(options) {
		return new Fx.Squish(this, options);	
	},
	
	puff: function(options) {
		return new Fx.Puff(this, options);	
	}
});

fxToHash(Element.Properties, ['bubble', 'fading', 'dropOut', 'squish', 'puff']);

Fx.Shake = new Class({
					 
	Extends: Fx.Tween,
	
	options: {
		mode: 'vertical',
		size: 10,
		link: 'chain',
		times: 14
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
		switch(this.options.mode) {
			case 'horizontal': this.prop = 'left';
					  break;
			case 'vertical': this.prop = 'top';
					  break;
		};
		this.setPosition();
		this.element.setStyles({'overflow': 'hidden'});
		this.initStyles('top', 'left').removeAuto('top', 'left');
	},
	
	start: function(mode) {
		if(!mode) (this.options.mode == 'horizontal') ? this.prop = 'left' : this.prop = 'top';
		if(mode == 'vertical') this.prop = 'top';
		if(mode == 'horizontal') this.prop = 'left';
		for(var i=0; i<this.options.times; i++) {
			this.parent(this.prop, (i%2 == 0) ? this.options.size : -this.options.size);
		}
		this.parent(this.prop, 0);
	}
});

Fx.Move = new Class({
					
	Extends: Fx.Morph,				
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.setPosition().initStyles('top', 'left').removeAuto('top', 'left');
	},
	
	start: function(top, left) {
		if(!this.check(arguments.callee, top, left)) return this;
		return this.parent({
			'top': top,
			'left': left
		});
	}
});

Fx.Rumble = new Class({
					  
	Extends: Fx.Morph,
	
	options: {
		duration: 800,
		transition: 'elastic:out'
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.setPosition();
		this.initStyles('top', 'left', 'cursor').removeAuto('top', 'left');
		this.obj = {'top': this.init.top, 
					'left': this.init.left
		};
	},

	start: function() {
		this.element.setStyle('cursor', 'move');
		var top = this.init.top; var left = this.init.left;
		var superMethod = arguments.callee;
		
		(!this.drag) ?
		this.drag = new Drag.Move(this.element, {
				onComplete: function() { 
					this.parentOf(superMethod, this.obj); 
				}.bind(this)
		}) : this.drag.attach();	
	},
	
	detach: function() {
		if(this.drag) this.drag.detach();	
		this.element.setStyle('cursor', this.init.cursor);
	}	
});

Fx.ScrollOut = new Class({
					
	Extends: Fx.Tween,		
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.setPosition();
		this.initStyles('top', 'left').removeAuto('top', 'left');
		this.wrapper = new Element('div', {
		'styles': {'overflow': 'hidden', 'width': this.element.getWidth(), 'position': 'relative'}}).wraps(this.element);
	},
	
	start: function(where) {
		if (!this.check(arguments.callee, where)) return this;
		if(where == 'up' || !where) return this.parent('top', -this.element.getHeight());
		if(where == 'down') return this.parent('top', this.element.getHeight());
		if(where == 'left') return this.parent('left', -this.element.getWidth());
		if(where == 'right') return this.parent('left', this.element.getWidth());
		if(where == 'reset') {
			if(this.element.getStyle('top').toInt() != this.init.top) return this.parent('top', this.init.top);
			if(this.element.getStyle('left').toInt() != this.init.left) return this.parent('left', this.init.left);	
		}
	}
});

Element.implement({
	
	shake: function(options) {
		return new Fx.Shake(this, options);	
	},
	
	move: function(options) {
		return new Fx.Move(this, options);	
	},
	
	rumble: function(options) {
		return new Fx.Rumble(this, options);	
	},
	
	scrollOut: function(options) {
		return new Fx.ScrollOut(this, options);	
	}
});

fxToHash(Element.Properties, ['shake', 'move', 'rumble', 'scrollOut']);

Fx.Pulsate = new Class({
					 
	Extends: Fx.Tween,
	
	options: {
		duration: 200,
		link: 'chain',
		times: 14
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
	},
	
	start: function(last) {
		var last = ($type(last) == 'number') ? last : 1;
		for(var i=0; i<this.options.times; i++) {
			this.parent('opacity', (i%2 == 0) ? 0 : 1);
		}
		this.parent('opacity', last);
	}
});

Fx.SwitchOff = new Class({
					
	Extends: Fx.Morph,
	
	options: {
		mode: 'vertical',
		switchDuration: 100
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.element.setStyle('overflow', 'hidden');
	},
	
	start: function(mode) {
		var mode = mode || this.options.mode;
		switch(mode) {
			case 'vertical':  var last = {'height': 0};
					   break;
			case 'horizontal':  var last = {'width': 0};
					   break;
		};
		this.duration = this.options.duration;
		this.options.duration = this.options.switchDuration;
		
		var superMethod = arguments.callee;
		this.parent({'opacity': 0}).chain(
			function() { this.parentOf(superMethod, {'opacity': 1}); },
			function() { this.options.duration = this.duration; this.parentOf(superMethod, last); }
		);
	}		
});

Fx.Gradient = new Class({
					 
	Extends: Fx.Tween,
	
	options: {
		duration: 1000,
		link: 'chain',
		end: true,
		gradient: 'background-color'
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.initStyles('backgroundColor', 'color');
	},
	
	start: function(colors, gradient) {
		if(!gradient) var gradient = this.options.gradient;
		else if(gradient != 'background-color' && gradient != 'color') var gradient = 'background-color';
		var superMethod = arguments.callee;
		var length = colors.length-1;
		colors.each(function(color, i) {
			this.parentOf(superMethod, [gradient, color]);
			if(i == length && this.options.end)
				this.parentOf(superMethod, [gradient, (gradient == 'background-color') ? this.init.backgroundColor : this.init.color]);
		}, this);
	}
});

Element.implement({
	
	pulsate: function(options) {
		return new Fx.Pulsate(this, options);	
	},
	
	switchOff: function(options) {
		return new Fx.SwitchOff(this, options);	
	},
	
	gradient: function(options) {
		return new Fx.Gradient(this, options);	
	}
});

fxToHash(Element.Properties, ['pulsate', 'switchOff', 'gradient']);


Fx.Toggle = new Class({
					  
	Extends: Fx.Tween,
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.initStyles('height', 'width', 'opacity');
		this.element.setStyle('overflow', 'hidden');
	},
	
	toggleHeight: function() {
		(this.element.getStyle('height').toInt() > 0) ? this.start('height', 0) : this.start('height', this.init.height);
		return this;
	},
	
	toggleWidth: function() {
		(this.element.getStyle('width').toInt() > 0) ? this.start('width', 0) : this.start('width', this.init.width);
		return this;
	},
	
	toggleOpacity: function() {
		(this.element.getStyle('opacity').toInt() > 0) ? this.start('opacity', 0) : this.start('opacity', this.init.opacity);
		return this;
	},
	
	toggleDisplay: function() {
		this.toggleProperty('display', 'none', 'block');
		return this;
	},
	
	toggleVisibility: function() {
		this.toggleProperty('visibility', 'hidden', 'visible');
		return this;
	},
	
	toggleProperty: function(property, from, to, fx) {
		if($string(from) && $string(to)) {
			if(!fx)
				(this.element.getStyle(property) == from.toLowerCase()) ? this.element.setStyle(property, to) : this.element.setStyle(property, from);
			else
				(this.element.getStyle(property) == from.toLowerCase()) ? this.start(property, to) : this.start(property, from);
		}
		else if($int(from) && $int(to)) {
			if(!fx)
				(this.element.getStyle(property).toInt() == from) ? this.set(property, to) : this.set(property, from);
			else
				(this.element.getStyle(property).toInt() == from) ? this.start(property, to) : this.start(property, from);
		}
		return this;
	},
	
	toggle: function(property) {
		switch(property) {
			case 'height': this.toggleHeight();
						break;
			case 'width': this.toggleWidth();
						break;
			case 'opacity': this.toggleOpacity();
						break;
			case 'display': this.toggleDisplay();
						break;
			case 'visibility': this.toggleVisibility();
						break;
		}
		return this;
	}
});
			
Element.extend({
	toggle: function(options) {
		return new Fx.Toggle(this, options);
	}
});

Fx.Cycle = new Class({
	
	Extends: Fx.Morph,
	
	options: {
		animeOut: {},
		animeIn: {},
		cssBefore: {},
		//cssAfter: {},
		animeInType: 'set',
		overflow: 'visible',
		autostart: true,
		steps: 2000,
		handles: {
			next: false,
			prev: false,
			toFirst: false,
			toLast: false,
			autostart: false,
			stop: false
		},
		enable: {
			keyboard: false	
		},
		onAnimeIn: $empty,
		onAnimeOut: $empty
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.imgs = this.element.getChildren();
		this.uimgs = this.element.getChildren().reverse();
		this.element.setStyles({'position': 'relative', 'overflow': this.options.overflow});
		this.first = this.element.getFirst();
		
		this.height = this.first.getStyle('height').toInt();
		this.width = this.first.getStyle('width').toInt();
		this.parentHeight = this.element.getStyle('height').toInt();
		this.parentWidth = this.element.getStyle('width').toInt();
		
		this.uimgs.each(function(img, i) {
			img.setStyles({'position': 'absolute', 'top': '0px', 'left': '0px', 'z-index': i});
		}, this);
		this.count = 0;
		this.length = this.imgs.length-1;
		this.fullLength = this.imgs.length;
		if(this.options.autostart) this._autostart = this.next.periodical(this.options.steps, this);
		this.attachHandles();
		if(this.options.enable.keyboard) this.attachKeys.bindWithEvent(this)();
	},
	
	next: function() {
		if(!this.timer) {
			this.checkAutostart();
			this.element = this.imgs[this.count];
			(this.count != this.length) ? this.count++ : this.count = 0;
			this.main();
		}
	},
	
	prev: function() {
		if(!this.timer) {
			this.checkAutostart();
			this.element = this.imgs[this.count];
			(this.count == 0) ? this.count = this.length : this.count--;
			this.main();
		}
	},
	
	goTo: function(to) {
		if(!this.timer && to != this.count) {
			this.checkAutostart();
			this.element = this.imgs[this.count];
			this.count = to;
			this.main();
		}
	},
	
	toFirst: function() {
		if(!this.timer && this.count != 0) {
			this.checkAutostart();
			this.element = this.imgs[this.count];
			this.count = 0;
			this.main();
		}
	},
	
	toLast: function() {
		if(!this.timer && this.count != this.length) {
			this.checkAutostart();
			this.element = this.imgs[this.count];
			this.count = this.length;
			this.main();
		}
	},
	
	autostart: function() {
		this._autostart = this.next.periodical(this.options.steps, this);
	},
	
	stop: function() {
		this._autostart = $clear(this._autostart);	
	},
	
	checkAutostart: function() {
		if(this._autostart) {
			this._autostart = $clear(this._autostart);
			this._autostart = this.next.periodical(this.options.steps, this);
		}
	},
	
	attachHandles: function() {
		for(var mtd in this.options.handles) {
			var method = mtd.toString();
			if(this.options.handles[mtd] && $function(this[method])) {
				$(this.options.handles[mtd]).addEvent('click', function(event, method) {
					event.preventDefault();	
					this[method]();
				}.bindWithEvent(this, method));	
			}
		}
	},
	
	attachKeys: function(event) {
		$(document).addEvent('keydown', function(event) {
			switch(event.key) {
				case 'left': this.prev();
					break;
				case 'right': this.next();
					break;
				case 'a': this.autostart();
					break;
				case 's': this.stop();
					break;
				case 'f': this.toFirst();
					break;
				case 'l': this.toLast();
					break;
			}
		}.bind(this));
	},
	
	main: function() {
		this.element.setStyle('z-index', this.fullLength);
		this.imgs[this.count].setStyle('z-index', 1);
		
		this.currSlide = this.element;
		this.nextSlide = this.imgs[this.count];
		
		this.fireEvent('onAnimeOut', [this.currSlide, this.nextSlide]);
		this.start(this.options.animeOut).chain(
			function() {
				var type = this.options.animeInType;
				if(type == 'set') this.fireEvent('onAnimeIn', [this.currSlide, this.nextSlide]);
				this.element.setStyle('z-index', 0);
				this.imgs.each(function(img, i) {
					if(i != this.count) img.setStyle('z-index', 0).setStyles(this.options.cssBefore);
				}, this);
				if(type == 'set') this[type](this.options.animeIn); // set instead of start
				if(type == 'start') this[type](this.options.animeIn).chain(function() { this.fireEvent('onAnimeIn', [this.currSlide, this.nextSlide]); });
			}
		);
	}
					 
});

(function() {
var methods = {};

['animeOut', 'animeIn', 'cssBefore'].each(function(method) {
	methods[method] = function(styles) {
		for(var style in styles)
			if($defined(styles[style])) this.options[method][style] = styles[style]; 
	}					
});

Fx.Cycle.implement(methods);
})();

Fx.Cycle.shuffle = new Class({

	Extends: Fx.Cycle,
	
	options: {
		animeInType: 'start',
		animeIn: {
			top: 0,
			left: 0
		},
		sizes: [20, -110]
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.animeOut({top: this.options.sizes[0], left: this.options.sizes[1]});
	}
});

Fx.Cycle.fade = new Class({

	Extends: Fx.Cycle,
	
	options: {
		animeOut: {
			opacity: 0
		},
		cssBefore: {
			opacity: 1	
		}
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
	}
});

Fx.Cycle.slideUp = new Class({

	Extends: Fx.Cycle,
	
	options: {
		cssBefore: {
			top: 0, left:0
		},
		overflow: 'hidden'
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.animeOut({top: -this.parentHeight});
	}
});

Fx.Cycle.slideDown = new Class({

	Extends: Fx.Cycle,
	
	options: {
		cssBefore: {
			top: 0, left:0
		},
		overflow: 'hidden'
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.animeOut({top: this.parentHeight});
	}
});

Fx.Cycle.slideRight = new Class({

	Extends: Fx.Cycle,
	
	options: {
		cssBefore: {
			top: 0, left:0
		},
		overflow: 'hidden'
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.animeOut({left: this.parentWidth});
	}
});

Fx.Cycle.slideLeft = new Class({

	Extends: Fx.Cycle,
	
	options: {
		cssBefore: {
			top: 0, left:0
		},
		overflow: 'hidden'
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.animeOut({left: -this.parentWidth});
	}
});

Fx.Cycle.foldUp = new Class({

	Extends: Fx.Cycle,
	
	options: {
		animeOut: {
			height: 0
		},
		animeIn: {
			left: 0, top: 0
		},
		overflow: 'hidden'
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.cssBefore({top: 0, height: this.height});
	}
});

Fx.Cycle.foldDown = new Class({

	Extends: Fx.Cycle,
	
	options: {
		animeIn: {
			left: 0, top: 0
		},
		overflow: 'hidden'
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.animeOut({height: 0, top: this.height});
		this.cssBefore({top: 0, height: this.height});
	}
});

Fx.Cycle.foldRight = new Class({

	Extends: Fx.Cycle,
	
	options: {
		animeOut: {
			width: 0
		},
		animeIn: {
			left: 0, top: 0
		},
		overflow: 'hidden'
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.cssBefore({top: 0, width: this.width});
	}
});

Fx.Cycle.foldLeft = new Class({

	Extends: Fx.Cycle,
	
	options: {
		animeIn: {
			left: 0, top: 0
		},
		overflow: 'hidden'
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.animeOut({width: 0, left: this.width});
		this.cssBefore({top: 0, width: this.width});
	}
});

Fx.Cycle.zoom = new Class({

	Extends: Fx.Cycle,
	
	options: {
		cssBefore: {
			top: 0, left: 0
		},
		overflow: 'hidden'
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.animeOut({width: 0, height: 0, top: this.height/2, left: this.width/2});
		this.animeIn({top: 0, left: 0, width: this.height, height: this.width});
	}
});

Fx.Cycle.diagonalUp = new Class({

	Extends: Fx.Cycle,
	
	options: {
		animeIn: {
			top: 0, left: 0
		},
		overflow: 'hidden'
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.animeOut({top: -this.parentHeight, left: -this.parentWidth});
	}
});

Fx.Cycle.diagonalDown = new Class({

	Extends: Fx.Cycle,
	
	options: {
		animeIn: {
			top: 0, left: 0
		},
		overflow: 'hidden'
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
		this.animeOut({top: this.parentHeight, left: this.parentWidth});
	}
});

Fx.Cycle.linear = new Class({

	Extends: Fx.Cycle,
	
	options: {
		animeOut: {
			display: 'none'
		},
		cssBefore: {
			display: 'block'
		}
	},
	
	initialize: function(element, options) {
		this.parent(element, options);
	}
});

Element.implement({
	
	cycle: function(type, options) {
		return new Fx.Cycle[type](this, options);
	}				  

});

Fx.Cycles = new Class({
	
	Extends: Fx.Elements,
	
	options: {
		animeOut: {},
		animeIn: {},
		cssBefore: {},
		cssAfter: {},
		reset: {},
		overflow: 'visible',
		autostart: true,
		steps: 2000,
		duration: 3000,
		handles: {
			next: false,
			prev: false,
			toFirst: false,
			toLast: false,
			autostart: false,
			stop: false
		},
		enable: {
			keyboard: false	
		},
		onAnimeIn: $empty,
		onAnimeOut: $empty
	},
	
	initialize: function(element, options) {
		this.element = $(element);
		this.elements = this.element.getChildren();
		this.parent($$(this.elements), options);
		this.imgs = this.element.getChildren();
		this.uimgs = this.element.getChildren().reverse();
		this.element.setStyles({'position': 'relative', 'overflow': this.options.overflow});
		this.first = this.element.getFirst();
		
		this.height = this.first.getStyle('height').toInt();
		this.width = this.first.getStyle('width').toInt();
		this.parentHeight = this.element.getStyle('height').toInt();
		this.parentWidth = this.element.getStyle('width').toInt();
		
		this.uimgs.each(function(img, i) {
			img.setStyles({'position': 'absolute', 'top': '0px', 'left': '0px', 'z-index': i});
		}, this);
		this.count = 0;
		this.where = -1;
		this.length = this.imgs.length-1;
		this.fullLength = this.imgs.length;
		if(this.options.autostart) this._autostart = this.next.periodical(this.options.steps, this);
		this.attachHandles();
		if(!this.options.enable.keyboard) this.attachKeys.bindWithEvent(this)();
	},
	
	next: function() {
		if(!this.timer) {
			this.checkAutostart();
			this.element = this.imgs[this.count];
			(this.count != this.length) ? this.count++ : this.count = 0;
			(this.where == -1) ? this.where = 0 : (this.count == 0) ? this.where = this.length : this.where = this.count-1;
			this.main();
		}
	},
	
	prev: function() {
		if(!this.timer) {
			this.checkAutostart();
			this.element = this.imgs[this.count];
			(this.count == 0) ? this.count = this.length : this.count--;
			(this.where == -1) ? this.where = 0 : (this.count == this.length) ? this.where = 0 : this.where = this.count+1;
			this.main();
		}
	},
	
	goTo: function(to) {
		if(!this.timer && to != this.count) {
			this.checkAutostart();
			this.element = this.imgs[this.count];
			this.where = this.count;
			this.count = to;
			this.main();
		}
	},
	
	toFirst: function() {
		if(!this.timer && this.count != 0) {
			this.checkAutostart();
			this.element = this.imgs[this.count];
			this.where = this.count;
			this.count = 0;
			this.main();
		}
	},
	
	toLast: function() {
		if(!this.timer && this.count != this.length) {
			this.checkAutostart();
			this.element = this.imgs[this.count];
			this.where = this.count;
			this.count = this.length;
			this.main();
		}
	},
	
	autostart: function() {
		this._autostart = this.next.periodical(this.options.steps, this);
	},
	
	stop: function() {
		this._autostart = $clear(this._autostart);	
	},
	
	checkAutostart: function() {
		if(this._autostart) {
			this._autostart = $clear(this._autostart);
			this._autostart = this.next.periodical(this.options.steps, this);
		}
	},
	
	attachHandles: function() {
		for(var mtd in this.options.handles) {
			var method = mtd.toString();
			if(this.options.handles[mtd] && $function(this[method])) {
				$(this.options.handles[mtd]).addEvent('click', function(event, method) {
					event.preventDefault();	
					this[method]();
				}.bindWithEvent(this, method));	
			}
		}
	},
	
	attachKeys: function(event) {
		$(document).addEvent('keydown', function(event) {
			switch(event.key) {
				case 'left': this.prev();
					break;
				case 'right': this.next();
					break;
				case 'a': this.autostart();
					break;
				case 's': this.stop();
					break;
				case 'f': this.toFirst();
					break;
				case 'l': this.toLast();
					break;
			}
		}.bind(this));
	},
	
	main: function() {
		this.element.setStyle('z-index', this.fullLength);
		this.imgs[this.count].setStyle('z-index', 1).setStyles(this.options.current);
		
		this.imgs.each(function(img, i) {
				if(i!=this.where)
					img.setStyles(this.options.cssBefore);
		}, this);
		
		var o = {};

		var curr = this.where;
		var next = this.count;
		
		this.currSlide = this.imgs[curr];
		this.nextSlide = this.imgs[next];
			
		o[curr] = this.options.animeOut;
		o[next] = this.options.animeIn;
		
		this.fireEvent('onAnimeOut', [this.currSlide, this.nextSlide]);
		this.imgs[next].setStyles(this.options.reset);
		this.start(o).chain(function() {
			this.imgs[curr].setStyles(this.options.cssAfter); 
			this.fireEvent('onAnimeIn', [this.currSlide, this.nextSlide]);	
		});
	}
					 
});

(function() {
var methods = {};

['animeOut', 'animeIn', 'cssBefore', 'cssAfter', 'reset'].each(function(method) {
	methods[method] = function(styles) {
		for(var style in styles)
			if($defined(styles[style])) this.options[method][style] = styles[style]; 
	}					
});

Fx.Cycles.implement(methods);
})();

Fx.Cycles.scrollUp = new Class({

	Extends: Fx.Cycles,
	
	options: {
		overflow: 'hidden'
	},
	
	initialize: function(elements, options) {
		this.parent(elements, options);
		this.animeOut({top: [0, -this.parentHeight]});
		this.animeIn({top: [this.parentHeight, 0]});
	}
});

Fx.Cycles.scrollDown = new Class({

	Extends: Fx.Cycles,
	
	options: {
		overflow: 'hidden'
	},
	
	initialize: function(elements, options) {
		this.parent(elements, options);
		this.animeOut({top: [0, this.parentHeight]});
		this.animeIn({top: [-this.parentHeight, 0]});
	}
});

Fx.Cycles.scrollLeft = new Class({

	Extends: Fx.Cycles,
	
	options: {
		overflow: 'hidden'
	},
	
	initialize: function(elements, options) {
		this.parent(elements, options);
		this.animeOut({left: [0, -this.parentWidth]});
		this.animeIn({left: [this.parentWidth, 0]});
	}
});

Fx.Cycles.scrollRight = new Class({

	Extends: Fx.Cycles,
	
	options: {
		overflow: 'hidden'
	},
	
	initialize: function(elements, options) {
		this.parent(elements, options);
		this.animeOut({left: [0, this.parentWidth]});
		this.animeIn({left: [-this.parentWidth, 0]});
	}
});

Fx.Cycles.fadeZoom = new Class({

	Extends: Fx.Cycles,
	
	options: {
		overflow: 'hidden'
	},
	
	initialize: function(elements, options) {
		this.parent(elements, options);
		this.animeOut({opacity: [1, 0], display: 'block'});
		this.animeIn({left: [this.width/2, 0], top: [this.height/2, 0], width: [0, this.width], height: [0, this.height], display: 'block'});
		this.cssBefore({height: 0, width: 0, display: 'none'});
		this.reset({height: this.height, width: this.width, opacity: 1, top: this.height/2, left: this.width/2, display: 'none'});
	}
});

Fx.Cycles.turnDown = new Class({

	Extends: Fx.Cycles,
	
	options: {
		overflow: 'hidden'
	},
	
	initialize: function(elements, options) {
		this.parent(elements, options);
		this.animeOut({height: [this.height, 0], top: [0, this.height]});
		this.animeIn({height: [0, this.height]});
		this.reset({display: 'block', height: this.height, width: this.width, top: 0, left: 0});
		this.cssAfter({display: 'none', width: 0});
	}
});

Fx.Cycles.turnUp = new Class({

	Extends: Fx.Cycles,
	
	options: {
		overflow: 'hidden'
	},
	
	initialize: function(elements, options) {
		this.parent(elements, options);
		this.animeOut({height: [this.height, 0], top: 0});
		this.animeIn({height: [0, this.height], top: 0});
		this.reset({display: 'block', top: this.height, width: this.width});
		this.cssAfter({display: 'none', width: 0});
	}
});

Fx.Cycles.turnLeft = new Class({

	Extends: Fx.Cycles,
	
	options: {
		overflow: 'hidden'
	},
	
	initialize: function(elements, options) {
		this.parent(elements, options);
		this.animeOut({width: [this.width, 0], left: 0});
		this.animeIn({width: [0, this.width], left: [this.width, 0]});
		this.reset({display: 'block', left: this.width, width: this.width});
		this.cssAfter({display: 'none', width: 0});
	}
});

Fx.Cycles.turnRight = new Class({

	Extends: Fx.Cycles,
	
	options: {
		overflow: 'hidden'
	},
	
	initialize: function(elements, options) {
		this.parent(elements, options);
		this.animeOut({width: [this.width, 0], left: [0, this.width]});
		this.animeIn({width: [0, this.width], left: 0});
		this.reset({display: 'block', left: 0, width: this.width});
		this.cssAfter({display: 'none', width: 0});
	}
});

Fx.Cycles.inOutLeft = new Class({

	Extends: Fx.Cycles,
	
	options: {
		overflow: 'hidden'
	},
	
	initialize: function(elements, options) {
		this.parent(elements, options);
		this.animeOut({top: this.parentHeight, left: this.parentWidth});
		this.animeIn({top:0, left: 0});
		this.cssBefore({display: 'none'});
		this.reset({top: -this.parentHeight, left: this.parentWidth, display: 'block'});
	}
});

Fx.Cycles.inOutRight = new Class({

	Extends: Fx.Cycles,
	
	options: {
		overflow: 'hidden'
	},
	
	initialize: function(elements, options) {
		this.parent(elements, options);
		this.animeOut({top: -this.parentHeight, left: -this.parentWidth});
		this.animeIn({top:0, left: 0});
		this.cssBefore({display: 'none'});
		this.reset({top: this.parentHeight, left: -this.parentWidth, display: 'block'});
	}
});

Fx.Cycles.inOutUp = new Class({

	Extends: Fx.Cycles,
	
	options: {
		overflow: 'hidden'
	},
	
	initialize: function(elements, options) {
		this.parent(elements, options);
		this.animeOut({top: -this.parentHeight});
		this.animeIn({left: 0});
		this.cssBefore({display: 'none'});
		this.reset({top: 0, left: this.parentWidth, display: 'block'});
	}
});

Fx.Cycles.inOutDown = new Class({

	Extends: Fx.Cycles,
	
	options: {
		overflow: 'hidden'
	},
	
	initialize: function(elements, options) {
		this.parent(elements, options);
		this.animeOut({top: this.parentHeight});
		this.animeIn({left: 0});
		this.cssBefore({display: 'none'});
		this.reset({top: 0, left: this.parentWidth, display: 'block'});
	}
});

Element.implement({
	
	cycles: function(type, options) {
		return new Fx.Cycles[type](this, options);
	}				  

});

var Virtual = new Class({
		
	Implements: [Overlay, Options, Events],
	
	options: {
		enable: {
			arrows: true,
			closeButton: true,
			arrowsKeyboard: true,
			closeKeyboard: true,
			caption: true
		},
		effect: 'open',
		effectOptions: {
			duration: 1000	
		},
		style: true,
		adjustStyles: true,
		zones: {
			main: '',
			wrapper: '',
			caption: '',
			captionText: '',
			captionTextTitle: '',
			captionTextContent: '',
			arrowsBox: '',
			arrowsBoxText: '',
			leftArrow: '',
			rightArrow: ''
		},
		arrowsBoxText: false,
		leftArrowText: 'prev',
		rightArrowText: 'next',
		closeButtonText: 'close',
		captionOpacity: 0.4,
		imageText: false,
		onShow: $empty,
		onClose: $empty,
		onNext: $empty,
		onPrev: $empty
	},	
	
	initialize: function(options) {
		this.setOptions(options);
		this.effects = {
			main: new Fx.Elements(null, $merge(this.options.effectOptions, {link: 'ignore'})),
			caption: new Fx.Elements(null, {duration: 1000, link: 'ignore'})	
		};
		this.fullWidth = [];
		this.fullHeight = [];
		this.captionHeight = [];
	},
	
	mechanize: function() {
		this.createOverlay('virtualBoxOverlay', 'darken');
		this.createFullPage('virtualBoxFullPage');
		
		this.main = new Element('div', {
			'id': 'virtualMain',
			'class': this.options.zones.main
		});
		
		if(this.options.style)
			this.main.setStyles({
				'background-color': '#FFFFFF',
				'padding': '8px'
			});
		
		this.wrapper = new Element('div', {
			'id': 'virtualBox',
			'class': this.options.zones.wrapper,
			'onclick': 'virtual.remove()',
			'styles': {
				'position': 'relative',
				'overflow': 'hidden',
				'cursor':'pointer'
			}
		}).inject(this.main);
		
		if(this.options.enable.caption) {
			this.caption = new Element('div', {
				'id': 'virtualCaption',	
				'class': this.options.zones.caption,
				'styles': {
					'position': 'absolute',
					'bottom': '0px',
					'opacity': this.options.captionOpacity,
					'z-index': 1,
					'overflow': 'hidden',
					'visibility': 'hidden'
				}
			}).inject(this.wrapper);
			
			if(this.options.style) this.caption.setStyles({'background-color': '#CCCCCC'});
			
			this.captionText = new Element('div', {
				'id': 'virtualCaptionText',	
				'class': this.options.zones.captionText,
				'styles': {
					'position': 'absolute',
					'bottom': '0px',
					'opacity': 1,
					'z-index': 2,
					'overflow': 'hidden',
					'visibility': 'hidden'
				}
			}).inject(this.wrapper);
			
			this.captionTextTitle = new Element('p', {
				'id': 'virtualCaptionTitle',
				'class': this.options.zones.captionTextTitle
			}).inject(this.captionText);
			
			this.captionTextContent = new Element('p', {
				'id': 'virtualCaptionContent',
				'class': this.options.zones.captionTextContent
			}).inject(this.captionText);
		}
		
		if(this.options.enable.arrows) {
			this.arrowsBox = new Element('div', {
				'id': 'virtualArrowsBox',	
				'class': this.options.zones.arrowsBox,
				 'styles': {
					 'position': 'absolute',
					 'bottom': '0px',
					 'visibility': 'hidden' 
				 }
			});
			
			this.arrowsBoxText = new Element('div', {
				'id': 'virtualArrowsBoxText', 
				'class': this.options.zones.arrowsBoxText,
				'styles': {
					'display': 'block',
					'visibility': 'hidden'
				}
			}).inject(this.arrowsBox);
			
			this.leftArrow = new Element('a', {
				'id': 'virtualLeftArrow',
				'class': this.options.zones.leftArrow,
				'href': '#'
			}).set('html', this.options.leftArrowText);
			
			this.rightArrow = new Element('a', {
				'id': 'virtualRightArrow',
				'class': this.options.zones.rightArrow,
				'href': '#'
			}).set('html', this.options.rightArrowText);
			
			this.leftArrow.addEvent('click', function(event) {
				event.preventDefault();
				this.prev();
			}.bind(this));
			
			this.rightArrow.addEvent('click', function(event) {
				event.preventDefault();
				this.next();
			}.bind(this));
			
			$$(this.leftArrow, this.rightArrow).inject(this.arrowsBox);
			
			if(this.options.enable.closeButton) {
				this.closeButton = new Element('a', {
					'id': 'virtualCloseButton',
					'class': this.options.zones.closeButton,
					'href': '#'
				}).set('html', this.options.closeButtonText).addEvent('click', function(event) {
					event.preventDefault();
					this.closeBox();
				}.bind(this));
				this.closeButton.inject(this.arrowsBox);
			}
			else {
				this.attachCloseEvent();
			}
		}
		
		if(this.options.enable.closeKeyboard) document.addEvent('keydown', this.keyboardClose.bind(this));
		if(!this.options.enable.arrows || !this.options.enable.closeButton) this.attachCloseEvent();
		if(this.options.enable.arrowsKeyboard) document.addEvent('keydown', this.keyboard.bindWithEvent(this));
		
		if(this.options.adjustStyles) {
			this.newsizes = function() {
				$$(this.main).setStyles({
					'top': window.getSize().y.toInt()/2,
					'left': window.getSize().x.toInt()/2
				});
			};
			window.addEvent('resize', this.newsizes.bind(this));
		}
	},
	
	createArrowsBox: function() {
		this.arrowsBox.inject(this.main);
		this.main.inject(this.fullpage);
		this.arrowsBoxHeight = this.arrowsBox.getSize().y + this.arrowsBoxText.getSize().y;
		this.arrowsBoxHalfHeight = this.arrowsBox.getHeight().toInt();
		this.main.setStyles({
			'position': 'absolute',
			'top': window.getSize().y.toInt()/2,
			'left': window.getSize().x.toInt()/2,
			'height': this.sizes.height+this.arrowsBoxHeight,
			'margin-top': -((this.sizes.height+this.arrowsBoxHeight)/2),
			'margin-left': -((this.sizes.width+this.arrowsBoxHeight)/2)
		});
	},
	
	setArrowsBoxText: function(text) {
		if(this.options.enable.arrows) { 
			var arrowsBoxText = this.options.arrowsBoxText || text;
			this.arrowsBoxText.set('html', arrowsBoxText).inject(this.main);
		}
	},
	
	reset: function() {
		$$(this.caption, this.captionText, this.arrowsBox, this.arrowsBoxText).setStyle('visibility', 'hidden');
		if(this.options.enable.caption) {
			this.captionText.dispose().setStyle('height', '0px');
			$$(this.captionTextTitle, this.captionTextContent).empty();
		}
	},
	
	makeCaptionEffect: function(i) {
		if(this.options.enable.caption) {
			this.captionText.inject(this.caption, 'after');
			if(!this.captionPadding) this.captionPadding = (this.captionText.getStyle('padding-top').toInt() + this.captionText.getStyle('padding-bottom').toInt());
			
			this.captionText.setStyle('height', 'auto');
			this.captionTextTitle.set('html', this.sizes.title).inject(this.captionText);
			this.captionTextContent.set('html', this.sizes.text).inject(this.captionText);
			
			if(!this.captionHeight[i]) this.captionHeight[i] = this.captionText.getSize().y - this.captionPadding;
			
			$$(this.caption, this.captionText).setStyles({'height': '0px', 'visibility': 'visible'});
			
			switch(this.options.effect) {
				case 'open':
				case 'slide:vertical':
				case 'slide:horizontal':
				case 'slide': this.captionDelay = this.effects.main.options.duration.toInt();
								break;
				case 'fix': this.captionDelay = 0;
							break;
				case 'fold': this.captionDelay = this.effects.main.options.duration.toInt()*2;
								break;
			}
			
			this.effects.caption.elements = $$(this.caption, this.captionText);
			this.effects.caption.start.delay(this.captionDelay, this.effects.caption, {
				'0': { height: [0, this.captionHeight[i]]},	
				'1': { height: [0, this.captionHeight[i]]}
			});
		}
	},
	
	next: function() {
		if(this.effects.main.timer || this.effects.caption.timer) return;
		(this.count != this.length) ? this.count++ : this.count = 0;
		this.attach(this.count);
		this.fireEvent('onNext', [this.count, this.fullLength]);
	},
	
	prev: function() {
		if(this.effects.main.timer || this.effects.caption.timer) return;
		(this.count == 0) ? this.count = this.length : this.count--;
		this.attach(this.count);
		this.fireEvent('onPrev', [this.count, this.fullLength]);
	},
	
	keyboard: function(event) {
		if(this.overlayActive) {
			if(event.key == 'right') {
				this.next();
			}
			else if(event.key == 'left') {
				this.prev();
			}
		}
	},
	
	keyboardClose: function(event) {
		if(this.overlayActive) {
			if(event.key == 'esc') this.closeBoxWithKeyboard();
		}
	},
	
	setEffect: function(mode) {
		this.options.effect = mode;
	},
	
	remove: function() {
		this.main.dispose();
		this.removeOverlay();
	},
	
	attachCloseEvent: function() {
		if(Browser.firefox) {
			this.overlay.addEvent('click', this.closeBox.bindWithEvent(this, 'overlay'));
			this.fullpage.addEvent('click', this.closeBox.bindWithEvent(this, 'fullpage'));
		}
		else {
			this.fullpage.addEvent('click', this.closeBox.bindWithEvent(this, 'fullpage'));
		}
	},
	
	closeBox: function(event, zone) {
		if(this.effects.main.timer || this.effects.caption.timer) return;
		if((!this.options.enable.arrows || !this.options.enable.closeButton) && event.target != this[zone]) return;
		this.fireEvent('onClose', [this.count, this.length]);
		this.count = 0;
		this.remove();
	},
	
	closeBoxWithKeyboard: function() {
		if(this.effects.main.timer || this.effects.caption.timer) return;
		this.fireEvent('onClose', [this.count, this.length]);
		this.count = 0;
		this.remove();
	},
	
	makeEffect: function(i) {
		if(this.options.effect == 'open') {
			if(Browser.firefox) this.fullpage.setStyle('height', 'auto');
			if(this.options.enable.arrows) this.createArrowsBox();
			else this.main.inject(this.fullpage);
			
			if(!this.fullWidth[i]) this.fullWidth[i] = this.main.getStyle('width').toInt();
			if(!this.fullHeight[i]) this.fullHeight[i] = (!this.arrowsBoxHeight) ? this.sizes.height : this.sizes.height+this.arrowsBoxHeight;
			
			$$(this.main, this.wrapper).setStyles({'visibility': 'visible', 'height': '0px', 'width': '0px'});
			$$(this.arrowsBox).setStyle('width', this.fullWidth[i]);
			
			this.effects.main.elements = $$(this.main, this.wrapper);
			this.effects.main.start({
				'0': {
					'width': this.fullWidth[i],	
					'height': this.fullHeight[i]
				},
				'1': {
					'width': this.fullWidth[i],	
					'height': this.sizes.height
				}
			}).chain(function() {
				if(this.options.enable.arrows) $$(this.arrowsBox, this.arrowsBoxText).setStyle('visibility', 'visible');	
			}.bind(this));
		}
		else if(this.options.effect == 'fix') {
			if(Browser.firefox) this.fullpage.setStyle('height', 'auto');
			if(this.options.enable.arrows) { 
				this.createArrowsBox();
				if(!this.fullWidth[i]) this.fullWidth[i] = this.main.getStyle('width').toInt();
				if(!this.fullHeight[i]) this.fullHeight[i] = (!this.arrowsBoxHeight) ? this.sizes.height : this.sizes.height+this.arrowsBoxHeight;
				$$(this.arrowsBox, this.arrowsBoxText).setStyle('visibility', 'visible');
				$$(this.arrowsBox).setStyle('width', this.fullWidth[i]);
			}
			else this.main.inject(this.fullpage);
		}
		else if(this.options.effect == 'fold') {
			if(Browser.firefox) this.fullpage.setStyle('height', 'auto');
			if(this.options.enable.arrows) this.createArrowsBox();
			else this.main.inject(this.fullpage);
			
			$$(this.main).setStyle('overflow', 'hidden');
			
			if(!this.fullWidth[i]) this.fullWidth[i] = this.main.getStyle('width').toInt();
			if(!this.fullHeight[i]) this.fullHeight[i] = (!this.arrowsBoxHeight) ? this.sizes.height : this.sizes.height+this.arrowsBoxHeight;
			
			$$(this.main, this.wrapper).setStyles({'visibility': 'visible', 'height': '0px', 'width': '0px'});
			$$(this.arrowsBox).setStyles({'height': '0px', 'width': '0px'});
			//$$(this.arrowsBox).setStyle('width', this.fullWidth[i]);
			
			this.effects.main.elements = (this.options.enable.arrows) ? $$(this.main, this.wrapper, this.arrowsBox) : $$(this.main, this.wrapper);
			
			var width = {
				'0': { 'width': [this.main.getStyle('width').toInt(), this.fullWidth[i]] },
				'1': { 'width': [this.main.getStyle('width').toInt(), this.fullWidth[i]] }
			};
			
			var height = {
				'0': { 'height': [this.main.getStyle('height').toInt(), this.fullHeight[i]] },
				'1': { 'height': [this.main.getStyle('height').toInt(), this.sizes.height] }
			};
			
			if(this.options.enable.arrows) {
				var arrwidth = { '2': { 'width': this.fullWidth[i] } };
				var arrheight = { '2': { 'height': [0, this.arrowsBoxHalfHeight] } };
			}
			
			this.effects.main.start((arrwidth) ? $merge(width, arrwidth) : width).chain(function() {
				this.effects.main.start((arrheight) ? $merge(height, arrheight) : height);
			}.bind(this)).chain(function() {
				if(this.options.enable.arrows) $$(this.arrowsBox, this.arrowsBoxText).setStyle('visibility', 'visible');	
			}.bind(this));
		}
		else if(this.options.effect == 'slide:vertical' || this.options.effect == 'slide:horizontal' || this.options.effect == 'slide') {
			if(Browser.firefox) this.fullpage.setStyle('height', 'auto');
			if(this.options.enable.arrows) this.createArrowsBox();
			else this.main.inject(this.fullpage);
			
			if(!this.fullWidth[i]) this.fullWidth[i] = this.main.getStyle('width').toInt();
			if(!this.fullHeight[i]) this.fullHeight[i] = (!this.arrowsBoxHeight) ? this.sizes.height : this.sizes.height+this.arrowsBoxHeight;
			
			var direction = this.options.effect.split(':')[1] || 'vertical';
			
			if(direction == 'vertical')
				$$(this.main).setStyles({'visibility': 'visible', 'height': this.fullHeight[i], 'width': this.fullWidth[i], 'top': -1000});
			else if(direction == 'horizontal')
				$$(this.main).setStyles({'visibility': 'visible', 'height': this.fullHeight[i], 'width': this.fullWidth[i], 'left': -1000});
			
			$$(this.arrowsBox).setStyle('width', this.fullWidth[i]);
			
			switch(direction) {
				case 'vertical': var styles = {'top': window.getSize().y.toInt()/2 };
								break;
				case 'horizontal': var styles = {'left': window.getSize().x.toInt()/2 };
								break;
			}
	
			this.effects.main.elements = $$(this.main);
			this.effects.main.start({
				'0': styles
			}).chain(function() {
				if(this.options.enable.arrows) $$(this.arrowsBox, this.arrowsBoxText).setStyle('visibility', 'visible');	
			}.bind(this));
			
		}
	},
	
	virtualStyle: function(path) {
		new Asset.css(path, {id: 'virtualStyle'});
		return this;
	},
	
	setIDs: function(names) {
		if($object(names)) {
			for(var name in names) {
				if(this[name]) this[name].set('id', names[name]);
			}	
		}
		return this;
	}
});

Virtual.single = new Class({
						   
	attachElement: function() {
		this.element.addEvent('click', function(event) {
			event.preventDefault();
			this.attach(0);	
		}.bind(this));
	},
	
	create: function() {
		this.attach(0);	
	}
});

Virtual.Box = new Class({
						
	Extends: Virtual,
	
	initialize: function(options, single) {
		this.links = $$('a[class=virtualbox]');
		this.preload = [];
		this.parent(options);
		
		this.mechanize();
		
		if(!single) {
			this.links.each(function(el, i) {
									 
				this.preload[i] = new Element('img');
				this.preload[i].src = el.getProperty('href');
		
				var fullText = el.getProperty('title').split(' :: ');
				
				this.preload[i].store('title', fullText[0]);
				this.preload[i].store('text', fullText[1]);
				
				el.addEvent('click', function(event) {
					event.preventDefault();
					this.attach(i);	
				}.bind(this));
				
			}, this);
		}
		
		this.count = 0;
		this.length = this.preload.length-1;
		this.fullLength = this.preload.length;
	},
	
	attach: function(i) {
		this.img = this.preload[i];
		this.count = i;
		
		if(!this.overlayActive) { 
			this.injectOverlay(true);
		}
		
		this.reset();
		
		this.prepareImage(i);
		this.makeCaptionEffect(i);
	},
	
	prepareImage: function(i) {
		this.sizes = {
			width: this.preload[i].width,
			height: this.preload[i].height,
			title: this.preload[i].retrieve('title'),
			text: this.preload[i].retrieve('text')
		};
		
		this.main.setStyles({
			'position': 'absolute',
			'width': this.sizes.width,
			'height': this.sizes.height,
			'top': window.getSize().y.toInt()/2,
			'left': window.getSize().x.toInt()/2,
			'margin-top': -(this.sizes.height/2),
			'margin-left': -(this.sizes.width/2)
		});
		
		this.wrapper.setStyles({
			'background-color': '#FFFFFF',
			'background-repeat': 'no-repeat',
			'background-image': 'url(' + this.preload[i].src + ')',
			'overflow': 'hidden',
			'width': this.sizes.width,
			'height': this.sizes.height			   
		});
		
		$$(this.caption, this.captionText).setStyles({'width': this.sizes.width});
		
		this.setArrowsBoxText('image ' + (i+1) + '/' + this.preload.length);
		this.fireEvent('onShow');
		this.makeEffect(i);
	}
});

Virtual.Box.single = new Class({
								
	Extends: Virtual.Box,
	
	Implements: Virtual.single,
	
	initialize: function(element, options) {
		this.element = $(element);
		this.parent($merge(options, {enable: {arrows: false, arrowsKeyboard: false}}), true);
		this.preload[0] = new Element('img');
		var fullText = this.element.getProperty('title').split(' :: ');
	
		this.preload[0].src = this.element.getProperty('href');
		this.preload[0].store('title', fullText[0]);
		this.preload[0].store('text', fullText[1]);
			
		this.attachElement();
	}
});

Virtual.Ajax = new Class({
						
	Extends: Virtual,
	
	options: {
		width: 400,
		height: 300,
		requestOptions: {}
	},
	
	initialize: function(options, single) {
		this.links = $$('a[class=virtualajax]');
		this.preload = [];
		this.parent(options);
		this.request = new Request.HTML($merge(this.options.requestOptions, {update: this.wrapper}));
		
		this.mechanize();
		this.wrapreq = new Element('div').inject(this.wrapper, 'top');
		
		if(!single) {
			this.links.each(function(el, i) {				 
				this.preload[i] = new Hash();
				var fullText = el.getProperty('title').split(' :: ');
				
				this.preload[i].set('src',  el.get('href'));
				this.preload[i].set('width',  fullText[0].toInt() || this.options.width);
				this.preload[i].set('height',  fullText[1].toInt() || this.options.height);
				this.preload[i].set('title',  fullText[2]);
				this.preload[i].set('text', fullText[3]);
				
				el.addEvent('click', function(event) {
					event.preventDefault();
					this.attach(i);	
				}.bind(this));
			}, this);
		}
		
		this.count = 0;
		this.length = this.preload.length-1;
		this.fullLength = this.preload.length;
	},
	
	attach: function(i) {
		this.img = this.preload[i];
		this.count = i;
		
		if(!this.overlayActive) { 
			this.injectOverlay(true);
		}
		
		if(Browser.opera) this.main.dispose();
		this.reset();
		this.prepareRequest(i);
		this.makeCaptionEffect(i);
	},
	
	prepareRequest: function(i) {
		this.sizes = {
			width: this.preload[i].get('width'),
			height: this.preload[i].get('height'),
			title: this.preload[i].get('title'),
			text: this.preload[i].get('text')
		};
		
		this.main.setStyles({
			'position': 'absolute',
			'width': this.sizes.width,
			'height': this.sizes.height,
			'top': window.getSize().y.toInt()/2,
			'left': window.getSize().x.toInt()/2,
			'margin-top': -(this.sizes.height/2),
			'margin-left': -(this.sizes.width/2)
		});
		
		this.wrapper.setStyles({
			'width': this.sizes.width,
			'height': this.sizes.height
		});
		
		$$(this.caption, this.captionText).setStyles({'width': this.sizes.width});
		
		this.request.setOptions({url: this.preload[i].src, update: this.wrapreq,
			onSuccess: function() {
				if(this.options.enable.caption) {
					$$(this.caption, this.captionText).setStyles({
						'width': this.sizes.width				   
					}).inject(this.wrapper);
					this.captionTextTitle.set('html', this.sizes.title).inject(this.captionText);
					this.captionTextContent.set('html', this.sizes.text).inject(this.captionText);
				}		
			}.bind(this, i)
		}).post();
		
		this.setArrowsBoxText('Virtual Ajax ' + (i+1) + '/' + this.preload.length);
		this.fireEvent('onShow');
		this.makeEffect(i);
	}
});

Virtual.Ajax.single = new Class({
								
	Extends: Virtual.Ajax,
	
	Implements: Virtual.single,
	
	initialize: function(element, options) {
		this.element = $(element);
		this.parent($merge(options, {enable: {arrows: false, arrowsKeyboard: false}}), true);
		this.preload[0] = new Hash();
		var fullText = this.element.getProperty('title').split(' :: ');
		this.preload[0].set('src',  this.element.get('href'));
		this.preload[0].set('width',  fullText[0].toInt() || this.options.width);
		this.preload[0].set('height',  fullText[1].toInt() || this.options.height);
		this.preload[0].set('title',  fullText[2]);
		this.preload[0].set('text', fullText[3]);
			
		this.attachElement();
	}
});

Virtual.HTML = new Class({
						
	Extends: Virtual,
	
	options: {
		width: 400,
		height: 300,
		contents: []
	},
	
	initialize: function(options, single) {
		this.links = $$('a[class=virtualhtml]');
		this.preload = [];
		this.parent(options);
		
		this.mechanize();
		this.content = new Element('div', {'id': 'virtualHTMLContent'});
		
		if(!single) {
			this.links.each(function(el, i) {
									 
				this.preload[i] = new Hash();
				var fullText = el.getProperty('title').split(' :: ');
				
				this.preload[i].set('width',  fullText[0].toInt() || this.options.width);
				this.preload[i].set('height',  fullText[1].toInt() || this.options.height);
				this.preload[i].set('title',  fullText[2]);
				this.preload[i].set('text', fullText[3]);
				
				el.addEvent('click', function(event) {
					event.preventDefault();
					this.attach(i);	
				}.bind(this));
				
			}, this);
		}
		
		this.count = 0;
		this.length = this.preload.length-1;
		this.fullLength = this.preload.length;
	},
	
	attach: function(i) {
		this.img = this.preload[i];
		this.count = i;
		
		if(!this.overlayActive) { 
			this.injectOverlay(true);
		}
		
		if(Browser.opera) this.main.dispose();
		this.reset();
		this.prepareContent(i);
		this.makeCaptionEffect(i);
	},
	
	prepareContent: function(i) {
		this.sizes = {
			width: this.preload[i].get('width'),
			height: this.preload[i].get('height'),
			title: this.preload[i].get('title'),
			text: this.preload[i].get('text')
		};
		
		this.main.setStyles({
			'position': 'absolute',
			'width': this.sizes.width,
			'height': this.sizes.height,
			'top': window.getSize().y.toInt()/2,
			'left': window.getSize().x.toInt()/2,
			'margin-top': -(this.sizes.height/2),
			'margin-left': -(this.sizes.width/2)
		});
		
		this.wrapper.setStyles({
			'width': this.sizes.width,
			'height': this.sizes.height
		});
		
		$$(this.caption, this.captionText).setStyles({'width': this.sizes.width});
		
		this.content.set('html', this.options.contents[i]).inject(this.wrapper, 'top');
		this.setArrowsBoxText('Virtual HTML ' + (i+1) + '/' + this.preload.length);
		this.fireEvent('onShow');
		this.makeEffect(i);
	}
});

Virtual.HTML.single = new Class({
								
	Extends: Virtual.HTML,
	
	Implements: Virtual.single,
	
	options: {
		content: ''
	},
	
	initialize: function(element, options) {
		this.element = $(element);
		this.parent($merge(options, {enable: {arrows: false, arrowsKeyboard: false}}), true);
		this.preload[0] = new Hash();
		var fullText = this.element.getProperty('title').split(' :: ');
		this.preload[0].set('width',  fullText[0].toInt() || this.options.width);
		this.preload[0].set('height',  fullText[1].toInt() || this.options.height);
		this.preload[0].set('title',  fullText[2]);
		this.preload[0].set('text', fullText[3]);
		
		this.options.contents[0] = this.options.content;
		this.attachElement();
	}
});

var Kwick = {};

Kwick.Base = new Class({
					   
	Extends: Fx.Elements,
	
	options: {
		large: 200,
		normal: 100,
		small: 50,
		link: 'cancel',
		duration:300,
		transition: 'back:out'
	},	
	
	initialize: function(elements, options) {
		this.parent(elements, options);
	},
	
	enter: function(prop, el, i) {
		var o = {};
		o[i] = {};
		o[i][prop] = [el.getStyle(prop), this.options.large];
		this.elements.each(function(other, j) {
			if(i != j) {
				var p = other.getStyle(prop);
				if(p != this.options.small) { 
					o[j] = {};
					o[j][prop] = [p, this.options.small];
				}
			}
		}, this);
		this.start(o);
	},
	
	out: function(prop) {
		var o = {};
		this.elements.each(function(el, i) {
			o[i] = {};
			o[i][prop] = [el.getStyle(prop), this.options.normal];
		}, this);
		this.start(o);
	},
	
	build: function(prop, el, i) {
		el.addEvent("mouseenter", this.enter.bind(this, [prop, el, i]));
	}
});

Kwick.Menu = new Class({
					   
	Extends: Kwick.Base,
	
	options: {
		mode: 'horizontal'
	},
	
	initialize: function(elements, options) {
		this.parent(elements, options);
		this.ul = this.elements.getParent();
		switch(this.options.mode) {
			case 'vertical': this.elements.each(function(el, i) { this.build('height', el, i); }, this);
					  this.elements.each(function(el) { el.addEvent('mouseleave', this.out.bind(this, 'height')); }, this);
					  break;
					  
			case 'horizontal': this.elements.each(function(el, i) { this.build('width', el, i); }, this);
					  this.elements.each(function(el) { el.addEvent('mouseleave', this.out.bind(this, 'width')); }, this);
					  break;
		}; 
	}
});

Kwick.All = new Class({
					   
	Extends: Kwick.Base,
	
	initialize: function(elements, property, options) {
		this.parent(elements, options);
		this.property = property;
		this.elements.each(function(el, i) { this.build(this.property, el, i); }, this);
		this.elements.each(function(el) { el.addEvent('mouseleave', this.out.bind(this, this.property)); }, this);
	}
});

var Glider = new Class({
					   
	Implements: [Overlay, Options, Events],
	
	options: {
		enable: {
			resizeHeight: true,
			resizeWidth: false,
			preloader: true,
			captions: true,
			thumbnails: false,
			arrows: false,
			arrowsLimits: false,
			arrowsKeyboard: false,
			autostart: false,
			fullscreen: false,
			toNormalButton: true,
			toFullScreenButton: false
		},
		steps: 3000,
		mode: 'scroll',
		captions: [],
		captionWrapper: 'captionWrapper',
		captionFadeEffect: true,
		captionHeightEffect: true,
		scrollOptions: {},
		morphOptions: {},
		thumbnailWrapper: 'thumbsWrapper',
		thumbTexts: [],
		toNormalButtonClass: '',
		toNormalButtonText: 'normal mode',
		toNormalButtonType: 'a',
		toFullScreenButtonClass: '',
		toFullScreenButtonText: 'full screen',
		toFullScreenButtonType: 'a',
		onFullScreen: $empty,
		onNormalScreen: $empty,
		onNext: $empty,
		onPrev: $empty,
		onGoTo: $empty,
		onFirst: $empty,
		onLast: $empty
	},

	initialize: function(element, options) {
		this.element = $(element);
		this.setOptions(options);
		this.fx = new Fx.Scroll(this.element, $merge(this.options.scrollOptions, {link:'chain', wheelStops:false}));
		this.count = 0;
		this.matter = 0;
		this.length = this.element.getChildren().length.toInt()-1;
		this.fullLength = this.element.getChildren().length.toInt();
		this.wrapper = this.element.getParent();
		this.main = this.wrapper.getParent();
		this.main.setStyle('position', 'relative');
		this.caption = new Element('div', { 'id': this.options.captionWrapper}).inject(this.element.getParent(), 'after').setStyle('display', (this.options.enable.captions) ? 'block' : 'none');
		if(this.options.enable.captions && this.options.captions[0]) this.caption.set('html', this.options.captions[0]);
		this.fxcapt = new Fx.Morph(this.caption, this.options.morphOptions);
		this.activizeFullscreen = false;
		
		this.checkResize();
		
		if(this.options.enable.preloader) {
			this.images = [];
			this.element.getChildren().each(function(li, i) {
				this.images[i] = li.getFirst().getProperty('src');
			}, this);
			new Asset.images(this.images);
		}
		
		if(this.options.enable.arrows) {
			this.leftArrow = new Element('li', {'id': 'leftArrow'}).addEvent('click', this.prev.bind(this));
			this.rightArrow = new Element('li', {'id': 'rightArrow'}).addEvent('click', this.next.bind(this));
			
			if(this.options.enable.arrowsLimits) {
				this.leftArrowLimit = new Element('li', {'id': 'leftArrowLimit'}).addEvent('click', this.toFirst.bind(this));
				this.rightArrowLimit = new Element('li', {'id': 'rightArrowLimit'}).addEvent('click', this.toLast.bind(this));
			}
			
			if(!this.options.enable.thumbnails) {
				this.thumbsWrapper = new Element('div', {'id': this.options.thumbnailWrapper}).inject(this.caption, 'after');
				this.thumbs = new Element('ul').injectInside(this.thumbsWrapper);
				this.leftArrow.inject(this.thumbs, 'top');
				this.rightArrow.inject(this.thumbs);
				
				if(this.options.enable.arrowsLimits) {
					this.leftArrowLimit.inject(this.thumbs, 'top');
					this.rightArrowLimit.inject(this.thumbs);
				}
			}
		}
		
		if(this.options.enable.arrowsKeyboard) {
			this.boundKeyboard = this.keyboard.bindWithEvent(this);
			document.addEvent('keydown', this.boundKeyboard);
		}
		
		if(this.options.enable.thumbnails) {
			this.thumbsWrapper = new Element('div', {'id': this.options.thumbnailWrapper}).inject(this.caption, 'after');
			this.thumbs = new Element('ul').injectInside(this.thumbsWrapper);
			this.items = [];
			this.element.getChildren().each(function(li, i) {
				(this.options.thumbTexts[i]) ? this.text = this.options.thumbTexts[i] : this.text = 'item ' + i;
				this.items[i] = new Element('li').set('html', this.text).addEvent('click', function(event) {
					event.stop();
					this.items.each(function(item) { item.removeClass('activeThumb')});
					this.items[i].addClass('activeThumb');
					this.goTo(i);
				}.bind(this)).injectInside(this.thumbs);
			}, this);
			this.activize(0);
			if(this.options.enable.arrows) {
				this.leftArrow.inject(this.thumbs, 'top');
				this.rightArrow.inject(this.thumbs);
			}
			if(this.options.enable.arrowsLimits) {
				this.leftArrowLimit.inject(this.thumbs, 'top');
				this.rightArrowLimit.inject(this.thumbs);
			}
		}
		
		this.createFullScreenButton();
		
		if(this.options.enable.autostart) { 
			if(this.options.enable.thumbnails) this.activize(0);
			this.start();
		}
		
		if(this.options.enable.fullscreen) {
			this.wrapperStyles = this.wrapper.getStyles();
			if(this.main.getParent()) this.mainParent = this.main.getParent();
			this.boundFullScreen = this.fullscreen.bindWithEvent(this);
			document.addEvent('keydown', this.boundFullScreen);
		}
	},
	
	next: function() {
		(this.count != this.length) ? this.count++ : this.count = 0;
		this.checkResize();
		this.setFullScreenSizes();
		this.makeScroll(this.count, false, 'next');
		this.addCaption(this.options.captionFadeEffect, this.options.captionHeightEffect);
		this.fireEvent('onNext', [this.count, this.fullLength]);
		if(this.options.enable.thumbnails) this.activize(this.count);
	},
	
	prev: function() {
		(this.count == 0) ? this.count = this.length : this.count--;
		this.checkResize();
		this.setFullScreenSizes();
		this.makeScroll(this.count, false, 'prev');
		this.addCaption(this.options.captionFadeEffect, this.options.captionHeightEffect);
		this.fireEvent('onPrev', [this.count, this.fullLength]);
		if(this.options.enable.thumbnails) this.activize(this.count);
	},
	
	goTo: function(where, fix, from) {
		var where = where;
		this.count = where;
		this.checkResize();
		this.setFullScreenSizes();
		if(this.autostart) {
			this.steps = $clear(this.steps);
			this.steps = this.next.periodical(this.options.steps, this);
		}
		this.makeScroll(this.count, fix || false, from);
		this.addCaption(this.options.captionFadeEffect, this.options.captionHeightEffect);
		this.fireEvent('onGoTo', [this.count, this.fullLength]);
		if(this.options.enable.thumbnails) this.activize(this.count);
	},
	
	start: function() {
		this.steps = this.next.periodical(this.options.steps, this);
		this.autostart = true;
	},
	
	stop: function() {
		this.steps = $clear(this.steps);	
		this.autostart = false;
	},
	
	toFirst: function() {
		this.goTo(0, false, 'first');
		this.fireEvent('onFirst', [this.count, this.fullLength]);
	},
	
	toLast: function() {
		this.goTo(this.length, false, 'last');
		this.fireEvent('onLast', [this.count, this.fullLength]);
	},
	
	makeScroll: function(where, fix, from) {
		if(fix)
			this.element.scrollTop = this.element.getChildren()[where].getPosition(this.element).y.toInt();
		else {
			switch(this.options.mode) {
				case 'scroll':
					this.fx.start(0, this.element.getChildren()[this.count].getPosition(this.element).y.toInt());
					break;
				
				case 'fix':
					this.element.scrollTop = this.element.getChildren()[where].getPosition(this.element).y.toInt();
					break;
			}
		}
	},
	
	setMode: function(mode) {
		if(mode == 'fix' || mode == 'scroll') this.options.mode = mode;
	},
	
	checkResize: function() {
		if(this.options.enable.resizeHeight) {
			this.style = this.element.getChildren()[this.count].getFirst().getStyle('height').toInt();
			$$(this.wrapper, this.element, this.element.getChildren()[this.count]).setStyle('height', this.style);
		}
		if(this.options.enable.resizeWidth) {
			this.width = this.element.getChildren()[this.count].getFirst().getStyle('width').toInt();
			$$(this.wrapper, this.element, this.element.getChildren()[this.count], this.caption).setStyle('width', this.width);
			if(this.thumbsWrapper) this.thumbsWrapper.setStyle('width', this.width);
		}
	},
	
	addCaption: function(fade, height) {
		if(this.options.enable.captions && this.options.captions.length !=0) {
			if(this.options.captions[this.count]) this.caption.set('html', this.options.captions[this.count]);
			this.fxcaption = {};
			if(fade) 
				this.fxcaption['opacity'] = [0, 1];
			if(height)
				this.fxcaption['height'] = (this.options.captionHeightEffect) ? [0, this.caption.getStyle('height')] : [this.caption.getStyle('height')];			
			this.fxcapt.start(this.fxcaption);
		}
	},
	
	keyboard: function(event) {
		if(event.key == 'right') this.next();
		else if(event.key == 'left') this.prev();	
	},
	
	fullscreen: function(event) {
		if(event.shift && event.key == 'f') this.toFullScreenMode();			
	},
	
	setFullScreenSizes: function() {
		if(this.activizeFullscreen) {
			this.sizes = { 
				width: this.wrapper.getStyle('width').toInt() + this.caption.getStyle('width').toInt() + this.thumbsWrapper.getStyle('width').toInt(),
				height: this.wrapper.getStyle('height').toInt() + this.caption.getStyle('height').toInt() + this.thumbsWrapper.getStyle('height').toInt(),
				top: this.wrapper.getSize().y/2 + this.caption.getSize().y/2 + this.thumbsWrapper.getSize().y/2,
				left: this.wrapper.getSize().x/2
			};
			
			this.full.setStyles({
				'width': this.sizes.width,
				'height': this.sizes.height,
				'top': '50%', 
				'left': '50%', 
				'position': (!Browser.ie6) ? 'fixed' : 'absolute', 
				'margin-top': -this.sizes.top, 
				'margin-left': -this.sizes.left
			});
		}
	},
	
	toFullScreenMode: function(event) {
		if(this.activizeFullscreen) return;
			this.full = new Element('div').wraps(this.wrapper).wraps(this.caption);
			this.activizeFullscreen = true;
			
			if(this.thumbsWrapper) { 
				this.createNormalButton();
				this.full.wraps(this.thumbsWrapper);
			}
			this.createOverlay('gliderOverlay', 'darken');
			this.createFullPage('gliderFullPage');
			this.overlay.inject(document.body);
			
			this.fixOverlay();
			
			(this.options.enable.toNormalButton) ? this.toNormal.addEvent('click', this.toNormalMode.bindWithEvent(this)) : this.fullpage.addEvent('click', this.toNormalMode.bindWithEvent(this));
			this.fullpage.inject(document.body);
			
			this.setFullScreenSizes();
			this.full.inject(this.fullpage);
			
			this.goTo(this.count, true);
			this.fireEvent('onFullScreen', [this.count, this.fullLength]);
	},
	
	toNormalMode: function(event) {
		event.preventDefault();
		if(!this.options.enable.toNormalButton && event.target != this.fullpage) return;
		
		this.activizeFullscreen = false;
		if(this.mainParent) {
			if(this.options.enable.toNormalButton) this.toNormal.dispose();
			if(this.options.enable.toFullScreenButton) this.createFullScreenButton();
			this.wrapper.inject(this.main);
			this.caption.inject(this.wrapper, 'after');
			if(this.thumbsWrapper) this.thumbsWrapper.inject(this.caption, 'after');
			this.goTo(this.count, true);
			this.fireEvent('onNormalScreen', [this.count, this.fullLength]);
		}
		
		this.removeOverlay();
		this.fullpage.dispose();
	},
	
	createNormalButton: function() {
		if(this.options.enable.toNormalButton) {
			if(this.options.toNormalButtonType == 'a') {
				this.toNormal = new Element('a', {
				'class': this.options.toNormalButtonClass, 'href': '#'});
				this.toNormal.set('html', this.options.toNormalButtonText).inject(this.thumbsWrapper);
				if(this.toFull) this.toFull.dispose();
			}
			else if(this.options.toNormalButtonType == 'li') {
				this.toNormal = new Element('li', {
				'class': this.options.toNormalButtonClass});
				this.toNormal.set('html', this.options.toNormalButtonText).inject(this.thumbs);
				if(this.toFull) this.toFull.dispose();
			}
		}
	},
	
	createFullScreenButton: function() {
		if(this.options.enable.toFullScreenButton && (this.options.enable.arrows || this.options.enable.thumbnails)) {
			if(this.options.toFullScreenButtonType == 'a') {
				this.toFull = new Element('a', {
				'class': this.options.toFullScreenButtonClass, 'href': '#'});
				this.toFull.set('html', this.options.toFullScreenButtonText).inject(this.thumbsWrapper);
			}
			else if(this.options.toFullScreenButtonType == 'li') {
				this.toFull = new Element('li', {
				'class': this.options.toFullScreenButtonClass});
				this.toFull.set('html', this.options.toFullScreenButtonText).inject(this.thumbs);
			}
			this.toFull.addEvent('click', this.toFullScreenMode.bindWithEvent(this))
		}
	},
	
	setIDs: function(names) {
		if(!names) return;
		if(names.captionWrapper) this.caption.set('id', names.captionWrapper);
		if(names.thumbnailWrapper) this.thumbsWrapper.set('id', names.thumbnailWrapper);
		if(names.leftArrow) this.leftArrow.set('id', names.leftArrow);
		if(names.rightArrow) this.rightArrow.set('id', names.rightArrow);
		if(names.leftArrowLimit) this.leftArrowLimit.set('id', names.leftArrowLimit);
		if(names.rightArrowLimit) this.rightArrowLimit.set('id', names.rightArrowLimit);
		if(names.toFullScreenButton) this.toFull.set('id', names.toFullScreenButton);
		if(names.toNormalButton) this.toNormal.set('id', names.toNormalButton);
	},
	
	activize: function(i) {
		if(this.options.enable.thumbnails) {
			this.items.each(function(item) { item.removeClass('activeThumb')});
			this.items[i].addClass('activeThumb');
		}
	}
					   
});

var Tutorial = new Class({
						 
	Extends: Fx.Elements,
						 
	options: {
		arrowsKeyboard: true,
		names: {
			step: 'step',
			next: 'next',
			prev: 'prev'
		},
		cycle: false,
		autostart: false,
		steps: 4000
	},
	
	initialize: function(element, options) {
		this.element = $(element);
		this.parent(null, $merge(options, {link:''}));
		this.steps = this.element.getElements('div.' + this.options.names.step);
		this.length = this.steps.length-1;
		this.padding = this.element.getStyle('padding-top').toInt() + this.element.getStyle('padding-bottom').toInt();
		this.element.setStyle('height', this.steps[0].getHeight().toInt()+this.padding);
		this.count = 0;
		
		this.steps.each(function(step, i) {
			if(step.getElement('a.' + this.options.names.next)) { 
				step.store('next', step.getElement('a.' + this.options.names.next));
				step.retrieve('next').addEvent('click', function(event) {
					event.stop();
					this.next();
				}.bind(this));
			}
			
			if(step.getElement('a.' + this.options.names.prev)) {
				step.store('prev', step.getElement('a.' + this.options.names.prev));
				step.retrieve('prev').addEvent('click', function(event) {
					event.stop();
					this.prev();
				}.bind(this));
			}
	
			step.store('height', step.getHeight().toInt()+this.padding).store('position', i);
			
			if(i!=0) step.setStyle('height', 0);
			
		}, this);	
		
		if(this.options.arrowsKeyboard) document.addEvent('keydown', this.arrows.bindWithEvent(this));
		if(this.options.autostart) this.autostart();
	},
	
	next: function() {
		var obj = {};
		
		if(this._autostart && this.count == this.length) $clear(this._autostart);
		
		if(!this.timer) {
			if(this.options.cycle || this.count < this.length) this.setNext(obj);
		}
	},
	
	setNext: function(obj) {
		this.first = this.steps[this.count];
		(this.count != this.length) ? this.count++ : this.count = 0;
		this.second = this.steps[this.count];
			
		this.main(obj);
	},

	prev: function() {
		var obj = {};
		
		if(!this.timer) {
			if(this.options.cycle || this.count > 0) this.setPrev(obj);
		}
	},
	
	setPrev: function(obj) {
		this.first = this.steps[this.count];
		(this.count == 0) ? this.count = this.length : this.count--;
		this.second = this.steps[this.count];
		
		this.main(obj);
	},
	
	main: function(obj) {
		this.elements = $$(this.first, this.second, this.element);
		
		obj['0'] = {'height': 0};
		obj['1'] = {'height': this.second.retrieve('height')};
		obj['2'] = {'height': this.second.retrieve('height')};
		
		this.start(obj);
	},
	
	autostart: function() {
		this._autostart = this.next.periodical(this.options.steps || 4000, this);
	},
	
	stop: function() {
		$clear(this._autostart);
	},
	
	arrows: function(event) {
		if(event.key == 'left') this.prev();	
		if(event.key == 'right') this.next();
	}
});

var Tabs = new Class({
	
	Implements: [Events, Options],
	
	options: {
		effect: 'scroll',
		autoresize: true,
		names: {
			wrapper: 'tabs',
			sections: 'sections',
			tab: 'tab'
		},
		scrollOptions: {},
		onChange: $empty,
		onOpen: $empty,
		opening: 0,
		openingEffect: 'fix'
	},
	
	initialize: function(element, options) {
		this.main = $(element);
		this.setOptions(options);
		this.wrapper = this.main.getElement('.' + this.options.names.wrapper);
		this.sections = this.main.getElement('ul.' + this.options.names.sections).getElements('li');
		this.tabs = this.wrapper.getElements('.' + this.options.names.tab);
		
		this.wrapper.setStyles({'overflow': 'hidden'});
		
		this.tabs.each(function(tab, i) {
			tab.store('height', tab.getHeight());
		}, this);
		
		this.fx = new Fx.Scroll(this.wrapper, this.options.scrollOptions);
		
		if($int(this.options.opening) && this.sections[this.options.opening]) { 
			this.goTo(this.sections[this.options.opening], this.options.opening, this.options.openingEffect);
			this.fireEvent('onOpen', [this.sections[this.options.opening], this.options.opening]);	
		}
		
		this.sections.each(function(section, i) {
			section.addEvent('click', this.goTo.bind(this, [section, i]));
		}, this);
	},
	
	goTo: function(section, i, effect) {
		var tab = this.tabs[i], height = tab.retrieve('height'), count = i, method = false, eff = this.options.effect;
		
		if(effect) this.options.effect = effect;
		
		if(eff == 'scroll' && !this.fx.timer)
			method = 'start';
		else if(eff == 'fix')
			method = 'set';
		
		if(method) {
			this.fireEvent('onChange', [tab, section, count]);
			if(this.options.autoresize) $$(this.wrapper, tab).setStyle('height', height);
			this.fx[method](0, tab.getPosition(this.wrapper).y.toInt());
		}
		
		if(effect)	this.options.effect = eff;
	}

});