$(document).ready(function(){
	$('#nav ul:first li:last').addClass('last');
	$('div.play a').click(function(e){
		e.preventDefault();
		$('#content').fadeOut("slow",function(){
			$('#topbannerflash').fadeIn(function(){
				playFlash();
			});
		}); 
	});
	$(".colorbox").colorbox({iframe:true, width:550, height:485});
});

function flashToHTMLSwap(){
	$('#topbannerflash').fadeOut("slow", function(){ // Once the flash has faded out...
		$('#content').fadeIn("normal", function() {  // Fade in the HTML replacement content
			// Nothing to do; here for debgug only
		});
		$('#topbannerflash').empty(); // Clear out the html contents so that the flash doesn't keep playing
		
		$("#nav").css("z-index", "5000"); // Force to the top to solve IE 7 problems with menus appearing behind content
	});
}

function playFlash() {
	var soBanner = new SWFObject("Airwear-splash-screen.swf", "8", "816", "281", "1", "#000000");
	soBanner.addParam("quality", "high");
	soBanner.addParam("wmode", "transparent");
	soBanner.addParam("allowScriptAccess","always");
	soBanner.addParam("vslink", "Airwear-splash-screen.swf");
	soBanner.write("topbannerflash");
}	

  sfHover = function() {
	   var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	   for (var i=0; i < sfEls.length; i++) {
		    sfEls[i].onmouseover= function() { this.className+=" sfhover";		}
	     	sfEls[i].onmouseout = function() { this.className=this.className.replace(new RegExp(" sfhover\\b"), "");}
     }
  }
  if (window.attachEvent) window.attachEvent("onload", sfHover);

// Three functions grabbed from http://essilorusa.com/Welcome/
function elem_click( objElement ){
	try	{
		if( returnAttribute( objElement, 'popup' ) ){	openWin( returnAttribute( objElement, 'url' ), '_blank', 400, 400, 200, 200 ) ;	}	
		else { window.location =  returnAttribute( objElement, 'url' ) ; }
	}
	catch( _exception )	{	alert( _exception.description ) ;	}
}

function returnAttribute( objElement, attribute ){
	try	{
		if( document.getElementById(objElement.id).getAttribute(attribute) != "" || document.getElementById(objElement.id).getAttribute(attribute) != null || document.getElementById(objElement.id).getAttribute(attribute) != " " )	{
			return ( document.getElementById(objElement.id).getAttribute( attribute ) ) ;
		}	else	{
			return ( false ) ;
		}
	}
	catch( _exception )	{		alert( _exception.description ) ;	}
}

function openWin ( nomsite, nomtitre, width, height, left, top ) {
	var windowVar1 = window.open( nomsite, nomtitre, "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=" + width + ",height=" + height + ",screenX=" + left + ",screenY=" + top ) ;}

		$(function(){
				$.stylesheetInit();	// Call stylesheet init so that all stylesheet changing functions will work.
				
				// This code loops through the stylesheets when you click the link with an ID of "toggler" below.
				$('#toggleup').bind(  'click', function(e) { $.stylesheetToggleUp();   return false;} );
				$('#toggledown').bind('click', function(e) { $.stylesheetToggleDown(); return false;} );
				
				// When one of the styleswitch links is clicked then switch the stylesheet to
				// the one matching the value of that links rel attribute.
				// NOT USED... YET
				$('.styleswitch').bind(
					'click',
					function(e)
					{
						$.stylesheetSwitch(this.getAttribute('rel'));
						return false;
					}
				);
			}
		);


