var margin = '0px';
var slideTime = 1000;


function switchAjax(wich, where)
{
    $(where+ " .leftContent").load("/includes/products/leftContent_" + wich +".php");
    $(where+ " .rightContent").load("/includes/products/rightContent_" + wich +".php?entrance=1", function (responseText, textStatus, XMLHttpRequest) {
            if(textStatus == 'success')
            {
                    $("#nav1").droppy({speed: 100});
                    $("#nav2").droppy({speed: 100});
                    $(".subLinkOne").click(function () {
                            var arg = $(this).attr("id").split("_");
                            var argLength = $(arg).size();
                            if(argLength==3)
                            {
                            var wich = $(this).attr("id").split("_")[1]+"_"+$(this).attr("id").split("_")[2];
                            }else{var wich = $(this).attr("id").split("_")[1];}

                            var where = "#"+$(this).attr("id").split("_")[0];
                            switchAjax(wich, where);
                    });

            }
    });
}





function moveto(whereto)
{
    whereto = whereto.substr(1);
    switch(whereto){
        // première section //
        case 'firstOne':
        margin = '0px';
        break;

        // seconde section //
        case 'secondOne':
        margin = '-1750px';
        break;

        // troisième section //
        case 'thirdOne':
        margin = '-3500px';
        break;
    }
	
    // animation de la page //
    $("#wrapper").animate({ marginLeft: margin }, slideTime);
}




var winHeight  = $(window).height(); 
var marginTop;
var firstOne;

$(document).ready(function(){
	
	// On retrouve la section de la gallerie jquery pour les bookmarks depuis l'url courante //
	var wheretoUrl = location.href.split("#");
	var urlLength = $(wheretoUrl).size();
        var wich = '#firstOne';

        //Si on a bien une url qui contient une valeur après #
	if(urlLength>1)
	{
            var wheretoA = wheretoUrl[1].split("_");
            var whereto = wheretoA[0];
            var wheretoSub = wheretoA[1];
			
			
			for(i=0; i<$jsProd.length; i++){
				//alert($jsProd[i][0]+' = '+whereto);
               if($jsProd[i][0]==whereto){
                   wich = '#'+$jsProd[i][1];
               }
            }

            if(wheretoSub){
                whereto = whereto+"_"+wheretoSub;
            }
                
	} else { var whereto = wheretoUrl[0]; }


        //Si on a déjà un nom d'article dans la barre d'adresse
	if(whereto!=''){ moveto(wich);}

        var $selectedTab = wich.substr(1);
        $('#to_'+$selectedTab).addClass('selected');


	// on click sur les boutons du footer (galleries) //
        $('.bottom_tab').click(function(){
            $whereTo = $(this).attr('id');
            
            $(this).parent().find('.bottom_tab').removeClass('selected');
            $(this).addClass('selected');
            $whereTo = $whereTo.substr(3);
            moveto('#'+$whereTo);
        });
	
});
