var currentPosition;
var player;
var status_player=true;
var rewind_player=false;
var soundtest=false;
var isplaying=false;
function playerReady(thePlayer) {
    var player_id = thePlayer.id;
    player = window.document[player_id];
    addListeners(player);
}

function addListeners(player) {
	player.addModelListener('TIME', 'timeListener');
	player.addModelListener('STATE', 'stateListener');
}

function timeListener(obj) {
	currentPosition = parseFloat(obj.position); 
	var temp=document.getElementById('myamount').innerHTML;
	if (soundtest==false){
		player.sendEvent('volume', temp);
	}

if (currentPosition >25.1){
 document.getElementById('layer').style.visibility="visible"
   $('#layer').fadeTo('slow', 1);
	}
if (currentPosition >25.7){
document.getElementById('pause').style.display="none";
document.getElementById('play').style.display="block";
player.sendEvent('bufferlength', '0');
status_player=false;
var rewind_player=true;
}

if (currentPosition <0.5){
status_player=true;
isplaying=true;
var rewind_player=false;
document.getElementById('mp1').style.opacity="1";
document.getElementById('layer').style.visibility="hidden";
document.getElementById('pause').style.display="block";
player.sendEvent('MUTE','false');
document.getElementById('unmute').style.display="none";
document.getElementById('play').style.display="none";
document.getElementById('mute').style.display="block";
$('.demo').show();
   $('#layer').fadeOut(0);
	}
}
function stateListener(obj) {
if(obj.id=="mp1" && (obj.newstate=="PAUSED")){
document.getElementById('play').style.display="block";
document.getElementById('pause').style.display="none";
}else if(obj.id=="mp1" && (obj.newstate=="PLAYING")){
document.getElementById('play').style.display="none";
document.getElementById('pause').style.display="block";
}
if(obj.id=="mp1" && (obj.newstate=="COMPLETED")){
 document.getElementById('mp2').style.visibility="visible"
 document.getElementById('mp2').style.zIndex="9999";
}
else{
	document.getElementById('mp2').style.visibility="hidden";
	document.getElementById('mp2').style.zIndex="-1";
}
}
function again_play(){
if (status_player==false){
status_player=true;
//player.sendEvent('PLAY',true);
 player.sendEvent('repeat','single');

//player.sendEvent('SEEK', start);
	document.getElementById('mp2').style.visibility="hidden";
	document.getElementById('mp2').style.zIndex="-1";
}
}
function mute(){
player.sendEvent('MUTE','true');
soundtest=true;
$("#slider-range-max").slider({
	value: 0
});

$('#mute').hide();
$('#unmute').show();
}
function unmute(){
player.sendEvent('MUTE','false');$('#unmute').hide();$('#mute').show();
soundtest=false;
var slide_val=document.getElementById('myamount').innerHTML;
$("#slider-range-max").slider({
	value: slide_val
});
}
function set_css() {
 $('.ui-corner-tl').css({'-moz-border-radius-topleft' : '4px', '-webkit-border-top-left-radius' : '4px', 'border-top-left-radius' : '4px'});
 $('.ui-corner-tr').css({'-moz-border-radius-topright' : '4px', '-webkit-border-top-right-radius' : '4px', 'border-top-right-radius' : '4px'});
 $('.ui-corner-bl').css({'-moz-border-radius-bottomleft' : '4px', '-webkit-border-bottom-left-radius' : '4px', 'border-bottom-left-radius' : '4px'});
 $('.ui-corner-br').css({'-moz-border-radius-bottomright' : '4px', '-webkit-border-top-left-radius' : '4px', 'border-bottom-right-radius' : '4px'});
 $('.ui-corner-top').css({'-moz-border-radius-topleft' : '4px', '-webkit-border-top-left-radius' : '4px', 'border-top-left-radius' : '4px', ' -moz-border-radius-topright' : '4px', ' -webkit-border-top-right-radius' : '4px', 'border-top-right-radius' : '4px'});
 $('.ui-corner-bottom').css({'-moz-border-radius-bottomleft' : '4px', '-webkit-border-bottom-left-radius' : '4px', 'border-bottom-left-radius' : '4px', ' -moz-border-radius-bottomright' : '4px', ' -webkit-border-bottom-right-radius' : '4px', 'border-bottom-right-radius' : '4px'});
 $('.ui-corner-right').css({'-moz-border-radius-topright' : '4px', '-webkit-border-top-right-radius' : '4px', 'border-top-right-radius' : '4px', ' -moz-border-radius-bottomright' : '4px', '-webkit-border-bottom-right-radius' : '4px', 'border-bottom-right-radius' : '4px'});
 $('.ui-corner-left').css({'-moz-border-radius-topleft' : '4px', '-webkit-border-top-left-radius' : '4px', 'border-top-left-radius' : '4px', '-moz-border-radius-bottomleft' : '4px', '-webkit-border-bottom-left-radius' : '4px', 'border-bottom-left-radius' : '4px'});
 $('.ui-corner-all').css({'-moz-border-radius' : '4px', '-webkit-border-radius' : '4px', 'border-radius' : '4px'});
 };
