/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// HOVER

function hoverBG(obj, bool) {
	if(bool){
		obj.style.backgroundColor = "#343333";
	} else {
		obj.style.backgroundColor = "transparent";
	}
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// TRACK PLAYS

function addPlay(songID){
	
	var options = {
		method : 'post',
		parameters : {song_id: songID}
	};
	new Ajax.Request('_inc/plays.php', options);
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// SEND TO FLASH

function setVar(str){	
	if(window.miniPlayer) window.document["miniPlayer"].SetVariable("myText", str);
	if(document.miniPlayer) document.sample.SetVariable("myText", str);
}

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		if(document[movieName].length != undefined){
			return document[movieName][1];
		}
		return document[movieName];
	}
}

function songSend(id) {
	thisMovie("maxi_player").gotoSong(id);
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// REORDER SONGS

function startReorder(){
	Position.includeScrollOffsets = true;
	function saveOrder(){
		var options = {
			method : 'post',
			parameters : Sortable.serialize('listContainer')
		};
		function endReorder(){
			alert('Reordered'); 
		}
		new Ajax.Request('_inc/reorder.php', options);
		
		//new Ajax.Updater('message', '_inc/reorder.php', options);
		
	}
	Sortable.create('listContainer', {constraint:'vertical', tag:'div', handle:'handle', scroll: window, onUpdate: saveOrder});
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// SET RECENT PLACEMENT

var indexSlideTimeout = 0;
var indexSlideInterval = 0;
var imageOn = 1;

function startRecentPlacement(){
	indexSlideTimeout = setTimeout("setRecentPlacement('2')", 8000);
}

function setRecentPlacement(id){
	i = 1;
	while(document.getElementById('rp_' + i)){
		$('rp_' + i).style.display = (i == id)? "block" : "none";
		i++;
	}
	i--;
	nextImg = (parseInt(id) < i)? parseInt(id)+1 : 1;
	clearTimeout(indexSlideTimeout);
	clearInterval(indexSlideInterval);
	indexSlideInterval = setInterval("setRecentPlacement('"+ nextImg +"')", 8000);
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// SWITCH TAB

function switchTab(id, tot){
	for(i=1; i<=tot; i++){
		$('tab_' + i).className = (i == id)? "onHeader" : "offHeader";
		$('list_' + i).style.display = (i == id)? "block" : "none";
	}	
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// SWITCH SERIES TAB

function switchTabSeries(id, tot){
	for(i=1; i<=tot; i++){
		$('tab_' + i).className = (i == id)? "onHeader" : "offHeader";
	}	
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// SWITCH SERIES TAB

function setClass(id, classVar){
	$(id).className = classVar;	
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// SWITCH SERIES TAB

function getElementsByClassName(classname, node)  {
    if(!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

function startTrack(id){

	var exes = getElementsByClassName('ex');
	for (var i = 0, j = exes.length; i < j; i++) {
		exes[i].style.display = 'none';
	}
	
	var exes2 = getElementsByClassName('ex2');
	for (var i = 0, j = exes2.length; i < j; i++) {
		exes2[i].style.display = 'none';
	}
	
	var tee = getElementsByClassName('tee');
	for (var i = 0, j = tee.length; i < j; i++) {
		tee[i].style.display = 'inline';
	}
	
	
	
	document.getElementById('X_' + id).style.display = 'inline';	
}

function deleteTrack1(id){
	document.getElementById('X2_' + id).style.display = 'inline';
	document.getElementById('X_' + id).style.display = 'none';
	document.getElementById('T_' + id).style.display = 'none';
}

function deleteTrack2no(id){
	document.getElementById('X_' + id).style.display = 'inline';
	document.getElementById('X2_' + id).style.display = 'none';
	document.getElementById('T_' + id).style.display = 'inline';
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// SHOW HIDE

var numID = 1;

function showBOX(n){
    document.getElementById(n).style.display = 'block';
}

function hideBOX(n){
    document.getElementById(n).style.display = 'none';
}  
  
function swapBOX(n){
	document.getElementById(n).style.display = document.getElementById(n).style.display=='none'?'block':'none';
} 

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=450,left = 440,top = 212');");
}

function popTrack(id) {
	//day = new Date();
	//id = day.getTime();
	URL = "track.php?id="+id;
	window.location=URL;
	//fadeSCREEN(); hidePLAYER(); showALERT(URL); return false;
      //check_UPLOAD();return false;
	//eval("pageTrack = window.open(URL, 'pageTrack', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=700,height=500,left = 440,top = 212');");
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// ADD TO PLAYLIST

var tempID = false;
var tempTxt = false;

function startAdd(id, txt) {

	hideBOX("addSuccess");
	hideBOX("addExisting");
	hideBOX("addNew");
		
	showBOX("addPlayer");
	tempID = id;
	tempTxt = txt;
	//alert("ID:" + id);
}

var busy_add = 0;

function addPlaylistTrack(playlist) {
	
	holdVallue = playlist;
	
	playlist = (playlist)? playlist: $("newPlaylist").value;
	
	var regExp = /^[a-zA-Z0-9_ ]{1,35}$/;
 	var tempMatch = regExp.test(playlist);
	if(!tempMatch){
		alert("'" + playlist + "' is not a valid playlist name.\nPlaylist names must be less than 35 characters\nand contain only letters, numbers, underscores and spaces.");
		return false;
	}
	
	if (busy_add == 0) {	
		busy_add = 1;
		hideBOX("addPlayer");
		hideBOX("addExisting");
		hideBOX("addNew");
		
		showBOX("addSuccess");
		new Ajax.Updater('playerStatus', 'panes/ajaxAddPlaylist.php?playlist='+playlist+'&track='+tempID, {onComplete:function(){ 
				busy_add = 0;
				$("playerAddName").innerHTML = tempTxt;
				$("playerAddPlaylist").innerHTML = playlist;
				if(!holdVallue){
					location.reload(true);
				}

			}});
	}
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// ADD TO PLAYLIST (MINI)

var tempIDMini = false;
var tempTxtMini = false;

function startAddMini(id, txt) {
	//alert("ID:" + id);
	
	hideBOX("mini_player_cont");
	
	hideBOX("addSuccess");
	hideBOX("addExisting");
	hideBOX("addNew");
		
	showBOX("addPlayer");
	tempIDMini = id;
	tempTxtMini = txt;

}

var busy_add_mini = 0;

function addPlaylistTrackMini(playlist) {
	
	holdVallue = playlist;
	
	playlist = (playlist)? playlist: $("newPlaylist").value;
	
	var regExp = /^[a-zA-Z0-9_ ]{1,35}$/;
 	var tempMatch = regExp.test(playlist);
	if(!tempMatch){
		alert("'" + playlist + "' is not a valid playlist name.\nPlaylist names must be less than 35 characters\nand contain only letters, numbers, underscores and spaces.");
		return false;
	}
	
	if (busy_add_mini == 0) {	
		busy_add_mini = 1;
		hideBOX("addPlayer");
		hideBOX("addExisting");
		hideBOX("addNew");
		
		showBOX("addSuccess");
		new Ajax.Updater('playerStatus', 'panes/ajaxAddPlaylist.php?playlist='+playlist+'&track='+tempIDMini, {onComplete:function(){ 
				busy_add_mini = 0;
				$("playerAddName").innerHTML = tempTxtMini;
				$("playerAddPlaylist").innerHTML = playlist;
				if(!holdVallue){
					location.reload(true);
				}
			}});
	}
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////

function scrollCont(down) {
	//alert($("scrollCont").style.top);
	if(down){
		tempVal = (parseInt($("scrollCont").style.top) - 10);
		tempDiff = parseInt($("scrollParent").style.height) - parseInt($("scrollCont").offsetHeight) - 20;
		//alert(parseInt($("scrollCont").offsetHeight));
		$("scrollCont").style.top = (tempVal < tempDiff)? tempDiff + "px" : tempVal + "px";
	} else {
		tempVal = (parseInt($("scrollCont").style.top) + 10);
		$("scrollCont").style.top = (tempVal > 0)? "0px" : tempVal + "px";
		
	}
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
