$(function(){
	init();
	initNav();
	initPopUpLink();
	initFlash();
	
	function initNav() {
		var tESubNav = $(".subNav");
		tESubNav.find(".linkCol").each(function(){

			var tE = $(this);
			var tEP = tE.parent();
			var tED1 = tEP.find(".d1");
			var tED2 = tEP.find(".d2");
			
			tEP.show();
			
			var tH = tE.height() - 8;
			var tOrigD1H = tED1.height();
			var tOrigD2H = tED2.height();
			//alert("initNav: " + tH + ", tOrigD1H:" + tOrigD1H + ", tOrigD2H:" + tOrigD2H);
			tED1.height(tOrigD1H + tH);
			tED2.height(tOrigD2H + tH);
			
			tEP.hide();

		});
		tESubNav.css({display:"none"});
		
		$(".nav a").mouseenter(onActionShowSubNav);
				
		function onActionShowSubNav(e) {
			subNavShow($(this).attr("rel"));
			if (e != null) e.preventDefault();
		}
		function subNavShow(aSelector) {
			var tE = $("." + aSelector);
			if (tE != null) {
				$(tE).css({display:"block"}).mouseleave(subNavHide);
			}
		};
		function subNavHide() {
			tESubNav.hide();
		};
	
	}
	
	function initPopUpLink() {
		$("a.popUpLink").click(function(e){
			var tRef = $(this).attr("rel");
			var tAdd = (tRef=="")?"width=613,height=502":tRef;
			var tWin = window.open(this.href, "blank", "toolbar=no," + tAdd);
			tWin.focus();
			if (e != null) e.preventDefault();
		});
	}
	
	function initFlash() {
		$(".flash").each(function(){
			var tE = $(this);
			var tId     = tE.attr("id");
			if (tId != "") {
				var tSrcSWF = tE.attr("rel");
				if (tSrcSWF == "") {
					var tSrc = $("img", tE).attr("src");
					tSrcSWF = tSrc.replace(/(gif|jpg|png)/gi, "swf");
				}
				var tHref   = tE.attr("href");
				var tW = tE.width() + "";
				var tH = tE.height() + "";
				var tFlashVars = new Object();
				if (tHref != "") tFlashVars.clickTAG = tHref;
				swfobject.embedSWF(tSrcSWF, tId, tW, tH, "10.0.0", "lib/expressInstall.swf", tFlashVars, {
					allowFullscreen: "true",
					allowScriptAccess: "always",
    				wmode: "transparent"
				}, {});
			}
		});
	}
	
	function init() {
		try {
			document.execCommand("BackgroundImageCache",false,true);
		} catch(e) {}
		
		if (!Util.isSupportMultipleBackground()) $('body').addClass('ie');

		if (Util.isIE6()) {
			try {
				DD_belatedPNG.fix('.pngFix,#header a,#header span');
			} catch(e) {}
		}
		
		// Conversion Name: Gold - Home - Jan 2011
		if (Project.mediaMindTrackId != "") {
			var rnd = '' + ((Math.random() * 1000000) >> 0);
			var tEbAS = document.createElement('script');
			tEbAS.type = 'text/javascript';
			tEbAS.async = true;
			tEbAS.src = 'http://bs.serving-sys.com/BurstingPipe/ActivityServer.bs?cn=as&ActivityID=' + Project.mediaMindTrackId + '&rnd=' + rnd;
			var s = document.getElementsByTagName('script')[0];
			s.parentNode.insertBefore(tEbAS, s);
		}
	}
	
});
/**
* jQuery Cookie plugin
*
* Copyright (c) 2010 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
jQuery.cookie = function (key, value, options) {
	
	// key and at least value given, set cookie...
	if (arguments.length > 1 && String(value) !== "[object Object]") {
		options = jQuery.extend({}, options);

		if (value === null || value === undefined) {
			options.expires = -1;
		}

		if (typeof options.expires === 'number') {
			var days = options.expires, t = options.expires = new Date();
			t.setDate(t.getDate() + days);
		}
		
		value = String(value);
		
		return (document.cookie = [
			encodeURIComponent(key), '=',
			options.raw ? value : encodeURIComponent(value),
			options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
			options.path ? '; path=' + options.path : '',
			options.domain ? '; domain=' + options.domain : '',
			options.secure ? '; secure' : ''
		].join(''));
	}

	// key and possibly options given, get cookie...
	options = value || {};
	var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
	return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

function gaTrackEvent(aCat, aAction, aOptLabel, aOptValue) {
	_gaq.push(['_trackEvent', aCat, aAction, aOptLabel, aOptValue]);
}
function gaTrackPageview(aLoc) {
	_gaq.push(['_trackPageview', aLoc]);
}

Util = {
	
	getQuerystring:function(key, default_) {
		if (default_==null) default_=""; 
		key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
		var qs = regex.exec(window.location.href);
		if(qs == null)
			return default_;
		else
			return qs[1];
	},
	
	getURLwithoutExt:function(aURL) {
		var tList = String(aURL).split(".");
		tList.pop();
		return tList.join(".");
	},
	
	isSupportMultipleBackground:function() {
		if(($.browser.msie) || ($.browser.mozilla && parseInt($.browser.version.substr(0,1))<=1 && parseInt($.browser.version.substr(2,1))<=9 && parseInt($.browser.version.substr(4,1))<=1)){
			return false;
		} else {
			return true;
		}
	},
	isIE6:function() {
		if($.browser.msie && parseInt($.browser.version.substr(0,1)) < 7) {
			return true;
		} else {
			return false;
		}
	},
	isMobile:function() {
		return !!navigator.userAgent.match(/(ipad|iphone|ipod|android|opera mini|blackberry|pre\/|palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine)/i);
	},
	isSupportHTML5Video:function() {
		var tR = false;
		try {
			if (!!document.createElement("video").canPlayType) tR = true;
		} catch(e) {}
		return tR;
	},
	getVideoFormatSupportInfo:function() {
		var tR = {h264:false, ogg:false, preferExt:""};
		try {
			var tE = document.createElement("video");
			if (!!tE.canPlayType) {
				tR.ogg  = tE.canPlayType('video/ogg; codecs="theora"');
				//tR.webm = tE.canPlayType('video/webm; codecs="vp8, vorbis"');
				var h264 = 'video/mp4; codecs="avc1.42E01E';
				tR.h264 = tE.canPlayType(h264 + '"') || tE.canPlayType(h264 + ', mp4a.40.2"');
			}
		} catch(e) {}
		if (tR.ogg) tR.preferExt = "ogg";
		//if (tR.webm) tR.preferExt = "webm";
		if (tR.h264) tR.preferExt = "mp4";
		return tR;
	},
	dummyLastFunction:function() {}
}


