$(document).ready(function(){

	var currLang; 

	// language selection
	var langSelect = $("#langSelect").text();
	if(langSelect=="EN"){
		currLang="BG"
		}else{
		currLang="EN"
	}
	
	
	//site navigation array
	var siteNav = {
		HOME:['0', 'HOME', 'home.html', 'en_home.html']
		, MANIFESTO:['1', 'MANIFESTO', 'manifest.html', 'en_manifest.html']
		, FORUM:['2', 'FORUM', 'forum.html', 'en_forum.html']
		, REGISTRATION:['2_1', 'REGISTRATION', 'registracia.html', 'en_registracia.html']
		, REGISTRATIONTHANKS:['2_1_1', 'REGISTRATIONTHANKS', 'registracia.done.html', 'en_registracia.done.html']
		, EXPOSITIONS:['3', 'EXPOSITIONS', 'expositions.html', 'en_expositions.html']
		, LECTURERS:['4', 'LECTURERS', 'lektori.html', 'en_lektori.html']
		, WORKSHOPS:['5', 'WORKSHOPS', 'workshops.html', 'en_workshops.html']
		, BLOG:['6', 'BLOG', 'http://sofiadesignweek.com/blog', 'http://sofiadesignweek.com/blog']
		, PARTNERS:['7', 'PARTNERS', 'partners.html', 'en_partners.html']
		, PRESS:['8', 'PRESS', 'press.html', 'en_press.html']
		, CONTACTS:['9', 'CONTACTS', 'contact.html', 'en_contact.html']
	};	

	//load content 
	function pageload(hash) {
		if(hash) {
			
			document.title = 'SOFIA DESIGN WEEK - ' + siteNav[hash][1]; // set document title

			if(currLang=="BG"){
				urlToLoad=siteNav[hash][2];
			}else{
				urlToLoad=siteNav[hash][3];
			}
			
			pageTracker._trackPageview("'/" + siteNav[hash][1] + "'");
			
		} else {
		
			if(currLang=="BG"){
				urlToLoad=siteNav['HOME'][2];
			}else{
				urlToLoad=siteNav['HOME'][3];
			}
			
		}
		
		 //
		 
		 checkCurrent(hash);
		 
		
		 
		$("#container").load(urlToLoad, function(){
			 document.getElementById('container').scrollTop=0;
		}); 
		

			
	}
	
	
	  function checkCurrent(current) {
			$("#navigation a").each(function(i){
				$(this).removeClass("selected");
			
				if($(this).attr("href") == "#" + current){
					$(this).addClass("selected");
				};
			 });	
	  };
	  

	//handle links from the AJAX loaded content
	$("#container a[rel*=internal]").live("click", function(){
		$("#container").load(this.href);
		return false;					
	});

	//handle  container
	$("#container a[rel*=history]").live("click", function(){
		hash = this.href;
		hash = hash.replace(/^.*#/, '');
		$.historyLoad(hash);
		return false;
	});
	
	
	//handle  navigation panel
	$("a[rel*=history]").click(function(){
		hash = this.href;
		hash = hash.replace(/^.*#/, '');
		$.historyLoad(hash);
		return false;
	});


	$("#navigation").draggable(); // make the navigation panel draggable
	$.historyInit(pageload);

});