// JavaScript Document
recentHash = '';

$(document).ready(function() {

	// checks the hash for any values
	checkHash(); // this won't be caught by the back button
	//poll the hash continuously rather than looking for it onload..
	//its the only way to catch the back button	
	setInterval(pollHash,200);
	
	setUpNav();
});

function setUpNav()
{
	$('a#collections').click(
	function(event){
		$('ul#collectionsSubnav').slideDown(300);
	});
}


function checkHash()
{
	if (window.location.hash)
	{
		debug('page just loaded, there is a hash');
	}
}

function pollHash()
{
     if (window.location.hash==recentHash) {
       return; // Nothing's changed since last polled.
     }
     recentHash = window.location.hash;
	 // URL has changed, update the UI accordingly.
     parseHash(recentHash);
}

function parseHash(hash)
{
	if(hash.length > 0)
	{
		hash = hash.substr(1,hash.length);
		args = hash.split('/');

		debug('parsing hash elements '+args.length);
		// hook here.
		callmethod = args[0]+'AjaxCall';
		callargs = args.slice(1, args.length-1);
		if(window[callmethod] ) 
		{
			// function exists, so we can now call it
			window[callmethod](callargs);
		}
		else
		{
			debug(callmethod + ' not exists');
		}
	}
}



var eee = 0;
// ronseal
debug = function (log_txt) {
	if(!DEV_SERVER)
	{
		// do absolutley nothing, be quiet as a mouse.
		// shhh.
		return;
	}
    if (window.console != undefined) {
        console.log(log_txt);
    }
	else
	{
		//$('body').append('<div id="debugger'+eee+'" style="font-size:10px;border:1px solid #000;padding:3px">'+log_txt+'</div>');	
		//$('div#debugger'+eee).fadeOut(5000);
		//eee++;
	}
}


