/* stop IE6 flicker */
try { document.execCommand("BackgroundImageCache", false, true); } catch(err) {}

// Return true if browser is Internet Explorer and version 6 or earlier
$.IE6Below = function() {
	if ($.browser.msie) {
		try {
			if (ScriptEngineMajorVersion() <= 5 && ScriptEngineMinorVersion() < 7) { // ie 6- only
				return true;
			}
		} catch(err) { return false; };
		return false;
	} else {
		return false;
	};
};

// embed our flash with UFO
// samples page flash
var samplesFlashObject = { movie:"/flash/sample-player/sample_player.swf", width:"742", height:"650", majorversion:"9", build:"115", bgcolor:"#E5E7E9", wmode:"opaque", menu:"false", name:"sample-player", flashvars:"globalAssetPath=/flash/sample-player/assets/" };
UFO.create(samplesFlashObject, "sample-library");
// home page flash
var homeFlashObject = { movie:"/flash/homev2/dmx_main.swf", width:"955", height:"260", majorversion:"9", build:"0", bgcolor:"#d9d9d9", wmode:"opaque", menu:"false", name:"sample-player", base:"/flash/homev2/", flashvars:"globalAssetPath=/flash/home/assets/" };
UFO.create(homeFlashObject, "flash-area");

// ** open/close navs **
// **                 **
$(function(){ // (executes when the dom is ready)
	// search for nav-something or snav-something in the body tag
	// this tells us if a link should be active by default
	// (this is because each of our nav links uses an id, e.g. nav-home, so we define
	//  active links by simply declaring this id in the body tag of each page as a class name)
	$("body[@class*=nav-]").each(function(i) {
		var bodyClasses = $(this).attr("class").split(" ");
		var regex1 = /\bnav-\b/;
		var regex2 = /\bsnav-\b/;
		$.each(bodyClasses, function(i, n) {
			if (regex1.test(n) || regex2.test(n)) {
				// add class "active" to the first link in the li#nav-something or li#snav-something
				//$('#'+n+'>a').addClass("active");
				// see if we're dealing with a sub nav, if so it uses class instead of id
				if (regex2.test(n)) {
					//$('.'+n+'>a').addClass("active");
					$('.'+n).removeClass("collapsed");
				};
			};
		 });
	});
});

// ** open/close logins **
// **                  **
$(function(){ // (executes when the dom is ready)
	// expects LoginLinksWidth variable to be set already
	$("#login-switch").css("cursor","pointer");
	$("#login-switch").click(function(){ // reveal links on click
		$(this).animate({opacity: .7}).css("cursor","default");
		$("#login-links a").css("cursor","default");
		$("#login-links").animate({ 
			width: LoginLinksWidth
		}, 500, 'swing', function(){
			$(this).css("white-space","normal");
			$("#login-links a").css("cursor","pointer");
		});
	});
});


// ** Misc **
// **      **
$(function(){ // (executes when the dom is ready)
	// make logo a link to go back to home page
	$("#logo").click(function(){
		document.location = "/";
	}).css("cursor","pointer");
	// make any links with rel="external" to open in new windows
	$("a[@rel$='external']").click(function(){
		this.target = "_blank";
	});
	// make rel="popup" open pop up windows
	$("a[@rel$='popup']").click(function(){
		window.open(this.href, '', 'menubar=0, toolbar=0, scrollbars=0, resizable=0, width=775, height=530');
		return false;
	});
	// make rel="channel" open pop up windows
	$("a[@rel$='channel']").click(function(){
		window.open(this.href, '', 'menubar=0, toolbar=0, scrollbars=1, resizable=0, width=400, height=400');
		return false;
	});
	// make rel="whats-playing" open pop up windows
	$("a[@rel$='whats-playing']").click(function(){
		window.open(this.href, '', 'menubar=0, toolbar=0, scrollbars=1, resizable=0, width=620, height=410');
		return false;
	});
	// give radio buttons and checkboxes "type-checkbox" and "type-radio" classes for ie
	if ($.IE6Below()) {
		$(":checkbox").addClass("type-checkbox");
		$(":radio").addClass("type-radio");
	};
	
	// fix rollovers for ie 6-
	if ($.IE6Below()) {
		$("#navigation a").hover(function(){
			$(this).addClass("hover");
		},function(){
			$(this).removeClass("hover");
		});
	};
	
	// make close button close the window (used with popup window)
	$("#close").click(function(){
		self.close();
	}).css("cursor","pointer");
	// collapse/decollapse navigation
	$(".toggle").toggle(function(){
	  $(this).next().slideDown("normal");
		// $(this).next().removeClass("collapsed");
	},function(){
	  $(this).next().slideUp("normal");
		// $(this).next().addClass("collapsed");
	});
	// Add rollover for services on home page
	$(".sbox-link").hover(
		function(){
			var temp = $(this).attr("rel");
			$("."+temp).addClass(temp+"-hover");
		},
		function(){
			var temp = $(this).attr("rel");
			$("."+temp).removeClass(temp+"-hover");
		});
});

