if (!window.GoFans)
	window.GoFans = {};

GoFans.CanvasPlayer = function(pPlayer) 
{
    this.Player = pPlayer;   
    this.Interspace = 8; 
    this.isButtonPlayShown = true;
    this.isMediaOpened = false;
    this.isFullScreen = false;
    this.isControlPanelEnabled = false;
    this.isSliderMarkerDragged = false;
    this.isVolumeMarkerDragged = false;
    this.downloadProgress = 0;
    this.differenceMouseCursor = 0;
    this.SliderMarkerLeft = 0;
    this.colorActiveTop = "#FF976B22";
    this.colorActiveBottom = "#FFDC992C";
    this.colorInactiveTop = "#FF787878";
    this.colorInactiveBottom = "#FFCCCCCC";
    this.defaultVolume = 0.66;
    this.isMute = false;
}

GoFans.CanvasPlayer.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
		this.control = control;
        var host = control; 
        
        this.LogicCheck();
        this.InitControls(rootElement);      
        control.content.onfullScreenChange = this.onFullScreenChanged; 	
	},
	LogicCheck: function()
	{
	    if(this.Player.AutoDownload == false && this.Player.AutoPlay == true)
	    {
	        this.Player.AutoDownload = true;
	    }
	},
	InitControls: function(rootElement)
	{
		this.TextBlockProgressbarValue = rootElement.findName("TextBlockProgressbarValue");
		this.canvasTimer = rootElement.findName("CanvasTimer");
		
		this.InitCanvasPlayer(rootElement);
	},
	InitCanvasPlayer: function(rootElement)
	{
		this.CanvasPlayer = rootElement.findName("CanvasPlayer");
		this.CanvasPlayer.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.CanvasPlayer_MouseEnter));
		this.CanvasPlayer.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.CanvasPlayer_MouseLeave));

		this.InitCanvasBackground(rootElement);
		this.InitScreen(rootElement);
		this.InitCanvasControlPanel(rootElement);
	},
	InitScreen: function(rootElement)
	{	    		
		this.Screen = rootElement.findName("Screen");
		this.Screen["Width"] = this.CanvasPlayer["Width"];	
	    this.Screen["Height"] =  this.CanvasPlayer["Height"];
		this.Screen["Stretch"] = this.Player.Medium.Stretch;		
		this.Screen.addEventListener("DownloadProgressChanged", Silverlight.createDelegate(this, this.Screen_MediaDownloadChanged));
		this.Screen.addEventListener("MediaOpened", Silverlight.createDelegate(this, this.Screen_MediaOpened));
		this.Screen.addEventListener("MediaEnded", Silverlight.createDelegate(this, this.Screen_MediaEnded));
		if(this.Player.AutoDownload == true)
		{
		    this.Screen["Source"] = this.Player.Medium.Source;
		}
	},
	InitCanvasBackground: function(rootElement)
	{	    		
		this.CanvasBackground = rootElement.findName("CanvasBackground");
		this.CanvasBackground["Width"] = this.CanvasPlayer["Width"];	
	    this.CanvasBackground["Height"] =  this.CanvasPlayer["Height"];
		
		this.CanvasLogo = rootElement.findName("CanvasLogo");
	    
		this.LightBottom = rootElement.findName("LightBottom");
		
		this.PositionCanvasBackgroundChilds();
	},
	InitCanvasControlPanel: function(rootElement)
	{
		this.CanvasControlPanel = rootElement.findName("CanvasControlPanel");
		this.CanvasControlPanel.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.CanvasControlPanel_MouseLeftButtonUp));	
		this.CanvasControlPanel["Canvas.Top"] = this.CanvasPlayer["Height"] - (this.CanvasControlPanel["Height"]);
		this.CanvasControlPanel["Width"] = this.CanvasPlayer["Width"];	
				
		this.ControlPanelBackground = rootElement.findName("ControlPanelBackground");
		this.ControlPanelBackground["Width"] = this.CanvasControlPanel["Width"];
	    		
		this.InitCanvasButtons(rootElement);
		this.InitCanvasSlider(rootElement);
		this.InitCanvasVolume(rootElement);
		this.InitCanvasFullScreen(rootElement);
	},
	InitCanvasButtons: function(rootElement)
	{
		this.CanvasButtons = rootElement.findName("CanvasButtons");
		this.CanvasButtons["Canvas.Left"] = (this.CanvasControlPanel["Width"] - this.CanvasButtons["Width"]) / 2;
		
		this.CanvasButtonChapterBack = rootElement.findName("CanvasButtonChapterBack");		
		this.CanvasButtonChapterBack.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.CanvasButtonChapterBack_MouseLeftButtonUp));
		
		this.CanvasButtonPlayPause = rootElement.findName("CanvasButtonPlayPause");
		this.CanvasButtonPlayPause.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.CanvasButtonPlayPause_MouseLeftButtonUp));
		if(this.Player.AutoPlay == true)
		{
		    this.isButtonPlayShown = false;
		    rootElement.findName("CanvasButtonPlayPause_SwitchToPause").begin()
		}
				
		this.CanvasButtonChapterNext = rootElement.findName("CanvasButtonChapterNext");		
		this.CanvasButtonChapterNext.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.CanvasButtonChapterNext_MouseLeftButtonUp));
	},
	InitCanvasSlider: function(rootElement)
	{
		this.CanvasSlider = rootElement.findName("CanvasSlider");
		this.CanvasSlider["Width"] = ((this.CanvasControlPanel["Width"] - this.CanvasButtons["Width"] - this.Interspace) / 2) - this.Interspace;
		this.CanvasSlider["Canvas.Left"] = this.Interspace;
		this.CanvasSlider.addEventListener("MouseMove", Silverlight.createDelegate(this, this.CanvasSlider_MouseMove));
		
		this.SliderBackground = rootElement.findName("SliderBackground");
		this.SliderBackground["Width"] = this.CanvasSlider["Width"];
		
		this.SliderMarker = rootElement.findName("SliderMarker");		
		this.SliderMarker.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.SliderMarker_MouseLeftButtonDown));
		
		this.SliderDownload = rootElement.findName("SliderDownload");
		
		this.SliderTime = rootElement.findName("SliderTime");
		this.SliderTime["Canvas.Left"] = this.CanvasSlider["Width"] - this.SliderTime["Width"];
	},
	InitCanvasVolume: function(rootElement)
	{
		this.CanvasButtonVolume = rootElement.findName("CanvasButtonVolume");	
		
		this.CanvasFullScreen = rootElement.findName("CanvasFullScreen");
		
		this.CanvasVolume = rootElement.findName("CanvasVolume");
		this.CanvasVolume["Canvas.Left"] = (this.CanvasControlPanel["Width"] + this.CanvasButtons["Width"] + this.Interspace) / 2;
		this.CanvasVolume["Width"] = ((this.CanvasControlPanel["Width"] - this.CanvasButtons["Width"] - this.Interspace) / 2) - this.CanvasFullScreen["Width"] - this.Interspace;
		this.CanvasVolume.addEventListener("MouseMove", Silverlight.createDelegate(this, this.CanvasVolume_MouseMove));
		this.CanvasVolume.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.CanvasVolume_MouseLeftButtonUp));
		
		this.VolumeBackground = rootElement.findName("VolumeBackground");
		this.VolumeBackground["Width"] = this.CanvasVolume["Width"] - this.CanvasButtonVolume["Width"] - this.Interspace / 2;
		
		this.VolumeActive = rootElement.findName("VolumeActive");
		
		this.VolumeMarker = rootElement.findName("VolumeMarker");
		this.VolumeMarker.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.VolumeMarker_MouseLeftButtonDown));
		
		this.CanvasButtonVolume = rootElement.findName("CanvasButtonVolume");
		this.CanvasButtonVolume.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.CanvasButtonVolume_MouseLeftButtonUp));
		
		this.SoundSourceColorTop = rootElement.findName("SoundSourceColorTop");
		this.SoundSourceColorBottom = rootElement.findName("SoundSourceColorBottom");
		
		this.SoundWave1ColorTop = rootElement.findName("SoundWave1ColorTop");
		this.SoundWave1ColorBottom = rootElement.findName("SoundWave1ColorBottom");
		
		this.SoundWave2ColorTop = rootElement.findName("SoundWave2ColorTop");
		this.SoundWave2ColorBottom = rootElement.findName("SoundWave2ColorBottom");
		
		this.SoundWave3ColorTop = rootElement.findName("SoundWave3ColorTop");
		this.SoundWave3ColorBottom = rootElement.findName("SoundWave3ColorBottom");
		
		this.SetVolume(this.defaultVolume);
	},
	CanvasButtonVolume_MouseLeftButtonUp: function()
	{
	    this.SetVolume(0);
	},
	InitButtonVolume: function()
	{
	    this.SoundSourceColorTop["Color"] = this.colorInactiveTop;
	    this.SoundSourceColorBottom["Color"] = this.colorInactiveBottom;
	    this.SoundWave1ColorTop["Color"] = this.colorInactiveTop;
	    this.SoundWave1ColorBottom["Color"] = this.colorInactiveBottom;
	    this.SoundWave2ColorTop["Color"] = this.colorInactiveTop;
	    this.SoundWave2ColorBottom["Color"] = this.colorInactiveBottom;
	    this.SoundWave3ColorTop["Color"] = this.colorInactiveTop;
	    this.SoundWave3ColorBottom["Color"] = this.colorInactiveBottom;
	},
	SetVolumeForButtonVolume: function(volumeValue)
	{
        this.InitButtonVolume();
		
		if(volumeValue > 0)
		{
		    this.SoundSourceColorTop["Color"] = this.colorActiveTop;
		    this.SoundSourceColorBottom["Color"] = this.colorActiveBottom;
		    this.SoundWave1ColorTop["Color"] = this.colorActiveTop;
		    this.SoundWave1ColorBottom["Color"] = this.colorActiveBottom;
		    
	        if(volumeValue > 0.33)
	        {
	            this.SoundWave2ColorTop["Color"] = this.colorActiveTop;
	            this.SoundWave2ColorBottom["Color"] = this.colorActiveBottom;
	            
		        if(volumeValue > 0.66)
		        {
		            this.SoundWave3ColorTop["Color"] = this.colorActiveTop;
		            this.SoundWave3ColorBottom["Color"] = this.colorActiveBottom;
		        }
	        }
		}
	},
	SetVolumeForSlider: function(volumeValue)
	{
		this.VolumeMarker["Canvas.Left"] = volumeValue * (this.VolumeBackground["Width"] - this.VolumeMarker["Width"]);
		this.VolumeActive["Width"] = this.VolumeMarker["Canvas.Left"];
	},
	SetVolumeForScreen: function(volumeValue)
	{
	    this.Screen["Volume"] = volumeValue;
	},
	SetVolume: function(volumeValue)
	{
        this.SetVolumeForSlider(volumeValue);
        this.SetVolumeForButtonVolume(volumeValue);
        this.SetVolumeForScreen(volumeValue);
	},
	VolumeMarker_MouseLeftButtonDown: function(sender, args)
	{
	    this.isVolumeMarkerDragged = true;
	    
        var mousePositionX = args.getPosition(this.CanvasVolume).x;
        var currentLeft = this.VolumeMarker["Canvas.Left"];
	    	    
        this.differenceMouseCursor = mousePositionX - currentLeft;
	},
	CanvasVolume_MouseLeftButtonUp: function(sender, args)
	{
	    if(this.isVolumeMarkerDragged == true)
	    {
	        this.isVolumeMarkerDragged = false;
	    }
	},
    CanvasVolume_MouseMove: function(sender, args)
    {
        if(this.isVolumeMarkerDragged == true)
        {
            var mousePositionX = args.getPosition(this.CanvasVolume).x; 
            var newLeft = 0;    
            var newVolumeValue = 0;      
    
            if(mousePositionX > (0 +  this.differenceMouseCursor) && mousePositionX < (this.VolumeBackground["Width"] - this.VolumeMarker["Width"] + this.differenceMouseCursor))
            {
                newLeft = mousePositionX - this.differenceMouseCursor;
            }
            else if(mousePositionX >= (this.VolumeBackground["Width"] - this.VolumeMarker["Width"] + this.differenceMouseCursor))
            {
                newLeft = this.VolumeBackground["Width"] - this.VolumeMarker["Width"];
            }
            
            newVolumeValue = newLeft / (this.VolumeBackground["Width"] - this.VolumeMarker["Width"]);
            
            this.SetVolume(newVolumeValue);
        }
    },  
	InitCanvasFullScreen: function(rootElement)
	{
		this.CanvasFullScreen["Canvas.Left"] = this.CanvasControlPanel["Width"] - this.CanvasFullScreen["Width"] - this.Interspace;
		
		this.CanvasButtonFullScreen = rootElement.findName("CanvasButtonFullScreen");		
		this.CanvasButtonFullScreen.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.CanvasButtonFullScreen_MouseLeftButtonUp));
	},
	CanvasButtonPlayPause_MouseLeftButtonUp: function(sender, args)
	{
        if(this.isButtonPlayShown == true)
        {	    
            if(this.Player.AutoDownload == false && this.isMediaOpened == false)
            {
                this.Screen["Source"] = this.Player.Medium.Source;
            }
            else
            {
                _doTick = true;
                this.isButtonPlayShown = false;

                sender.findName("CanvasButtonPlayPause_SwitchToPause").begin();
                if(this.Screen.position.seconds < this.Player.Medium.StartPosition)
                {
                    this.SetDurtionForScreen(this.Player.Medium.StartPosition);
                }
                this.Screen.Play();
                var st = sender.findName("CanvasTimer_Tick");
                st.begin();
            }
        }
	    else if(this.isButtonPlayShown == false)
	    {
	        this.Screen.Pause();
	        
	        _doTick = false;
	        this.isButtonPlayShown = true;	        
	        sender.findName("CanvasButtonPlayPause_SwitchToPlay").begin();
	    }
	},
	CanvasButtonChapterBack_MouseLeftButtonUp: function(sender, args)
	{	
	    this.Screen.Stop();
	    _doTick = false;
	    
	    if(this.isButtonPlayShown == false)
	    {
	        this.isButtonPlayShown = true;	        
	        sender.findName("CanvasButtonPlayPause_SwitchToPlay").begin();
	    }
	    	    
        this.SetDurtionForScreen(this.Player.Medium.StartPosition);
        this.Screen.Pause();
	},
	CanvasButtonChapterNext_MouseLeftButtonUp: function(sender, args)
	{	
	    this.Screen.Stop();
	    _doTick = false;
	    
	    if(this.isButtonPlayShown == false)
	    {
	        this.isButtonPlayShown = true;	        
	        sender.findName("CanvasButtonPlayPause_SwitchToPlay").begin();
	    }
	    	    
        this.SetDurtionForScreen(this.Player.Medium.StartPosition);
        this.Screen.Pause();
	},
    onFullScreenChanged: function(sender, args)
    {    
        var silverlightPlugin = sender.getHost();
        var CanvasControlPanel = sender.findName("CanvasControlPanel");
        var CanvasPlayer = sender.findName("CanvasPlayer");
        var Screen = sender.findName("Screen");
        var CanvasBackground = sender.findName("CanvasBackground");
        var CanvasLogo = sender.findName("CanvasLogo");
        var LightBottom = sender.findName("LightBottom");
        
        if (silverlightPlugin.content.fullScreen == true)
        {
            CanvasControlPanel.opacity = 0;
            CanvasPlayer["Width"] = silverlightPlugin.content.actualWidth;
            CanvasPlayer["Height"] = silverlightPlugin.content.actualHeight;
            Screen["Width"] = CanvasPlayer["Width"];
            Screen["Height"] = CanvasPlayer["Height"];
            Screen["canvas.top"] = 0;
            Screen["canvas.left"] = 0;
            CanvasControlPanel["Visibility"] = "Collapsed";
            this.isFullScreen = true;
        }
        else 
        {
            CanvasControlPanel.opacity = 1;
            CanvasControlPanel["Visibility"] = "Visible";
            CanvasPlayer["Width"] = silverlightPlugin.content.actualWidth;
            CanvasPlayer["Height"] = silverlightPlugin.content.actualHeight;
            Screen["Width"] = CanvasPlayer["Width"];
            Screen["Height"] = CanvasPlayer["Height"];
            Screen["canvas.top"] = 0;
            Screen["canvas.left"] = 0;
            this.isFullScreen = false;
        }     
		CanvasBackground["Width"] = CanvasPlayer["Width"];	
	    CanvasBackground["Height"] =  CanvasPlayer["Height"];	    
		CanvasLogo["Canvas.Top"] = (CanvasBackground["Height"] - CanvasLogo["Height"]) / 2;
		CanvasLogo["Canvas.Left"] = (CanvasBackground["Width"] - CanvasLogo["Width"]) / 2;
		LightBottom["Canvas.Top"] = (CanvasLogo["Canvas.Top"] + CanvasLogo["Height"]) - (LightBottom["Height"] / 2);
		LightBottom["Canvas.Left"] = (CanvasBackground["Width"] - LightBottom["Width"]) / 2;
    },
	PositionCanvasBackgroundChilds: function()
	{
		this.CanvasBackground["Width"] = this.CanvasPlayer["Width"];	
	    this.CanvasBackground["Height"] =  this.CanvasPlayer["Height"];
	    
		this.CanvasLogo["Canvas.Top"] = (this.CanvasBackground["Height"] - this.CanvasLogo["Height"]) / 2;
		this.CanvasLogo["Canvas.Left"] = (this.CanvasBackground["Width"] - this.CanvasLogo["Width"]) / 2;
		
		this.LightBottom["Canvas.Top"] = (this.CanvasLogo["Canvas.Top"] + this.CanvasLogo["Height"]) - (this.LightBottom["Height"] / 2);
		this.LightBottom["Canvas.Left"] = (this.CanvasBackground["Width"] - this.LightBottom["Width"]) / 2;
	},
	CanvasButtonFullScreen_MouseLeftButtonUp: function(sender, args)
	{    
	    var silverlightPlugin = sender.getHost();
        silverlightPlugin.content.fullScreen = !silverlightPlugin.content.fullScreen;        
	},
    Screen_MediaDownloadChanged: function(sender, args)
    {
        /*download progress*/
        this.downloadProgress = sender.downloadProgress;
        var width = Math.floor(this.downloadProgress * this.SliderBackground["Width"]); 
        this.SliderDownload["Width"] = width;
        
        var startPositionInPercent = this.Player.Medium.StartPosition / this.Screen.NaturalDuration.Seconds;
        
        if((this.Player.Medium.StartPosition + 5/* 5sec. buffer */) < ((this.downloadProgress * this.Screen.NaturalDuration.Seconds)) && this.isControlPanelEnabled == false)
        {
            this.isControlPanelEnabled = true;
            this.SetDurtionForScreen(this.Player.Medium.StartPosition);
            this.Screen.Pause();
            
            if(this.Player.AutoPlay == true || this.Player.AutoDownload == false)
            {
	            if(this.Screen.position.seconds < this.Player.Medium.StartPosition)
	            {
                    this.SetDurtionForScreen(this.Player.Medium.StartPosition);
                }
	            this.isButtonPlayShown = false;    		    
	            sender.findName("CanvasButtonPlayPause_SwitchToPause").begin();
	            this.Screen.Play();
		        _doTick = true;
	            sender.findName("CanvasTimer_Tick").begin();
            }
        }
    },
    Screen_MediaOpened: function(sender, args)
    {
        this.isMediaOpened = true;
        this.Screen.opacity = 1;
    },
    Screen_MediaEnded: function(sender, args)
    {
        this.Screen.stop();
      
        this.SetDurtionForScreen(this.Player.Medium.StartPosition);
        this.Screen.Pause();

        this.isButtonPlayShown = true;        
        sender.findName("CanvasButtonPlayPause_SwitchToPlay").begin();
	    _doTick = false;
    },
    SliderMarker_MouseLeftButtonDown: function(sender, args)
    {
        if(this.isMediaOpened == true)
        {
            this.isSliderMarkerDragged = true;
	        this.Screen.Pause();
	        _doTick = false; 
    	    	    
	        var mousePositionX = args.getPosition(this.CanvasSlider).x;
	        var currentLeft = this.SliderMarker["Canvas.Left"];
    	    	    
	        this.differenceMouseCursor = mousePositionX - currentLeft;
    	    
	        if(this.isButtonPlayShown == true)
	        {
	            this.isButtonPlayShown = false;    	        
	            sender.findName("CanvasButtonPlayPause_SwitchToPause").begin();
	        }
	    }
    },
    CanvasControlPanel_MouseLeftButtonUp: function(sender, args)
    {    
        if(this.isSliderMarkerDragged == true)
        {    
            this.isSliderMarkerDragged = false;
            
	        this.Screen.Play();    	    
		    sender.findName("CanvasTimer_Tick").begin();
		    _doTick = true;
		}
    },
    CanvasPlayer_MouseEnter: function(sender, args)
    {
        if(this.isFullScreen == false)
        {
	        sender.findName("CanvasPlayer_MouseEnter").begin();
	    }
    },
    CanvasPlayer_MouseLeave: function(sender, args)
    {
        if(this.isFullScreen == false)
        {
	        sender.findName("CanvasPlayer_MouseLeave").begin();
	    }
    },
	SetDurtionForSlider: function()
	{
        this.SliderMarker["Canvas.Left"] = (this.Screen.position.seconds / this.Screen.naturalDuration.seconds) * (this.SliderBackground["Width"] - this.SliderMarker["Width"]);
	},
	SetDurtionForScreen: function(durationValue)
	{
        var position = this.Screen.position;
        position.seconds = durationValue;
        this.Screen.position = position;  
	},
    CanvasSlider_MouseMove: function(sender, args)
    {        
        if(this.isSliderMarkerDragged == true)
        {
            var mousePositionX = args.getPosition(this.CanvasSlider).x;
            var naturalDuration = this.Screen.naturalDuration.seconds;
            var timeLineLength = (this.SliderBackground["Width"] - this.SliderMarker["Width"]) * this.downloadProgress;
            var startPositionInPercent = this.Player.Medium.StartPosition / naturalDuration;
            var newLeft = 0;    
            var newDurationValue = 0;        
    
            if(mousePositionX > ((startPositionInPercent * timeLineLength) +  this.differenceMouseCursor) && mousePositionX < (timeLineLength + this.differenceMouseCursor))
            {
                newLeft = mousePositionX - this.differenceMouseCursor;
            }
            else if(mousePositionX >= (timeLineLength + this.differenceMouseCursor))
            {
                newLeft = timeLineLength;
            }
            
            newDurationValue = (newLeft / (this.SliderBackground["Width"] - this.SliderMarker["Width"])) * naturalDuration;
            
            this.SetDurtionForScreen(newDurationValue);
            this.SetDurtionForSlider();
        }
    },
    InitSetDurationByMediaDuration: function(sender)
    {
        this.Screen = sender.findName("Screen"); 
        this.SliderBackground = sender.findName("SliderBackground");
        this.SliderMarker = sender.findName("SliderMarker");
        this.SliderTime = sender.findName("SliderTime");
    },    
    SetDurationByMediaDuration: function(sender)
    {
        this.InitSetDurationByMediaDuration(sender);
        this.SetDurationForSliderTime(sender);
        this.SetDurtionForSlider();
        if(_doTick == true)
	    {
	        sender.findName("CanvasTimer_Tick").begin();
	    }
    },
    SetDurationForSliderTime: function()
    {        
        var naturalDuration = this.GetTimeToString(this.Screen.naturalDuration.seconds);
        var duration = this.GetTimeToString(this.Screen.position.seconds);
        
        this.SliderTime.Text = duration + " / " + naturalDuration;
    },
    GetTimeToString: function(seconds)
    {
        var string;
        
        var seconds = Math.floor(seconds);  
        var minutes = Math.floor(seconds / 60);
        var hours = Math.floor(minutes / 60);
        
        seconds = seconds - (minutes * 60);
        minutes = minutes - (hours * 60);
        
        seconds = this.ConvertIntToStringWithTwoChars(seconds);
        minutes = this.ConvertIntToStringWithTwoChars(minutes);
        hours = this.ConvertIntToStringWithTwoChars(hours);

        string = hours + ":" + minutes + ":" + seconds;
        
        return string;
    },
    ConvertIntToStringWithTwoChars: function(number)
    {
        var string;
        
        if(number.toString().length == 1)
        {
            string = "0" + number.toString();
        }
        else
        {
            string = number.toString();
        }

        return string;
    }
}
_doTick = false;

function CanvasTimer_TickCompleted(sender, args)
{    
    this.GoFans.CanvasPlayer.prototype.SetDurationByMediaDuration(sender);
}