/* debug function. guess what this does. */
function debug(message){
	//alert (message);
}

/* image rollovers. */
function rollyImageObj(theId,width,height,state){
	this.state = state;			
	this.theId = theId;
	this.height = height;
	this.width = width;			
	this.over= new Image(this.width,this.height);
	this.over.src = imagePath+this.theId+"_over.gif";
	this.off= new Image(this.width,this.height);
	this.off.src = imagePath+this.theId+"_off.gif";
	this.on = new Image(this.width,this.height);
	this.on.src = imagePath+this.theId+"_on.gif";
	this.disable= new Image(this.width,this.height);
	this.disable.src = imagePath+this.theId+"_disable.gif";
}	

/* other btns */
var btn_play = new rollyImageObj("btn_play",17,15,"off");
var btn_next = new rollyImageObj("btn_next",17,15,"off");
var btn_previous = new rollyImageObj("btn_previous",17,15,"off");
var btn_pause = new rollyImageObj("btn_pause",17,15,"off");
var btn_stop = new rollyImageObj("btn_stop",17,15,"off");
var btn_mute = new rollyImageObj("btn_mute",20,15,"off");
var btn_fs = new rollyImageObj("btn_fs",17,15,"off");
			
function getState(theId){
	theObj = eval(theId);
	return theObj.state;		
}

function changeState(theId,theState){
	theObj = eval(theId);
	checkState = theObj.state;
	theObj.state = theState;
	document.getElementById(theId).src=imagePath+theId+"_"+theState+".gif";
}
		
function toggle(theId,state){
	theObj = eval(theId);
	theState = theObj.state;
	if(theState == "on" || theState == "disable"){
		return;
	}
	document.getElementById(theId).src=imagePath+theId+"_"+state+".gif";		
}




/* player controls */
function controlPlay(){
	if(playerObj.CanPlay()){
		playerObj.DoPlay();
		changeState("btn_play","on");
		changeState("btn_pause","off");
	}
}

function controlPause(){
	if(playerObj.CanPause()){
		playerObj.DoPause();
		changeState("btn_pause","on");
		changeState("btn_play","off");
	}else{
		playerObj.DoPlay();
		changeState("btn_play","on");
		changeState("btn_pause","off");
	}
}

function controlPreviousTrack() {
	if(playerObj.HasPrevEntry()){
		playerObj.DoPrevEntry();
	}
}

function controlNextTrack() {
	if(playerObj.HasNextEntry()){
		playerObj.DoNextEntry();
	}
}

function controlMute(){
	if(btn_mute.state == "off"){
		setVolume(0);
		changeState("btn_mute","on");
	}else{
		setVolume(prevVol);
		changeState("btn_mute","off");
	}				
}
function setVolume(theVol){
	volLevel = (theVol*10);
	playerObj.SetVolume(volLevel);
	prevVol = volumeSetAt;
	volumeSetAt = theVol;
	volumeDisplay();
	if(theVol > 0 && prevVol == 0){
		if(btn_mute.state == "on"){
			changeState("btn_mute","off")
		}
	}
}


var vol_over_color = "#77b777";
var vol_off_color = "#797979";
var vol_on_color = "#2e7f2e";
var vol_disable_color = "#d7d7d7";
	
function redrawvolume(){
	volumeDisplay();
}

function toggleVol(theId,state,pos){
	for(i=pos;i>=1;i--){
		var theNewId = "vol_"+i;
		var thecolor = eval("vol_"+state+"_color");
		document.getElementById(theNewId).style.backgroundColor=thecolor;
	}		
}
	
var volIDPrefixes = new Array("vol_1","vol_2","vol_3","vol_4","vol_5","vol_6","vol_7","vol_8","vol_9","vol_10");
function volumeDisplay() {
	for(i=0;i<volIDPrefixes.length;i++){
		actualPos = i+1;
		if(volumeSetAt == 0){
			document.getElementById(volIDPrefixes[i]).style.backgroundColor=vol_disable_color;
		}else{
			if(actualPos<=volumeSetAt){
				document.getElementById(volIDPrefixes[i]).style.backgroundColor=vol_on_color;					
			}else{
				document.getElementById(volIDPrefixes[i]).style.backgroundColor=vol_off_color;
			}
		}
	}
}



/* other handy functions used lots of places */
function hideThis(someIds){
	for (i=0; i<arguments.length;i++){
		document.getElementById(arguments[i]).style.display="none";
		document.getElementById(arguments[i]).style.visibility="hidden";
	}
}			
function showThis(theId){
	for (i=0; i<arguments.length;i++){
		document.getElementById(arguments[i]).style.display="block";
		document.getElementById(arguments[i]).style.visibility="visible";
	}
}

function openWin(name,url,width,height){
	newwindow = window.open(url,name,"width="+width+",height="+height+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0");
	newwindow.focus();
	return newwindow;
}
