/*

Script : moo3dmenu.js
originally by christopher wait aka virtualgadjo / chris at virtual-gadjo dot com
*/
var moo3Dmenu = new Class({
	
	Implements: Options,

	options: {
		resizeTop		: 10,
		resizeRight		: 10,
		offsetLeft		: 0,
		zindex			: 5
	},

	initialize: function(container, items, options) {
		this.container 	= $(container);
		this.setOptions(options);
		this.menu		= [];
		this.formerabs	= [];
		this.formerord	= [];
		this.largeur	= [];
		this.hauteur	= [];
		this.effect		= [];
		this.newZindex	= this.options.zindex;
		$$(items).each(function(el, i){
			this.absi		= el.getCoordinates(this.container).left;
			this.ord		= el.getCoordinates(this.container).top;
							
			this.linkWidth		= el.getCoordinates(this.container).width;
			this.linkHeight		= el.getCoordinates(this.container).height;
			
			this.formerabs.push(this.absi);
			this.formerord.push(this.ord);
			this.largeur.push(this.linkWidth);
			this.hauteur.push(this.linkHeight);

			this.newLink = el.clone();
			this.newLink.setStyles({
				'position'	: 'absolute',
				'top'		: this.ord,
				'left'		: this.absi,
				'z-index'	: this.newZindex
			});
			this.newLink.inject(this.container, 'top');

			this.newEffect	= new Fx.Morph (this.newLink, {duration:'short',link: 'cancel',transition:Fx.Transitions.Sine.easeOut });

			this.menu.push(this.newLink);
			this.effect.push(this.newEffect);

			el.setStyle('visibility', 'hidden');
			this.newZindex++;
		},this);

		//et c'est reparti...
		
		$$(this.menu).each(function(elem, j){

			elem.addEvents({
				'mouseenter': function(){
					this.getCoordonnees(j);
					this.zoomIn(j);
				}.bind(this),

				'mouseleave': function(){
					this.zoomOut(j);
				}.bind(this)
			});

		}.bind(this));

	},

	getCoordonnees: function(j){
		this.departx		= this.formerabs[j];
		this.departy		= this.formerord[j];
		this.formerWidth	= this.largeur[j]; 
		this.formerHeight	= this.hauteur[j];
		this.zoomord		= this.departy - this.options.resizeTop;
		this.zoomabsi		= this.departx + this.options.offsetLeft;
		this.ZoomWidth		= this.formerWidth + this.options.resizeRight;
		this.ZoomHeight		= this.formerHeight + this.options.resizeTop;
	},

	zoomIn: function(j){
		this.effect[j].start({
			'top'		: [this.departy, this.zoomord],
			'width'		: [this.formerWidth, this.ZoomWidth],
			'height'	: [this.formerHeight, this.ZoomHeight],
			'left': [this.departx,this.zoomabsi]
		});
	},

	zoomOut: function(j){
		this.effect[j].start({
			'top'		: this.departy,
			'width'		: this.formerWidth,
			'height'	: this.formerHeight,
			'left': this.departx
		});
	}

});