var margin = '0px';
var slideTime = 1000;
var menucss1 = 'menu_footer_selected';
var menucss2 = 'menu_footer_notselected';
var menucss3 = 'menu_footer_notselected';
var menucss4 = 'menu_footer_notselected';
var menucss5 = 'menu_footer_notselected';

jQuery.preloadImages = function()
{
	for(var i = 0; i<arguments.length; i++)
	{
		jQuery("<img>").attr("src", arguments[i]);
	}
}

$.preloadImages("../images/grandes/table/haute/01.jpg", "../images/grandes/table/haute/02.jpg", "../images/grandes/table/haute/03.jpg", "../images/grandes/table/haute/04.jpg", "../images/grandes/table/basse/01.jpg", "../images/grandes/table/basse/02.jpg");


/*
function getMargin()
{
	winHeight  = $("#conteneur").height(); 
	firstOne = $("#firstOne").height();
	
	
	$("#wrapper").height(winHeight-380);
	
	$("#secondOne").height($("#wrapper").height());
	
	marginTop = ((winHeight-210) - firstOne)/2;
	$("#wrapper").css("margin-top", marginTop);
}
*/


function switchAjax(wich, where)
{
	$(where+ " .leftContent").load("includes/" + wich +".php");
	$(where+ " .rightContent").load("includes/rightContent_" + wich +".php", function (responseText, textStatus, XMLHttpRequest) {
  		if(textStatus == 'success')
		{
			//getMargin();
			$("#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);
				//getMargin();
			});
			
		}
	});
}





function moveto(whereto)
{
	switch(whereto){
	// première section //
	case 'MrsIppy':
		margin = '0px';
		menucss1 = 'menu_footer_selected';
		menucss2 = 'menu_footer_notselected';
		menucss3 = 'menu_footer_notselected';
		menucss4 = 'menu_footer_notselected';
		menucss5 = 'menu_footer_notselected';
		break;
		
	// seconde section //
	case 'Big-Daisy':
		margin = '-1750px';
		menucss1 = 'menu_footer_notselected';
		menucss2 = 'menu_footer_selected';
		menucss3 = 'menu_footer_notselected';
		menucss4 = 'menu_footer_notselected';
		menucss5 = 'menu_footer_notselected';
		break;

	
	
	// troisième section //
	case 'Little-Daisy':
		margin = '-3500px';
		menucss1 = 'menu_footer_notselected';
		menucss2 = 'menu_footer_notselected';
		menucss3 = 'menu_footer_selected';
		menucss4 = 'menu_footer_notselected';
		menucss5 = 'menu_footer_notselected';
		break;

	// quatrième section //
	case 'Scripto':
		margin = '-5250px';
		menucss1 = 'menu_footer_notselected';
		menucss2 = 'menu_footer_notselected';
		menucss3 = 'menu_footer_notselected';
		menucss4 = 'menu_footer_selected';
		menucss5 = 'menu_footer_notselected';
		break;

	// cinquième section //
	case 'BellaX':
		margin = '-7000px';
		menucss1 = 'menu_footer_notselected';
		menucss2 = 'menu_footer_notselected';
		menucss3 = 'menu_footer_notselected';
		menucss4 = 'menu_footer_notselected';
		menucss5 = 'menu_footer_selected';
		break;
	}
	
	// animation de la page //
	$("#wrapper").animate({ marginLeft: margin }, slideTime);
		
	// on nettoye les styles des boutons du footer //
	$("#tableBasseBTDiv").removeClass();
	$("#tableBTDiv").removeClass();
	$("#chaiseBTDiv").removeClass();
	$("#styloBTDiv").removeClass();
	$("#lampeBTDiv").removeClass();	
	$("#horlogeBTDiv").removeClass();

	
	// on applique les nouveaux styles //
	$("#tableBasseBTDiv").addClass(menucss3);
	$("#tableBTDiv").addClass(menucss2);
	$("#chaiseBTDiv").addClass(menucss1);
	$("#styloBTDiv").addClass(menucss4);
	$("#lampeBTDiv").addClass(menucss5);
	//$("#horlogeBTDiv").addClass(menucss5);
	
}




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

$(document).ready(function(){
	

switchAjax("MrsIppy", "#firstOne");
switchAjax("Big-Daisy", "#secondOne");
switchAjax("Little-Daisy", "#thirdOne");
switchAjax("Scripto", "#fourthOne");
switchAjax("BellaX", "#fifthOne");


// On retrouve la section de la gallerie jquery pour les bookmarks //
var wheretoUrl = location.href.split("#");
var urlLength = $(wheretoUrl).size();

if(urlLength>1)
{

	var wheretoA = wheretoUrl[1].split("_");
	var whereto = wheretoA[0];
	var wheretoSub = wheretoA[1];
	switch(whereto){
	// première section //
	case 'Big-Daisy':
		wich = '#secondOne';
		break;
		
	case 'Little-Daisy':
		wich = '#thirdOne';
		break;
	
	case 'MrsIppy':
		wich = '#firstOne';
		break;
	
	case 'Scripto':
		wich = '#fourthOne';
		break;
		
	case 'BellaX':
		wich = '#fifthOne';
		break;
	}
	
	switchAjax(whereto+"_"+wheretoSub, wich);


} else { var whereto = wheretoUrl[0]; }



if(whereto!='')
{
	
	moveto(whereto);
	
}else{	whereto = 'Big-Daisy';	}
	

	// on click sur les boutons du footer (galleries) //
	$("a#tableBT").click(function(){moveto('Big-Daisy')});
	$("a#tableBasseBT").click(function(){moveto('Little-Daisy')});
	$("a#chaiseBT").click(function(){moveto('MrsIppy')});
	$("a#styloBT").click(function(){moveto('Scripto')});
	$("a#lampeBT").click(function(){moveto('BellaX')});	
	

/*	
	$(window).bind('resize', function(){
			getMargin();
	});
*/
	
});