﻿//<![CDATA[
                var argListener = new Object();
                
                /**
                 * Initialisation
                 */
                argListener.onInit = function()
                {
                    this.position = 0;
                };
                /**
                 * Update
                 */
                argListener.onUpdate = function()
                {                    
                    var isPlaying = (this.isPlaying == "true");
                    document.getElementById("playerplay").style.display = (isPlaying)?"none":"block";
                    document.getElementById("playerpause").style.display = (isPlaying)?"block":"none";
					$("#slider").slider( "option", "max", this.duration );
					$("#slider").slider( "option", "value", this.position );
                    /*
                    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);
                    
                    if (sliderPosition < sliderPositionMin) {
                        sliderPosition = sliderPositionMin;
                    }
                    if (sliderPosition > sliderPositionMax) {
                        sliderPosition = sliderPositionMax;
                    }
                    
                    document.getElementById("playerslider").style.left = sliderPosition+"px";
					*/
                };
                
                function getFlashObject()
                {
                    return document.getElementById("argFlash");
                }
                function play()
                {
                    getFlashObject().SetVariable("method:play", "");
                    getFlashObject().SetVariable("enabled", "true");
                }
                function pause()
                {
                    getFlashObject().SetVariable("method:pause", "");
                }
                function stop()
                {
                    getFlashObject().SetVariable("method:stop", "");
                }
                function setPosition(position)
                {
                    getFlashObject().SetVariable("method:setPosition", position);
                }
                function setVolume(volume)
                {
                    getFlashObject().SetVariable("method:setVolume", volume);
                }
				function setURL(url)
				{
					getFlashObject().SetVariable("method:setUrl", url);
				}
//]]>
$(document).ready(function() {
	$("#slider").slider({
			range: "min",
			slide: function() { setPosition($("#slider").slider("value")); }
	});
});
function unloadPage(){  
	if (argListener.isPlaying == "true") { 
	return "Há um episódio carregado, se sair da página irá parar de ouví-lo.";
	}
}
window.onbeforeunload = unloadPage;
