var prevBubble;
var menuItemSelected;
var menuTabs = new Array(5);

menuTabs[0] = "<div id=\"navHomeButton\" class=\"navHomeButton\" onMouseOver=\"tabHover('home','rollover')\" onMouseOut=\"tabHover('home','off')\">#1#<img id=\"home_tab\" src=\"http://assets.johnq.com/images/nav/btn_home_off.gif\" width=\"110px\" height=\"33px\" border=\"0px\">#2#</div>";
menuTabs[1] = "<div id=\"navAudioButton\" class=\"navAudioButton\" onMouseOver=\"tabHover('audio','rollover')\" onMouseOut=\"tabHover('audio','off')\">#1#<img id=\"audio_tab\" src=\"http://assets.johnq.com/images/nav/btn_audio_off.gif\" width=\"110px\" height=\"33px\" border=\"0px\">#2#</div>";
menuTabs[2] = "<div id=\"navVideoButton\" class=\"navVideoButton\" onMouseOver=\"tabHover('video','rollover')\" onMouseOut=\"tabHover('video','off')\">#1#<img id=\"video_tab\" src=\"http://assets.johnq.com/images/nav/btn_video_off.gif\" width=\"110px\" height=\"33px\" border=\"0px\">#2#</div>";
menuTabs[3] = "<div id=\"navDesktopButton\" class=\"navDesktopButton\" onMouseOver=\"tabHover('desktop','rollover')\" onMouseOut=\"tabHover('desktop','off')\">#1#<img id=\"desktop_tab\" src=\"http://assets.johnq.com/images/nav/btn_desktop_off.gif\" width=\"110px\" height=\"33px\" border=\"0px\">#2#</div>";
menuTabs[4] = "<div id=\"navAdultButton\" class=\"navAdultButton\" onMouseOver=\"tabHover('after_hours','rollover')\" onMouseOut=\"tabHover('after_hours','off')\">#1#<img id=\"after_hours_tab\" src=\"http://assets.johnq.com/images/nav/btn_after_hours_off.gif\" width=\"175px\" height=\"33px\" border=\"0px\">#2#</div>";
var activeTab;

function setupTabMenu() {
	var url = window.location.toString();
	if ((url.indexOf(".htm") == -1) || (url.indexOf("/home.htm") != -1)) {
		document.write(menuTabs[0].replace("#1#","").replace("#2#",""));
		activeTab = "home";
	}
	else document.write(menuTabs[0].replace("#1#","<a href=\"home.htm\">").replace("#2#","</a>"));

	if (url.indexOf("/audio.htm") != -1) {
		document.write(menuTabs[1].replace("#1#","").replace("#2#",""));
		activeTab = "audio";
	}
	else document.write(menuTabs[1].replace("#1#","<a href=\"audio.htm\">").replace("#2#","</a>"));

	if (url.indexOf("/video.htm") != -1) {
		document.write(menuTabs[2].replace("#1#","").replace("#2#",""));
		activeTab = "video";
	}
	else document.write(menuTabs[2].replace("#1#","<a href=\"video.htm\">").replace("#2#","</a>"));

	if (url.indexOf("/desktop.html") != -1) {
		document.write(menuTabs[3].replace("#1#","").replace("#2#",""));
		activeTab = "desktop";
	}
	else document.write(menuTabs[3].replace("#1#","<a href=\"desktop.html\">").replace("#2#","</a>"));

	if (url.indexOf("/channel.htm?cid=24") != -1) {
		document.write(menuTabs[4].replace("#1#","").replace("#2#",""));
		activeTab = "after_hours";
	}
	else document.write(menuTabs[4].replace("#1#","<a href=\"channel.htm?cid=24\">").replace("#2#","</a>"));

	document.write("<div id=\"navBottomBar\" class=\"navBottomBar\"></div>");
}
function setActiveTab() {
	var url = window.location.toString();
	if ((url.indexOf(".htm") == -1) || (url.indexOf("/home.htm") != -1)) {
		document.getElementById('home_tab').src = "http://assets.johnq.com/images/nav/btn_home_front.gif";
		document.getElementById('navHomeButton').className = "navHomeButtonActive";
		document.getElementById('home_tab').height = 41;
	}
	else if (url.indexOf("/audio.htm") != -1) {
		document.getElementById('audio_tab').src = "http://assets.johnq.com/images/nav/btn_audio_front.gif";
		document.getElementById('navAudioButton').className = "navAudioButtonActive";
		document.getElementById('audio_tab').height = 41;
	}
	else if (url.indexOf("/video.htm") != -1) {
		document.getElementById('video_tab').src = "http://assets.johnq.com/images/nav/btn_video_front.gif";
		document.getElementById('navVideoButton').className = "navVideoButtonActive";
		document.getElementById('video_tab').height = 41;
	}
	else if (url.indexOf("/desktop.html") != -1) {
		document.getElementById('desktop_tab').src = "http://assets.johnq.com/images/nav/btn_desktop_front.gif";
		document.getElementById('navDesktopButton').className = "navDesktopButtonActive";
		document.getElementById('desktop_tab').height = 41;
	}
	else if (url.indexOf("/channel.htm?cid=24") != -1) {
		document.getElementById('after_hours_tab').src = "http://assets.johnq.com/images/nav/btn_after_hours_front.gif";
		document.getElementById('navAdultButton').className = "navAdultButtonActive";
		document.getElementById('after_hours_tab').height = 41;
	}
}
function setLogo() {
	document.write("<span style=\"position:absolute;top:0px;width:166px;height:97px;font-size:0px\"><a href=\"http://www.johnq.com\"><img src=\"http://assets.johnq.com/images/nav/logo_header.gif\" width=\"166px\" height=\"97px\" border=\"0px\"></a></span>");
	document.write("<span style=\"position:absolute;top:97px;width:781px;height:10px;font-size:0px\"><img src=\"http://assets.johnq.com/images/nav/bottom_grey_bar.gif\" width=\"781px\" height=\"10px\" border=\"0px\"></span>");
	document.write("<span style=\"position:absolute;top:28px;left:166px;font-size:0px\"><img src=\"http://assets.johnq.com/images/nav/tagline_header.gif\" width=\"145px\" height=\"18px\" border=\"0px\"></span>");
}
function getBubblePoint(divId, topVal) {
	if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1)
		document.write("<div id=\"" + divId + "_bubble_point\" class=\"detailBubblePoints\" style=\"top:" + topVal + "px\"><img src=\"http://assets.johnq.com/images/layout/bubble_point.png\" width=\"30px\" height=\"25px\" border=\"0px\"></div>");
	else
		document.write("<div id=\"" + divId + "_bubble_point\" class=\"detailBubblePoints\" style=\"top:" + topVal + "px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://assets.johnq.com/images/layout/bubble_point.png',sizingMethod='scale')\"></div>");
}
function tabHover(tabImage, state) {
	if (activeTab != tabImage)
		document.getElementById(tabImage + '_tab').src = "http://assets.johnq.com/images/nav/btn_" + tabImage + "_" + state + ".gif";
}
function menuItemHover(hovered, itemId) {
	if ((menuItemSelected == null) || (itemId != menuItemSelected)) {
		if (hovered == true) {
			document.getElementById(itemId).style.border = "1px solid #DDDDDD";
			document.getElementById(itemId).style.background = "#DDDDDD";
		}
		else {
			if ((itemId.indexOf("channelMenu_") != -1) || (itemId.indexOf("sChannelMenu_") != -1) || (itemId.indexOf("episode_") != -1)) {
				document.getElementById(itemId).style.border = "1px solid #FFFFFF";
				document.getElementById(itemId).style.background = "#FFFFFF";
			}
			else {
				if (parseInt(itemId.substring(itemId.indexOf("_")+1))%2 == 1) {
					document.getElementById(itemId).style.border = "1px solid #F4F4F4";
					document.getElementById(itemId).style.background = "#F4F4F4";
				}
				else {
					document.getElementById(itemId).style.border = "1px solid #FFFFFF";
					document.getElementById(itemId).style.background = "#FFFFFF";
				}
			}
		}
	}
}
function menuItemUnderline(hovered, thisRef, itemId) {
	if ((menuItemSelected == null) || (itemId != menuItemSelected)) {
		if (hovered == true)
			thisRef.style.textDecoration = 'underline';
		else
			thisRef.style.textDecoration = 'none';
	}
}
function hoverSwap(imgObj, imageName) {
	imgObj.src = "http://assets.johnq.com/images/buttons/" + imageName;
}
function navSelect() {
	var url = window.location.toString();
	var pageCode;
	if ((url.indexOf("?cid=") != -1) || (url.indexOf("&cid=") != -1)) {
		if (url.indexOf("?cid=") != -1)
			pageCode = url.substring(url.indexOf("?cid=")+5);
		else if (url.indexOf("&cid=") != -1)
			pageCode = url.substring(url.indexOf("&cid=")+5);
		if (pageCode.indexOf("&") != -1)
			pageCode = pageCode.substring(0, pageCode.indexOf("&"));
		if (pageCode != null) {
			document.getElementById('channelMenu_' + pageCode).style.border = "1px solid #DDDDDD";
			document.getElementById('channelMenu_' + pageCode).style.background = "#DDDDDD";
			document.getElementById('channelMenu_' + pageCode).style.cursor = "default";
			menuItemSelected = "channelMenu_" + pageCode;
		}
	}
	else if (url.indexOf("?scid=") != -1) {
		var pageCode = url.substring(url.indexOf("?scid=")+6);
		if (pageCode.indexOf("&") != -1)
			pageCode = pageCode.substring(0, pageCode.indexOf("&"));
		if (pageCode != null) {
			document.getElementById('sChannelMenu_' + pageCode).style.border = "1px solid #DDDDDD";
			document.getElementById('sChannelMenu_' + pageCode).style.background = "#DDDDDD";
			document.getElementById('sChannelMenu_' + pageCode).style.cursor = "default";
			menuItemSelected = "sChannelMenu_" + pageCode;
		}
	}
}
function navigate(page) {
	var url = window.location.toString();
	url = url.substring(url.lastIndexOf("/")+1);
	if (url.indexOf("&") != -1)
		url = url.substring(0, url.indexOf("&"));
	if (url != page)
		window.location = page;
}
function tabSelect(tabIdOff, tabIdOn, divOff, divOn) {
	document.getElementById(tabIdOff + "_active").style.display = "none";
	document.getElementById(tabIdOff).style.display = "inline";
	document.getElementById(divOff).style.display = "none";

	document.getElementById(tabIdOn).style.display = "none";
	document.getElementById(tabIdOn + "_active").style.display = "inline";
	document.getElementById(divOn).style.display = "block";
}
function showHideInfo(divId, detailPaneDivId) {
	if (prevBubble != null) document.getElementById(prevBubble).style.display = "none";
	if (divId != prevBubble) {
		document.getElementById(divId).style.display = "block";
		document.getElementById(detailPaneDivId).style.display = "none";
		document.getElementById(divId + "_point").style.display = "block";
		prevBubble = divId;
	}
	else {
		document.getElementById(detailPaneDivId).style.display = "block";
		prevBubble = null;
	}
}
function showHide(divId) {
	if (document.getElementById(divId).style.display == "none")
		document.getElementById(divId).style.display = "block";
	else document.getElementById(divId).style.display = "none";
}
function checkAge(requestedPage) {
	if (document.cookie) {
		var avArray = document.cookie.split(';');
		for (var x = 0; x < avArray.length; x++) {
			var innerArray = avArray[x].split('=');
			for (var y = 0; y < innerArray.length; y++) {
				if (innerArray[y].charAt(0) == " ")
					innerArray[y] = innerArray[y].substring(1, innerArray[y].length);
			}
			avArray[x] = innerArray;
		}
		if (((avArray[0][0] == "name") && (avArray[0][1] == "AgeVerify")) && ((avArray[1][0] == "domain") && (avArray[1][1] == "johnq.com"))) {
			if ((avArray[2][0] == "verified") && (avArray[2][1] == "true"))
				window.location = requestedPage;
			else window.location = "/2young.html";
		}
		else window.location = "/av.html?page=" + requestedPage;
	}
	else window.location = "/av.html?page=" + requestedPage;
}
function createCookie(ofAge, requestedPage) {
	document.cookie = "name=AgeVerify";
	document.cookie = "domain=johnq.com";
	document.cookie = "verified=" + ofAge;
	checkAge(requestedPage);
}
function invokePlayer(contentTitle,contentPath,refreshUrl) {
	playerWindow = window.open('','Media_Player','width=340,height=310,top=' + ((screen.availHeight/2)-130) + ',left=' + ((screen.availWidth/2)-160) + ',resizable=0,scrollbars=0,titlebar=0,toolbar=0,menubar=0,status=0,directories=0,personalbar=0');
	playerWindow.focus();
	var winContent = "<html><head><title>" + unescape(contentTitle) + "</title>";
	if (refreshUrl != "")
		winContent += "<script>opener.location='" + refreshUrl + "';setTimeout('self.focus()',500);</script>";
	winContent += "</head><body bgcolor='#DDDDDD' topmargin='0px'>";
	winContent += "<table cellpadding='0px' cellspacing='0px' valign='middle' style='font-family:verdana;font-size:12px;font-weight:bold;color:#435664;width:100%;height:40px;border:0px'><tr><td>";
	winContent += unescape(contentTitle);
	winContent += "</td></tr></table>";
	winContent += "<object width='340' height='310'>";
	winContent += "<param name='src' value='" + contentPath + "'>";
	winContent += "<param name='autoplay' value='true'>";
	winContent += "<param name='controller' value='true'>";
	winContent += "<param name='bgcolor' value='#DDDDDD'>";
	winContent += "<embed src='" + contentPath + "' autostart='true' loop='false' width='320' height='260' controller='true' bgcolor='#DDDDDD'></embed>";
	winContent += "</object>";
	winContent += "</body></html>";
	playerWindow.document.write(winContent);
	playerWindow.document.close();
}

function openMP(surl, guid, jqurl, pc, sid, eid, refreshUrl) {
	var mp = '/player/MediaPlayer.jsp?surl=' + surl + '&guid=' + guid + '&jqurl=' + jqurl + '&pc=' + pc;
	if(refreshUrl != null)
		mp = mp + '&refreshUrl=' + refreshUrl;
	window.open( mp, 'Media_Player', 'width=535, height=492');

	var track = "/playclick/" + sid;
	if(eid != 0)
		track = track + '+' + eid;
	urchinTracker(track);

	var track="/tracking/playclick.gif?sid=" + sid;
	if(eid != 0)
		track = track + "&eid=" + eid;
	var img = new Image();
	img.src = track;
}