/* Copyright (c) 2009 WhiteInteractive
 *
 * Version: 4.0
 *
 * Requires: jQuery 1.3.1+, jQuery Cookie plugin
 */

(function($){
		  
	$.visualTweaks = function() {
		// ********************************************************************** 
		// Make any section or page specific visual tweaks
		// **********************************************************************
		
		// Highlight the selected section in the top navigation
		if ($('.weDesign #markerDesign').size() > 0) {
			$('#section2 a').addClass("selectedSection");
		} else if ($('.weBuild #markerBuild').size() > 0) {
			$('#section3 a').addClass("selectedSection");
		} else if ($('.wePromote #markerPromote').size() > 0) {
			$('#section4 a').addClass("selectedSection");
		} else if ($('.weSupport #markerSupport').size() > 0) {
			$('#section5 a').addClass("selectedSection");
		} else if ($('.frontPage #whatWeDo').size() > 0) {
			$('#section1 a').addClass("selectedSection");
		}
		
		// Tidy up the bottom of the sub-navigation list
		$('#subNavigation ul li:last').css('margin-bottom','0px');
		
		// IE6 has display problems (not unsurprisingly) - display an upgrade message!
		if($.browser.msie) {
			if($.browser.version == "6.0") {
				if ($.cookie('ie6') != "1") {
					$('#IE6').show();
					
					$('#messageCloseButton img').bind('click',function(event) {
						$('#IE6').hide();
						$.cookie('ie6','1');
					});
				}
			}
		}
		
		// Flash version needs to be at least 10 - display an upgrade message if older
		var version = getFlashVersion().split(',');
		var vMaj = new Number(version.shift());
		var vMin = new Number(version.shift());
		var vRev = new Number(version.shift());
		var bOldFlash = false;
		
		if (vMaj < 10) {
			bOldFlash = true;	
		}
		
		if (bOldFlash) {
			if ($.cookie('flash') != "1") {
				$('#oldFlash').show();
				
				$('#messageFlashCloseButton img').bind('click',function(event) {
					$('#oldFlash').hide();
					$.cookie('flash','1');
				});
			}
		}
	}
	
	$.fontSize = function() {
		// ********************************************************************** 
		// If the fontsize cookie is set then the site fontsize is increased
		// **********************************************************************
		
		if ($.cookie('fontsize') == "1") {
			$('body').css("font-size","75%");
		} else if ($.cookie('fontsize') == "2") {
			$('body').css("font-size","85%");
		}	
	}
	
	function saveFontSize(i) {
		// ********************************************************************** 
		// Saves the font size as a cookie or deletes as appropriate
		// **********************************************************************
		
		if (i == '1') {
			$.cookie('fontsize','1');
			$('body').css("font-size","68%");
		} else if (i == '2') {
			$.cookie('fontsize','2');
			$('body').css("font-size","75%");
		} else { 
			$.cookie('fontsize', null);
			$('body').css("font-size","62.5%");
		}
	}
	
	$.createFontSizeLinks = function() {
		// ********************************************************************** 
		// Attaches events to the font sizing links
		// **********************************************************************
		
		$('#fontSize0').bind('click',function(event) {
			saveFontSize('0');
		});
		
		$('#fontSize1').bind('click',function(event) {
			saveFontSize('1');
		});
		
		$('#fontSize2').bind('click',function(event) {
			saveFontSize('2');
		});
	}
	
	$.createAnimationLink = function() {
		// ********************************************************************** 
		// Attaches event to the elearning animation box
		// **********************************************************************
		
		$('#animationLink').bind('click',function(event) {
			$('#elearningAnimation').show('slow');
		});
	}
	
	function getFlashVersion(){ 
	  	// ie 
	  	try { 
			try { 
		  		// avoid fp6 minor version lookup issues 
		  		// see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/ 
		  		var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6'); 
		  		try { axo.AllowScriptAccess = 'always'; } 
		  			catch(e) { return '6,0,0'; } 
			} catch(e) {} 
			return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1]; 
	  	// other browsers 
	  	} catch(e) { 
			try { 
		  		if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){ 
					return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1]; 
		  		} 
			} catch(e) {} 
	  	} 
	  	return '0,0,0'; 
	} 
	
	
})(jQuery);