/*-------------------------------------------------------------------
Player javascript API
-------------------------------------------------------------------*/

function sendEvent(swf,typ,prm) { 
	thisMovie(swf).sendEvent(typ,prm);	
}

function getUpdate(typ,pr1,pr2,swf) {
	if(typ == "item" && swf == "jstest3"){
		$('#current_vitri').html(pr1);
		hilightCurrentItem(pr1);
		current_song=pr1;
	}
	if(typ == "state" && swf == "jstest3"){		
		if(pr1==3){ 
			if(play_one){ 
				sendEvent('jstest3','playitem',get_current_song);   
			}else if(play_random){ 
				sendEvent('jstest3','playitem',Math.floor(Math.random()*getLength("jstest3")));   
			}else{
			    var repeat_playlist=getLength("jstest3") - 1;
		        if(repeat_playlist==pr1)
		        	sendEvent('jstest3','playitem',0); 
			}
	   }		
	}		
}

function loadFile(swf,obj) {
	thisMovie(swf).loadFile(obj); 	
}

function getLength(swf) { 	
	var len = thisMovie(swf).getLength(); 	
	return len;
}

function addItem(swf,obj,idx) {	
	thisMovie(swf).addItem(obj,idx);
}

function removeItem(swf,idx) {
	thisMovie(swf).removeItem(idx);
}

function itemData(swf,idx) { 
	var obj = thisMovie(swf).itemData(idx);
	var title_song=new Array();
	title_song[0]= obj["title"];
	title_song[1]= obj["file"];
	title_song[2]= obj["id_song"];
	return title_song;
}

function thisMovie(movieName) {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		var $rs =  window[movieName];
	} else {
		var $rs =  document[movieName];
	}	
	return $rs;
}

//set value radio
function setCheckedValue(name,newValue) {
	var rad=$(name);
	var radioLength=rad.length;
	for(var i = 0; i < radioLength; i++) {
		rad[i].checked = false;
		if(rad[i].value == newValue.toString()) {
			rad[i].checked = true;
		}
	}
}
//play mode
function playMode(){
	 if( getValueRadio("tuychon") == 1 ){
		play_one=true;
		play_random=false;
		if(current_song > 0)
			get_current_song = current_song - 1;
		else
			get_current_song = 0;	
	   }else if(getValueRadio("tuychon") == 2){
			play_one=false;
			play_random=true;
		}else{
			play_one=false;
			play_random=false;
		}

}