/* 
Filename: moo.rd - A lightweight Mootools extension 

Author: Riccardo Degni, <http://www.riccardodegni.it/> 

License: GNU GPL License 

Copyright: copyright 2007 Riccardo Degni 
*/ 

var Moo = {};

Moo.Rd = {
	version: '1.2',
	author: 'Riccardo Degni'
};



var Custom = {};

var Table = new Class({	
	initialize: function(element) {
		this.element = $(element);
	}
});

var Make = {};


Fx.Base.implement({
	initStyles: function() {
		this.init = {};
		$A(arguments).each(function(a) {
			(this.element.getStyle(a).test('px')) ? this.init[a] = this.element.getStyle(a).toInt() : this.init[a] = this.element.getStyle(a);
		}, this);	
	},
	
	removeAuto: function() {
		if(!this.init) this.init = {};
		$A(arguments).each(function(a) {
			(this.element.getStyle(a).test('auto')) ? this.element.setStyle(a, '0px') : this.element.getStyle(a);
			(this.init[a] != 'auto') ? this.init[a] : this.init[a] = 0;
		}, this);
	}
});




String.extend({
	
	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 />');
	},
	
	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;');
	},
	
	trim: function() {
		return this.replace(/^\s+|\s+$/g,'');
	},
	
	ltrim: function() {
		return this.replace(/^\s+/g,'');
	},
	
	rtrim: function() {
		return this.replace(/\s+$/g,'');
	}		
});




String.extend({
	
	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, '');
	},
	
	stripScripts: 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());	
	}
			  
});




Array.extend({
	
	print_r: function(results) {
		var r = 'Array ( ' + '<br />';
		this.each(function(el, index) {
			r += '[' + index + ']' + ' => ' + el + '<br />';
		});
		r += ')';
		$(results).setHTML(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($type(v) == 'array') v.print_r(results);
}




Element.extend({
	
	getId: function() {
		return this.getProperty('id');
	},
	
	getClassName: function() {
		return this.className;
	},
	
	getWidth: function() {
		return (!int) ? this.getStyle('width') : this.getStyle('width').toInt();
	},
	
	getHeight: function() {
		return this.getStyle('height');
	},
	
	getOpacity: function() {
		return (!int) ? this.getStyle('opacity') : this.getStyle('opacity').toInt();
	},
	
	getColor: function() {
		return this.getStyle('color');
	},
	
	getBg: function() {
		return this.getStyle('background-color');
	},
	
	getBorder: function(where) {
		return (where) ? this.getStyle('border-' + where) : this.getStyle('border');
	},
	
	getMargin: function(where) {
		return (where) ? this.getStyle('margin-' + where) : this.getStyle('margin');
	},
	
	getPadding: function(where) {
		return (where) ? this.getStyle('padding-' + where) : this.getStyle('padding');
	}
		
});



	
Table.implement({

	zebra: function(color1, color2, firstLine) {
		if(this.element.getTag() != 'table')  return false;
		
		this.cells = this.element.getElements('tr').getElements('td');
		this.cells.each(function(cell, index) {
			if(index%2 == 0)
				(firstLine && index == 0) ? cell.setStyles(firstLine) : cell.setStyle('background-color', color1);
			else
				cell.setStyle('background-color', color2);
		});
			
	},
	
	overClickRows: function(color, clickcolor) {
		this.rows = this.element.getElements('tr');
		
		this.rows.each(function(row, index) {
			row.addEvent('mouseover', function() {
				if(!this.init) this.init = row.getElement('td').getStyle('background-color');
				if(this.getElement('td').getStyle('background-color').toUpperCase() != clickcolor)
					row.getElements('td').setStyle('background-color', color);
			});
			
			row.addEvent('mouseout', function() {
				if(this.getElement('td').getStyle('background-color').toUpperCase() != clickcolor)
					row.getElements('td').setStyle('background-color', this.init);
			});
			
			row.addEvent('click', function() {
				if(this.getElement('td').getStyle('background-color').toUpperCase() != clickcolor)
					this.getElements('td').setStyle('background-color', clickcolor);
				else
					this.getElements('td').setStyle('background-color', this.init);
			});
		});
	},
	
	overRows: function(color) {
		this.rows = this.element.getElements('tr');
		
		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 = this.element.getElements('tr');
		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({
	
	overClickCells: function(color, clickcolor) {
		this.rows = this.element.getElements('tr');
		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(this.getStyle('background-color').toUpperCase() != clickcolor)
						td.setStyle('background-color', color);
				});
				
				td.addEvent('mouseout', function() {
					if(this.getStyle('background-color').toUpperCase() != clickcolor)
						td.setStyle('background-color', this.init);
				});
				
				td.addEvent('click', function() {
					if(this.getStyle('background-color').toUpperCase() != clickcolor)
						this.setStyle('background-color', clickcolor);
					else
						this.setStyle('background-color', this.init);
				});
			});
		});
	},
	
	overCells: function(color) {
		this.rows = this.element.getElements('tr');
		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 = this.element.getElements('tr');
		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({	
				
	overClickCols: function(color, clickcolor, firstLine) {
		this.rows = this.element.getElements('tr');
		this.rows.each(function(row, indexRow) {
			
		  row.getElements('td').each(function(td,indexTd) {
			 
			var i = indexTd;
			var tdcolor = td.getStyle('background-color').toUpperCase();
			
			td.addEvent('mouseover', function() {
				this.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', tdcolor);
							else if(c.getStyle('background-color').toUpperCase() != clickcolor)
								c.setStyle('background-color', color);
							else
								c.setStyle('background-color', clickcolor);
					});
				});
			});
			
			td.addEvent('mouseout', function() {
				this.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', tdcolor);
					});
				});
			});
				
			td.addEvent('click', function() {
				this.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', tdcolor);
							else if((!firstLine))
								 if(c.getStyle('background-color').toUpperCase() != clickcolor)
								  c.setStyle('background-color', clickcolor);
							  else
								  c.setStyle('background-color', tdcolor);
					});
				});
			});
				
			  
		  });		
		});
	},
	
	overCols: function(color, firstLine) {
		this.rows = this.element.getElements('tr');
		this.rows.each(function(row, indexRow) {
			
			  row.getElements('td').each(function(td,indexTd) {
				 
				var i = indexTd;
				var tdcolor = td.getStyle('background-color').toUpperCase();
				
				td.addEvent('mouseover', function() {
					this.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', tdcolor);
								else if(c.getStyle('background-color').toUpperCase() != color)
									c.setStyle('background-color', color);
								else
									c.setStyle('background-color', tdcolor);
						});
					});
				});
				
				td.addEvent('mouseout', function() {
					this.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', tdcolor);
						});
					});
				});
			  
			});		
		});
	},
	
	clickCols: function(color, firstLine) {
		this.rows = this.element.getElements('tr');
		this.rows.each(function(row, indexRow) {
			
		  row.getElements('td').each(function(td,indexTd) {
			 
			var i = indexTd;
			var tdcolor = td.getStyle('background-color').toUpperCase();
			
			td.addEvent('click', function() {
				this.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', tdcolor);
							else if(c.getStyle('background-color').toUpperCase() != color)
								c.setStyle('background-color', color);
							else
								c.setStyle('background-color', tdcolor);
					});
				});
			});
		  
		  });		
		});
	}
});




Custom.Alert = new Class({
		
	options: {
		height: '100px',
		width: '300px',
		buttonText: 'OK',
		opacify: true,
		alertbox: null,
		alerthead: null,
		alertbody: null
	},

	initialize: function(title, text, options) {
		this.title = title;
		this.text = text;
		this.setOptions(options);
		this.alertbox = new Element('div', {
			'id': 'customAlert',
			'styles': {
				'position': 'fixed',
				'top': '50%',
				'left': '50%',
				'z-index': 1000,
				'height': this.options.height,
				'width': this.options.width
			}
		});
		this.overlay = new Element('div', {
			'id': 'customAlertOverlay',
			'styles': {
				'position': 'absolute',
				'top': '0px',
				'left': '0px',
				'width': '100%',
				'height': window.getScrollHeight(),
				'background-image':'url(g.gif)',
				'z-index': 900
			}
		});
		this.mechanize();
		this.fx = new Fx.Style(this.alertbox, 'opacity', {duration:1000});
		if(this.options.initialize) this.options.initialize.call(this);
	},
	
	create: function() {
		this.customize();
	},
	
	mechanize: function() {
		if(this.options['alertbox']) this.alertbox.addClass(this.options['alertbox']);

		this.alertbox.setStyles({
			'margin-left': - this.alertbox.getStyle('width').toInt()/2,
			'margin-top': - this.alertbox.getStyle('height').toInt()/2
		});
		
		this.head = new Element('div').injectInside(this.alertbox);
		if(this.options.alerthead) this.head.addClass(this.options['alerthead']);
		this.head.appendText(this.title);
		
		this.content = new Element('div').injectInside(this.alertbox);
		if(this.options.alerthead) this.content.addClass(this.options['alertbody']);
		this.content.appendText(this.text);
	
		this.closebox = new Element('div').injectInside(this.alertbox);
		this.closebox.setProperty('align', 'center');
	
		this.button = new Element('a').injectInside(this.closebox);
		this.button.setProperty('href', '#');
		this.button.appendText(this.options.buttonText);
		this.button.addEvent('click', function(event) {
			var event = new Event(event).preventDefault();
		});
		if(this.options.opacify)  this.button.addEvent('click', this.opacify.bind(this));
		else this.button.addEvent('click', this.remove.bind(this));
	},
	
	customize: function() {
		if($('customAlert'))  return;
		
		this.alertbox.injectInside(this.overlay);
		this.overlay.injectInside($E('body'));
		
		if(this.options.opacify) this.alertbox.setStyle('opacity', 0);
		this.fx.start(1);
	},
	
	opacify: function() {
		this.fx.start(0).chain(function() {
			this.alertbox.remove();
			this.overlay.remove();
		}.bind(this));
	},
	
	remove: function() {
		this.alertbox.remove();
		this.overlay.remove();
	},
	
	setText: function(text) {
		this.content.setHTML(text);
		return this;
	},
	
	setTitle: function(title) {
		this.title = title;	
		return this;
	}
});

Custom.Alert.implement(new Options);




Custom.Confirm = new Class({
		
	options: {
		height: '100px',
		width: '300px',
		confirmText: 'OK',
		cancelText: 'Cancel',
		opacify: true,
		confirmbox: null,
		confirmhead: null,
		confirmbody: null,
		onConfirm: function() {
			return true;	
		},
		onCancel: function() {
			return false;	
		}
	},
	
	initialize: function(title, text, options) {
		this.title = title;
		this.text = text;
		this.setOptions(options);
		this.confirmbox = new Element('div', {
			'id': 'customConfirm',
			'styles': {
			'position': 'fixed',
			'top': '50%',
			'left': '50%',
			'z-index': 1000,
			'height': this.options.height,
			'width': this.options.width	
			}
		});
		this.overlay = new Element('div', {
			'id': 'customConfirmOverlay',
			'styles': {
				'position': 'absolute',
				'top': '0px',
				'left': '0px',
				'width': '100%',
				'height': window.getScrollHeight(), //window.getHeight() + window.getScrollTop(),
				'background-image':'url(g.gif)',
				'z-index': 900
			}
		});
		this.mechanize();
		this.fx = new Fx.Style(this.confirmbox, 'opacity', {duration:1000});
		if(this.options.initialize) this.options.initialize.call(this);
	},
	
	create: function() {
		this.customize();
	},
	
	mechanize: function() {
		if(this.options['confirmbox']) this.confirmbox.addClass(this.options['confirmbox']);
		this.confirmbox.setStyles({
			'margin-left': - this.confirmbox.getStyle('width').toInt()/2,
			'margin-top': - this.confirmbox.getStyle('height').toInt()/2
		});
		
		this.head = new Element('div').injectInside(this.confirmbox);
		if(this.options.confirmhead) this.head.addClass(this.options['confirmhead']);
		this.head.appendText(this.title);
		
		this.content = new Element('div').injectInside(this.confirmbox);
		if(this.options.confirmhead) this.content.addClass(this.options['confirmbody']);
		this.content.appendText(this.text);
	
		this.closebox = new Element('div').injectInside(this.confirmbox);
		this.closebox.setProperty('align', 'center');
	
		this.confirmButton = new Element('a').injectInside(this.closebox);
		this.confirmButton.setProperty('href', '#');
		this.confirmButton.appendText(this.options.confirmText);
		this.confirmButton.addEvent('click', function(event) {
			var event = new Event(event).preventDefault();
		});
		if(this.options.opacify)  this.confirmButton.addEvent('click', this.opacifyConfirm.bind(this));
		else this.confirmButton.addEvent('click', this.confirmRemove.bind(this));
		
		this.cancelButton = new Element('a').injectInside(this.closebox);
		this.cancelButton.setProperty('href', '#');
		this.cancelButton.appendText(this.options.cancelText);
		this.cancelButton.addEvent('click', function(event) {
			var event = new Event(event).preventDefault();
		});
		if(this.options.opacify)  this.cancelButton.addEvent('click', this.opacifyCancel.bind(this));
		else this.cancelButton.addEvent('click', this.cancelRemove.bind(this));
	},
	
	customize: function() {
		if($('customConfirm'))  return false;
		
		this.confirmbox.injectInside(this.overlay);
		this.overlay.injectInside($E('body'));
		
		if(this.options.opacify) this.confirmbox.setStyle('opacity', 0);
		this.fx.start(1);
		
	},
	
	opacifyConfirm: function() {
		this.fireEvent('onConfirm');
		this.fx.start(0).chain(function() {
			this.confirmbox.remove();
			this.overlay.remove();
		}.bind(this));
	},
	
	opacifyCancel: function() {
		this.fireEvent('onCancel');
		this.fx.start(0).chain(function() {
			this.confirmbox.remove();
			this.overlay.remove();
		}.bind(this));
	},
	
	confirmRemove: function() {
		this.fireEvent('onConfirm');
		this.confirmbox.remove();
		this.overlay.remove();
	},
	
	cancelRemove: function() {
		this.fireEvent('onCancel');
		this.confirmbox.remove();
		this.overlay.remove();
	},
	
	setText: function(text) {
		this.content.setHTML(text);
		return this;
	},
	
	setTitle: function(title) {
		this.title = title;
		return this;
	}
});

Custom.Confirm.implement(new Options, new Events);




var SmoothScrolling = new Class ({
	   
	initialize: function(options, links) {
		(!links) ? this.links = $$('a') : this.links = links;
		this.setOptions(options);
		this.fxscroll = new Fx.Scroll(window, this.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.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));
			}
		}
	  }, this);
	},
	
	makeScroll: function(lnk) {
		this.fxscroll.scrollTo(0,document.getElementsByName(lnk.targetName)[0].getTop());
	}
	
});

SmoothScrolling.implement(new Options);



Fx.Fold = Fx.Style.extend({	
	initialize: function(element, options, opt2) {
		this.parent(element, 'height', options);
		this.fx = new Fx.Style(element, 'width', opt2);
		this.element.setStyle('overflow', 'hidden');
	},
	
	start: function() {
		this.parent(0).chain(function() {
			this.fx.start(0); 
		});
	}		
});
	
Fx.Squish = Fx.Styles.extend({		
	initialize: function(element, options) {
		this.parent(element, options);
		this.element.setStyle('overflow', 'hidden');
	},
	
	start: function() {
		this.parent({
			'height': [0],
			'width': [0],
			'opacity': [0]
		});
	}		
});
		
Fx.Puff = Fx.Styles.extend({	
	initialize: function(element, options) {
		this.parent(element, options);
		this.initStyles('height', 'width', 'fontSize');
		this.element.setStyles({position: 'relative', overflow: 'hidden'});
	},
	
	start: function() {
		this.parent({
			'height': [this.init.height*1.3],
			'width': [this.init.width*1.3],
			'font-size': [this.init.fontSize*1.3],
			'opacity': [0]
		}).chain(function() { this.element.setStyle('display', 'none'); });
	}			
});
		
Fx.Shrink = Fx.Styles.extend({		
	initialize: function(element, options, opt2) {
		this.parent(element, options);
		this.fx = new Fx.Style(this.element, 'opacity', opt2);
		this.initStyles('fontSize');
		this.element.setStyles({position: 'relative', overflow: 'hidden'});
	},
	
	start: function() {
		this.parent({
			'height': [0],
			'width': [0],
			'font-size': [this.init.fontSize, 0]
		}).chain(function() {
			this.fx.start(1,0);
		});
	}		
});
		
Fx.Grow = Fx.Styles.extend({	
	initialize: function(element, options, values) {
		this.parent(element, options);
		this.values = values || {};
		this.element.setStyle('overflow', 'hidden');
	},
	
	start: function() {
		this.parent({
			'height': [0, this.values.height],
			'width': [0, this.values.width],
			'font-size': [0, this.values.fontsize]
		});
	}	
});

Element.extend({
	fold: function(options, opt2) {
		return new Fx.Fold(this, options, opt2);	
	},
	
	squish: function(options) {
		return new Fx.Squish(this, options);	
	},
	
	puff: function(options) {
		return new Fx.Puff(this, options);	
	},
	
	shrink: function(options, opt2) {
		return new Fx.Shrink(this, options, opt2);	
	},
	
	grow: function(options, values) {
		return new Fx.Grow(this, options, values);	
	}
});



Fx.FadeOut = Fx.Style.extend({
	initialize: function(element, options) {
		this.parent(element, 'opacity', options);
	},
	
	start: function() {
		this.parent(0);
	}
});

Fx.SwitchOffH = Fx.Style.extend({	
	initialize: function(element, options) {
		this.parent(element);
		this.fx = new Fx.Style(this.element, 'opacity', {duration:100});
		this.fx2 = new Fx.Style(this.element, 'height', options);
		this.element.setStyle('overflow', 'hidden');
	},
	
	start: function() {
		this.fx.start(0).chain(function() {
			this.fx.start(1);
		}.bind(this)).chain(function() {
			this.fx2.start(0);	
		}.bind(this));
	}
});

Fx.SwitchOffW = Fx.Style.extend({
	initialize: function(element, options) {
		this.parent(element);
		this.fx = new Fx.Style(this.element, 'opacity', {duration:100});
		this.fx2 = new Fx.Style(this.element, 'width', options);
		this.element.setStyle('overflow', 'hidden');
	},
	
	start: function() {
		this.fx.start(0).chain(function() {
			this.fx.start(1);
		}.bind(this)).chain(function() {
			this.fx2.start(0);	
		}.bind(this));
	}
});

Fx.ShakeH = Fx.Style.extend({	
	initialize: function(element, options) {
		this.parent(element);
		this.fx = new Fx.Style(this.element, 'top', options || {duration:100});
		this.element.setStyles({'position': 'relative', 'overflow': 'hidden'});
	},
	
	start: function() {
		this.fx.start(-10).chain(function() {
			this.fx.start(10);
		}.bind(this)).chain(function() {
			this.fx.start(-10);
		}.bind(this)).chain(function() {
			this.fx.start(10);
		}.bind(this)).chain(function() {
			this.fx.start(-10);
		}.bind(this)).chain(function() {
			this.fx.start(10);
		}.bind(this)).chain(function() {
			this.fx.start(-10);
		}.bind(this)).chain(function() {
			this.fx.start(10);
		}.bind(this)).chain(function() {
			this.fx.start(-10);
		}.bind(this)).chain(function() {
			this.fx.start(0);
		}.bind(this));
	}
});

Fx.ShakeW = Fx.Style.extend({
	initialize: function(element, options) {
		this.parent(element);
		this.fx = new Fx.Style(this.element, 'left', options || {duration:100});
		this.element.setStyles({'position': 'relative', 'overflow': 'hidden'});
	},
	
	start: function() {
		this.fx.start(-10).chain(function() {
			this.fx.start(10);
		}.bind(this)).chain(function() {
			this.fx.start(-10);
		}.bind(this)).chain(function() {
			this.fx.start(10);
		}.bind(this)).chain(function() {
			this.fx.start(-10);
		}.bind(this)).chain(function() {
			this.fx.start(10);
		}.bind(this)).chain(function() {
			this.fx.start(-10);
		}.bind(this)).chain(function() {
			this.fx.start(10);
		}.bind(this)).chain(function() {
			this.fx.start(-10);
		}.bind(this)).chain(function() {
			this.fx.start(0);
		}.bind(this));
	}
});


Element.extend({
	fadeOut: function(options) {
		return new Fx.FadeOut(this, options);	
	},
	
	switchOffH: function(options) {
		return new Fx.switchOffH(this, options);	
	},
	
	switchOffW: function(options) {
		return new Fx.FixswitchOffH(this,options);	
	},
	
	shakeH: function(options) {
		return new Fx.ShakeH(this, options);	
	},
	
	shakeW: function(options) {
		return new Fx.ShakeW(this, options);	
	}
});



Fx.Pulsate = Fx.Style.extend({	
	initialize: function(element) {
		this.parent(element, 'opacity');
		this.fx = new Fx.Style(this.element, this.property, {duration:100});
		this.element.setStyle('overflow', 'hidden');
	},
	
	start: function() {
		this.fx.start(0).chain(function() {
			this.fx.start(1);
		}.bind(this)).chain(function() {
			this.fx.start(0);
		}.bind(this)).chain(function() {
			this.fx.start(1);
		}.bind(this)).chain(function() {
			this.fx.start(0);
		}.bind(this)).chain(function() {
			this.fx.start(1);
		}.bind(this)).chain(function() {
			this.fx.start(0);
		}.bind(this)).chain(function() {
			this.fx.start(1);
		}.bind(this)).chain(function() {
			this.fx.start(0);
		}.bind(this)).chain(function() {
			this.fx.start(1);
		}.bind(this));
	}
});
		
Fx.Gradient = Fx.Style.extend({
	initialize: function(element, color, options, opt2) {
		this.parent(element,'background-color',  options);
		this.color = color;
		this.fx = new Fx.Style(this.element, 'background-color', opt2);
		this.initStyles('backgroundColor');
	},
	
	start: function() {
		this.parent(this.color).chain(function() {
			this.fx.start(this.init.backgroundColor);
		}.bind(this));
	}
});

Fx.FixGradient = Fx.Style.extend({
	initialize: function(element, color, options) {
		this.parent(element, 'background-color', options);
		this.color= color;
	},
	
	start: function() {
		this.parent(this.color);
	}
});

Fx.FadeIn = Fx.Style.extend({
	initialize: function(element, options) {
		this.parent(element, 'opacity', options);
	},
	
	start: function() {
		this.parent(1);
	}
});

Fx.Rumble = Fx.Styles.extend({	
	initialize: function(element, options) {
		this.parent(element);
		this.element.setStyles({'position': 'relative', 'cursor': 'move'});
		this.initStyles('top', 'left');
		this.obj = {'top': [this.element.getStyle('top').toInt(), this.init.top], 
					'left': [this.element.getStyle('left').toInt(), this.init.left]
				   };
		this.fx = new Fx.Styles(this.element, options || {duration: 800, transition: Fx.Transitions.Elastic.easeOut});
	},

	start: function() {
		var top = this.init.top; var left = this.init.left;
		var coord = {'top': (top != 'auto' ? top : 0), 'left': (left != 'auto' ? left : 0)};
		var fx = function() { this.fx.start(coord); };
		new Drag.Move(this.element).addEvent('onComplete', fx.bind(this));		   
	}
			
});


Element.extend({
	pulsate: function() {
		return new Fx.Pulsate(this);	
	},
	
	gradient: function(color, options, opt2) {
		return new Fx.Gradient(this, color, options, opt2);	
	},
	
	fixgradient: function(color, options) {
		return new Fx.FixGradient(this, color, options);	
	},
	
	shrink: function(options) {
		return new Fx.FadeIn(this, options);	
	},
	
	rumble: function(options) {
		return new Fx.Rumble(this, options);	
	}
});



Fx.BubbleH = Fx.Styles.extend({
	initialize: function(element, options) {
		this.parent(element, options || {duration:3000});
		this.element.setStyle('overflow', 'hidden');
	},
	
	start: function() {
		this.parent({
			'height': [0],
			'font-size': [0],
			'opacity': [0]
		});
	}
});


Fx.BubbleW = Fx.Styles.extend({		
	initialize: function(element, options) {
		this.parent(element, options || {duration:3000});
		this.element.setStyle('overflow', 'hidden');
	},
	
	start: function() {
		this.parent({
			'width': [0],
			'font-size': [0],
			'opacity': [0]
		});
	}
});


Fx.Morph = Fx.Styles.extend({
	initialize: function(element) {
		this.parent(element);
	},
 
	start: function(className){

		var to = {};

		$each(document.styleSheets, function(style){
			var rules = style.rules || style.cssRules;
				$each(rules, function(rule) {
					if (!rule.selectorText.test('\.' + className + '$')) return;
					CSSProperties.each(function(style) {
						if (!rule.style || !rule.style[style]) return;
						var ruleStyle = rule.style[style];
						to[style] = (style.test(/color/i) && ruleStyle.test(/^rgb/)) ? ruleStyle.rgbToHex() : ruleStyle;
					});
				});
		});
		return this.parent(to);
	}

});
 
CSSProperties = ["backgroundColor", "backgroundPosition", "backgroundImage", "color", "width", "height", "left", "top", "bottom", "right", "fontSize", "letterSpacing", "lineHeight", "textIndent", "opacity"];
 
CSSProperties.extend(Element.Styles.padding);
CSSProperties.extend(Element.Styles.margin); 

Element.Styles.border.each(function(border){
	['Width', 'Color'].each(function(property){
		CSSProperties.push(border + property);
	});
});

Fx.DropOut = Fx.Styles.extend({		
	initialize: function(element, options) {
		this.parent(element, options);
		this.element.setStyle('position', 'relative');
		this.initStyles('top');
		this.removeAuto('top');
	},
	
	start: function() {
		this.parent({
			'top': [this.init.top + 40],
			'opacity': [0]
		});
	}
});


Fx.Move = Fx.Styles.extend({	
	initialize: function(element, options) {
		this.parent(element, options);
		this.element.setStyle('position', 'relative');
		this.initStyles('top', 'left');
		this.removeAuto('top', 'left');
	},
	
	start: function(top, left) {
		this.parent({
			'top': top,
			'left': left
		});
	}
});


Element.extend({
	bubbleH: function(options) {
		return new Fx.BubbleH(this, options);	
	},
	
	bubbleW: function(options) {
		return new Fx.BubbleW(this, options);	
	},
	
	morph: function(color) {
		return new Fx.Morph(this);	
	},
	
	dropOut: function(options) {
		return new Fx.DropOut(this, options);	
	},
	
	move: function(options) {
		return new Fx.Move(this, options);	
	}
});




Fx.Toggle = Fx.Style.extend({
	initialize: function(element, options) {
		this.parent(element, null, options);
		this.initHeight = this.element.getStyle('height').toInt();
		this.initWidth = this.element.getStyle('width').toInt();
		this.initOpacity = this.element.getStyle('opacity').toInt();
	},
	
	toggleHeight: function() {
		this.property = 'height';
		(this.element.getStyle(this.property).toInt() > 0) ? this.start(0) : this.start(this.initHeight);
	},
	
	toggleWidth: function() {
		this.property = 'width';
		(this.element.getStyle(this.property).toInt() > 0) ? this.start(0) : this.start(this.initWidth);
	},
	
	toggleOpacity: function() {
		this.property = 'opacity';
		(this.element.getStyle(this.property).toInt() > 0) ? this.start(0) : this.start(this.initOpacity);
	},
	
	toggleProperty: function(property, from, to, options) {
		this.property = property;
		var options = options || {fx:false};
		if(($type(from) == 'string') && ($type(to) == 'string') && !options.fx)
			((this.element.getStyle(this.property)) == from.toLowerCase()) ? this.element.setStyle(this.property, to) : this.element.setStyle(this.property, from);
		else if(($type(from) == 'string') && ($type(to) == 'string') && options.fx)
			((this.element.getStyle(this.property)) == from.toLowerCase()) ? this.start(to) : this.start(from);
		else if(($type(from) == 'number') && ($type(to) == 'number'))
			((this.element.getStyle(this.property).toInt()) == from) ? this.start(to) : this.start(from);
	}
});
			
Element.extend({
	toggle: function(options) {
		return new Fx.Toggle(this, options);
	}
});




Fx.Toggle.implement({
	toggleColor: function(from, to, options) {
		this.property = 'background-color';
		this.toggleProperty(this.property, from, to, options);
	},
	
	display: function() {
		this.property = 'display';
		this.toggleProperty(this.property, 'block', 'none');
	},
	
	see: function() {
		this.property = 'visibility';
		this.toggleProperty(this.property, 'visible', 'hidden');
	}
});

