//	Javascript class developped by Michaël Villar
//	http://www.nemstudio.com/
//	Require script.aculo.us library
//	Cette création est mise à disposition selon le Contrat Paternité-Partage des Conditions Initiales 
//	à l'Identique 2.0 Belgique disponible en ligne http://creativecommons.org/licenses/by-sa/2.0/be/ 
//	ou par courrier postal à Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
SliderMenu = Class.create();
SliderMenu.prototype = {
	menu : Object,
	slider : Object,
	options : "",
	
	// Private variables
	effectObject : null,
	slidingDown : false,
	slidingUp : false,
	position : "",
	
	initialize: function(menu, slider) {
		this.options = Object.extend({
			afterSlideDown: "",
			afterSlideUp: "",
			duration: 0.2,
			timing: 100,
			eventToShow: "onmouseover",
			eventToHide: "onmouseout"}, arguments[2] || {});
		
		this.menu = $(menu);
		this.slider = $(slider);
	
		this.menu.style.display = "none";
		this.position = "up";
		
		window.sliderMenu = this.menu.ref = this.slider.ref = this;
		this.slider[this.options.eventToShow] = function() {
			this.ref.showMenu();
		}
		this.slider[this.options.eventToHide] = function() {
			this.ref.hideMenu();
		}
		this.menu.onmouseover = function() {
			clearTimeout(this.ref.hiderTimeout);
		}
		this.menu.onmouseout = function() {
			this.ref.hideMenu();
		}
		
	},
	
	showMenu: function() {
		clearTimeout(this.hiderTimeout);
		if (this.menu.style.display == "none" && this.slidingDown != true && this.slidingUp != true && this.position != "down") {
			if (this.effectObject != null)
				this.effectObject.cancel();
			this.effectObject = Effect.SlideDown(this.menu.id, {duration:this.options.duration,afterFinish:function(obj) {obj.ref.slidingDown = false;obj.ref.position = "down";obj.ref.options.afterSlideDown();}});
			this.effectObject.ref = this;
			this.slidingDown = true;
		}
	},

	hideMenu: function() {
		clearTimeout(this.hiderTimeout);
		this.hiderTimeout = setTimeout('sliderMenu.hideMenuForced();',this.options.timing);
	},
	
	hideMenuForced: function() {
		if (this.slidingDown != true && this.slidingUp != true && this.position != "up") {
			if (this.effectObject != null)
				this.effectObject.cancel();
			this.slidingUp = true;
			this.effectObject = Effect.SlideUp(this.menu.id, {duration:this.options.duration,afterFinish:function(obj) {obj.ref.slidingUp = false;obj.ref.position = "up";obj.ref.options.afterSlideUp();}});	
			this.effectObject.ref = this;
		}
		else if(this.slidingUp != true){
			clearTimeout(this.hiderTimeout);
			this.hiderTimeout = setTimeout('sliderMenu.hideMenuForced();',this.options.duration);
		}
	}
}