
/**
 * MENU LAYER
 */
var menuLayer = function(options){
	
	this.options = {
		defaulLayerNumber 		: 0,
		cssSelectorButtonNav	: '.btnMainNav',
		cssSelectorLayerNav 	: '.layerMainNav',
		cssClassLayerEnable		: 'enable',
		timoutNav				: 400,
		taskHideLayer			: null
	};
	
	this.init = function(options) {

		var self = this; // To set as a context on sub
        
		this.options = jQuery.extend({}, this.options, options);		
		this.hideAll()

		/**
		 * Numbering of toggle and content elements
		 */		
		jQuery(this.options.cssSelectorButtonNav).each(function(index){ 
			jQuery(this).data('num', index);
		});		
		jQuery(this.options.cssSelectorLayerNav).each(function(index){
			jQuery(this).data('num', index);
		});
		
		/**
		 * display event
		 */
		jQuery(this.options.cssSelectorButtonNav).live('mouseenter', { self : self}, function(event){
			var self = event.data.self;
			window.clearTimeout(self.options.taskHideLayer);
			self.displayLayerByNumber(jQuery(this).data('num'));
		});
		
		/**
		 * hide event when living button
		 */
		jQuery(this.options.cssSelectorButtonNav).live('mouseleave', { self : self}, function(event){	
			var self = event.data.self;
			self.options.taskHideLayer = window.setTimeout( function (){self.hideAll()}, self.options.timoutNav);
		});
		
		/**
		 * hide event when living layer
		 */
		jQuery(this.options.cssSelectorLayerNav).live('mouseleave', { self : self}, function(event){
			var self = event.data.self;	
			self.options.taskHideLayer = window.setTimeout( function (){self.hideAll()}, self.options.timoutNav);
		});
		
		/**
		 * clearing timeout event on enter layer
		 */
		jQuery(this.options.cssSelectorLayerNav).live('mouseenter', { self : self}, function(event){
			var self = event.data.self;	
			window.clearTimeout(self.options.taskHideLayer);
		});
    }
    
	/**
	 * Change selected toggle
	 */
    this.displayLayer = function(currentLayer) {
		this.hideAll()
		jQuery(currentLayer).css('display', 'block');		
    }
	
	/**
	 * Hide all layers
	 */
	this.hideAll = function(){
		jQuery(this.options.cssSelectorLayerNav).css('display', 'none');
	}
	
	/**
	 * Change selected toggle by number
	 */
	this.displayLayerByNumber = function(num){
		this.hideAll()
		var self = this;
		jQuery(this.options.cssSelectorLayerNav).each(function(){
			if(num == jQuery(this).data('num')){
				self.displayLayer(this);
			}
		});
	}
	
	/**
	 * Launch init
	 */
	this.init(options);
};

/**
 * Gestion de l'affichage d'erreurs des champs de formulaire
 */
function initFormError(){
	
	$jq('.boutique_compte_box_form_erreur').live('keyup', function(){
		$jq(this).removeClass('boutique_compte_box_form_erreur');
		$jq(this).parents('td.containerFieldForm:first').find('.boutique_compte_legende_erreur').parents('div:first').css('display', 'none');
		$jq(this).parents('td.containerFieldForm:first').find('.boutique_compte_legende_erreur').css('display', 'none');
	});
	
	$jq('select.boutique_compte_box_form_erreur').live('change', function(){
		$jq(this).removeClass('boutique_compte_box_form_erreur');
		$jq(this).parents('td.containerFieldForm:first').find('.boutique_compte_legende_erreur').parents('div:first').css('display', 'none');
		$jq(this).parents('td.containerFieldForm:first').find('.boutique_compte_legende_erreur').css('display', 'none');
	});
	
	$jq('.fieldCheckBoxError').live('click', function(){
		$jq(this).removeClass('fieldCheckBoxError');
		$jq(this).parents('td.containerFieldForm:first').find('.boutique_compte_legende_erreur').parents('div:first').css('display', 'none');
		$jq(this).parents('td.containerFieldForm:first').find('.boutique_compte_legende_erreur').css('display', 'none');		
	});
}

