


$.getDocHeightJQ = function()
{
     var D = document;
     return Math.max(Math.max(D.body.scrollHeight,    D.documentElement.scrollHeight), Math.max(D.body.offsetHeight, D.documentElement.offsetHeight), Math.max(D.body.clientHeight, D.documentElement.clientHeight));
};


// ---------------------------------------------------------------------------------------
//
function init()
{

	$('#HeroImagesFade').innerfade({
			speed: 2000,
			timeout: 5000,
			type: 'sequence'
	});
	
	
	$('#Ticker').innerfade({
			speed: 1500,
			timeout: 4000,
			type: 'sequence'
	});	

	 //safe mailto's
	 $('a[href*="[at]"][href*="[dot]"]').each(function() {
	  var email = $(this).attr('href').split('[at]').join('@').split('[dot]').join('.');
	  $(this).attr('href', 'mailto:' + email.toLowerCase());
	  if ($(this).text().length == 0) $(this).text(email);
	 });

/*
	var canvas = document.getElementById('backgroundGradientCanvas');	
	if (canvas.getContext) { } else { }
			
	window.addEventListener('resize', windowWasResized, false);
	
	drawBgGradient();	
*/
	//alert( $.getDocHeightJQ() );
	//alert( "" + getDocHeight() + ", " + $.getDocHeightJQ() );

}

// ---------------------------------------------------------------------------------------
//
function windowWasResized()
{
	drawBgGradient();	
	
	//alert( "" + getDocHeight() + ", " + $.getDocHeightJQ() );	
}

// ---------------------------------------------------------------------------------------
//
function drawBgGradient()
{
	var canvas = document.getElementById('backgroundGradientCanvas');
	if (canvas.getContext)
	{	
		//document.getElementById("backgroundGradientCanvas").setAttribute("height", getDocHeight() + "px" );
	
		var $body = $(this.ie6 ? document.body : document); // using document in ie6 causes a crash		
		//alert( $body.height() );
		
		var windowWidth  = $body.width(); //window.innerWidth;
		var windowHeight = getDocHeight(); //$body.height(); //window.innerHeight;			
					
		//alert( $(window).height() + ", " + $body.height() + ", " + $(document).height() );
								
		// clear it!!
		canvas.width  = windowWidth; 
		canvas.height = windowHeight;			
				
		var ctx = canvas.getContext('2d');
		
		var myGradient = ctx.createLinearGradient(0, 0, 0, windowHeight);
		
		// calculate the stop, get the height of the window, calculate what percentage gives us X amount of pixels of gradient on the bottom.
		
		var desiredBottomGradientPixels = 190;
		var desiredBottomGradientFraction = desiredBottomGradientPixels / windowHeight;
		
		myGradient.addColorStop(0, "rgb(246,246,246)");			

		myGradient.addColorStop((1.0 - desiredBottomGradientFraction), "rgb(246,246,246)");			
		
		myGradient.addColorStop(1.0, "rgb(162,162,162)");
		
		ctx.fillStyle = myGradient;
		ctx.fillRect(0, 0, windowWidth, windowHeight);	
		
		//alert( windowWidth + ", " + windowHeight + "   0.0 " + (1.0 - desiredBottomGradientFraction) + " 1.0" );
	}
}

// ---------------------------------------------------------------------------------------
//
function getDocHeight() 
{
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}
