﻿//On load page, init the timer which check if the there are anchor changes each 300 ms
$().ready(function(){
	setInterval("checkAnchor()", 300);
});
var currentAnchor = null;
//Function which chek if there are anchor changes, if there are, sends the ajax petition
function checkAnchor(){
	//Check if it has changes
	if(currentAnchor != document.location.hash){
		currentAnchor = document.location.hash;
		//if there is not anchor, the loads the default section
		if(!currentAnchor)
			query = "section=intro";
		else
		{
			//Creates the  string callback. This converts the url URL/#main&id=2 in URL/?section=main&id=2
			var splits = currentAnchor.substring(1).split('&');
			//Get the section
			var section = splits[0];
			delete splits[0];
			//Create the params string
			var params = splits.join('&');
			var query = "section=" + section + params;
		}
		//Send the petition
		$.get("callbacks.php",query, function(data){
			$("#contenthold").html(data);
			languagechange = $("#language");
			if(section=="boutiquesEN" || section=="careersEN" || section=="pressEN" || section=="vipEN" || section=="aboutEN" ||  section=="contactEN"){
				didnavaway=1;
				menu_item_2.html('');
				menu_item_3.html('');
				menu_item_4.html('');
				menu_item_5.html('');
				menu_item_6.html('');
				menu_item_1.html('');
				menu_item_7.html('');
				menu_item_1.load("index_en.php #aboutwrap", hideLoading);
				menu_item_2.load("index_en.php #collectionswrap", hideLoading);
				menu_item_3.load("index_en.php #storeswrap", hideLoading);
				menu_item_4.load("index_en.php #careerswrap", hideLoading);
				menu_item_5.load("index_en.php #presswrap", hideLoading);
				menu_item_6.load("index_en.php #vipwrap", hideLoading);
				menu_item_7.load("index_en.php #contactwrap", hideLoading);
				menu_item_2.fadeIn(2400);
				menu_item_3.fadeIn(2400);
				menu_item_4.fadeIn(2400);
				menu_item_5.fadeIn(2400);
				menu_item_6.fadeIn(2400);
				menu_item_1.fadeIn(2400);
				menu_item_7.fadeIn(2400);
				$('div#language').html('<img src="images/francais.png" width="52" height="13" alt="Francais" id="lang_fr" />');
				languagechange.fadeIn(2400);	userlang="english";
			}
			if(section=="boutiquesFR" || section=="careersFR" || section=="pressFR" || section=="vipFR" || section=="aboutFR" ||  section=="contactFR")
				{
				didnavaway=1;
				menu_item_2.html('');
				menu_item_3.html('');
				menu_item_4.html('');
				menu_item_5.html('');
				menu_item_6.html('');
				menu_item_1.html('');
				menu_item_7.html('');
				document.getElementById("language").style.marginTop="-12px";
			
				menu_item_2.load("index_fr.php #collectionswrapfr", hideLoading);
				menu_item_3.load("index_fr.php #storeswrapfr", hideLoading);
				menu_item_4.load("index_fr.php #careerswrapfr", hideLoading);
				menu_item_5.load("index_fr.php #presswrapfr", hideLoading);
				menu_item_6.load("index_fr.php #vipwrapfr", hideLoading);
				menu_item_1.load("index_fr.php #aboutwrapfr", hideLoading);
				menu_item_7.load("index_fr.php #contactwrapfr", hideLoading);
				menu_item_2.fadeIn(2400);
				menu_item_3.fadeIn(2400);
				menu_item_4.fadeIn(2400);
				menu_item_5.fadeIn(2400);	
				menu_item_6.fadeIn(2400);	
				menu_item_1.fadeIn(2400);	
				menu_item_7.fadeIn(2400);
				$('div#language').html('<img src="images/english.png" width="46" height="9" alt="English" id="lang_en"/>');
				languagechange.fadeIn(2400);	userlang="french";
				}
			
		});
	}
}

