/**
 * Onload
 */
$(document).ready(function(){
	
	/* preload specified images */
	var preloadImages = new Array(
			"/images/graf_top_banner.png",
			"/images/graf_middle_banner.png",
			"/images/graf_bottom_banner.png"
	);
	for(var i = 0; i<preloadImages.length; i++)
	{
		$("<img>").attr("src", preloadImages[i]);
	}
	
});

/**
 * Since IE has some serious issues with the lightbox, I've decided to 
 * simply redirect IE6 users to the static page we use for deep-linking.
 *
 * This block of code builds the hash from the clicked element href and 
 * updates the url so that deeplinks can by copied and pasted and still work.
 *
 * In the case of IE, we just set a new url, which causes redirect and the 
 * hash-redirector to pick up and redirect. Tricky.
 * 
 */
function imageLoadCompleteHandler(objId)
{
  var generatedURL = document.getElementById(objId).getAttribute('href');
  var currentHost = 'http://' + document.location.hostname;

  // if the generatedURL (from the object href) contains the http + host, we remove the host to get the request path.
  var requestPath; 
  if(generatedURL.indexOf(currentHost) > -1){ requestPath = generatedURL.substring(currentHost.length,generatedURL.length); }
  else{ requestPath= generatedURL; }

  // if IE, redirect to the page, else just tag the ajax url on the hash.
  if( ($.browser.msie && parseInt(jQuery.browser.version) <= 6) ||
	  (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)))
  { 
	  document.location.href = 'http://' + document.location.hostname + requestPath; 
  }
  else 
  { 
    $('#'+objId).lightBox()(document.getElementById(objId));
      document.location.hash = requestPath; 
    }
    
  return false;
}

/**
 * Generic function to swap the header images out on the frontend. 
 */
function krylonBomb()
{
	$('#topImage').addClass('topGraf').removeClass('topNormal');
	$('#middleImage').addClass('middleGraf').removeClass('middleNormal');
	$('#bottomImage').addClass('bottomGraf').removeClass('bottomNormal');
	
}