// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function afficher_masquer(element_id, visible)
{
	if (visible)
	{Element.show(element_id);}
	else
	{Element.hide(element_id);}
}


var Placeholder = Class.create({
	initialize: function (element) {
		this.element = element;
		this.placeholder = element.readAttribute('placeholder');
		this.blur();
		Event.observe(this.element, 'focus', this.focus.bindAsEventListener(this));
		Event.observe(this.element, 'blur', this.blur.bindAsEventListener(this));
	},
	focus: function () {
		if (this.element.hasClassName('placeholder'))
		this.element.clear().removeClassName('placeholder');
	},
	blur: function () {
		if ((this.element.value == '') || (this.element.value == this.placeholder))
		this.element.addClassName('placeholder').value = this.placeholder;
	}
});

// Extensions Prototype
var MyUtils = {
    toggleText: function(element, text1, text2){
        element = $(element);
		if (element.innerHTML==text1) {element.update(text2);}
		else {element.update(text1);};
        return true;
    }
}
Element.addMethods(MyUtils);

var DropDownMenu = Class.create({
	initialize: function () {
		var tabs = $$('.nav .dropdown-nav');
		tabs.each(function(element) {
			element.observe('mouseover',function()
			{
				var $that=$(this);
				clearTimeout($that.timeout);
				$that.addClassName('hover').select('.sub-nav').each(function(element) {element.show()});
				tabs.each(function(element) {
					if (element!=$that)
					element.removeClassName('hover').select('.sub-nav').each(function(element) {element.hide()});
				});
			});
		});
		tabs.each(function(element) {
			element.observe('mouseout',function()
			{
				var $that=$(this);
				$that.timeout=setTimeout(function() {
					 $that.removeClassName('hover').select('.sub-nav').each(function(element) {element.hide()});
				},300);
			});
		});
	}
});
document.observe('dom:loaded', function() { new DropDownMenu(); });
