/***********************************************************************************************************************
DOCUMENT: includes/javascript.js
DEVELOPED BY: Ryan Stemkoski
COMPANY: Zipline Interactive
EMAIL: ryan@gozipline.com
PHONE: 509-321-2849
DATE: 3/26/2009
UPDATED: 3/25/2010
DESCRIPTION: This is the JavaScript required to create the accordion style menu.  Requires jQuery library
NOTE: Because of a bug in jQuery with IE8 we had to add an IE stylesheet hack to get the system to work in all browsers. I hate hacks but had no choice :(.
************************************************************************************************************************/
$(document).ready(function() {
	 
	//ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
	$('.accordionButton').click(function() {

		//REMOVE THE ON CLASS FROM ALL BUTTONS
		$('.accordionButton').removeClass('on');
		  
		//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
	 	$('.accordionContent').slideUp('normal');
   		if($(this).next().is(':hidden') == false) {
   			$(this).next().slideUp('normal');
   		}
   
		//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
		if($(this).next().is(':hidden') == true) {
			
			//ADD THE ON CLASS TO THE BUTTON
			$(this).addClass('on');
			  
			//OPEN THE SLIDE
			$(this).next().slideDown('normal');
			
			//MB - 04/11/2011
			// on lance l'ajax sur la page php avec certains paramètres   
            $.ajax({type: "GET", 
                   url: "ajax.php", 
                   data: "action=deroule_bloc_accordeon&id_bloc_ouvert=" + $(this).attr("id"),   
                   success: function(msg){ // au succès on renvoie le résultat de la requête   
                    //alert(msg); // on l'affiche   
                   }});     

		 } 
		  
	 });
	 
	
	  
	
	/*** REMOVE IF MOUSEOVER IS NOT REQUIRED ***/
	
	//ADDS THE .OVER CLASS FROM THE STYLESHEET ON MOUSEOVER 
	$('.accordionButton').mouseover(function() {
		$(this).addClass('over');
		
	//ON MOUSEOUT REMOVE THE OVER CLASS
	}).mouseout(function() {
		$(this).removeClass('over');										
	});
	
	/*** END REMOVE IF MOUSEOVER IS NOT REQUIRED ***/
	
	
	/********************************************************************************************************************
	CLOSES ALL S ON PAGE LOAD
	********************************************************************************************************************/	
	$('.accordionContent').hide();
	
	/********************************************************************************************************************
	OPENS THE DIV THAT IS ASSIGNED WITH THE ID open
	********************************************************************************************************************/	
	//$("#open1").trigger('click');
	//$("#open2").trigger('click');
	
	//MB - 04/11/2011
	if ($("#bloc_accordeon_ouvert").val() == 'hebergements'){
        $("#hebergements").trigger('click');
    } else {
        $("#forfaits").trigger('click');
    }

});

function ouvrir_accordeon(id_accordion) {

		//REMOVE THE ON CLASS FROM ALL BUTTONS
		$(id_accordion).removeClass('on');
		  
		//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
	 	$(id_accordion).slideUp('normal');
   
		//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
		if($(this).next().is(':hidden') == true) {
			
			//ADD THE ON CLASS TO THE BUTTON
			$(this).addClass('on');
			  
			//OPEN THE SLIDE
			$(this).next().slideDown('normal');
		 } 
		  
}

function div_cache(nomdiv)
{
var style = document.getElementById(nomdiv).style.visibility;
var display  = "block";
if (style != "hidden")
{
style ="hidden";
display = "none";
}
document.getElementById(nomdiv).style.visibility= style;
document.getElementById(nomdiv).style.display = display; 
}

function div_montre(nomdiv)
{
var style = document.getElementById(nomdiv).style.visibility;
var display  = "block";

if (style != "visible")
{
style ="visible";
display = "block";
}

document.getElementById(nomdiv).style.visibility= style;
document.getElementById(nomdiv).style.display = display; 
}

