/**
 * @author Chrisps - 2008 - chrisps@gmail.com
 * If you are looking at this code thinking of copying it, then please just drop me a line.
 * I am more than happy for my stuff to be re-used, but I'm always interested in where it is
 * going. Also, if you need anything explained to you, just ask.
 */

/**
 * This is called when the window is ready (i.e. when the DOM tree has loaded.
 * I use it mainly for setting up the re-sizing of the background.
 */
$(document).ready(function() {
	//Go and make sure the BG image is the correct size
	doCheckSize();
	//Make sure that it resizes all the time
	$(window).bind("resize", function(){
		doCheckSize();
	 });
	 
	//This is for page reloads
	setInterval("checkAnchor()", 300);
	//checkAnchor();
	
//	$("a").click(function() {
//    	alert($("#content").html());
//	});
	
//	document.getElementById('bgimage').style.display = 'none';
//	document.getElementById('logo').style.display = 'none';
//	document.getElementById('menu').style.display = 'none';
//	document.getElementById('menuzone').style.display = 'none';
//	document.getElementById('content').style.display = 'none';
});

/**
 * This will check the size of the background image and modify it to make sure
 * that it always fills the whole page. I need to work on making this a bit smarter
 * as at the minute it anchors in the top left, which is not ideal
 */
function doCheckSize()
{
		var $winwidth = $(window).width();		
		//I make all my bg images square
		//This just basically makes sure that it is always filling the page.
		$("img.source-image").attr({
			width: $winwidth
		});
}


var currentAnchor = null;  
/**This function is from http://yensdesign.com/2008/11/creating-ajax-websites-based-on-anchor-navigation/
 * to dynamically reload pages while maintaining "back button" capability
 */
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;  
		}  
		
		$("#content").hide();
		$.scrollTo(0,200,{queue:true});
		$("#loading").show();
		
		//Send the petition  
		$.get("be/ajaxserve.php",query, function(data){  
			document.getElementById('content').innerHTML = data;
			//For some really odd reason, the JQuery way of changing element HTML (below) doesnt work :\
			//$("#content").html(data); 
			$("#loading").hide();
			$("#content").show();
	        $('a[@rel*=lightbox]').lightBox();

			//Everything is ready, so show the site
			$("#menu").show();
			$("#menuzone").show();
			$("#logo").show();
			$("#content").show();
			$("#bgimage").show();
			
			document.styleSheets[0].addRule('div', 'behavior: url(iepngfix.htc)');
			document.styleSheets[0].addRule('img', 'behavior: url(iepngfix.htc)');
		}); 
	}  
} 

function getIPTC(imageName)
{
	$.get("be/ajaxserve.php","section=albums&imageinfo=caption&image="+imageName, function(data)
	{
		 document.getElementById('lightboxcaptionzone').innerHTML = data;
	});
}
