//Lee's Liquor Lounge Virtual Jukebox
//by John Mason
//version 1.02
//04/20/2007


/* CONFIRMED TO WORK WITH:
    * Firefox 2
    * IE7
    * Netscape 8
    * Opera 9   
*/

//variables used in scrolling
TICKER_RIGHTTOLEFT = false;
TICKER_SPEED = 2;
TICKER_STYLE = "font-family:cursive,Arial; font-size:16px; color:#ffff00;";
TICKER_PAUSED = false;
spacer =  "..........................................";
message = spacer + "Please make your selection below" + spacer;


function playSelection(msg,mp3Path,imgPath) {
	//change scroll message
	//message = msg;
	//ticker_start();
	document.getElementById("TICKER_BODY").innerHTML = spacer + msg + spacer;

	//play mp3
	ctlWindow = document.getElementById("jc");
	ctlWindow.innerHTML = embedPlayer(mp3Path);
    //change jpg
	if (imgPath.length > 0) {
        document["swapImg"].src=imgPath;
        document["swapImg"].border=5;
    }
    else {
        document["swapImg"].src="images/jukePicBg.jpg";
        document["swapImg"].border=0;
    }	
}    

function embedPlayer(audioURL) { 

// Get Operating System 
var isWin = navigator.userAgent.toLowerCase().indexOf("windows") != -1
var rtn = "";
if (isWin) { // Use MIME type application/x-mplayer2
	visitorOS="Windows";
} else { // Use MIME type audio/mpeg, audio/x-wav, etc.
	visitorOS="Other";
}

var objTypeTag = "application/x-mplayer2"; // The  MIME type to load the WMP plugin in non-IE browsers on Windows
if (visitorOS != "Windows") { objTypeTag = "audio/mpeg"}; // The MIME type for Macs and Linux 

rtn = "<span background-image: url(images/jukeControlBg.jpg);>";
rtn = "<object width='209' height='92'>"; // Width is the WMP minimum. Height = 45(WMP controls) + 24 (WMP status bar) 
rtn = rtn + "<param name='type' value='" + objTypeTag + "'>";
rtn = rtn + "<param name='src' value='" + audioURL + "'>";
rtn = rtn + "<param name='autostart' value='true'>";
rtn = rtn + "<param name='showcontrols' value='1'>";
rtn = rtn + "<param name='showstatusbar' value='0'>";
rtn = rtn + "<embed src ='" + audioURL + "' type='" + objTypeTag + "' autoplay='true' autostart='true' width='209' height='92' controller='1' showstatusbar='1' bgcolor='#990000' kioskmode='true' loop='true'></embed>" // Firefox and Opera Win require both autostart and autoplay
rtn = rtn + "</object></span>";

return rtn
}

function ticker_start() {
	var tickerSupported = false;
    
	// For Firefox, Safari & Netscape use table cell for ticker body
	if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1
        || navigator.userAgent.indexOf("Netscape")!=-1) {
		document.getElementById("TICKER").innerHTML = "<TABLE  cellspacing='0' cellpadding='0' width='100%'><TR><TD nowrap='nowrap'><SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' width='100%'>&nbsp;</SPAN></TD></TR></TABLE>";
		tickerSupported = true;
	}
	// For IE & Opera use div for ticker body element
	if (navigator.userAgent.indexOf("MSIE")!=-1 || navigator.userAgent.indexOf("Opera")!=-1) { 
		document.getElementById("TICKER").innerHTML = "<DIV nowrap='nowrap' style='width:100%;'><SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' width='100%'></SPAN></DIV>";
		tickerSupported = true;
	}	
	
	if(!tickerSupported) document.getElementById("TICKER").outerHTML = ""; else {
        document.getElementById("TICKER").scrollLeft = TICKER_RIGHTTOLEFT ? document.getElementById("TICKER").scrollWidth - document.getElementById("TICKER").offsetWidth : 0;
		document.getElementById("TICKER_BODY").innerHTML = message;
		document.getElementById("TICKER").style.display="block";
		TICKER_tick();
	}
}

function TICKER_tick() {
	if(!TICKER_PAUSED) document.getElementById("TICKER").scrollLeft += TICKER_SPEED * (TICKER_RIGHTTOLEFT ? -1 : 1);
	
    if(TICKER_RIGHTTOLEFT && document.getElementById("TICKER").scrollLeft <= 0) document.getElementById("TICKER").scrollLeft = document.getElementById("TICKER").scrollWidth  - document.getElementById("TICKER").offsetWidth;

    if(!TICKER_RIGHTTOLEFT && document.getElementById("TICKER").scrollLeft >= document.getElementById("TICKER").scrollWidth - document.getElementById("TICKER").offsetWidth) document.getElementById("TICKER").scrollLeft = 0;
	window.setTimeout("TICKER_tick()", 30);
}
