/* 
	functions-front.js
	===============================================================
	Wellington on a Plate
	CT: Frontend Functions
	
	Last Updated: See SVN	
	
	#t-* used to apply template level override of shared styles
	#st-* used to apply sub template level override of shared styles	
	
	Note that jQuery uses the jQuery shortcut (rather than $)
	to prevent conflicts with Prototype which is used by the backend.

	To sort, search for '@'		
	Debugging is via the Firebug // console: // console.debug
	---------------------------------------------------------------		

	Validation

	To assist with x-browser debugging, this file has been validated at http://www.jslint.com/, 
	with the following exceptions:
	* some implied globals	
	* some functions called before defined
	* some variables redefined
	* document.write used once
	
  ===============================================================
*/

/*
	@ detect_browser()
	---------------------------------------------------------------		
	browser detection - fails in an external function for some unknown reason...
	jQuery browser detection, based on user string.		
	http://docs.jquery.com/Utilities/jQuery.browser
	http://webdevel.blogspot.com/2008/07/overview-of-jquerybrowser.html				
	
	note: detected version is in fact version of render engine
	
	parseFloat on browser version doesn't work without .substring(0,3)
	as eg 1.1.1 is not a number (only 1 decimal is allowed in a number)
	_______________________________________________________________
*/			

	function detect_browser()
	{				
		var jbrowserVersion = parseFloat(jQuery.browser.version.substring(0,3));				
		
//		alert( 'jQuery.browser.version = ' + jQuery.browser.version + ', jbrowserVersion = ' + jbrowserVersion );
		
		if (jQuery.browser.mozilla)
		{						
			if (jbrowserVersion >= 1.8)
			{		
				jQuery.globals.isFirefox15up = true;
			}
			if (jbrowserVersion < 1.9)
			{				
				jQuery.globals.isFirefox2 = true;
			}
			if (jbrowserVersion >= 1.9)
			{				
				jQuery.globals.isFirefox3up = true;
			}					
		}
		else if (jQuery.browser.msie)
		{		
			if (jQuery.browser.version == 6.0)
			{
				jQuery.globals.isIE6 = true;				
			}			
			if (jQuery.browser.version >= 6.0)
			{
				jQuery.globals.isIE6up = true;				
			}			
		}
		else if (jQuery.browser.safari)
		{					
			if ( (jQuery.browser.version >= 522) || (jbrowserVersion >= 522) ) // latter for mac safari 3
			{			
				jQuery.globals.isSafari3up = true;				
			}				
			if ( (jQuery.browser.version >= 528) || (jbrowserVersion >= 528) )
			{		
				jQuery.globals.isSafari4up = true;				
			}	
			else if ( (jQuery.browser.version < 528) || (jbrowserVersion < 528) )
			{
				jQuery.globals.isSafari3down = true;					
			}				
		}		
		
		if ( jQuery.globals.isFirefox15up || jQuery.globals.isIE6up || jQuery.globals.isSafari3up )
		{
			isHiFi = true;
		}		
		
//		alert( 'jQuery.globals.isSafari3up = ' + jQuery.globals.isSafari3up );
		
		return isHiFi;			
	}
		
/*
	@ detect_platform()
	---------------------------------------------------------------		
	_______________________________________________________________
*/			
		
	function detect_platform()
	{
		var ua = navigator.userAgent.toLowerCase(); 
		var platform = '';			
		
		if (ua.indexOf('win') != -1)
		{
			platform = 'win';
		}
		else if (ua.indexOf('mac') != -1)
		{
			platform = 'mac';
		}
		else if (ua.indexOf('unix') != -1)
		{
			platform = 'unix';
		}
		else if (ua.indexOf('linux') != -1)
		{
			platform = 'linux';
		}		
		
		return platform;
	}
	
/*	
	@ hovers()
  ---------------------------------------------------------------
	_______________________________________________________________
*/		
	
	function hovers(el)
	{
		jQuery(el)
		.bind('focus, hover, mouseenter, mouseover', 
			function()
			{
				jQuery(this)
				.addClass('hover');				
				
				if (el == 'a.faux-button')
				{
					jQuery(this).find('.outer')
					.addClass('outer-hover');	
				}		
			}
		)
		.bind('blur, mouseleave, mouseout', 
			function()
			{
				jQuery(this)
				.removeClass('hover');					
				
				if (el == 'a.faux-button')
				{
					jQuery(this).find('.outer')
					.removeClass('outer-hover');	
				}											
			}
		);		
	}	
	
/*	
	@ load_script()
  ---------------------------------------------------------------
	_______________________________________________________________
*/		
	
	function load_script(filename)
	{
		// attach the stylesheet that contains the styles to output
		jQuery('head')
		.append(
			jQuery('<script/>')
			.attr(
				{
					type: 'text/javascript',
					src: filename
				}
			)
		);	
	}				
	
/*	
	@ browser_warning()
  ---------------------------------------------------------------
	_______________________________________________________________
*/			

	function browser_warning()
	{
		var w = '';
				
		w += '<p class="browser"><strong>This page works best in modern browsers. </strong></p>';
		w += '<p class="noscript note">Please upgrade to <a href="http://www.apple.com/safari/download/">Safari</a> 3<sup>+</sup>, ';
		w += '<a href="http://www.mozilla-europe.org/en/firefox/">Firefox</a> 2<sup>+</sup>, or ';
		w += '<a href="http://www.microsoft.com/windows/internet-explorer/default.aspx">Internet Explorer</a> 7<sup>+</sup>) ';		
		w += 'to get the most from this page. </p>';			
		
		document.write(w);			
	}	
	
/*	
	@ browser_warning_remove()
  ---------------------------------------------------------------
	#t-planner
	_______________________________________________________________
*/		

	function browser_warning_remove()
	{
		jQuery('#warning').remove();
	}
