// JavaScript Document

	

//run this when the HTML is done downloading
$(function(){
	
	//defining the variables
	
	//add div "loading" to DOM
	$("#content-area").before("<div style='display: none;' id='loading'><p class='highlight'><img src='images/ui/hat_blinking.gif' width='20' height='11' alt='hat' /> Loading...</p></div>");
	
	
	//Preload Images
	$.preloadImages("/images/ui/bg_bar_bl.gif", "/images/ui/hat_blinking.gif");
	

	

	
});

//do this stuff when the HTML is all ready
$(document).ready(function(){
	//init the timer which check if the there are anchor changes each 300 ms
    setInterval("checkAnchor()", 300);
	
	//make share buttom visible
	$("#share").css("visibility", "visible");
	$("#login").css("visibility", "visible");
	
	$.formFieldFocusBlur("#login_form");
	
	$.formSender("#registerArea");
	
	
	
	$("#menubar #menuItemsLeft a").click (function () {
		location.hash=$(this).attr("href").substring(0, $(this).attr("href").length - 4);
		return false;
	});
	
});

var currentAnchor = null;

function checkAnchor(){

    //Check if it has changes
    if(document.location.hash != ""){
		if(currentAnchor != document.location.hash){  
			currentAnchor = document.location.hash;
			
			$.ajax({
				url: location.hash.substring(1) + ".php",
				data: {AJAX:'1'},
				type: 'GET',
				dataType: 'html',
				//timeout: 1000,
				beforeSend: function(){
					$("#content-area").hide();
					$("#loading p").html("<img src='images/ui/hat_blinking.gif' width='20' height='11' alt='hat' /> Loading...");
					$("#loading").show();
				},
				error: function(){
					$("#loading").hide();
					location="http://www.nestoor.com/404.php?url="+location.hash.substring(1) ;
					//$.get("404.php", {AJAX:'1'}, function(data){  
					//$("#content-area").html(data);}
					//)
				},
				success: function(data){
					//$("#content-area").html(data);
					$("#loading").hide();
					$("#content-area").html(data).show();  
				}
			});
		}
	}else{
		if(document.location == "http://www.nestoor.com/"){
			//document.location.hash="index";
			//currentAnchor = "#index";
			$("#content-area").show();
		}else{
			document.location="http://www.nestoor.com/#" + document.location.pathname.substring(1, location.pathname.length - 4);
		}
		//alert(currentAnchor);
		$("#content-area").show();
	}  
}
