/**
 *	@desc	This file contains all local javascripts that are needed for the vdbj website.
 *	@author	Niels Bartels <niels@7u.nl>
 */

// Fire up the document ready method of jquery.
$(document).ready(function()
{
	// Make sure all "a tags" are visible untill the font files are fully loaded.
	$(".nav").css("visibility", "hidden");
	$("a").css("visibility", "hidden");
});

// Fires up the window load method of jquery (when all resources are loaded properly).
$(window).load(function()
{
	// Make the links visible, no font hickups anymore.
	$("a").css("visibility", "visible");
	$(".nav").css("visibility", "visible");

	if($("#img_home").length != 0)
	{
		// Get access to the source for the header image.
		headerImage = $("#scalesize").attr("rel");
			
		// Clear the rel attribute.
		$("#scalesize").attr("rel", "");
		
		// Hide the image.
		$("#scalesize").hide();
		
		// Generate a random string.
		if($.browser.msie)
		{
			headerImage = headerImage + "#" + randomString();
		}
		
		// Change the source of the image (now loading the full header background image.
		$("#scalesize").attr("src", headerImage);
		
		// Not cached yet, lets render it when it's loaded.
		$("#scalesize").load(function()
		{
			// Render the header image.
			renderHeaderImage();
		});
	}
});

function renderHeaderImage()
{
	// Scale the background.
	$("#img_home").backgroundScale({
		imageSelector: "#scalesize",
		centerAlign: false
	});
		
	$("#scalesize").fadeIn("slow");
}

function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 20;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}
