//On load page, init the timer which check if the there are anchor changes each 300 ms
//center line under of flash
//image clicks

  var flashMovie;
  function init(){
    if(document.getElementById){
      flashMovie = document.getElementById("habFlash.swf");
    }
	alert("initialized");
  }
  window.onLoad = init;

$().ready(function(){
	setInterval("checkAnchor()", 50);
});
var currentAnchor = null;
var sub;
var oldSection = null;
var olderSection = 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=home";
		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;
			sub = params.split('=');
			sub = sub[1];
			olderSection = oldSection;
			oldSection = section;

		}
		//Send the petition
		$.get("callbacks.php",query, function(data){
//alert( typeof(olderSection));
			if(oldSection!= olderSection){
			//alert("old section" + oldSection + "section" + section + "olderSection "+olderSection);
			$("#homeFlash").addClass("hideClass");
			$("#oldContent").html("");
			$("#oldContent").show();
			$("#content").clone().appendTo('#oldContent').attr('id','#newThing');
			$("#oldContent").fadeOut(1000);
			$("#content").hide();
			$("#content").html(data);
			$("#content").fadeIn(1000);
			$("#content").removeClass();
			$("#content").addClass(sub);


			}else{
			//alert("old section" + oldSection + "section" + section);
	
				$("#content").html(data);
				$("#content").removeClass();
				$("#content").addClass(sub);
			}
			

			if(flashMovie){
      			flashMovie.sendTextToFlash(section);
    		}
		

		});
		//oldSection=section;
	}

}
