
var onglets = {
	ongletClass	: '',
	ongletName 	: '',
	conteneurClass:'',
	conteneurName:'',
	id 			: 0,
	position	: 0,
	
	init: function(ongletClass,ongletName,conteneurClass,conteneurName,position){
		this.ongletClass 	= ongletClass;
		this.ongletName		= ongletName;
		this.conteneurClass	= conteneurClass;
		this.conteneurName	= conteneurName;
		this.setOngletPosition(position);
		this.moveContent();
		this.moveOnglet();
	},
	clickOngletAction: function(id){
		this.setOngletPosition(id-1);
		this.moveContent();
		this.moveOnglet();
	},
	setOngletPosition: function(position){
		this.position = position;
		this.id = this.position+1;
	},
	getOngletPosition: function(){
		return this.position;
	},
	moveOnglet: function(){
		$(this.ongletClass).removeClass('selected');
		$(this.ongletName+'_'+this.id).addClass('selected');
	},
	moveContent: function(){
		$(this.conteneurClass).removeClass('selected');
		$(this.conteneurName+'_'+this.id).addClass('selected');
	}
};


var AllSlideContent = {
	nameGroupButton		: '',
	nameUpClass			: '',
	nameDownClass		: '',
	textForUp			: '',
	textForDown			: '',
	init:function(nameGroupButton, nameUpClass, nameDownClass, textForUp, textForDown){
		this.nameGroupButton	= nameGroupButton;
		this.nameUpClass 		= nameUpClass;
		this.nameDownClass 		= nameDownClass;
		this.textForUp			= textForUp;
		this.textForDown		= textForDown;
		this.bindBtnAction();
	},
	unbindBtnAction: function(){
		$('.'+this.nameGroupButton+'.'+this.nameDownClass).unbind('click');
		$('.'+this.nameGroupButton+'.'+this.nameUpClass).unbind('click');
	},
	
	bindBtnAction: function(){
		this.bindMoinsBtnAction();
		this.bindPlusBtnAction();
	},

	bindPlusBtnAction: function(){
		//alert('test');
		$('.'+this.nameGroupButton+'.'+this.nameUpClass).bind('click',function(e){
			e.stopPropagation();
			$($($(this).parent()[0]).children()[2]).toggle('slow');
			
			$(this).removeClass(AllSlideContent.nameUpClass);
			
			$(this).addClass(AllSlideContent.nameDownClass);
			
			$(this).children().each(function(){$(this).html(AllSlideContent.textForDown);});
			
			AllSlideContent.unbindBtnAction();
			AllSlideContent.bindBtnAction();
			return false;
		});
	},
	
	bindMoinsBtnAction	: function(){
		//alert('test');
		$('.'+this.nameGroupButton+'.'+this.nameDownClass).bind('click',function(e){
			e.stopPropagation();
			$($($(this).parent()[0]).children()[2]).toggle('slow');
			$(this).removeClass(AllSlideContent.nameDownClass);
			$(this).addClass(AllSlideContent.nameUpClass);
			$(this).children().each(function(){$(this).html(AllSlideContent.textForUp);});
			AllSlideContent.unbindBtnAction();
			AllSlideContent.bindBtnAction();
			return false;
		});
	}
};



var MenuDeroulant = {
	nomGroupeBouton		: '',
	nomClasseMonter		: '',
	nomClasseDescendre	: '',
	//textForUp			: '',
	//textForDown		: '',
	init:function(nomGroupeBouton, nomClasseMonter, nomClasseDescendre){//, textForUp, textForDown){
		this.nomGroupeBouton	= nomGroupeBouton;
		this.nomClasseMonter 	= nomClasseMonter;
		this.nomClasseDescendre = nomClasseDescendre;
		//this.textForUp		= textForUp;
		//this.textForDown		= textForDown;
		this.lierBtnAction();
	},
	delierBtnAction: function(){
		$('.'+this.nomGroupeBouton+'.'+this.nomClasseDescendre).unbind('click');
		$('.'+this.nomGroupeBouton+'.'+this.nomClasseMonter).unbind('click');
	},
	
	lierBtnAction: function(){
		this.lierMoinsBtnAction();
		this.lierPlusBtnAction();
	},

	lierPlusBtnAction: function(){
		$('.'+this.nomGroupeBouton+'.'+this.nomClasseMonter).bind('click',function(e){
	
			e.stopPropagation();
			$($($(this).parent()[0]).children()[1]).toggle('slow');
			
			$(this).removeClass(MenuDeroulant.nomClasseMonter);
			
			$(this).addClass(MenuDeroulant.nomClasseDescendre);
			
			//$(this).children().each(function(){$(this).html(MenuDeroulant.textForDown);});
			
			MenuDeroulant.delierBtnAction();
			MenuDeroulant.lierBtnAction();
			return false;			
		});
		$('.'+this.nomGroupeBouton+'.'+this.nomClasseMonter).bind('mouseover',function(e){
			$(this).css('backgroundPosition','right top');
		});
		$('.'+this.nomGroupeBouton+'.'+this.nomClasseMonter).bind('mouseout',function(e){
			$(this).css('backgroundPosition','left top');
		});
		$('.'+this.nomGroupeBouton+'.'+this.nomClasseMonter).children().bind('click',function(e){
			e.stopPropagation();
			return true;
		});		
	},
	
	lierMoinsBtnAction	: function(){
		$('.'+this.nomGroupeBouton+'.'+this.nomClasseDescendre).bind('click',function(e){
			e.stopPropagation();
			$($($(this).parent()[0]).children()[1]).toggle('slow');
			$(this).removeClass(MenuDeroulant.nomClasseDescendre);
			$(this).addClass(MenuDeroulant.nomClasseMonter);
			
			//$(this).children().each(function(){$(this).html(MenuDeroulant.textForUp);});
			
			MenuDeroulant.delierBtnAction();
			MenuDeroulant.lierBtnAction();
			return false;
		});
		$('.'+this.nomGroupeBouton+'.'+this.nomClasseMonter).bind('mouseover',function(e){
			$(this).css('backgroundPosition','right top');
		});
		$('.'+this.nomGroupeBouton+'.'+this.nomClasseMonter).bind('mouseout',function(e){
			$(this).css('backgroundPosition','left top');
		});
		$('.'+this.nomGroupeBouton+'.'+this.nomClasseMonter).children().bind('click',function(e){
			e.stopPropagation();
			return true;
		});
	}
};


var MenuNavigation = {
	n1:'',
	init:function(){
		this.chercheN1actif();
		if (this.n1 !== '') {
			$('ul#menu > li[class!='+this.n1+'] > a').bind('mouseover',function(e){
				e.stopPropagation();
				MenuNavigation.hideN1actif();
				MenuNavigation.showN1hover($(this));
				return true;
			});
			$('ul#menu > li[class!='+this.n1+'] > a').bind('mouseout',function(e){
				e.stopPropagation();
				MenuNavigation.showN1actif();
				MenuNavigation.hideN1hover($(this));
				return true;
			});
			$('ul#menu > li[class!='+this.n1+'] > ul').bind('mouseover',function(e){
				MenuNavigation.hideN1actif();
				MenuNavigation.showN1hover($($(this).parent().children()[0]));
				return true;
			});
			$('ul#menu > li[class!='+this.n1+'] > ul').bind('mouseout',function(e){
				MenuNavigation.showN1actif();
				MenuNavigation.hideN1hover($($(this).parent().children()[0]));
				return true;
			});
		}
		else {
			$('ul#menu > li > a').bind('mouseover',function(e){
				e.stopPropagation();
				MenuNavigation.showN1hover($(this));
				return true;
			});
			$('ul#menu > li > a').bind('mouseout',function(e){
				e.stopPropagation();
				MenuNavigation.hideN1hover($(this));
				return true;
			});
			$('ul#menu > li > ul').bind('mouseover',function(e){
				MenuNavigation.showN1hover($($(this).parent().children()[0]));
				return true;
			});
			$('ul#menu > li > ul').bind('mouseout',function(e){
				MenuNavigation.hideN1hover($($(this).parent().children()[0]));
				return true;
			});
		}
	},
	chercheN1actif:function(){
		if ($('ul#menu > li > a.selected').length) {
			this.n1 = $('ul#menu > li > a.selected').parent()[0].className;
		}
	},
	hideN1actif:function(){
		$('ul#menu > li.'+this.n1+' > a').css('background-position','left top');
		$('ul#menu > li.'+this.n1+' > a').css('color','#13448E');
		$('ul#menu > li.'+this.n1+' > ul').css('display','none');
	},
	showN1actif:function(){
		$('ul#menu > li.'+this.n1+' > a').css('background-position','left bottom');
		$('ul#menu > li.'+this.n1+' > a').css('color','#FFFFFF');
		$('ul#menu > li.'+this.n1+' > ul').css('display','block');
	},
	hideN1hover:function(elt){
		elt.css('background-position','left top');
		elt.css('color','#13448E');
		$($(elt).parent().children()[1]).css('display','none');
	},
	showN1hover:function(elt){
		elt.css('background-position','left bottom');
		elt.css('color','#FFFFFF');
		$($(elt).parent().children()[1]).css('display','block');
	}
};

function testRechercheGoogle() {
	
	if ($('input#chp_recherche').val() === '') {
		return false;
	}
	else if ($('select#search_section').val() === "Google") {
		$('input#val_recherche_google').val($('input#chp_recherche').val());
		$('form#rechercheGoogle').submit();
		return false;
	}
	else {
		return true;
	}

}

$(document).ready(function() {
	
	//Gestion de la page glossaire.
	// Onglets.
	var ongletName = ".onglet_structure";
	if ($(ongletName).length > 0){
		onglets.init(ongletName, '#onglet', '.conteneur', '#conteneur', 0);
		$(ongletName).each(function(e){
			$('#'+this.id).click(function(E){
				var id = this.id.split('_')[1];
				onglets.clickOngletAction(id);
				return false;
			});
		});
	}
	//Gestion des slider de la page glossaire.
	if ($('.btn_action').length > 0){
		AllSlideContent.init('btn_action', 'plus', 'moins', 'Lire la suite', 'Fermer');
	}
	//Gestion du menu déroulant
	if ($('.deplier').length > 0){
		MenuDeroulant.init('deplier', 'plus', 'moins');//, 'Lire la suite', 'Fermer');
	}

	// Gestion BarreNavigation
	MenuNavigation.init();

	/* plan site */
	 $(".plan_site").hide();
	
	
	 $(".link_plan_site").click(function () {
										  
		  var ie = (document.all && !window.opera)?true:false;
		  
		  if(ie==true){
			  	  $("select").toggle();
		  }
	
		  $(".link_plan_site").toggleClass("selection");
	      $(".plan_site").toggle("slow");
	    });
});