
//On load page, init the timer which check if the there are anchor changes each 300 ms
$().ready(function(){
	setInterval("checkAnchor()", 500);
});
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;
		//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;
			var url = section + params;
		}
		//Send the petition
		$("#content").append('<span id="load"></span>').fadeIn("fast");
		$.get("callbacks.php",query, function(data){
				
		//console.log(url);
		if (url == "home") {		
			$("#header").css("backgroundImage", "url(images/header_bg.jpg)");
			$("#wrapper").css("backgroundImage", "url(images/body_bg.jpg)");
		} else if (url == "bio") {
			$("#header").css("backgroundImage", "url(images/header_bio_bg.jpg)");
			$("#wrapper").css("backgroundImage", "url(images/body_bio_bg.jpg)");
		} else if (url == "portfolio") {
			$("#header").css("backgroundImage", "url(images/header_bg.jpg)");
			$("#wrapper").css("backgroundImage", "url(images/body_bg.jpg)");
			$.getScript("js/additional.js");
		} else if (url == "artwork") {
			$("#header").css("backgroundImage", "url(images/header_artwork_bg.jpg)");
			$("#wrapper").css("backgroundImage", "url(images/body_artwork_bg.jpg)");
			$.getScript("js/jquery.lightbox-0.5.js");
			$.getScript("js/additional.js");
		} else if (url == "photography") {
			$("#header").css("backgroundImage", "url(images/header_zoo09_bg.jpg)");
			$("#wrapper").css("backgroundImage", "url(images/body_zoo09_bg.jpg)");
			$.getScript("js/jquery.lightbox-0.5.js");
			$.getScript("js/additional.js");
		} else if (url == "contact") {
			$("#header").css("backgroundImage", "url(images/header_bg.jpg)");
			$("#wrapper").css("backgroundImage", "url(images/body_bg.jpg)");
		} else if (url == "links") {
			$("#header").css("backgroundImage", "url(images/header_bg.jpg)");
			$("#wrapper").css("backgroundImage", "url(images/body_bg.jpg)");
			$.getScript("js/additional.js");
			$.getScript("js/jquery.favicons.js");
		} else if (url == "site_map") {
			$("#header").css("backgroundImage", "url(images/header_bg.jpg)");
			$("#wrapper").css("backgroundImage", "url(images/body_bg.jpg)");	
		} else if (url == "butterfly_pavilion") {
			$("#header").css("backgroundImage", "url(images/header_butterfly_bg.jpg)");
			$("#wrapper").css("backgroundImage", "url(images/body_butterfly_bg.jpg)");	
			$.getScript("js/jquery.lightbox-0.5.js");
			$.getScript("js/additional.js");
		} else if (url == "insects_flowers") {
			$("#header").css("backgroundImage", "url(images/header_insectsFlowers_bg.jpg)");
			$("#wrapper").css("backgroundImage", "url(images/body_insectsFlowers_bg.jpg)");	
			$.getScript("js/jquery.lightbox-0.5.js");
			$.getScript("js/additional.js");
		} else if (url == "insects_flowers09") {
			$("#header").css("backgroundImage", "url(images/header_insectsFlowers_bg.jpg)");
			$("#wrapper").css("backgroundImage", "url(images/body_insectsFlowers_bg.jpg)");	
			$.getScript("js/jquery.lightbox-0.5.js");
			$.getScript("js/additional.js");				
		} else if (url == "fall_colors08") {
			$("#header").css("backgroundImage", "url(images/header_fall08_bg.jpg)");
			$("#wrapper").css("backgroundImage", "url(images/body_fall08_bg.jpg)");	
			$.getScript("js/jquery.lightbox-0.5.js");
			$.getScript("js/additional.js");	
		}	
		
		
			$("#content").hide().html(data).fadeIn("slow");
				$("h3").click(function(){
					var nextDiv = $(this).parent().next();
					console.log(nextDiv);
					$(nextDiv).slideToggle(1100);
				});
			$("#loading").hide("slow");
		});
	}
}


/*
// Home What's New Accordian
$(function(){
	$("div.currentWebsitesBar").hide();
	$("div.whatsNew > h3").click(function(){
		var $nextDiv = $(this).next();
		var $visibleSiblings = $nextDiv.siblings("div:visible");		
		if ($visibleSiblings.length) {
			$visibleSiblings.slideUp("slow", function(){
				$nextDiv.slideToggle("slow");
			});
		} else {
			$nextDiv.slideToggle("slow");
		}
	});
});
*/

// Main navigation
/*$(function(){
$("#sidenav a").click(function(e){
	var url = $(this).attr("href");
	//console.log(url);
	// make the current sidenav link black bold
	$("#sidenav a").removeClass("selected");
	$("#footerNav a").removeClass("selected");
	//$(this).addClass("selected");
    // Find the #footerNav <a> that have the same URL as the selected #sidenav <a>
    $("#footerNav a[href=" + url + "]").addClass("selected");
    // add arrow to current link
    $("strong.arrow").remove();
    $(this).addClass("selected");
    $(this).prepend("<strong class=\"arrow\">&raquo; </strong>");
  });  
}); */

/*
$(function(){
	$("div.currentWebsites").eq(0).hide();
	//$("div.aboutMe").eq(0).slideDown(1300);
	//$("div.aboutMe").siblings("div:last").slideDown(1300);
});
*/

// Footer navigation
 $(function(){
  $("#footerNav a").click(function(e){
      var footerURL = $(this).attr("href");
      $("#footerNav a").removeClass("selected");
      $("#sidenav a").removeClass("selected");
      $("strong.arrow").remove();
      $(this).addClass("selected");
      // Find the #sidenav <a> that have the same URL as the selected #footerNav <a>
      $("#sidenav a[href=" + footerURL + "]").addClass("selected");
      //$(this).prepend("<strong class=\"arrow\">&raquo; </strong>");
      // Find the #sidenav <a> that have the same URL as the selected #footerNav <a>
      $("#sidenav a[href=" + footerURL + "]").prepend("<strong class=\"arrow\">&raquo; </strong>");
  });   
}); 

/*
$(function(){
	$('.gallery, .galleryTitle, #photoNav li a, ul.siteMap li a').livequery('click', function(e) {
	$("#content .galleryTitle").siblings(".gallery").hide();
	$("#content .galleryTitle:first").next().show(".gallery").fadeIn("slow");
	//$("#content .galleryTitle").next(".gallery").slideToggle("normal").siblings(".gallery").slideUp("normal");
	e.preventDefault();
	});
});


// This function will dynamic pull in the js file for each page
$(function(){
$("#sidenav a, #footerNav a, #photoNav a").click(
  function(){
	$.getScript("js/additional.js");
	$.getScript("js/jquery.lightbox-0.5.js");
  });	
}); 

*/