var Player = new Object(); 

$(function(){
//	Player = document.getElementById('PlayerOBJ');
//	alert(Player);
	$("div.trackCont").hover(
		function(){
  			$(this).addClass("tover");
			//$(this).css("cursor", "pointer");
		},
		function(){
  			$(this).removeClass("tover");
			//$(this).css("cursor", "default");
		}
	);
});

function colorTrack(d, currentFileUrl){
	
  	$("div.trackSelect").removeClass("ton");
	$("div#trackSelect" + d).addClass("ton");
	$("div.trackName").removeClass("whiteName");
	$("div.trackNote").removeClass("whiteNote");
	$("div#trackName" + d).addClass("whiteName");
	$("div#trackNote" + d).addClass("whiteNote");
	
	currentFileUrl = musicUrl + currentFileUrl; 
	var html = '<OBJECT ID="PlayerOBJ" CLASSID="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" CODEBASE="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab# Version=5,1,52,701" STANDBY="Loading Microsoft Windows® Media Player components..." TYPE="application/x-oleobject" width="360" height="46">'; 
		html = html + '<param id="MYFILE" name="fileName" value="' + currentFileUrl +'">'
		html = html + '<param name="animationatStart" value="true">'
		html = html + '<param name="transparentatStart" value="true">'
		html = html + '<param name="autoStart" value="true">'
		html = html + '<param name="showControls" value="true">'
		html = html + '<param name="Volume" value="-100">';
		html = html + '<embed id="EMYFILE" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="' + currentFileUrl + '" name="mplayer" width=360 height=46 autostart=1 showcontrols=1 volume=-100>';
		html = html + '</OBJECT>';
		$("div#WSWINCONTROLS").html(html);
}


var volIsDown = false; 
var downX = 0; 
var downY = 0; 

var i; 
var ve = new Array();
for(i = 5; i < 20; i++){
	ve[i] = document.getElementById('wsv' + String(i));
}

function playTrack(track){
	track = musicUrl + track;
	Player.URL = track; 
	playOn = false; 
	togglePlay();
}



function pressStop(){
	var img = imageUrl + "stop_down.png";
	$("img#STOP").src(img);		
}
function doStop(){
	Player.controls.stop();
	var img = imageUrl + "stop.png";
	$("img#STOP").src(img);
	img = imageUrl + "play.png";
	$("img#PLAY").src(img);		
	playOn = false; 	
}



var playOn = true;
function pressPlay(){
	if(playOn){
		var img = imageUrl + "pause_down.png";
		$("img#PLAY").src(img);		
	}
	else {
		var img = imageUrl + "play_down.png";
		$("img#PLAY").src(img);		
	}
}
function togglePlay(){
	if(playOn){
		playOn = false; 
		var img = imageUrl + "play.png";
		$("img#PLAY").src(img);
        Player.controls.pause();
	}
	else {
		playOn = true; 
		var img = imageUrl + "pause.png";
		$("img#PLAY").src(img);
        Player.controls.play(); 
	}	
}

var volOn = true;
function toggleVolume(doVol){
	if(volOn){
		var saveVol = lastVol; 
		volDown(4);
		lastVol = saveVol; 
		// needs to be after volOn call.
		volOn = false; 
		var img = imageUrl + "audio_off.png";
		$("img#SPEAK").src(img);
	}
	else {
		volDown(lastVol);
	}	
}

// VOLUME 

var iLow = 4; 
var lastVol = 4;
function volDown(volNum){
	lastVol = volNum; 
	volIsDown = true; 
	volOn = true; 
	var img = imageUrl + "audio_on.png";
	$("img#SPEAK").src(img);
	changeVol(volNum);
	//document.addEventListener("mouseup", volKill, true);
	$(document).mouseup(volKill);
}

function changeVol(volNum){
	var j; 
	for(j = iLow+1; j < volNum+1; j++){
		ve[j].style.backgroundColor = "#7777FF";
	}
	for(j = volNum+1; j < 20; j++){
		ve[j].style.backgroundColor = "#CCCCFF";	
	}
	Player.settings.volume = 100*(volNum-4)/15;
}

function volMove(volNum){
	if(volIsDown){
		changeVol(volNum);
	}
}

var volKill = function volKill(){
	if(volIsDown){
		volIsDown = false; 
		//document.removeEventListener("mouseup", volKill(), true);
		$(document).mouseup(false);
	}
}



