﻿// On load page, init the timer which check if the there are anchor changes each 300 ms
$().ready(function(){
	setInterval("checkAnchor()", 1);
});
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;
		
		//check last element of url
		var loc_array = document.location.href.split('/');

		//assign non anchor starting place
		if((!currentAnchor) && (loc_array[loc_array.length-1] == 'building')){
			query = "section=building";
		} else if((!currentAnchor) && (loc_array[loc_array.length-1] == 'experience')){
			query = "section=experience";
		} else if((!currentAnchor) && (loc_array[loc_array.length-1] == 'developer')){
			query = "section=developer";
		} else if((!currentAnchor) && (loc_array[loc_array.length-1] == 'space-available')){
			query = "section=space-available";
		} 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("http://500capitolmall.com/scripts/callbacks.php",query, function(data){
			$(".content-area").html(data).hide();
			$(".content-area").fadeIn(200);
		});
	}
}
