//On load page, init the timer which check if the there are anchor changes each 300 ms
/*$().ready(function(){
	setInterval("checkAnchor()", 200);
});*/

var currentAnchor = null;
//Function which check if there are anchor changes, if there are, sends the ajax petition


function checkAnchor(){

	var target  = "popupBox";

	$(window).resize(function() {
		centerPopup(target);
	});


	//Check if it has changes
	if(currentAnchor != document.location.hash || $('#save_url').attr('data') == ""){

		currentAnchor = document.location.hash;
		//if there is not anchor, the loads the default section
		if(!currentAnchor || currentAnchor == '#fresh_reload')
			window.location = "/#home";
		else
		{
			var query = currentAnchor.substring(1, currentAnchor.length);
		}
		
		// if page is a blog/article page
		if( query.substring(0, 5) == "blog/" )
		{ 
			var splits = query.split('/');
			
			getArticle(splits[1]);
			
			popupStatus = 0;
			//centering with css
			
			//load popup
			setTimeout('centerPopup( \'' + target + '\' ); loadPopup( \'' + target + '\' );', 200);
			
			// if no previous non-blog page saved, defaults to #home
			if(!$('#save_url').attr('data')){
				$('#save_url').attr('data', '#fresh_reload');
			}
		}
		else // all other pages
		{
			disablePopup(target);

			if($('#save_url').attr('data') != document.location.hash)
			{
				$('#save_url').attr('data', currentAnchor);
			
			
				//Send the petition
				$.ajax({
				  url: '/tbd/' + query,
				  beforeSend: function(){
					$('#main_col').html("<div id=\"pageLoader\" class=\"hide\"></div>");
					$('#pageLoader').fadeIn('slow');
				  },
				  success: function(data) {
					$('#pageLoader').fadeOut('fast');
					$('#main_col').html(data);
				  }
				});
			}
		}
	}
}

