// ==============================================================================================================
// Browser detection functions
// Loosely inspired by jQbrowser : http://davecardwell.co.uk/geekery/javascript/jquery/jqbrowser/
// ==============================================================================================================

function isBrowserMsie()
{
	return /MSIE/.test(navigator.userAgent) ;
}

function browserVersion()
{
	var browserVersion = 0 ;
	
	// Currently only implemented for MSIE
	if(isBrowserMsie())
		browserVersion = parseFloat(navigator.userAgent.match(/MSIE (\d+(?:\.\d+)+(?:b\d*)?)/)[1]) ;
	return browserVersion ;
}



// ==============================================================================================================
// email address utilities
// ==============================================================================================================

function decodeAddress()
{
	var encodedStr = "^RZ]e`+WZcdeT`_eRTe1a`Xa]RjXc`f_UT`^" ;
	var decodedStr = "" ;
	for(var i = 0 ; i < encodedStr.length ; i++)
	{
		decodedStr = decodedStr + String.fromCharCode(encodedStr.charCodeAt(i) + 15) ;
	}
	return decodedStr
}

function encodeAddress()
{
	var str = "" ;
	var encodedStr = "" ;
	for(var i = 0 ; i < str.length ; i++)
	{
		encodedStr = encodedStr + String.fromCharCode(str.charCodeAt(i) - 15) ;
	}
	return encodedStr
}

function getEmailAddress()
{
	return decodeAddress() ;
	//return "mailto:" + encodeAddress() ;
}



// ==============================================================================================================
// debug functions
// ==============================================================================================================

function getInfo()
{
	alert("display=" + $("#largerIllustration1").css("display") + " ; opacity=" + $("#largerIllustration1").css("opacity")) ;
	//<br /><br /><br /><br /><a href="javascript:getInfo();">get info</a>
}



// ==============================================================================================================
// Load handler
// ==============================================================================================================

function onLoadHandler()
{
	tweakRendering() ;
	if(this._onLoadHandler)
		// Call specific load handler for the page
		_onLoadHandler() ;
}

$(document).ready( function() { onLoadHandler() ; } ) ;



// ==============================================================================================================
// Screen size spy
// ==============================================================================================================

function getScreenSize()
{
	var urlStr = "../scripts/s.py.cgi?" + screen.width + "x" + screen.height + "x" + screen.pixelDepth + "x" + screen.colorDepth ;
	$.ajax({type: 'GET', url: urlStr, dataType: "xml"}) ;
}



// ==============================================================================================================
// Browser specific optimization (or behaviorial workarounds)
// ==============================================================================================================

function tweakRendering()
{
	$("#headerContainer").load("header.html", function(responseText, status, res) {
		if(status != "success")
			$("#headerContainer").load("../header.html") ;
	} ) ;
	$("#footerContainer").load("footer.html", function(responseText, status, res) {
		if(status != "success")
			$("#footerContainer").load("../footer.html") ;
	} ) ;
}


