/*
	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: type.js
	
	[Description]
		Contains shortcut functions to detect the type of an object using the $type function and the $dump function to detect the value and the type of every objects
	[/Description]
	
	Contains: A collection of functions based on the $type function plus the $dump function
	
	[Functions]
		$dump --- returns the value and the type of the object passed in
		$string --- returns true if the object is a string
		$int --- returns true if the object is a number
		$array --- returns true if the object is an array
		$object --- returns true if the object is an object
		$function --- returns true if the object is a function
		$date --- returns true if the object is a date
		$class --- returns true if the object is a class
		$element --- returns true if the object is an element
		$collection --- returns true if the object is a collection
		$arguments --- returns true if the object is the arguments object
		$textnode --- returns true if the object is a textnode
		$whitespace --- returns true if the object is a whitespace
		$window --- returns true if the object is the window object
		$document --- returns true if the object is the document object
	[/Functions]
*/
/*
	Function: $dump
	Description: returns the value and the type of the object passed in
	[Arguments]
		obj :: the object to analize
		results :: optional. the element to put the results to. If false returns the result string.
	[/Arguments]
	[Example] 
		> var s = 'some data';
		>
		> $dump(s, 'box');
		> // returns
		> '(
		>   Value: some data
		>   Type: string
		> )'
		>
		> var a = ['a', 'b', 'c', 'd'];
		>
		> $dump(a, 'box');
		> // returns
		> '(
		>   Value: a, b, c, d
		>   Type: array
		> )'
	[/Example]
*/
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
	Description: returns true if the object is a string
*/
function $string(obj) {
	return $type(obj) == 'string';
}

/*
	Function: $int
	Description: returns true if the object is a number
*/
function $int(obj) {
	return $type(obj) == 'number';
}

/*
	Function: $array
	Description: returns true if the object is an array
*/
function $array(obj) {
	return $type(obj) == 'array';
}

/*
	Function: $object
	Description: returns true if the object is an object
*/
function $object(obj) {
	return $type(obj) == 'object';
}

/*
	Function: $function
	Description: returns true if the object is a function
*/
function $function(obj) {
	return $type(obj) == 'function';
}

/*
	Function: $date
	Description: returns true if the object is a date
*/
function $date(obj) {
	return $type(obj) == 'date';
}

/*
	Function: $class
	Description: returns true if the object is a class
*/
function $class(obj) {
	return $type(obj) == 'class';
}

/*
	Function: $element
	Description: returns true if the object is an element
*/
function $element(obj) {
	return $type(obj) == 'element';
}

/*
	Function: $collection
	Description: returns true if the object is a collection
*/
function $collection(obj) {
	return $type(obj) == 'collection';
}

/*
	Function: $arguments
	Description: returns true if the object is the arguments object
*/
function $arguments(obj) {
	return $type(obj) == 'arguments';
}

/*
	Function: $textnode
	Description: returns true if the object is a textnode
*/
function $textnode(obj) {
	return $type(obj) == 'textnode';
}

/*
	Function: $whitespace
	Description: returns true if the object is a whitespace
*/
function $whitespace(obj) {
	return $type(obj) == 'whitespace';
}

/*
	Function: $window
	Description: returns true if the object is the window object
*/
function $window(obj) {
	return $type(obj) == 'window';
}

/*
	Function: $document
	Description: returns true if the object is the document object
*/
function $document(obj) {
	return $type(obj) == 'document';
}

/*
	Filename: browser.js
	
	[Description]
		Contains some Browser properties to ease the detection of the browser which is working
	[/Description]
	
	Contains: Hash Browser
	
	[Summary]
		Browser ::: Extends the Browser Hash with new properties 
	[/Summary]
*/
/*
	Hash: Browser
	
	[Description]  
		Extends the Browser Hash with new properties, to speed up and ease the detection of the browser which is working.
	[/Description]
	
	[Hash]
		 Browser.ie : alias of Browser.Engine.trident
		 Browser.ie6 : alias of Browser.Engine.trident4
		 Browser.ie7 : alias of Browser.Engine.trident5
		 Browser.firefox : alias of Browser.Engine.gecko
		 Browser.safari : alias of Browser.Engine.webkit
		 Browser.safari2 : alias of Browser.Engine.webkit419
		 Browser.safari3 : alias of Browser.Engine.webkit420
		 Browser.opera : alias of Browser.Engine.presto
		 Browser.opera925 : alias of Browser.Engine.presto925
		 Browser.opera950 : alias of Browser.Engine.presto950
	[/Hash]
*/
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;

/*
	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'
	},	
	
	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]));
	}
});

/*
	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'
	},
	
	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);
	}
});