/*
	Filename: 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'
	]
};

/*
	Filename: constructors.js
	
	[Description] 
		Contains some of the moo.rd native Constructors based on the MooTools Class. It permits a major modularity.
	[/Description]
	
	Contains: Class Table, Class Make
*/
/*
	Class: Table
	Description: Allows you to customize tables, tables rows, cells and columns 
*/
var Table = new Class({	
	initialize: function(element) {
		this.element = $(element);
		this.rows = this.element.getElements('tr');
		this.cells = this.element.getElements('tr').getElements('td');
	}
});

/*
	Class: Make
	Description: Wrapper to create Classes that make dinamically Elements.  
*/
var Make = new Class({
	Implements: [Options],
	options: {
		content: 'text'
	}
});

/*
	Filename: kwick_menu.js
	
	[Description]  
		Allows you to create customized kwick menu for every needs, horizontal or vertical.
		In addiction contains the Kwick.All Class which allows you to kwick each property you want.
	[/Description]
	
	Contains: Class Kwick.Base, Kwick.Menu, Kwick.All
	
	[Summary]
		Kwick.Base ::: Base Class, internal. A wrapper for the Kwick.Menu Class
		Kwick.Menu ::: Custom Class to create customized kwick menu, horizontal or vertical
		Kwick.All ::: Custom Class to kwick each property you want
	[/Summary]
*/
/*
	Class: Kwick.Base
	
	Description: Base Class, internal. A wrapper for the Kwick.Menu Class
	
	Extends: Fx.Elements
	
	Constructor: new Kwick.Base (elements, options)
	
	[Properties] 
		element - the $$(elements) to apply the kwick to
		options - optional. The Fx.Element options plus some other options
	[/Properties]
	
	[Options]
		large : int. the large size
		normal : int. the normal size
		small : int. the small size
	[/Options]
*/
var Kwick = {};

Kwick.Base = new Class({
					   
	Extends: Fx.Elements,
	
	options: {
		large: 200,
		normal: 100,
		small: 50,
		link: 'cancel',
		duration:300,
		transition: 'back:out',
		actual:0,
		//internal
		leavedout: true
	},	
	
	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.options.actual = i;
		this.options.leavedout = false;
		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) {
		this.options.leavedout = true;
		if (!this.options.dontleave)
		{ var o = {};
		  this.elements.each(function(el, i) {
			o[i] = {};
			o[i][prop] = [el.getStyle(prop), this.options.normal];
		  }, this);
		  this.start(o);
		}
	},
	
	open: function(index) {
		this.elements[index].fireEvent('mouseenter');
	},
	
	next: function() {
		if (this.options.leavedout)
		{ if (this.options.actual >= (this.elements.length-1))
		   this.options.actual = 0;
		  else
		   this.options.actual++;
		  this.open(this.options.actual);
		  this.options.leavedout = true;
		}
	},
	
	build: function(prop, el, i) {
		el.addEvent("mouseenter", this.enter.bind(this, [prop, el, i]));
	}
});

/*
	Class: Kwick.Menu
	Description:  Custom Class to create customized kwick menu, horizontal or vertical
	
	Extends: Class Kwick.Base
	
	Constructor: new Kwick.Menu (elements, options)
	
	[Properties] 
		element - the $$(elements) to apply the kwick to
		options - optional. The Kwick.Base options plus the following
	[/Properties]
	
	[Options]
		mode : 'vertical' (height transition, vertical) or 'horizontal' (width transition, horizontal, default)
	[/Options]
	
	[Example]
		> var kwick = new new Kwick.Menu($$("#kwick kwick"), {
		> 	mode: 'vertical'
		> });
	[/Example]
*/
Kwick.Menu = new Class({
					   
	Extends: Kwick.Base,
	
	options: {
		mode: 'horizontal',
		dontleave: true
	},
	
	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;
		};
	}
});

/*
	Class: Kwick.All
	Description:  Custom Class to kwick each property you want for creating complex kwick transitions
	
	Extends: Class Kwick.Base
	
	Constructor: new Kwick.All (elements, property, options)
	
	[Properties] 
		element - the $$(elements) to apply the kwick to
		property - the property to kwick
		options - optional. The Fx.Element options plus the Kwick.Base options (see above)
	[/Properties]
	
	[Example]
		> var kwick = new new Kwick.All($$("#kwick kwick"), 'color', {
		> 	large:'#424F6F',
		>	normal: '#009966',
		>	small: '#F5F5F5'
		> });
	[/Example]
*/
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);
	}
});
