/*
 * Purpose:	Generic handling of buttons and their actions
 *
 * CVS: $Id: buttons.js,v 1.3 2003/11/22 00:12:31 dsmith Exp $
 *
 * This file is a part of the Real Networks software library.
 * Copyright (C) 2001 Real Networks, Inc.
 * All rights reserved.
 *
 */

/* Preload buttons */
var bNames = new Array("enabled","disabled","over","down");
var iButtons = new Array();
var sendingEvent=false;

for( i=0; i<bNames.length; i++ )
{
	iButtons[bNames[i]] = new Image( button_width, button_height );
	iButtons[bNames[i]].src = "images/btns/"+button_dir+"/bttn_" + bNames[i] + ".gif";
}

var hoverDelay=null;
var tempButtonObj="";

function mouseOverDraw( btnObj )
{
	btnObj.style.backgroundImage = "url("+iButtons["over"].src+")";
}

function mouseOutDraw( btnObj )
{
	btnObj.style.backgroundImage = "url("+iButtons["enabled"].src+")";
}

function showevt()
{
        var evt,evtObj;
        evt = window.event;
        evtObj = evt.srcElement;

        if( evtObj.orig == null )return;

        var btnObj = eval("document.all."+evtObj.orig);

        switch( evt.type.toLowerCase() )
        {
                case "mouseover":
                		if( (hoverDelay!=null) && (tempButtonObj==btnObj.id) )
                		{
                        	clearTimeout(hoverDelay);
                        	hoverDelay=null;
						}
						mouseOverDraw(btnObj);
                        break;
                case "mouseout":
                		hoverDelay=setTimeout(btnObj.id+".style.backgroundImage = \"url(\"+iButtons[\"enabled\"].src+\")\";",200);
                		tempButtonObj=btnObj.id;
                        break;
                case "mousedown":
                        btnObj.style.backgroundImage = "url("+iButtons["down"].src+")";
                        window.event.cancelBubble;
                        break;
                case "mouseup":
                        btnObj.style.backgroundImage = "url("+iButtons["over"].src+")";
                        /* delay form submissions to allow button images to return */
                        setTimeout("sendEvent( \""+btnObj.handler+"\" );",100);
                        window.event.cancelBubble;
                        break;
        }
}

document.onmouseover=showevt;
document.onmouseout=showevt;
document.onmousedown=showevt;
document.onmouseup=showevt;

function sendEvent( val )
{
	if( sendingEvent ) return;
	sendingEvent = true;
	parent.window.catchEvent( val );
	setTimeout("sendingEvent=false;",500 );
}

/** Incomplete **/
function focusButton()
{
	if( document.readyState!="complete" && document.readyState!="interactive")
	{
		setTimeout("focusButton();",5000);
		return;
	}
	if(document.links.length==0)return;
}
document.onFocus=focusButton;
var off_buttons_loaded=true;

