var boolDebug = false;
//boolDebug = true;	//	uncomment to debug
var boolAlertDebug = false;
var boolConsoleLogDebug = false;
if(boolDebug) {
	boolAlertDebug = true;	//	commenting this will cause alerts to stop displaying
	//boolConsoleLogDebug = true;
}
var debug = "";

var oLi = undefined;
var $oLink = undefined;
var oTimer = undefined;
var oUl = undefined;
var intTimeout = 300;
if(boolDebug) {
	intTimeout *= 2;
}
var strNavList1Class = "";

function fOnLoad() {
	$(".email1").html("<a href=\"mailto:rjockel@cuttingedgeentertain.com\">rjockel@cuttingedgeentertain.com</a>");
	$(".email2").html("<a href=\"mailto:btosun@cuttingedgeentertain.com\">btosun@cuttingedgeentertain.com</a>");
	
	var oNavList1 = $("ul#navList1");
	$(oNavList1).find("a").hover(function() {
		strNavList1Class = "hover" + fGetLinkNumber($(this));
		$(oNavList1).addClass(strNavList1Class);
	}, function() {
		$(oNavList1).removeClass(strNavList1Class);
	});
	
	//fDebug("About to call fInitializeMenus().\n");
	fInitializeMenus();
	fMatchHeights("#whatsHotNewList li .background", "#whatsHotNewList li .foreground");
	fInitializeVideos();
}

/*
	Based on the global boolDebug, boolAlertDebug and boolConsoleLogDebug variables, display the passed debug information using the appropriate method.
	@param aString the debug string to display
*/
function fDebug(aString) {
	if(boolAlertDebug) {
		alert(aString);
	}
	if(boolConsoleLogDebug) {
		console.log(aString);
	}
}

/*
	Return an integer indicating which link is being passed by determine how many links preceed the passed link.  This is a recursive function.
	@param el a Jquery object referencing the link in question
*/
function fGetLinkNumber(el) {
	var output = 0;
	var oPrevLink = $(el).parent().prev("li").children("a");
	if($(oPrevLink).size() > 0) {	//	There is at least one preceeding link
		output += 1 + fGetLinkNumber(oPrevLink);
	}
	return output;
}

/*
	Hide the specified item.
	@param el the jquery object for the item to hide
*/
function fHide(el) {
	$(el).addClass("hidden");
}

/*
	Deactivate the main navigation section the user was previously focusing on, including all associated subnavigation.
	@param el the jquery selector for the main navigation link
*/
function fHideNavSystem(el) {
	$(el).removeClass("hover");
	var oSubnav = $(el).siblings("ul");
	fDebug("$(oSubnav).find(\"a.hover\").size() = " + $(oSubnav).find("a.hover").size() + "\n");
	$(oSubnav).find("a.hover").removeClass("hover");
	fHide($(oSubnav));
	$(oSubnav).find("ul").each(function() {	//	Hide all nested levels of subnavigation
		fHide($(this));
	});
}

function fInitializeMainNavHover() {
	fDebug("fInitializeMainNavHover() called.\n");
	$("ul#navList2 li a").hover(function() {
		clearTimeout(oTimer);		
		fDebug("hovered onto main nav tier 1 link");
		
		fShow($(this).siblings("ul"));
		var oSiblingMainNavLinks = $(this).parent().siblings("li").children("a");
		$(oSiblingMainNavLinks).each(function() {
			fHideNavSystem($(this));
		});
		
		$(oSiblingMainNavLinks).removeClass("hover").siblings("ul").addClass("hidden");	//	deactivate any leftover active sibling links and subnav
		$(this).addClass("hover");
	}, function() {
		fDebug("hovered out of main nav tier 1 link");
		var $oLink = $(this);
		oTimer = setTimeout(function() {	fHideNavSystem($oLink);	}, intTimeout);
		fDebug("$(this).attr(\"id\") = " + $(this).attr("id") + "\n$(this).siblings(\"ul\").size() = " + $(this).siblings("ul").size() + "\n");
	});
}

function fInitializeMainSubnavHover() {
	fDebug("fInitializeMainSubnavHover() called.\n");
	$("ul#navList2 li ul").hover(function() {
		clearTimeout(oTimer);
		fDebug("hovered onto subnav tier 2 link");
	}, function() {
		fDebug("hovered out of subnav tier 2 link");
		var $oLink = $(this).parents(".tier1").children("a");
		oTimer = setTimeout(function() {	fHideNavSystem($oLink);	}, intTimeout);
	});
}

function fInitializeMenus() {
	fDebug("fInitializeMenus() called.\n");
	fInitializeMainNavHover();
	fInitializeMainSubnavHover();
}

function fInitializeVideos() {
	var strFlashvars = "";
	var strHtml = "";
	var i = 0;
	var arrVideos = new Array();
	arrVideos[0] = "Augustine 2011.flv";
	arrVideos[1] = "Jay Black 2011.flv";
	arrVideos[2] = "Matt Corey 2011.flv";
	var arrImages = new Array();
	arrImages[0] = "img_aug 2011.jpg";
	arrImages[1] = "img_jayblack2011.jpg";
	arrImages[2] = "img_mattCorey.jpg";
	
	var requiredMajorVersion = 7;
	var requiredMinorVersion = 0;
	var requiredRevision = 0;
	var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);	
	
	$(".videoCell").each(function() {
		if(hasRequestedVersion) {
			strFlashvars = "file=../movies/" + arrVideos[i];
			strFlashvars += "&image=images/" + arrImages[i];
			fDebug("i = " + i + "\nstrFlashvars = " + strFlashvars + "\n");
			strHtml = fGetFlash("flash/player.swf", "videoPlayer" + (i + 1), 300, 240, strFlashvars, true);
		} else {
			strHtml = fGetNoFlash("images/img_getFlash.jpg", 300, 240, "THIS CONTENT REQUIRES THE LATEST FLASH PLAYER. Click to get Adobe Flash Player.");
		}
		$(this).html(strHtml);
		i++;
	});
}

/*
	Show the specified item.
	@param el the jquery object for the item to show
*/
function fShow(el) {
	$(el).removeClass("hidden");
}
