var myListener = new Object();
var volume = 100; 

function init_listener() {
	/**
	 * Initialisation
	 */
	 volume = 100; 
	myListener.onInit = function()
	{
	    
	};
	/**
	 * onClick event on the video
	 */
	myListener.onClick = function()
	{
	    var total = document.getElementById("info_click").innerHTML;
	    document.getElementById("info_click").innerHTML = Number(total)+1;
	};
	/**
	 * onKeyUp event on the video
	 */
	myListener.onKeyUp = function(pKey)
	{
	    document.getElementById("info_key").innerHTML = pKey;
	};
	/**
	 * onComplete event
	 */
	myListener.onFinished = function()
	{
	    //alert("finished");
	};
	/**
	 * Update
	 */
	myListener.onUpdate = function()
	{
	    document.getElementById("info_playing").innerHTML = this.isPlaying;
	    document.getElementById("info_url").innerHTML = this.url;
	    document.getElementById("info_volume").innerHTML = this.volume;
	    document.getElementById("info_position").innerHTML = this.position;
	    document.getElementById("info_duration").innerHTML = this.duration;
	    document.getElementById("info_buffer").innerHTML = this.bufferLength + "/" + this.bufferTime;
	    document.getElementById("info_bytes").innerHTML = this.bytesLoaded + "/" + this.bytesTotal + " (" + this.bytesPercent + "%)"; 
	    
		//window.status = "aaa";
		update_slider(this.duration,this.position)
	    var isPlaying = (this.isPlaying == "true");
	    
	    var timelineWidth = 160;
	    var sliderWidth = 40;
	    var sliderPositionMin = 40;
	    var sliderPositionMax = sliderPositionMin + timelineWidth - sliderWidth;
	    var sliderPosition = sliderPositionMin + Math.round((timelineWidth - sliderWidth) * this.position / this.duration);
	   // alert(sliderPosition); 
	    if (sliderPosition < sliderPositionMin) {
	        sliderPosition = sliderPositionMin;
	    }
	    if (sliderPosition > sliderPositionMax) {
	        sliderPosition = sliderPositionMax;
	    }
	    
	//    document.getElementById("playerslider").style.left = sliderPosition+"px";
	};
}

var currentMovie = "";

function getFlashObject()
{
    return getFlashMovieObject("flv_player");
}
function update_slider(duration,position)
{
	var slide_pos = Math.round(position/duration *100); 
	document.getElementById("vid_progres").width = Math.round(slide_pos*4.04);
}

function play()
{
	if (currentMovie.length > 0) {
	    //getFlashObject().SetVariable("method:setPosition", 0);
        //getFlashObject().SetVariable("method:setUrl", currentMovie);
	    getFlashObject().SetVariable("method:play", "");
	}
}
function setMovie()
{
getFlashObject().SetVariable("method:setUrl", currentMovie);

}

function pause()
{
    getFlashObject().SetVariable("method:pause", "");
}
function stop()
{
    getFlashObject().SetVariable("method:stop", "");
}
function setWidth()
{
    var width = document.getElementById("inputWidth").value;
    getFlashObject().width = width+"px";
}
function setHeight()
{
    var height = document.getElementById("inputHeight").value;
    getFlashObject().height = height+"px";
}
function setPosition()
{
    var position = document.getElementById("inputPosition").value;
    getFlashObject().SetVariable("method:setPosition", position);
}
function setVolume()
{
    //var volume = document.getElementById("inputVolume").value;
	getFlashObject().SetVariable("method:setVolume", volume);
	//alert(volume);
}
function loadImage()
{
    var url = document.getElementById("inputImage").value;
    var depth = document.getElementById("inputImageDepth").value;
    var verticalAlign = document.getElementById("inputImageVertical").value;
    var horizontalAlign = document.getElementById("inputImageHorizontal").value;
    
    getFlashObject().SetVariable("method:loadMovieOnTop", url+"|"+depth+"|"+verticalAlign+"|"+horizontalAlign);
}
function unloadImage()
{
    var depth = document.getElementById("inputUnloadDepth").value;
    getFlashObject().SetVariable("method:unloadMovieOnTop", depth);
}