// Author: Caleb Johnston | Big Spaceship
// Date: June 22, 2005
// Site: Billboard.com
// attn: DHTML interaction script



// NOTE: anytime something uses the buttonOver() or bubbleTab() methods but doesn't 
// pass "this" as the object reference parameter and passes a childNode object instead that childNode 
// object is expected (by some browsers) to be on the same line as the object that makes the call. 

//get the x position of an element
function xPos(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) curleft += obj.x;

	return curleft;
}

//get the y position of an element
function yPos(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y) curtop += obj.y;

	return curtop;
}

//radioSelect controls which radio button is selected in the topmost search menu of the header
//NOTE: used for selection menus with only two options -useful for writing less JS in the html
function radioSelect(selectedElementId, unselectedId) {
	var sel = document.getElementById(selectedElementId);
	var unsel = document.getElementById(unselectedId);
	sel.src = "/bbcom/images/frm_radio_1.gif";
	unsel.src = "/bbcom/images/frm_radio_0.gif";
}

//radioSelection is used on all radio select menus
//radioSelection takes 2 inputs --an array of possible radio selection items, and the item to become selected
//NOTE: used for selection menus with many different options -requires longer execution string
function radioSelection(possibleIds, selection) {
	if ((typeof(arguments[0])=="object")) {
		for (i=0; i<possibleIds.length; i++) {
			document.getElementById(possibleIds[i]).src = "/bbcom/images/frm_radio_0.gif";
		}
		selection.src = "/bbcom/images/frm_radio_1.gif";
	}
}

//toggle album mouse over state
//albumStates is used on the home page for the featured album overlays
function albumStates(cd, objId, mode) {
	if (xBrowser.ns6up) {
		var offSetX = -5;
		var offSetY = -38;
	} else if (xBrowser.ie5up) {
		var offSetX = -5;
		var offSetY = -40;
	}
	var overlay = document.getElementById(objId);
	var album = document.getElementById(cd);
	
	if (mode == 'on') {
		var lft = xPos(album);
		var tp = yPos(album);
		overlay.style.left = lft + offSetX;
		overlay.style.top = tp + offSetY;
		overlay.style.visibility = 'visible';
	} else if (mode == 'off') {
		overlay.style.left = -300;
		overlay.style.top = -100;
		overlay.style.visibility = 'hidden';
	}
}

//rollover function for situation where many things must happen at once
//buttonOver is used on many pages throughout the site -particularly for text link rollovers that make many style changes
function buttonOver(elementIds, elementProps, elementVals) {
	if ((typeof(arguments[0])=="object") && (typeof(arguments[1])=="object")) {
		if (elementIds.length == 2) {
			if (elementIds[0] == elementIds[1]) {
				var item1 = elementIds[0];
				elementIds.push(item1.childNodes[0].childNodes[0])
			}
		}
		for (i=0; i<elementIds.length; i++) {
			var object = elementIds[i];
			var property = elementProps[i];
			var value = elementVals[i];
			object.style[property] = value;
		}
	} else {
		var obj = document.getElementById(elementIds);
		obj.style[elementProps] = elementVals;
		//obj.childNodes[0].style.color = 'CCCCCC';
	}
}

//uesd for a special image rollover effect
//imgOver is used to create the image border effect by toggling the visibility property of an image
//NOTE: this function should never be used on the site for the borders mentioned above
//due to the site-wide removal of said borders
function imgOver(img, borderId, mode) {
	var imgBorder = document.getElementById(borderId);
	if (mode=="on") {
		var lft = xPos(img);
		var tp = yPos(img);
		imgBorder.style.left = lft;
		imgBorder.style.top = tp;
		imgBorder.style.visibility = 'visible';
	} else if (mode=="off") {
		imgBorder.style.left = -300;
		imgBorder.style.top = -100;
		imgBorder.style.visibility = 'hidden';
	}
}

//goto() is used for special links -essentially to make a small decrease in the HTML file sizes
function go(url) {
	window.location = url;
}

function openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

function reprints() { //v2.0
	window.open('/bbcom/reprints.jsp','toolbar','resizeable=no,scrollbar=no,height=350,width=350');
}

//bubbleTab is used for the cd/ringtones/digital download icons which have a bubble pop-up on the rollover
//bubbleTab is also used for the locked subscription bubble pop-up
//bubbleTab was previously being used for the RIAA certifications mini-pop-ups therefore
//some of its functionality is no longer needed.
function bubbleTab(state,hover,obj,object) {
	if (hover=="riaa") {
		var riaaBubble = document.getElementById(object);
		var lft = xPos(obj);
		var tp = yPos(obj);
		var x_disp = -104;
		var y_disp = 17;
		if (state=="on"){
			riaaBubble.style.top = tp+y_disp;
			riaaBubble.style.left = lft+x_disp;
			riaaBubble.style.visibility = "visible";
		} else if (state=="off") {
			riaaBubble.style.top = 0;
			riaaBubble.style.left = -300;
			riaaBubble.style.visibility = "hidden";
		}
	} else if (hover=="sub") {
		var subBubble = document.getElementById("bubble_sub");
		var lft = xPos(obj);
		var tp = yPos(obj);
		var x_disp = -57;
		var y_disp = -20;
		if (state=="on"){
			subBubble.style.top = tp+y_disp;
			subBubble.style.left = lft+x_disp;
			subBubble.style.visibility = "visible";
		} else if (state=="off") {
			subBubble.style.top = 0;
			subBubble.style.left = -300;
			subBubble.style.visibility = "hidden";
		}
	} else if ( (hover=="cd")||(hover=="rt")||(hover=="dl")||(hover=="dvd")||(hover=="fool") ) {
		var cdBubble = document.getElementById("bubble_cd");
		var dvdBubble = document.getElementById("bubble_dvd");
		var rtBubble = document.getElementById("bubble_rt");
		var dlBubble = document.getElementById("bubble_dl");
		var foolBubble = document.getElementById("bubble_video");
		
		var lft = xPos(obj);
		var tp = yPos(obj);
		var cdWidth = (cdBubble.offsetWidth)/2-8;
		var dvdWidth = (dvdBubble.offsetWidth)/2-8;
		var rtWidth = (rtBubble.offsetWidth)/2-8;
		var dlWidth = (dlBubble.offsetWidth)/2-8;
		var foolWidth = (foolBubble.offsetWidth)/2-8;
		
		if (state=="on") {
			object.swap(obj);
			cdBubble.style.top = tp-30;
			cdBubble.style.left = lft-cdWidth;
			dvdBubble.style.top = tp-30;
			dvdBubble.style.left = lft-dvdWidth;
			rtBubble.style.top = tp-30;
			rtBubble.style.left = lft-rtWidth;
			dlBubble.style.top = tp-30;
			dlBubble.style.left = lft-dlWidth;
			foolBubble.style.top = tp-30;
			foolBubble.style.left = lft-foolWidth;
			
			if (hover=="cd") cdBubble.style.visibility = "visible";
			if (hover=="dvd") dvdBubble.style.visibility = "visible";
			if (hover=="rt") rtBubble.style.visibility = "visible";
			if (hover=="dl") dlBubble.style.visibility = "visible";
			if (hover=="fool") foolBubble.style.visibility = "visible";
			
		} else if (state=="off") {
			object.swap(obj);
			if (hover=="cd") cdBubble.style.visibility = "hidden";
			if (hover=="dvd") dvdBubble.style.visibility = "hidden";
			if (hover=="rt") rtBubble.style.visibility = "hidden";
			if (hover=="dl") dlBubble.style.visibility = "hidden";
			if (hover=="fool") foolBubble.style.visibility = "hidden";
		}
	
	}
}

//used for the RIAA certification bubble pop-up in the charts pages
//NOTE: this function is outdated 
function overlay(page,state,obj,img,object) {
	var riaaBubble = document.getElementById(object);
	var lft = xPos(obj);
	var tp = yPos(obj);
	if (page=="11-50") {
		var x_disp = -129;
		var y_disp = 13;
	} else if (page=="1-10") {
		var x_disp = -104;
		var y_disp = 17;
	}
	if (state=="on"){
		obj.style.backgroundColor = '54672D';
		img.swap(obj.childNodes[1]);
		obj.childNodes[0].style.color = 'FFFFFF';
		obj.childNodes[2].style.color = 'FFFFFF';
		riaaBubble.style.top = tp+y_disp;
		riaaBubble.style.left = lft+x_disp;
		riaaBubble.style.visibility = "visible";
	} else if (state=="off") {
		obj.style.backgroundColor = 'BBDE00';
		img.swap(obj.childNodes[1]);
		obj.childNodes[0].style.color = '000000';
		obj.childNodes[2].style.color = '000000';
		riaaBubble.style.top = 0;
		riaaBubble.style.left = -300;
		riaaBubble.style.visibility = "hidden";
	}
}

//navRollover is being used on the header for the submenus of the topNav sections
//navRollover simply changes a link's background image and its rollover color at once
	
function navRollover(elementId,linkId,menu,state,subsection) {
	var obj = document.getElementById(elementId);
	var lnk = document.getElementById(linkId);
	
	if (state=="on") {
		obj.style.cursor = "pointer";
		
		if (menu=="charts")	{
		if (obj.style.backgroundImage=="url(/bbcom/images/top_nav_charts_submenu_sel.gif)") {
			obj.style.backgroundImage = "url(/bbcom/images/top_nav_charts_submenu_sel.gif)";
			lnk.style.color = "000000";
		} else {
			obj.style.backgroundImage = "url(/bbcom/images/top_nav_charts_submenu_hl.gif)";
			lnk.style.color = "288400";
			}
			
		} else if (menu=="news")	{
		if (obj.style.backgroundImage=="url(/bbcom/images/top_nav_news_submenu_sel.gif)") {
			obj.style.backgroundImage = "url(/bbcom/images/top_nav_news_submenu_sel.gif)";
			lnk.style.color = "000000";
		} else {
			obj.style.backgroundImage = "url(/bbcom/images/top_nav_news_submenu_hl.gif)";
			lnk.style.color = "004294";
			}
			
		} else if (menu=="artists")	{
		if (obj.style.backgroundImage=="url(/bbcom/images/top_nav_artists_submenu_sel.gif)") {
			obj.style.backgroundImage = "url(/bbcom/images/top_nav_artists_submenu_sel.gif)";
			lnk.style.color = "000000";
		} else {
			obj.style.backgroundImage = "url(/bbcom/images/top_nav_artists_submenu_hl.gif)";
			lnk.style.color = "FFCA97";
			}
			
			
		} else if (menu=="tools")	{
		if (obj.style.backgroundImage=="url(/bbcom/images/top_nav_tools_submenu_sel.gif)") {
			obj.style.backgroundImage = "url(/bbcom/images/top_nav_tools_submenu_sel.gif)";
			lnk.style.color = "000000";
		} else {
			obj.style.backgroundImage = "url(/bbcom/images/top_nav_tools_submenu_hl.gif)";
			lnk.style.color = "0033DE";
			}
			
		} else if (menu=="entertain")	{
		if (obj.style.backgroundImage=="url(/bbcom/images/top_nav_entertain_submenu_sel.gif)") {
			obj.style.backgroundImage = "url(/bbcom/images/top_nav_entertain_submenu_sel.gif)";
			lnk.style.color = "000000";
		} else {
			obj.style.backgroundImage = "url(/bbcom/images/top_nav_entertain_submenu_hl.gif)";
			lnk.style.color = "B03A00";
			}
			
		} else if (menu=="interact")	{
		if (obj.style.backgroundImage=="url(/bbcom/images/top_nav_interact_submenu_sel.gif)") {
			obj.style.backgroundImage = "url(/bbcom/images/top_nav_interact_submenu_sel.gif)";
			lnk.style.color = "000000";
		} else {
			obj.style.backgroundImage = "url(/bbcom/images/top_nav_interact_submenu_hl.gif)";
			lnk.style.color = "3C6B68";
			}
			
		} else if (menu=="about")	{
		if (obj.style.backgroundImage=="url(/bbcom/images/top_nav_about_submenu_sel.gif)") {
			obj.style.backgroundImage = "url(/bbcom/images/top_nav_about_submenu_sel.gif)";
			lnk.style.color = "000000";
		} else {
			obj.style.backgroundImage = "url(/bbcom/images/top_nav_about_submenu_hl.gif)";
			lnk.style.color = "597227";
			}
		}	
		
	} else if (state=="off") {
		obj.style.cursor = "auto";
		
		if (menu=="charts")	{
		
		if (obj.style.backgroundImage=="url(/bbcom/images/top_nav_charts_submenu_sel.gif)") {
			obj.style.backgroundImage = "url(/bbcom/images/top_nav_charts_submenu_sel.gif)";
			lnk.style.color = "000000";
		} else {
			obj.style.backgroundImage = "";
			lnk.style.color = "1A1D1E";
			}
			
		} else if (menu=="news") {
		
		if (obj.style.backgroundImage=="url(/bbcom/images/top_nav_news_submenu_sel.gif)") {
			obj.style.backgroundImage = "url(/bbcom/images/top_nav_news_submenu_sel.gif)";
			lnk.style.color = "000000";
		} else {
			obj.style.backgroundImage = "";
			lnk.style.color = "1A1D1E";
		}
			
		} else if (menu=="artists")	{
		if (obj.style.backgroundImage=="url(/bbcom/images/top_nav_artists_submenu_sel.gif)") {
			obj.style.backgroundImage = "url(/bbcom/images/top_nav_artists_submenu_sel.gif)";
			lnk.style.color = "000000";
		} else {
			obj.style.backgroundImage = "";
			lnk.style.color = "FFFFFF";
			}
			
			
		} else if (menu=="tools")	{
		if (obj.style.backgroundImage=="url(/bbcom/images/top_nav_tools_submenu_sel.gif)") {
			obj.style.backgroundImage = "url(/bbcom/images/top_nav_tools_submenu_sel.gif)";
			lnk.style.color = "000000";
		} else {
			obj.style.backgroundImage = "";
			lnk.style.color = "1A1D1E";
			}
			
		} else if (menu=="entertain")	{
		if (obj.style.backgroundImage=="url(/bbcom/images/top_nav_entertain_submenu_sel.gif)") {
			obj.style.backgroundImage = "url(/bbcom/images/top_nav_entertain_submenu_sel.gif)";
			lnk.style.color = "000000";
		} else {
			obj.style.backgroundImage = "";
			lnk.style.color = "1A1D1E";
			}
			
			
		} else if (menu=="interact")	{
		if (obj.style.backgroundImage=="url(/bbcom/images/top_nav_interact_submenu_sel.gif)") {
			obj.style.backgroundImage = "url(/bbcom/images/top_nav_interact_submenu_sel.gif)";
			lnk.style.color = "000000";
		} else {
			obj.style.backgroundImage = "";
			lnk.style.color = "1A1D1E";
			}
			
		} else if (menu=="about")	{
		if (obj.style.backgroundImage=="url(/bbcom/images/top_nav_about_submenu_sel.gif)") {
			obj.style.backgroundImage = "url(/bbcom/images/top_nav_about_submenu_sel.gif)";
			lnk.style.color = "000000";
		} else {
			obj.style.backgroundImage = "";
			lnk.style.color = "1A1D1E";
			}
		}
	}
}


//positionSection is used for the Reviews pages module
//positionSection repositions a selected element and then calls swapSection();
function positionSection(sec) {
	var obj = document.getElementById('reviewsModule');
	var menu = document.getElementById(sec);
	var obj_x = xPos(obj);
	var obj_y = yPos(obj);
	menu.style.top = obj_y;
	menu.style.left = obj_x;
	_section = sec;
}

//positionSection is used for the Reviews pages module
//positionSection repositions a selected element and then calls swapSection();
function positionSection2(sec) {
	var obj = document.getElementById('tvModule');
	var menu = document.getElementById(sec);
	var obj_x = xPos(obj);
	var obj_y = yPos(obj);
	menu.style.top = obj_y;
	menu.style.left = obj_x+12;
}

//swapSection is used for the Reviews pages module
//swapSection is used to control the visibility for any of the 4 elements that the module is composed of
function swapSection(sec) {
	var albumMod = document.getElementById('nwsReviewsModule_album');
	var singleMod = document.getElementById('nwsReviewsModule_single');
	var liveMod = document.getElementById('nwsReviewsModule_live');
	var bookMod = document.getElementById('nwsReviewsModule_book');
	albumMod.style.visibility = 'hidden';
	albumMod.style.left = 0;
	albumMod.style.top = 0;
	singleMod.style.visibility = 'hidden';
	singleMod.style.left = 0;
	singleMod.style.top = 0;
	liveMod.style.visibility = 'hidden';
	liveMod.style.left = 0;
	liveMod.style.top = 0;
	bookMod.style.visibility = 'hidden';
	bookMod.style.left = 0;
	bookMod.style.top = 0;
	document.getElementById(sec).style.visibility = 'visible';
	positionSection(sec);
}

//for changing text selected from a drop-down menu...
//ddChangeText is used on most drop down menu items that don't link the user immediately
function ddChangeText(elementId, newText) {
	document.getElementById(elementId).innerHTML = newText;
	xMenu.doHide();
}

//for changing the mouse cursor onMouseOver / onMouseOut
function changeCursor(obj, state) {
	if (state=="on") {
		obj.style.cursor = "pointer";
	} else {
		obj.style.cursor = "default";
	}
}






	
