/*
 * @(#) madonna.js	(c)2005 jon r. luini, chime interactive
 *
 * see http://www.chime.com/ for contact info/use permissions
 * note: this requires chime_request.js to be loaded already
 */

// the main content ID
var MAIN_CONTENT = "mainContent";
var currentLocation = "http://www.madonna.com/";
var myHistory = new Array ();
var myHistoryPos = 0;
var myLanguage = "ENGLISH";

// these globals that can be used from other routines
var pageWidth;
var pageHeight;
var contentHeight;

// window.onload	= function() { findDimensions(); };
// window.onresize	= function() { findDimensions(); };

function findDimensions ()
{
    var frameWidth;
    var frameHeight;
    var obj;
    var main_obj = myGetElementById(MAIN_CONTENT);
    var nav_obj = myGetElementById('nav');
    var nav_height = nav_obj ? nav_obj.offsetHeight : 0;
    var disco_obj = myGetElementById('disco');

    if (self.innerWidth)
    {
	frameWidth = self.innerWidth;
	frameHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientWidth)
    {
	frameWidth = document.documentElement.clientWidth;
	frameHeight = document.documentElement.clientHeight;
    }
    else if (document.body)
    {
	frameWidth = document.body.clientWidth;
	frameHeight = document.body.clientHeight;
    }
    else
	return;

    // if there's valid info, update the globals so they can be used elsewhere
    pageWidth = frameWidth;
    pageHeight = frameHeight;

    contentHeight = pageHeight - nav_height;

    main_obj.style.height = contentHeight + "px";
    if ( disco_obj )
	disco_obj.style.height = contentHeight + "px";

    if ( (bg_obj = myGetElementById('background')) )
    {
	bg_obj.style.height = contentHeight + "px";
    }

    if ( (bi_obj = myGetElementById('background_image')) )
    {
	var iWidth = bi_obj.width; 
	var iHeight = bi_obj.height;
	var iRatio = iWidth / iHeight;
	var fRatio = pageWidth / contentHeight;	
	var imagePageRatio = pageWidth / iWidth;
	var back_edge_obj = myGetElementById('background_edge');
	
	// make sure we don't do any background image work
	// until it's fully loaded and has both height & width values
	if ( iWidth == 0 || iHeight == 0 || iWidth == 1 || iHeight == 1 )
	    iRatio = 0;

	/*
	alert ("iWidth = " + iWidth
	    + " iHeight = " + iHeight
	    + " iratio = " + iRatio
	    + " nav height = " + nav_height
	    + " fRatio = " + fRatio);
	*/

	if ( pageWidth > 990 ) 
	{
	    if ( iRatio != 0 )
	    {
		bi_obj.style.width = pageWidth + "px";
		bi_obj.style.height = parseInt(imagePageRatio * iHeight) + "px";
		bg_obj.style.width = "100%";
		/*main_obj.style.height = contentHeight / iRatio; */
		/*
		if ( disco_obj )
		    disco_obj.style.height = contentHeight / iRatio;
		*/

		if ( back_edge_obj )
		{
		    back_edge_obj.style.width = "100%";
		    back_edge_obj.style.top = (nav_height + bi_obj.offsetTop + parseInt(bi_obj.style.height) - back_edge_obj.offsetHeight ) + "px";
		    back_edge_obj.style.display = "block";
		}
	    }

	    myGetElementById('nav').style.width = "100%";
	    // myGetElementById('DANCEFLOOR_ICON_BPM').style.visibility = "visible";
	    myGetElementById('DANCEFLOOR_ICON_CREDITS').style.visibility = "visible";
	    myGetElementById('DANCEFLOOR_ICON_MIXTAPE').style.visibility = "visible";
	}
	else
	{
	    if ( iRatio != 0 )
	    {
		bi_obj.style.width = 990;
		bi_obj.style.height = parseInt(900 * pageHeight / iWidth) + "px";
		bg_obj.style.width = 990;
		/*
		main_obj.style.height = 990 / iRatio;
		if ( disco_obj )
		    disco_obj.style.height = 990 / iRatio;
		*/

		if ( back_edge_obj )
		{
		    back_edge_obj.style.width = 990;
		    back_edge_obj.style.top = (nav_height + bi_obj.offsetTop + parseInt(bi_obj.style.height) - back_edge_obj.offsetHeight ) + "px";
		    back_edge_obj.style.display = "block";
		}
	    }

	    myGetElementById('nav').style.width = 990;
	    //myGetElementById('DANCEFLOOR_ICON_BPM').style.visibility = "visible";
	    myGetElementById('DANCEFLOOR_ICON_CREDITS').style.visibility = "visible";
	    myGetElementById('DANCEFLOOR_ICON_MIXTAPE').style.visibility = "visible";
	}
    }

    if ( (obj = myGetElementById('tagging')) )
    {
	obj.style.width = "100%";
	obj.style.height = 700;
	main_obj.style.height = 700;
	if ( back_edge_obj ) back_edge_obj.style.visibility = "hidden";
	//myGetElementById('DANCEFLOOR_ICON_BPM').style.visibility = "hidden";
	myGetElementById('DANCEFLOOR_ICON_CREDITS').style.visibility = "hidden";
	myGetElementById('DANCEFLOOR_ICON_MIXTAPE').style.visibility = "hidden";
    }
    if ( (obj = myGetElementById('timeline')) )
    {
	obj.style.width = "100%";
	obj.style.height = 700;
	main_obj.style.height = 700;
	if ( back_edge_obj ) back_edge_obj.style.visibility = "hidden";
	//myGetElementById('DANCEFLOOR_ICON_BPM').style.visibility = "hidden";
	myGetElementById('DANCEFLOOR_ICON_CREDITS').style.visibility = "hidden";
	myGetElementById('DANCEFLOOR_ICON_MIXTAPE').style.visibility = "hidden";
    }
}

function minval(value,min)
{
    if ( value < min ) return min;
    return value;
}

function startDisco ()
{
    var obj = myGetElementById('disco');
    var check;

    if ( ! obj ) return;

    if ( (check = myGetElementById('tagging')) )
    { 
	clearDisco();
    }
    else if ( (check = myGetElementById('timeline')) )
    { 
	clearDisco();
    }
    else
    {
	if ( obj )
	{
	    if ( obj.style.zIndex == 9 )
	    {
		clearDisco();
	    }
	    else
	    {
		sndReq ('disco', 'discolightsbig.html');
		obj.style.zIndex = 9;
	    }
	}
    }
}

function clearDisco()
{
    var obj = myGetElementById('disco');
    if ( obj )
    {
	obj.innerHTML = "";
	obj.style.zIndex = -1;
	obj.onClick = undefined;
    }
}

function emailSubmit (to, subj, msg)
{
    if ( ! subj ) subj = "MADONNA.COM";
    if ( ! msg ) msg = "Check out this page at the brand new Madonna.com and listen to her new single, HUNG UP!\r\r" + currentLocation;
    var url = "mailto:" + escape(to)
	+ "?subject=" + escape(subj)
	+ "&body=" + escape(msg);
    popup (url);
    return false;
}

function emailSubmitForm (form, what)
{
    var subj = "MADONNA.COM";
    var msg = "Check out this page at the brand new Madonna.com and listen to her new single, HUNG UP!\r\r" + currentLocation;
    var to = form.email.value;
    emailSubmit (to, subj, msg);
    minimizePanel(what);
    return false;
}

/*
 * flashSendSong() - send a song to the flash player
 */
function flashSendSong (url, title, album, image, buycd, buyringtones, buyitunes)
{
    if ( pageIsLoaded == true && window.document && window.document.player_swf )
    {
	try {
	    if ( ! window.document.player_swf.GetVariable("_root.addtrack") )
		return;
	    else
	    {
		//url = "http://download.wbr.com/madonna/swfmedia/" + url;
		url = "http://download.wbr.com/madonna/" + url;
		//debug ("flashSendSong("+title+","+album+","+url+","+image+","+buycd+","+buyringtones+","+buyitunes);
		window.document.player_swf.SetVariable("_root.ntitle", title);
		window.document.player_swf.SetVariable("_root.nalbum", album);
		window.document.player_swf.SetVariable("_root.nURL", url);
		window.document.player_swf.SetVariable("_root.nimage", image);
		window.document.player_swf.SetVariable("_root.nbuycd", buycd);
		window.document.player_swf.SetVariable("_root.nbuyringtones", buyringtones);
		window.document.player_swf.SetVariable("_root.nbuyitunes", buyitunes);
		window.document.player_swf.SetVariable("_root.addtrack", 1);
	    }
	}
	catch (e) { }
    }
    return;
}

/*
 * flashPausePlayer() - send a request to pause the flash player
 */
function flashPausePlayer ()
{
    if ( pageIsLoaded == true && window.document && window.document.player_swf )
    {
	try {
	    if ( ! window.document.player_swf.GetVariable("_root.pausePlayer") )
		return;
	    else
		window.document.player_swf.SetVariable("_root.pausePlayer", 1);
	}
	catch (e) { }
    }
    return;
}

/*
 * setLocation() - set's the location in the nav bar
 */
function setLocation (url)
{
    if ( pageIsLoaded == true && window.document )
    {
	if ( window.document.locbar_swf )
	{
	    try {
		if ( ! window.document.locbar_swf.GetVariable("_root.location") )
		    setTimeout ('window.document.locbar_swf.SetVariable("_root.location", currentLocation);', 500);
		else
		    window.document.locbar_swf.SetVariable("_root.location", currentLocation);
	    }
	    catch (e) { }
	}
	if ( window.document.nav_swf )
	{
	    try {
		if ( ! window.document.nav_swf.GetVariable("_root.location") )
		    setTimeout ('window.document.nav_swf.SetVariable("_root.location", currentLocation);', 500);
		else
		    window.document.nav_swf.SetVariable("_root.location", currentLocation);
	    }
	    catch (e) { }
	}
    }
}

function setLocationCurrent ()
{
    setLocation (currentLocation);
}

/*
 * openLink() - this updates the location content and also
 * opens a URL into "id"
 */
function openLink (area, id, loc_piece, anchorId, scrollDiv, thisHistoryPos)
{
    var loc_str;
    var url;

    // most pages are converted to using the
    // new database-created content which uses php to include
    // those pieces
    if ( area == "home"
    || area == "home_grid"
	|| area == "spin"
	|| area == "spin-singles"
	|| area == "read"
	|| area == "push"
	|| area == "dancefloor"
	|| area == "dancefloor-galleries"
	|| area == "dancefloor-magazinecovers"
	|| area == "news"
	|| area == "news-archives"
	|| area == "news-polls"
	|| area == "news-headlines" )
    {
	url = area + ".php";
    }
    else
    {
	url = area + ".html";
    }

    if ( ! id ) id = MAIN_CONTENT;
    if ( ! loc_piece )
    {
	var re = new RegExp("-", "g");
	var myArea = area.replace (re, "/");
	loc_piece = myArea + "/";
    }

    debug ("AJAX("+id+"): " + url + " myArea=" + myArea);

    // no point in having extra /home/ in there
    if ( loc_piece == "home/" ) loc_piece = "";

    loc_str = "http://www.madonna.com/" + loc_piece;
    currentLocation = loc_str;

    setLocationCurrent ();

//    if ( anchorId && ! scrollDiv )
//	scrollDiv = MAIN_CONTENT;

    if ( ! scrollDiv )
	scrollDiv = id;

    // make sure these are minimized before opening a new page
    minimizePanel('bpm_panel');
    minimizePanel('credits_content');

    // minimize this only if it's not a spin-related page
    if ( url.indexOf ("spin-") < 0 || url.indexOf("spin-video") >= 0 )
	minimizePanel('mixtape');
    else
    {
	// this is a stupid workaround to loading a spin page
	// through url rewriting which minimizes the mixtape panel
	// (see index.php) after the page has loaded which then
	// would override this. instead we set a timeout to show it 
	// again. when clicking direct to the page, this will be
	// redundant since it'll already be displayed
	setTimeout ("restorePanel('mixtape')", 1500);
    }

    // a safeguard against these being stuck across other pages
    hideSpinTip();

    sndReq (id, url, pageLoaded, area, anchorId, scrollDiv, thisHistoryPos);
}

function pageLoaded (url, id, area, anchorId, scrollDiv, thisHistoryPos)
{
    var bg;

    debug ("finished load of url=" + url + " into id=" + id + " area=" + area);

    // news story panels need to be set to the right language immediately 
    // after they are finished loading
    if ( url.indexOf ("news_story") > -1 && id == "news_items_content" )
	setLanguage (myLanguage, id);

    // reset all DANCEFLOOR_ICON_* to be invisible if this is loading
    // into the main content panel
    if ( id == MAIN_CONTENT )
    {
	var i, dobj;
	for (i = 1; dobj = myGetElementById ("DANCEFLOOR_ICON_"+i); i++ )
	{
	    dobj.style.visibility = "hidden"; 
	    dobj.style.display = "none"; 
	}
    }

    // update the background, javacript, panel positions and history
    // if needed (only on main content page)
    if ( id == MAIN_CONTENT )
    {
	updateBackground (id);
	updateJavascript (id);
	updatePanelPosition (id);
	historyPush (id, area, anchorId, scrollDiv, thisHistoryPos);
    }
    else
    {
	updateJavascript (id);
    }

    // look for any objects that need to be minimized
    // this is *not* the most efficient, so it should be
    // redone at some point to be a lot better. right now
    // it looks through all children of the currently loaded content id
    // for DIV's that have the "auto_minimize" attribute set to true
    var contentObj = myGetElementById (id);
    for ( var o = contentObj.firstChild; o; o = o.nextSibling )
    {
	if ( o.nodeName != "DIV" ) continue;
//	debug ("Checking " +o.getAttribute('id') + " for auto_minimize");
	if ( o.getAttribute("auto_minimize") == "true" )
	    minimizePanel (o.getAttribute('id'));
    }

    // reset scroll to the top
    var sobj = myGetElementById (scrollDiv);
    if ( sobj ) sobj.scrollTop = 0;

    // and then reset to a specific anchor, if one was specified
    if ( anchorId )
    {
	var aobj = myGetElementById (anchorId);
	if ( aobj && sobj )
	{
	    sobj.scrollTop = aobj.offsetTop;
//	    aobj.style.border = "solid 1px";
	}
    }

    findDimensions();
}

function setDanceFloorIconPos (num, top, right, bottom, left)
{
    var dfStr = "DANCEFLOOR_ICON_" + num;
    var obj = myGetElementById (dfStr);

    if ( obj )
    {
	if ( top ) { obj.style.top = top; }
	if ( right ) { obj.style.right = right; }
	if ( bottom ) { obj.style.bottom = bottom; }
	if ( left ) { obj.style.left = left; }
    }
}

function loadBackground (url)
{
    var obj = myGetElementById("background_image");

    if ( ! obj ) return;
    obj.src = url;
}

var revealNavIntervalId = undefined;
var hideNavIntervalId = undefined;
var hideNavTimerId = undefined;
var hideNavTimeout = undefined;
var hideNavTimerStart = undefined;

function revealNavPiece (id)
{
    var obj = myGetElementById(id);
    var top = parseInt (obj.style.top, 10);

    if ( top >= 0 )
    {
	obj.style.top = 0;
	clearInterval(revealNavIntervalId);
	revealNavIntervalId = undefined;
    }
    else
    {
	var newTop = (top + 30);
	if ( newTop > 0 ) newTop = 2;	// this gives is a little bump effect
	obj.style.top = newTop + "px";
    }
}

function revealNav ()
{
    var id = "nav";

    // if we're already revealing, don't bother trying again
    if ( revealNavIntervalId != undefined )
	return;

    var obj = myGetElementById(id);
    if ( obj )
    {
	// if saveTop is set, we're already out!
	if ( obj.saveTop != undefined )
	    return;

	obj.saveTop = obj.style.top;
	var cmd = "revealNavPiece ('" + id + "')";
	revealNavIntervalId = setInterval (cmd, 1);
	// obj.style.top = 0;

	// look for any objects that need to be minimized
	// this is *not* the most efficient, so it should be
	// redone at some point to be a lot better. right now
	// it looks through all children of MAIN_CONTENT for DIV's 
	// that have the "nav_open_minimize" attribute set to true
	var contentObj = myGetElementById (MAIN_CONTENT);
	for ( var o = contentObj.firstChild; o; o = o.nextSibling )
	{
	    if ( o.nodeName != "DIV" ) continue;
//	    debug ("Checking " +o.getAttribute('id')
//		+ " for nav_open_minimize: "
//		+ o.getAttribute("nav_open_minimize"));
	    if ( o.getAttribute("nav_open_minimize") == "true" )
		minimizePanel (o.getAttribute('id'));
	}

	// also check the main page
	var contentObj = myGetElementById ("BODY");
	for ( var o = contentObj.firstChild; o; o = o.nextSibling )
	{
	    if ( o.nodeName != "DIV" ) continue;
//	    debug ("Checking " +o.getAttribute('id')
//		+ " for nav_open_minimize: "
//		+ o.getAttribute("nav_open_minimize"));
	    if ( o.getAttribute("nav_open_minimize") == "true" )
		minimizePanel (o.getAttribute('id'));
	}

    }
}

function hideNavPiece (id)
{
    var obj = myGetElementById(id);

    var top = parseInt (obj.style.top, 10);
    var saveTop = parseInt (obj.saveTop, 10);

    if ( top <= saveTop  )
    {
	if ( pageIsLoaded == true && window.document && window.document.nav_swf )
	{
	    try { window.document.nav_swf.SetVariable("restoreloc", "1"); }
	    catch (e) { }
	}

	obj.style.top = obj.saveTop;
	obj.saveTop = undefined;
	clearInterval(hideNavIntervalId);
	hideNavIntervalId = undefined;

	// look for any objects that need to be minimized
	// this is *not* the most efficient, so it should be
	// redone at some point to be a lot better. right now
	// it looks through all children of MAIN_CONTENT for DIV's 
	// that have the "nav_open_minimize" attribute set to true
	var contentObj = myGetElementById (MAIN_CONTENT);
	for ( var o = contentObj.firstChild; o; o = o.nextSibling )
	{
	    if ( o.nodeName != "DIV" ) continue;
//	    debug ("Checking " +o.getAttribute('id')
//		+ " for nav_close_restore: "
//		+ o.getAttribute("nav_close_restore"));
	    if ( o.getAttribute("nav_close_restore") == "true" )
		restorePanel (o.getAttribute('id'));
	}

	// also check the main page
	var contentObj = myGetElementById ("BODY");
	for ( var o = contentObj.firstChild; o; o = o.nextSibling )
	{
	    if ( o.nodeName != "DIV" ) continue;
//	    debug ("Checking " +o.getAttribute('id')
//		+ " for nav_close_restore: "
//		+ o.getAttribute("nav_close_restore"));
	    if ( o.getAttribute("nav_close_restore") == "true" )
		restorePanel (o.getAttribute('id'));
	}
    }
    else
    {
	var newTop = (top - 60);
	if ( newTop < saveTop ) newTop = saveTop -2;	// this gives is a little bump effect
	obj.style.top = newTop + "px";
    }
}

function hideNav ()
{
    var id = "nav";

    var obj = myGetElementById(id);

    // clear the timeout id first thing
    if ( hideNavTimerId != undefined ) 
    {
	clearTimeout (hideNavTimerId);
	hideNavTimerId = undefined;
    }

    // Stop capturing mousemove and mouseup events in case they are active
    if (browser.isIE)
	document.detachEvent("onmousemove", hideNavTimerUpdate);
    if (browser.isNS) 
	document.removeEventListener("mousemove", hideNavTimerUpdate, true);

    hideNavTimerId = hideNavTimeout = hideNavTimerStart = undefined;

    // if there's no nav, forget it!
    if ( ! obj )
	return;

    // if we're already midway through hiding, don't bother trying again
    if ( hideNavIntervalId != undefined )
	return;

    // if we're already hidden, don't bother doing it again
    if ( ! obj.saveTop || obj.saveTop == undefined )
	return;

    // if a reveal is going on, cancel it since we're hiding
    if ( revealNavIntervalId != undefined )
    {
	clearInterval (revealNavIntervalId);
	revealNavIntervalId = undefined;
    }


    // obj.style.top = obj.saveTop;
    // obj.saveTop = undefined;

    var cmd = "hideNavPiece ('" + id + "')";
    hideNavIntervalId = setInterval (cmd, 1);
}

/*
 * hideNavTimer() - this is called onMouseOut of the nav to start
 *   a timer (actually as a mousemove event handler that calls
 *   hideNavTimerUpdate) to see when we should hide the nav.
 */
function hideNavTimer ()
{
    var navId = "nav";
    var navObj = myGetElementById(navId);

    if ( ! navObj )
	return;

    // first, get rid of any other pending hide timeout
    if ( hideNavTimerId )
    {
	clearTimeout (hideNavTimerId);
	hideNavTimerId = hideNavTimeout = hideNavTimerStart = undefined;
    }

    // if the nav is already hidden or are in the process of hiding,
    // don't bother checking to do it again
    if ( ! navObj.saveTop || navObj.saveTop == undefined || hideNavIntervalId )
	return;

    // browser variable is set in js/drag.js -- if not, just hide asap
    if ( ! browser )
	return hideNav();

    // Capture mouseMove events on the page so we can check
    // to see if we need to hide quicker
    if (browser.isIE)
	document.attachEvent("onmousemove", hideNavTimerUpdate);
    if (browser.isNS)
	document.addEventListener("mousemove", hideNavTimerUpdate, true);
}

/*
 * hideNavTimerUpdate() - this is called after you mouse out from
 *   the nav. the further you move the mouse away from the nav, the
 *   quicker the hideNav() function is called
 */
function hideNavTimerUpdate (event)
{
    var DEFAULT_ACTIVATE_PIXELS = 10;
    var DEFAULT_TIMEOUT = 1;

    var dx, dy, dstr, timeout_secs;
    var navId = "nav";
    var navObj = myGetElementById(navId);

    // if the nav is already hidden or are in the process of hiding,
    // don't bother checking to do it again
    if ( ! navObj.saveTop || navObj.saveTop == undefined || hideNavIntervalId )
    {
	debug ("hideNavTimerUpdate(): STOPPING " + new Date()); 
	// Stop capturing mousemove and mouseup events.
	if (browser.isIE)
	    document.detachEvent("onmousemove", hideNavTimerUpdate);
	if (browser.isNS) 
	    document.removeEventListener("mousemove", hideNavTimerUpdate, true);
	return;
    }

    if (browser.isIE)
    {
	dx = window.event.clientX + document.documentElement.scrollLeft
	    + document.body.scrollLeft;
	dy = window.event.clientY + document.documentElement.scrollTop
	    + document.body.scrollTop;
    }
    if (browser.isNS)
    {
	dx = event.clientX + window.scrollX;
	dy = event.clientY + window.scrollY;
    }

    dx -= (navObj.offsetLeft + navObj.offsetWidth);
    dy -= (navObj.offsetTop + navObj.offsetHeight);

    dstr = "hideNavTimer() at " + new Date()
	+ " dx=" + dx + ", dy=" + dy;
    debug (dstr);

    // this technically shouldn't happen since we should only be 
    // called onMouseOut so the cursor wouldn't be over the nav
    // but it could be from moving off and then back on top before
    // the timeout expires
    if ( dx < 0 && dy < 0 )
    {
	// Stop capturing mousemove and mouseup events.
	if (browser.isIE)
	    document.detachEvent("onmousemove", hideNavTimerUpdate);
	if (browser.isNS) 
	    document.removeEventListener("mousemove", hideNavTimerUpdate, true);

	if ( hideNavTimerId )
	{
	    clearTimeout (hideNavTimerId);
	    hideNavTimerId = hideNavTimeout = hideNavTimerStart = undefined;
	}

	debug ("hideNavTimerUpdate(): STOPPING 2 " + new Date()); 
	return;
    }

    if ( dx < 0 ) dx = 0;
    if ( dy < 0 ) dy = 0;

    if ( dx + dy < DEFAULT_ACTIVATE_PIXELS )
	return;

    if ( ! hideNavTimerStart )
    {
	var now = new Date();
	hideNavTimerStart = now.getTime();
    }

    /*
    400 = 10   400y = 10    y =         1/40
    200 = 5    200y = 5     y = 5/200 = 1/40
    100 = 2.5  100y = 2.5   y = 2.5/100 = 1/40
    20 = .5     20y = .5    y =         1/40
    */
    var tmp = parseInt ((dx + dy) / 40, 10);
    timeout_secs = DEFAULT_TIMEOUT - tmp;
    if ( timeout_secs < 0 ) timeout_secs = 0;
    else if ( timeout_secs > DEFAULT_TIMEOUT ) timeout_secs = DEFAULT_TIMEOUT;

    if ( hideNavTimeout == undefined || timeout_secs < hideNavTimeout )
    {
	var new_timeout = timeout_secs * 1000;

	if ( hideNavTimeout )
	{
	    // new timer is the new timeout - the elapsed time so far
	    var d = new Date();
	    new_timeout = (timeout_secs * 1000) - (d.getTime() - hideNavTimerStart);
	}

	// Windows/IE doesn't activate a setTimeout with a time of 0!
	if ( new_timeout <= 0 ) new_timeout = 1;

	hideNavTimeout = timeout_secs;

	// clear existing, if there is one
	if ( hideNavTimerId )
	    clearTimeout (hideNavTimerId);

	// reset new timeout
	hideNavTimerId = setTimeout ("hideNav()", new_timeout);
	dstr = "hideNavTimer() updated at " + new Date()
	    + " to " + timeout_secs + " / " + new_timeout + ", dy=" + dy + " id = " + hideNavTimerId;
    }
    else
	dstr = "hideNavTimer() updated at " + new Date()
	    + " dx=" + dx + ", dy=" + dy + " id = " + hideNavTimerId
	    + " new timeout_secs of " + timeout_secs 
	    + " >= current of " + hideNavTimeout;

    var d = new Date();
    var left = (hideNavTimeout * 1000) - (d.getTime() - hideNavTimerStart);
    dstr += " " + left + " left";
    debug (dstr);
}

/*
 * this is called to reset the background image and height/width
 */
function setBackground (url, width, height, placement, bgcolor, bgrepeat)
{
    var bg_obj = myGetElementById('background');
    var bg_img_obj = myGetElementById('background_image');

    if ( typeof(placement) == "undefined" || placement == null )
	placement = "";

    // failed to find the DIVs
    if ( ! bg_obj || ! bg_img_obj )
	return;

    if ( placement != "" )
    {
	bg_img_obj.style.display = "none";
	if ( typeof(bgrepeat) == "undefined" ) bgrepeat = "no-repeat";
	if ( typeof(bgcolor) == "undefined" ) bgcolor = "#FFFFFF";
	bg_obj.style.backgroundImage = "url(" + url + ")";
	//bg_obj.style.height = "100%";
	bg_obj.style.height = contentHeight + "px";
	bg_obj.style.width = "100%";
	bg_obj.style.backgroundRepeat = bgrepeat;
	bg_obj.style.backgroundColor = bgcolor;

	if ( typeof (height) != "undefined" )
	{
	    placement = placement.toLowerCase();
	    if ( contentHeight < height && placement.indexOf("bottom") > -1 )
	    {
		var re = new RegExp("bottom", "g");
		placement = placement.replace (re, "top");
	    }
	}

	bg_obj.style.backgroundPosition = placement;
    }
    else
    {
	// this forces the src to be different than it currently
	// is which guarantees the onload will fire (it won't if
	// the img hasn't changed, which is the case when switching
	// between background modes
	if ( bg_img_obj.style.display == "none" )
	    bg_img_obj.src = "images/placeholder.gif";

	bg_img_obj.onload = function () { 
	    bg_obj.style.background = "none";
	    bg_obj.style.height = "auto";
	    bg_obj.style.width = "auto";
	    this.style.display = "block";
	    if ( width ) this.style.width = width;
	    if ( height ) this.style.height = height;
	    findDimensions();
	}
	bg_img_obj.src = url;
    }
}

/*
 * this is called after a new page loads. id is the main content div
 * that has just been loaded and contains a special tag like:
 * <SPAN ID="PAGE_BACKGROUND" SRC="url" WIDTH="width" HEIGHT="height"></SPAN>
 *
 * Update 5/29/07 - now default to pull in new random background from
 * new js/random_bg.js unless we find a tag for PAGE_BACKGROUND_OVERRIDE
 * which then behaves just like PAGE_BACKGROUND did.  we need it to be
 * different so that we can override all of the older PAGE_BACKGROUNDs
 * that are still in the site
 *
 * Update 5/31/07 - back to using PAGE_BACKGROUND as primary and now
 * using <span id="PAGE_BACKGROUND_RANDOM"></span> to mean use random
 * as override
 *
 * Update 8/13/07 - new PAGE_BACKGROUND_STATIC option to pull in settings
 * based on js/static_bg.js
 */
function updateBackground (id)
{
    var obj = myGetElementById(id);
    if ( obj )
    {
	var newBgObj = myGetElementById("PAGE_BACKGROUND");
	var newBgPref = myGetElementById("PAGE_BACKGROUND_RANDOM");
	var newBgStatic = myGetElementById("PAGE_BACKGROUND_STATIC");

	if ( newBgStatic )
	{
	    var section = newBgStatic.getAttribute("section");
	    var page = newBgStatic.getAttribute("page");
	    var new_bg = get_static_background (section, page);
	    if ( new_bg )
	    {
		//alert ("new bg for " + section + "/" + page + " "  + new_bg.src);
		setBackground (new_bg.src,
		    new_bg.width,
		    new_bg.height,
		    new_bg.placement,
		    new_bg.bgcolor,
		    new_bg.bgrepeat);
		return;
	    }
	}

	if ( newBgPref )
	{
	    var placement = undefined;
	    var new_bg;

	    if ( newBgPref )
		placement = newBgPref.getAttribute("placement");

	    new_bg = get_background(placement);
	    if ( new_bg )
	    {
		setBackground (new_bg.src,
		    new_bg.width,
		    new_bg.height,
		    new_bg.placement,
		    new_bg.bgcolor,
		    new_bg.bgrepeat);
	    }
	}
	else if ( newBgObj )
	{
	    var src = newBgObj.getAttribute("src");

//	    alert ("Updating bg with " + src);
	    if ( src )
	    {
		setBackground (src,
		    newBgObj.getAttribute("width"),
		    newBgObj.getAttribute("height"),
		    newBgObj.getAttribute("placement"),
		    newBgObj.getAttribute("bgcolor"),
		    newBgObj.getAttribute("bgrepeat"));
	    }
	}
    }
}

/*
 * this is called after a new page loads. id is the main content div
 * that has just been loaded and contains a special tag like:
 * <SPAN ID="JAVASCRIPT">some code here</SPAN>
 */
function updateJavascript (id)
{
    var obj = myGetElementById(id);
    if ( obj )
    {
	var obj = myGetElementById("JAVASCRIPT");
	if ( obj && obj.innerHTML.length > 0 )
	{
	    try { eval (obj.innerHTML); }
	    catch (e) { alert(e); }
	}
    }
}

/*
 * add to our own internal history array
 */
function historyPush (id, area, anchorId, scrollDiv, thisHistoryPos)
{
    var obj = new Object();

    obj.id = id;
    obj.area = area;
    obj.anchorId = anchorId;
    obj.scrollDiv = scrollDiv;

    if ( typeof (thisHistoryPos) != "undefined" )
    {
	myHistoryPos = thisHistoryPos;
    }
    else
    {
	myHistory.push (obj);
	myHistoryPos = myHistory.length - 1;
    }
}

function hideHistory ()
{
    var obj = myGetElementById("history_show");

    if ( obj ) 
	obj.style.display = "none";
}

function showHistory ()
{
    var obj = myGetElementById("history_show");

    if ( obj )
    {
	var str = "";

	for ( i = 0; i < myHistory.length; i++ )
	{
	    var re = new RegExp("-", "g");
	    var dispArea = myHistory[i].area.replace (re, "/");
	    str += dispArea;
	    if ( i == myHistoryPos )
		str += " &nbsp;&nbsp;&lt;--";
	    str += "<BR>\n";
	}

	obj.innerHTML = str;
	obj.style.display = "block";
    }
}

/*
 * go back one step in our history
 */
function openHistoryBack ()
{
    if ( myHistoryPos > 0 )
    {
	myHistoryPos --;
	openLink (
	    myHistory[myHistoryPos].area,
	    myHistory[myHistoryPos].id,
	    undefined,
	    myHistory[myHistoryPos].anchorId,
	    myHistory[myHistoryPos].scrollDiv,
	    myHistoryPos);
    }
    else
	alert ("No previous history available");
}

/*
 * go forward one step in our history
 */
function openHistoryForward ()
{
    if ( myHistoryPos < (myHistory.length - 1) )
    {
	myHistoryPos++;
	openLink (
	    myHistory[myHistoryPos].area,
	    myHistory[myHistoryPos].id,
	    undefined,
	    myHistory[myHistoryPos].anchorId,
	    myHistory[myHistoryPos].scrollDiv,
	    myHistoryPos);
    }
    else
	alert ("No further history available");
}

/*
 * this is called after a new page loads. id is the main content div
 * that has just been loaded and contains a special tag like:
 * <SPAN ID="PANEL_ALIGNMENT">
 *   <SPAN ID="PANEL_spin_album_info_container"
 *   below="PANEL_spin_album_trax_container"></SPAN>
 * </SPAN>
 */
function updatePanelPosition (id)
{
    var obj = myGetElementById(id);
    if ( obj )
    {
	var posObj = myGetElementById("PANEL_ALIGNMENT");

	if ( ! posObj )
	    return;

	for ( var o = posObj.firstChild; o; o = o.nextSibling )
	{
	    var changeObj;
	    var changeObjName;
	    var otherObj;
	    var otherObjName;

	    if ( o.nodeName != "SPAN" ) continue;

	    changeObjName = o.getAttribute("ID");
	    re = new RegExp("PANEL_", "g");
	    changeObjName = changeObjName.replace (re, "");

	    otherObjName = o.getAttribute("below");
	    otherObjName = otherObjName.replace (re, "");

	    if ( ! changeObjName || ! otherObjName )
		return;

	    changeObj = myGetElementById (changeObjName);
	    otherObj = myGetElementById (otherObjName);

	    if ( changeObj && otherObj )
	    {
		var newTop = (otherObj.offsetTop + otherObj.offsetHeight + 2);
		/*
		alert (otherObjName + " is at " + 
		    otherObj.offsetLeft + "," + otherObj.offsetTop +
		    " height=" + otherObj.offsetHeight +
		    " moving " + changeObjName + " from " +
		    changeObj.offsetLeft + "," + changeObj.offsetTop +
		    " to " + otherObj.offsetLeft + "," + newTop);
		*/
		changeObj.style.top = newTop + "px";
		changeObj.style.left = otherObj.offsetLeft;
	    }
	}
    }
}


function setImage (what, imgBase)
{
    var obj;

    if ( typeof (what) == "string" )
	obj = myGetElementById(what);
    else
	obj = what;

    if ( obj ) obj.src = "images/" + imgBase + ".gif";
}

function setImageUrl (what, imgUrl)
{
    var obj;

    if ( typeof (what) == "string" )
	obj = myGetElementById(what);
    else
	obj = what;

    if ( obj ) obj.src = imgUrl;
}

var MIXTAPE_MAX_ITEMS = 8;
var MIXTAPE_PLAYLIST_ID = "mixtape_playlist";

function setupMixTape ()
{
    var obj;

    if ( (obj = myGetElementById ('mixtape_droparea')) )
    {
	obj.ondropover = function (dropObj) {
	    this.className = "mixtape_droparea_dropping";
	}
	obj.ondropout = function (dropObj) {
	    this.className = "mixtape_droparea";
	}

	obj.ondrop = mixTapeDrop;
    }
}

function mixTapeReset ()
{
    var playlistObj = myGetElementById (MIXTAPE_PLAYLIST_ID);

    if ( ! playlistObj )
	return;

    playlistObj.items = undefined;
    mixTapeDisplay();
}

/*
 * mixTapeDisplay() - update the display for the mix tape based
 *   on what has been dropped
 */
function mixTapeDisplay ()
{
    var playlistObj = myGetElementById (MIXTAPE_PLAYLIST_ID);
    var text;

    if ( ! playlistObj )
	return;

    text = "<TABLE CELLSPACING=1 CELLPADDING=1 BORDER=0 CLASS='mixtape_table'>";
    for ( var i = 0; i < MIXTAPE_MAX_ITEMS; i++ )
    {
	if ( (i % 2) == 0 )
	{
	    if ( i >= 0 ) text += "</TR>";
	    text += "<TR>";
	}
	text += "<TD WIDTH='50%' CLASS='mixtape_item'>";
	if ( playlistObj.items && i < playlistObj.items.length )
	    text += playlistObj.items[i].name;
	else text += "&nbsp;";
	text += "</TD>";

    }
    text += "</TR></TABLE>";

    playlistObj.innerHTML = text;
}

function mixTapeDrop (dropObj)
{
    var playlistObj = myGetElementById (MIXTAPE_PLAYLIST_ID);
    var text;
    var newObj;
    var title;

    if ( ! playlistObj )
	return;

//    var dstr = dropObj + " dropped onto " + this + ": " + dropObj.innerHTML;
//    for (var p in dropObj) dstr += "<BR>" + p + "=" + dropObj[p];
//    debug(dstr);

    if ( ! playlistObj.items )
	playlistObj.items = new Array();

    if ( playlistObj.items.length == MIXTAPE_MAX_ITEMS )
    {
	alert ("Only " + MIXTAPE_MAX_ITEMS + " songs can be included on each mix tape");
	return;
    }

    title = dropObj.arg2;

    // see if it's already in here
    for ( var i = 0; i < playlistObj.items.length; i++ )
    {
	if ( playlistObj.items[i].name == title )
	{
	    alert (playlistObj.items[i].name + " is already in your playlist.");
	    return;
	}
    }

    newObj = new Object();
    newObj.name = title;
    newObj.name = newObj.name.substr (0, 18);
    newObj.id = dropObj.arg1;

    playlistObj.items.push (newObj);

    mixTapeDisplay();
}

function mixTapeSend ()
{
    var playlistObj = myGetElementById (MIXTAPE_PLAYLIST_ID);
    var url = "/megamix.html?pl=";

    if ( ! playlistObj )
	return;

    if ( ! playlistObj.items || ! playlistObj.items.length )
    {
	alert ("You need to drag some songs over first.");
	return;
    }

    for ( var i = 0; i < playlistObj.items.length; i++ )
    {
	if ( i > 0 ) url += ","; 
	url += playlistObj.items[i].id;
    }

    debug (url);
    popup (url, "madonna_mixtape", "width=675,height=387,menubar=0,titlebar=0,toolbar=0,location=0,scrollbars=0,resizable=0,status=no");
    return false;
}

function minimizeAllPanels ()
{
    // look for any objects that can be minimized
    // this is *not* the most efficient, so it should be
    // redone at some point to be a lot better. right now
    // it looks through all children of MAIN_CONTENT for DIV's 
    // that have the "dancefloor_number" attribute set 
    var contentObj = myGetElementById (MAIN_CONTENT);
    for ( var o = contentObj.firstChild; o; o = o.nextSibling )
    {
	if ( o.nodeName != "DIV" ) continue;
	if ( o.getAttribute("dancefloor_number") )
	{
	    if ( minimizePanel (o.getAttribute('id')) )
		o.minimizedViaAll = true;
	}
    }

    // also check the main page
    var contentObj = myGetElementById ("BODY");
    for ( var o = contentObj.firstChild; o; o = o.nextSibling )
    {
	if ( o.nodeName != "DIV" ) continue;
	if ( o.getAttribute("dancefloor_number") )
	{
	    if ( minimizePanel (o.getAttribute('id')) )
		o.minimizedViaAll = true;
	}
    }

}

function restoreAllPanels ()
{
    // look for any objects that need to be minimized
    // this is *not* the most efficient, so it should be
    // redone at some point to be a lot better. right now
    // it looks through all children of MAIN_CONTENT for DIV's 
    // that have the "nav_open_minimize" attribute set to true
    var contentObj = myGetElementById (MAIN_CONTENT);
    for ( var o = contentObj.firstChild; o; o = o.nextSibling )
    {
	if ( o.nodeName != "DIV" ) continue;
	if ( o.MINIMIZED == true && o.minimizedViaAll == true )
	    restorePanel (o.getAttribute('id'));
    }

    // also check the main page
    var contentObj = myGetElementById ("BODY");
    for ( var o = contentObj.firstChild; o; o = o.nextSibling )
    {
	if ( o.nodeName != "DIV" ) continue;
	if ( o.MINIMIZED == true && o.minimizedViaAll == true )
	    restorePanel (o.getAttribute('id'));
    }
}

/*
 * minimizePanel() - this makes an object invisible and reveals another object
 *
 * the way it works is that there are a bunch of pre-placed (and hidden)
 * DIV tags that have the ID of DANCEFLOOR_ICON_N (where N is 1, 2, 3, etc).
 * each panel has a dancefloor_number= attribute that corresponds to
 * one of the DANCEFLOOR_ICON_N tags, causing it to be displayed when
 * the panel is minimized. when it's minimized, the DANCEFLOOR_ICON_N
 * object gets some extra information added into it just to make it
 * nice and easy to restore the panel.
 *
 * what can either be the object to be minimized *or* a text id string
 * of the object to be minimized
 */
var minimizeIntervalId = new Array();

function minimizePanel (what)
{
    var mainObj;
    var dfName;
    var dfObj;
    var minmaxObj;
    var o;
    var x, y, h, w;
    var dest_x = 226; 	// hardcoded positions to minimize to, in case
    var dest_y = 23;	// we can't find the minmax object

    if ( typeof (what) == "string" )
	mainObj = myGetElementById(what);
    else
    {
	mainObj = what;
	// reset to text since minimizePanelStep() needs it that way
	if ( mainObj ) what = mainObj.getAttribute('ID');
    }

    if ( ! mainObj )
	return false;

    // if we're in the middle on one for this panel already, wait until its done
    if ( minimizeIntervalId[what] )
	return false;

    // don't re-minimize if we're already minimized!
    if ( mainObj && mainObj.MINIMIZED && mainObj.MINIMIZED == true )
    {
//	debug ("minimizePanel(" + what + "): already minimized!");
	return false;
    }

    var dfName = "DANCEFLOOR_ICON_" + mainObj.getAttribute("dancefloor_number");

    // debug ("looking for " + dfName);
    dfObj = myGetElementById (dfName);

    // can't find it? don't minimize since otherwise it'd be lost!
    if ( ! dfObj )
    {
	alert ("minimize error: can't find " + dfName);
	dragStop();	// make sure we don't get stuck in a drag loop
	return false;
    }

    /* 
     * OLD STYLE: not using this now
    // first, hide the panel. i'd like to do display = none, but this
    // messes up flash such that when it's restored (display = block)
    // it doesn't refresh until some other event happens requiring it.
    // so instead we set it to invisible, but also reduce the height
    // so any scrollbars that might be affected by this height is
    // less likely to be affected :)
    mainObj.saveHeight = mainObj.offsetHeight;
    mainObj.style.height = "12px";
    mainObj.style.overflow = "hidden";
    mainObj.style.visibility = "hidden";
    */

    /*
     * NEW STYLE: save off info about our height/width/position
     */
    mainObj.saveStyle = new Object();
    mainObj.saveStyle.height = mainObj.style.height;
    mainObj.saveStyle.width = mainObj.style.width;
    mainObj.saveStyle.top = mainObj.style.top;
    mainObj.saveStyle.left = mainObj.style.left;
    mainObj.saveStyle.overflow = mainObj.style.overflow;
//    mainObj.saveStyle.content = mainObj.innerHTML;
    mainObj.dfObj = dfObj;

//    mainObj.innerHTML = "";
    mainObj.style.overflow = "hidden";

    // make sure we've got our page dimensions by now
    if ( ! pageWidth )
	findDimensions();

    if ( minmaxObj = myGetElementById ("minmax") )
    {
	dest_x = minmaxObj.offsetLeft;
	dest_y = minmaxObj.offsetTop;
    }

    x = parseInt ((dest_x - mainObj.offsetLeft) / 5, 10);
    y = parseInt ((dest_y - mainObj.offsetTop) / 5, 10);
    h = parseInt (mainObj.offsetHeight / 5, 10);
    w = parseInt (mainObj.offsetWidth / 5, 10);

    cmd = "minimizePanelStep('" + what + "'," + h + "," + w + "," + x + "," + y + ")";

    minimizeIntervalId[what] = setInterval (cmd, 10);
    return true;
}

function minimizePanelStep (what, h, w, x, y)
{
    var mainObj = myGetElementById (what);
    var newHeight, newWidth, newX, newY;
    var dstr = "";

    // compute if they aren't set on first step
    if ( ! mainObj.style.height ) mainObj.style.height = mainObj.offsetHeight;
    if ( ! mainObj.style.width ) mainObj.style.width = mainObj.offsetWidth;

    newHeight = parseInt (mainObj.style.height, 10) - h;
    newWidth = parseInt (mainObj.style.width, 10) - w;

    newX = parseInt (mainObj.style.left, 10) + x;
    newY = parseInt (mainObj.style.top, 10) + y;

    if ( newHeight < 16 ) newHeight = 16;
    if ( newWidth < 16 ) newWidth = 16;
    if ( newX > pageWidth - 40 ) newX = pageWidth - 40;
    if ( newY > pageHeight - 40 ) newY = pageHeight - 40;

    /*
    dstr += what + " pageWidth=" + pageWidth + " pageHeight=" + pageHeight
	+  " offwidth=" + mainObj.offsetWidth + " offh=" + mainObj.offsetHeight
	+ " offTop=" + mainObj.offsetTop + " offLeft=" + mainObj.offsetLeft
	+ " CUR h=" + mainObj.style.height + " w=" + mainObj.style.width + " x=" + mainObj.style.left + " y=" + mainObj.style.top
	+ " INT x=" + x + " y="+ y 
	+ " NEW h=" + newHeight + " w=" + newWidth + " x=" + newX + " y=" + newY;
    debug (dstr);
    */

    mainObj.style.left = newX + "px";
    mainObj.style.top = newY + "px";
    mainObj.style.height = newHeight + "px";
    mainObj.style.width = newWidth + "px";

    /*
    mainObj.style.clip = "rect("
	+ "0px "
	+ newWidth + "px "
	+ newHeight + "px "
	+ "0px);"
    */

    if ( newHeight == 16 && newWidth == 16 )
    {
	clearInterval (minimizeIntervalId[what]);
	minimizeIntervalId[what] = undefined;

	// now hide the main object
	mainObj.style.visibility = "hidden";

	// now make the DANCEFLOOR_ICON_N visible & displayed and add
	// a reference back to the panel that it's representing so
	// it's easy to restore w/out doing more lookups
	mainObj.dfObj.style.visibility = "visible"; 
	mainObj.dfObj.style.display = "block"; 
	mainObj.dfObj.mainObj = mainObj;

	// and finally mark the panel as minimized and also add a shortcut
	// to the DANCEFLOOR_ICON_N that represents it, just in case that's
	// useful later (like when a panel has shared content and needs to
	// be popped back open on a click)
	// NOTE: the dfObj is now assigned in minimizePanel() before here
	mainObj.MINIMIZED = true;
    }
}

/*
 * restorePanel() - this restores a panel minimized via minimizePanel()
 *
 * "what" is either the ID of the main panel, or it's the dfObj that's
 * being clicked
 */
function restorePanel (what)
{
    var mainObj;

    if ( typeof (what) == "string" )
	mainObj = myGetElementById(what);
    else
	mainObj = what.mainObj;

    if ( ! mainObj || ! mainObj.MINIMIZED )
	return;

    mainObj.MINIMIZED = undefined;
    mainObj.minimizedViaAll = undefined;
    mainObj.style.visibility = "visible";

    /* OLD STYLE: NOT USED */
    /*
    mainObj.style.height = mainObj.saveHeight;
    mainObj.style.overflow = "visible";
    */

    /* NEW STYLE */
//    mainObj.innerHTML = mainObj.saveStyle.content;
    mainObj.style.height = mainObj.saveStyle.height;
    mainObj.style.width = mainObj.saveStyle.width;
    mainObj.style.top = mainObj.saveStyle.top;
    mainObj.style.left = mainObj.saveStyle.left;
    mainObj.style.overflow = mainObj.saveStyle.overflow
    mainObj.saveStyle = undefined;

    mainObj.dfObj.style.visibility = "hidden"; 
    mainObj.dfObj.style.display = "none"; 
    mainObj.dfObj = undefined;

    hidePanelTip();
}

/*
 * showPanelTip() - this shows a little info about what is in a panel
 */
function showPanelTip (dfObj)
{
    var tipObj = myGetElementById('panelTip');
    var tipTextObj = myGetElementById('panelTipText');
    var tipStr;

    if ( ! tipObj || ! tipTextObj ) return;

    tipObj.dfObj = dfObj;

    // first look for into the in the panel that minimized us
    // and then look at us (the disco button isn't minimized by anything)
    if ( dfObj.mainObj )
	tipStr = dfObj.mainObj.getAttribute('dancefloor_tip');
    else
	tipStr = dfObj.getAttribute('dancefloor_tip');

    tipTextObj.innerHTML = tipStr;
    tipObj.style.display = "block";

    // i'm testing this part where i ignore (unset) whether the
    // current settings are based on bottom or right and
    // that results in being able use top/left for everything

	/* Hiding positioning for now...

    tipObj.style.bottom = "";
    tipObj.style.right = "";

    if ( tipObj.style.bottom )
	tipObj.style.bottom = pageHeight - dfObj.offsetTop - 5;
    else
	tipObj.style.top = dfObj.offsetTop - tipObj.offsetHeight + 5;

    if ( tipObj.style.right )
	tipObj.style.right = pageWidth - dfObj.offsetLeft - 5 + 7;
    else
	tipObj.style.left = dfObj.offsetLeft - tipObj.offsetWidth + 5 + 7;
	
	*/

    /*
    debug ("dbObj="+dfObj.getAttribute('ID')
	+ " tipObj.style.top=" + tipObj.style.top
	+ " offsetTop=" + dfObj.offsetTop
	+ " offsetLeft=" + dfObj.offsetLeft
	+ " tipTop=" + tipObj.offsetTop
	+ " tipLeft=" + tipObj.offsetLeft
	+ " tipWidth="  + tipObj.offsetWidth
	+ " tipHeight=" + tipObj.offsetHeight);
    */
	
}

function panelTipMouseOver (obj) { if ( obj.dfObj ) obj.dfObj.onmouseover(); }
function panelTipMouseOut (obj) { if ( obj.dfObj ) obj.dfObj.onmouseout(); }
function panelTipClick (obj) { if ( obj.dfObj ) obj.dfObj.onclick(); }

/*
 * hidePanelTip() - this shows a little info about what is in a panel
 */
function hidePanelTip ()
{
    var tipObj = myGetElementById('panelTip');
    var tipTextObj = myGetElementById('panelTipText');
    if ( tipObj && tipTextObj )
    {
	tipObj.style.display = "none";
	tipTextObj.innerHTML = "";
    }
}

// Plain old ordinary popup script with an optional arg to hide the nav
function popup (theURL, winName, features, hide_nav)
{
    window.open (theURL, winName, features);
    if ( hide_nav )
	hideNav();
}

// simple script to reset text in a specific id
function setText (id, text)
{
    var obj = myGetElementById (id);
    if ( obj )
	obj.innerHTML = text;
}

function hideId (id)
{
    var obj = myGetElementById(id);

    if ( obj && obj.style.display != "none" )
    {
	obj.saveDisplay = obj.style.display;
	obj.style.display = "none";
    }
}

function showId (id)
{
    var obj = myGetElementById(id);

    if ( obj )
    {
	var newDisplay = "block";
	if ( obj.saveDisplay )
	    newDisplay = obj.saveDisplay;
	obj.style.display = newDisplay;
    }
}

function setDragObject (event, srcObj, dropId, arg1, arg2)
{
    var dragObj = myGetElementById("dragObject");
    if ( dragObj )
    {
	var padding = 3;

	// save of some parameters
	dragObj.arg1 = arg1;
	if ( arg2 ) dragObj.arg2 = arg2;

	dragObj.innerHTML = arg2;
	dragObj.style.display = "block";
	dragObj.style.left = getAbsOffset(srcObj, 'offsetLeft') - padding;
	dragObj.style.top = getAbsOffset(srcObj, 'offsetTop') - padding;

	dragObj.style.cursor = "pointer";
	dragObj.style.border = "1px solid #333333";
	dragObj.style.backgroundColor = "#FFFFFF";
	dragObj.style.padding = padding + "px";
	dragObj.style.fontSize = "11px";

	dragStart(event, 'inside', 'dragObject', false, dropId);
	dragObj.onmouseup = clearDragObject;
    }
}

function clearDragObject ()
{
    var obj = myGetElementById("dragObject");
    if ( obj )
    {
	obj.innerHTML = "";
	obj.style.display = "none";
	obj.style.top = "135px";
	obj.style.left = "135px";
	obj.arg = undefined;
    }
}

/*
 * setLanguage() - looks through all elements and hides any that are
 *   language= anything other than as specified, and displayed any that
 *   match the requested language. also sets global myLanguage variable
 */
function setLanguage (lang, obj)
{
    var spanObjs;

    lang = lang.toUpperCase();

    // convert string id names into objects
    if ( obj && typeof (obj) == "string" )
        obj = myGetElementById(obj);

    if ( ! obj ) obj = document;

    spanObjs = obj.getElementsByTagName("SPAN");

    for (var i = 0; i < spanObjs.length; i++ )
    {
        var o = spanObjs[i];

        if ( o.getAttribute && (objLang = o.getAttribute("language")) )
        {
            if ( objLang.toUpperCase() == lang )
                o.style.display = "inline";
            else
                o.style.display = "none";
        }
    }

    myLanguage = lang;
}
