/* Adding a class to the HTML tag to preload styles before the DOM is ready */
if (document.documentElement && document.getElementById) {
    var docClass = document.documentElement.className != null ? document.documentElement.className : document.documentElement.getAttribute('class');
    docClass =  docClass !='' ? docClass + ' jsEnabled' : 'jsEnabled';
    document.documentElement.setAttribute('class',docClass);
    document.documentElement.className = docClass; //For IE
}

// Set sounds paths
var fx_airwoosh = 'uploads/flash/sounds/airwhoosh.swf';
var fx_bomb = 'uploads/flash/sounds/bomb.swf';
var fx_click = 'uploads/flash/sounds/click.swf';
var fx_beep = 'uploads/flash/sounds/digital_beep.swf';
var fx_beep2 = 'uploads/flash/sounds/digital_beep_2.swf';
var fx_chinook = 'uploads/flash/sounds/helicopter_chinook.swf';
var fx_flyby = 'uploads/flash/sounds/helicopter_flyby.swf';
var fx_multipleBomb = 'uploads/flash/sounds/multiple_bomb.swf';
var fx_soundtrack = 'uploads/flash/sounds/Soundtrack_15sec.swf';
var fx_sting = 'uploads/flash/sounds/sting.swf';
var fx_tick = 'uploads/flash/sounds/tick.swf';
var fx_warAmbience1 = 'uploads/flash/sounds/war_ambience_1.swf';
var fx_warAmbience2 = 'uploads/flash/sounds/war_ambience_2.swf';
var fx_warAmbience3 = 'uploads/flash/sounds/war_ambience_3.swf';
var fx_soundController = 'uploads/flash/sounds/muteButton.swf';

$(function () {	
	//*********************//
	//*** Sound effects ***//
	
	$("body").append("<div id=\"soundOnLoad\"></div>");
	$("body").append("<div id=\"soundOnEvent\"></div>");
	$("body").append("<div id=\"soundOnEventHome1\"></div>");
	$("body").append("<div id=\"soundOnEventHome2\"></div>");
	$("body").append("<div id=\"soundOnEventHome3\"></div>");
	
	//*********************//
	//*** Removed Sound effects on all rollover states ***//
	/*	
	$("div#news ul li a").hover(
		function(){
			setSound(fx_beep2, 'hover');
		},
		function(){
		}
	);
	
	$("div#subNavigation ul li:not('.active') a").hover(
		function(){
			setSound(fx_beep, 'hover');
		},
		function(){
		}
	);
	
	$("div#navigation ul li a, div#navigation_platform ul li a").hover(
		function(){
			setSound(fx_beep2, 'hover');
		},
		function(){
		}
	);	
	*/	
	//************************//
	//*** AVG page scripts ***//	
	$("input#m2fbrp__17").focus();
	
	$("body.avg input[type='image']").hover(
		function(){
			var input = $("body.avg input[type='image']");
			var src = input.attr("src");
			input.attr("src", src.replace(".jpg", "_over.jpg"));
		},
		function(){
			var input = $("body.avg input[type='image']");
			var src = input.attr("src");
			input.attr("src", src.replace("_over.jpg", ".jpg"));
		}
	);	

	//******************************//
	//*** Top navigation scripts ***//	
	$("div#subNavigation ul li:not(.active)").hover(
	function () {
		imageTag = $(this).find("img");
		imageSrc = imageTag.attr("src");
		if (imageSrc.indexOf("active") == -1){
			imageTag.attr({src:imageSrc.split(".png")[0] + "_active.png"});
		}
	}, 
    function () {
		imageTag = $(this).find("img");
		imageSrc = imageTag.attr("src");		
		imageTag.attr({src:imageSrc.replace("_active", "")});
	});	
	
	//*****************************************************//
	//*** Internet Explorer 6 image replacement scripts ***//
	if ($.support.opacity == false && $.browser.msie && $.browser.version == "6.0"){
		var imgPNGS = $("img.logo, div.NewsSummaryPostdate img, blockquote img, div#toc img, div.pagination img, div#NewsPostDetailReturnLink img, div#subImg img, div.system img, img#failText, img.avgAuth, img.404img, div#news img, img#packshotImg");
		imgPNGS.each(function(i){
			var src = $(this).attr("src");
			var width = $(this).width();
			var height = $(this).height();
			$(this).attr("src", "uploads/images/global/pngfix_transparent.gif");
			$(this).attr("width", width);
			$(this).attr("height", height);
			$(this).attr("style", "filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')");
		});
	
		var bgPNGS = $("div#mainContainer h1, div#pageContent h2, div#pageContent h3, div#pageContent h4, div.system, div.system ul");
		bgPNGS.each(function(i){
			src = $(this).css("backgroundImage");
			src = src.replace("url(", "");
			src = src.replace(")", "");
			$(this).css({"background-image": "url(uploads/images/global/pngfix_transparent.gif)"});
			$(this).css("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='crop')");
		});
	}
	
	//******************************************//
	//*** Add the coundController Flash File ***//
	if (document.getElementById("soundController") != undefined) {
		var flashvars = {};
		var params = {};
		swfobject.embedSWF(fx_soundController, 'soundController', '1', '1', '9.0.0', flashvars, params);
	}
});

function setSound(sound, event,panelNumber){
	if (typeof sound != 'undefined'){
		if (typeof panelNumber != 'undefined'){
			var divId = "soundOnEventHome" + panelNumber;
			swfobject.embedSWF(sound,divId, '1', '1', '9.0.0');
		} else {
			if (event == 'onload') {
				swfobject.embedSWF(sound, 'soundOnLoad', '1', '1', '9.0.0');
			} else {
				swfobject.embedSWF(sound, 'soundOnEvent', '1', '1', '9.0.0');
			}
		}
	}
}
