﻿if (!window.SilverlightSite6)
	SilverlightSite6 = {};

SilverlightSite6.Page = function(language, artist, mode) 
{
    this._artist = artist;
    this._mode = mode;
    this._language = language;
}

SilverlightSite6.Page.prototype =
{

  
    
    updateArtistInfo: function()
    {
        this._imgPreview.Source = this._artists[this._artist][this._currentMedia]["Preview"];
        this._txtArtistName.Text = this._artists[this._artist]["ArtistName"];
        this._txtLocation.Text = this._artists[this._artist]["Location"];
        for(var i=0; i<this._artists[this._artist].length; i++)
        {
        //   this._mediaThumb[i]["Thumbnail"].Source = this._artists[this._artist][i]["Thumbnail"];
        //   this._mediaThumb[i]["Title"].Text= this._artists[this._artist][i]["Title"];
        }
    },
    
	handleLoad: function(control, userContext, rootElement) 
	{
		this._control = control;
		//this.populateArtists();
		this._currentMedia = 0;

		this._cnvVolume = this._control.content.findName("cnvVolume");
		this._cnvVolumeReference = this._control.content.findName("cnvVolumeReference");
		this._volumeAngle = this._control.content.findName("volumeAngle");
		this._volumeRectangleBG = this._control.content.findName("volumeBG");
		
		
		this._cnvPositionReference = this._control.content.findName("cnvPositionReference");
		this._cnvPosition = this._control.content.findName("cnvPosition");		
		this._cnvMediaSpace = this._control.content.findName("cnvMediaSpace");		
		
		this._cnvPlay = this._control.content.findName("cnvPlay");		
		this._cnvPause = this._control.content.findName("cnvPause");		
		this._cnvArtistPhoto = this._control.content.findName("cnvArtistPhoto");		
		this._cnvPlayerLeftCover = this._control.content.findName("cnvPlayerCoverLeft");
		this._cnvPlayerRightCover = this._control.content.findName("cnvPlayerRightCover");
		this._positionAngle = this._control.content.findName("positionAngle");
		this._positionRectangleBG = this._control.content.findName("positionBG");
		
        this._media = this._control.content.findName("video");
        this._imgPreview = this._control.content.findName("imgPreview");
        
        this._txtArtistName = this._control.content.findName("txtArtistName");
        this._txtLocation = this._control.content.findName("txtLocation");
        this._txtDay = this._control.content.findName("txtDay");
        this._txtMediaPosition = this._control.content.findName("txtMediaPosition");
        
        /*this._mediaThumb = new Array();
        this._mediaThumb[0] = new Array();
        this._mediaThumb[0]["Thumbnail"] = this._control.content.findName("imgThumb0");
        this._mediaThumb[0]["Title"] = this._control.content.findName("txtThumb0");
        this._mediaThumb[0]["Thumbnail"].addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.changeVideo));
        
        this._mediaThumb[1] = new Array();
        this._mediaThumb[1]["Thumbnail"] = this._control.content.findName("imgThumb1");
        this._mediaThumb[1]["Title"] = this._control.content.findName("txtThumb1");
        this._mediaThumb[1]["Thumbnail"].addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.changeVideo));
        */
        this._imgPreview = this._control.content.findName("imgPreview");
        this._imgArtistPhoto = this._control.content.findName("imgArtistPhoto");
        this._imgArtistPhoto1 = this._control.content.findName("imgArtistPhoto1");
        this._sbdShiftArtistPhoto = this._control.content.findName("sbdShiftArtistPhoto");
        this._sbdCoversMove = this._control.content.findName("sbdCoversMove");
        
        this._playOverlayButton = control.content.findName('PlayOverlayButton');


        this._sbdPlayerCurtainUp = this._control.content.findName("sbdPlayerCurtainUp");
        this._sbdPlayerCurtainDown = this._control.content.findName("sbdPlayerCurtainDown");
        
        this._sbdVolumePopOut = this._control.content.findName("sbdVolumePopOut");
        this._sbdVolumePopIn = this._control.content.findName("sbdVolumePopIn");
        this._sbdPositionPopOut = this._control.content.findName("sbdPositionPopOut");
        this._sbdPositionPopIn = this._control.content.findName("sbdPositionPopIn");
        
        this._sbdPlayBtnIn = this._control.content.findName("playBtnIn");
        this._sbdPlayBtnOut = this._control.content.findName("playBtnOut");
        this._sbdPlayToPause = this._control.content.findName("playBtnOut");
        this._sbdPauseToPlay = this._control.content.findName("pauseToPlay");
        
        //this.updateArtistInfo();
        this._sbdPlayerCurtainUp.addEventListener("Completed", Silverlight.createDelegate(this, this.curtainOpened));
        
        this._sbdVolumePopIn.addEventListener("Completed", Silverlight.createDelegate(this, this.volumePopedIn));
        this._sbdPositionPopIn.addEventListener("Completed", Silverlight.createDelegate(this, this.positionPopedIn));
        
        this._sbdPlayToPause.addEventListener("Completed", Silverlight.createDelegate(this, this.playToPauseCompleted));
        this._sbdPauseToPlay.addEventListener("Completed", Silverlight.createDelegate(this, this.pauseToPlayCompleted));
        this._sbdShiftArtistPhoto.addEventListener("Completed", Silverlight.createDelegate(this, this.sbdShiftArtistPhotoCompleted));
		this._cnvVolume.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.volumeClicked));
		this._volumeRectangleBG.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.volumeBGClicked));
		this._cnvVolume.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.volumeUnclicked));
		this._cnvVolume.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.volumeUnclicked));
		
		this._cnvPosition.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.positionClicked));
		this._positionRectangleBG.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.positionBGClicked));
		this._cnvPosition.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.positionUnclicked));
		this._cnvPosition.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.positionUnclicked));
				
		this._media.addEventListener("MediaEnded", Silverlight.createDelegate(this, this.mediaEnded));
		this._media.addEventListener("CurrentStateChanged", Silverlight.createDelegate(this, this._onStateChanged));
		//this._playOverlayButton.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this._mouseLeftButtonUp));
		this._cnvMediaSpace.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this._mouseLeftButtonUp));
		
		this._cnvMediaSpace.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.mouseEnterScreen));
		
		this._cnvMediaSpace.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.mouseLeaveScreen));
		
		
		this.setVolume((this._media.Volume*100-50)/2);
		this._media.addEventListener("MarkerReached", Silverlight.createDelegate(this, this.markerReached));
		this._media.addEventListener("MediaOpened", Silverlight.createDelegate(this, this.mediaOpened));
		this.setMode();
			    this._imgArtistPhoto.Source = "/gfx/winner.jpg";
		
	},
	setMode: function()
	{
	    switch(this._mode){
	        case "home": {
	            this._media.Visibility = "Collapsed";
	            //this._playOverlayButton.Visibility="Collapsed";
	            this._cnvArtistPhoto.Visibility = "Visible";
	            this._cnvArtistPhoto.Cursor = "Hand";
	            this._cnvArtistPhoto.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.mouseEnterArtistPhoto));
	            this._cnvArtistPhoto.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.mouseLeaveArtistPhoto));
	            this._cnvArtistPhoto.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.mouseClickArtistPhoto));
	            
                this._control.content.findName("cnvLeftInfo").addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.mouseClickArtistPhoto));
	            this._control.content.findName("cnvLeftInfo").Cursor = "Hand";
	            
	            this._imgPreview.Visibility = "Collapsed";
	            this._cnvPlayerRightCover.IsHitTestVisible="False";
	            this._cnvPlayerLeftCover.IsHitTestVisible="False";
	      
	           Insys.Opener2008.Frontend.OpenerWS.GetArtistBillingFrom(99, Silverlight.createDelegate(this, this.dataLoaded), this.dataFailed, this);
	            //Insys.Sunrise.WebApp.SunriseWS.GetArtistsInBillingOrder(2,Sunrise.ArtistShowcase.createDelegate(this,this.ArtistsFireAdd), this.FailedArtistCallback, this);  
	        }; break;
	        case "player": {
	            this._media.Visibility = "Visible";
	            //this._playOverlayButton.Visibility="Visible";
	            this._cnvArtistPhoto.Visibility = "Collapsed";
	            this._imgPreview.Visibility = "Visible";
	            
	            Insys.Opener2008.Frontend.OpenerWS.GetArtistMediaByCodename(this._artist, Silverlight.createDelegate(this, this.dataLoaded), this.dataFailed, this);
	            Insys.Opener2008.Frontend.OpenerWS.GetArtistByCodename(this._artist, Silverlight.createDelegate(this, this.artistLoaded), this.dataFailed, this);
	        }; break;
	        case "gallery": {
	            this._media.Visibility = "Collapsed";
	            //this._playOverlayButton.Visibility="Collapsed";
	            this._cnvArtistPhoto.Visibility = "Visible";
	            this._cnvArtistPhoto.Cursor = "Hand";
	            
	            this._cnvArtistPhoto.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.mouseClickArtistPhoto));
	            
	            this._imgPreview.Visibility = "Collapsed";
	            this._cnvPlayerRightCover.IsHitTestVisible="False";
	            this._cnvPlayerLeftCover.IsHitTestVisible="False";
	      
	            Insys.Opener2008.Frontend.OpenerWS.GetHomePhotos(Silverlight.createDelegate(this, this.dataLoaded), this.dataFailed, this);
	            //Insys.Sunrise.WebApp.SunriseWS.GetArtistsInBillingOrder(2,Sunrise.ArtistShowcase.createDelegate(this,this.ArtistsFireAdd), this.FailedArtistCallback, this);  
	        }; break;
	        default: break;
	    }
	},
	
	showArtistAll: function(){
	            this._intervalId = window.setInterval(Silverlight.createDelegate(this, this.artistRotator), 4000);  
 this.showArtist();
	            this.showArtistPhoto();
},
	
	dataLoaded: function(data)
	{
	    switch(this._mode){
	        case "home": {
	            this._artists = data;
	            this._currentArtist = 0;

	           setTimeout(Silverlight.createDelegate(this,this.showArtistAll),3500);
			   if(this._language=="pl")
	            {
	                this._txtArtistName.Text = "Dziękujemy!"
	                this._txtLocation["Canvas.Top"]=this._txtArtistName["Canvas.Top"]+this._txtArtistName.ActualHeight+6;
	            this._txtLocation.FontSize="14";
	                this._txtLocation.Text = "Dziękujemy naszej publiczności, artystom, obsługującym imprezę patronom medialnym i pracującym na festiwalu dziennikarzom oraz wszystkim tym, którzy tworzą atmosferę festiwalową za kolejną świetną edycję Open'era."
	            } else {
	               this._txtArtistName.Text = "Thank you!"
	            }
	            //this.artistRotator();
	        }; break;
	        case "player": {
	            this._mediaTable = data;
	            this.showMedia(0);
	            
	        }; break;
	        case "gallery": {
	            this._artists = data;
	            this._currentArtist = 0;
				//misha wykomentowal galerie
	            //this._intervalId = window.setInterval(Silverlight.createDelegate(this, this.galleryRotator), 3000);  
	            this._intervalId = window.setInterval(Silverlight.createDelegate(this, this.artistRotator), 3000);  
	            
	            if(this._language=="pl")
	            {
	                this._txtArtistName.Text = "Dziękujemy!"
	                this._txtLocation["Canvas.Top"]=this._txtArtistName["Canvas.Top"]+this._txtArtistName.ActualHeight+6;
	            this._txtLocation.FontSize="14";
	                this._txtLocation.Text = "Dziękujemy naszej publiczności, artystom, obsługującym imprezę patronom medialnym i pracującym na festiwalu dziennikarzom oraz wszystkim tym, którzy tworzą atmosferę festiwalową za kolejną świetną edycję Open'era."
	            } else {
	               this._txtArtistName.Text = "Thank you!"
	            }
	            this.showArtistPhoto();
	            //this.artistRotator();
	        }; break;
	        default: break;
	    }        
	},
	
	setArtistName: function(name)
	{
	    this._txtArtistName.Text = name;
	    this._txtArtistName.FontSize = 24;
        while(this._txtArtistName.ActualWidth <= this._txtArtistName.Width-15 && this._txtArtistName.FontSize<=36) 
        { 
             this._txtArtistName.FontSize += 1; 
        } 
        //this._txtLocation["Canvas.Top"]=this._txtArtistName["Canvas.Top"]+this._txtArtistName.ActualHeight+6;
        //this._txtDay["Canvas.Top"]=this._txtArtistName["Canvas.Top"]+this._txtArtistName.ActualHeight+50;
	},
	
	artistLoaded: function(data)
	{
	    this.setArtistName(data.ArtistName);
	    this._txtLocation.Text = "";	 
	    this._txtDay.Text = "";   
	    /*var day;
	    for(var i=0; i<data.ShowTimes.length; i++)
	    {
	    if(data.ShowTimes[i].BeginTime.format("HH").substring(0,1)=="0")
	            {
	            day = data.ShowTimes[i].BeginTime.getDate()-1;
	        switch(this._language)
	        {
	            case "pl" :     
	            switch(data.ShowTimes[i].BeginTime.format("dd"))
	            {
	                
    	            case "01":this._txtDay.Text = "Czwartek"; break;
    	            case "02":this._txtDay.Text = "Czwartek"; break;
    	            case "03":this._txtDay.Text = "Piؤ…tek"; break;
    	            case "04":this._txtDay.Text = "Sobota"; break;
    	            case "05":this._txtDay.Text = "Niedziela"; break;
    	            default: break;
    	            
	            }; break;
	            case "en" :     
	            switch(data.ShowTimes[i].BeginTime.format("dd"))
	            {
    	            case "01":this._txtDay.Text = "Thursday"; break;
    	            case "02":this._txtDay.Text = "Thursday"; break;
    	            case "03":this._txtDay.Text = "Friday"; break;
    	            case "04":this._txtDay.Text = "Saturday"; break;
    	            case "05":this._txtDay.Text = "Sunday"; break;
    	            default: break;
	            }; break;
	            default: break;
	        }
	        } else {
	        day = data.ShowTimes[i].BeginTime.getDate();
	        switch(this._language)
	        {
	            case "pl" :     
	            switch(data.ShowTimes[i].BeginTime.format("dd"))
	            {
	                
    	            case "01":this._txtDay.Text = "Czwartek"; break;
    	            case "02":this._txtDay.Text = "Piؤ…tek"; break;
    	            case "03":this._txtDay.Text = "Sobota"; break;
    	            case "04":this._txtDay.Text = "Niedziela"; break;
    	            case "05":this._txtDay.Text = "Niedziela"; break;
    	            default: break;
    	            
	            }; break;
	            case "en" :     
	            switch(data.ShowTimes[i].BeginTime.format("dd"))
	            {
    	            case "01":this._txtDay.Text = "Thursday"; break;
    	            case "02":this._txtDay.Text = "Friday"; break;
    	            case "03":this._txtDay.Text = "Saturday"; break;
    	            case "04":this._txtDay.Text = "Sunday"; break;
    	            case "05":this._txtDay.Text = "Sunday"; break;
    	            default: break;
	            }; break;
	            default: break;
	        }
	        }
	        this._txtDay.Text += " "+ day + data.ShowTimes[i].BeginTime.format(".MM.yyyy");
	        //misha wykomentowal wyswietlanie sceny
		//this._txtLocation.Text = data.ShowTimes[i].BeginTime.format("HH:mm")+"  "+data.ShowTimes[i].Stage.StageName+"\n";
	    }*/
		if(this._language=="pl")
	            {
	                this._txtArtistName.FontSize="26";
					this._txtArtistName.Text = "Dziękujemy!"
	                this._txtLocation["Canvas.Top"]=this._txtArtistName["Canvas.Top"]+this._txtArtistName.ActualHeight+6;
	            this._txtLocation.FontSize="14";
	                this._txtLocation.Text = "Dziękujemy naszej publiczności, artystom, obsługującym imprezę patronom medialnym i pracującym na festiwalu dziennikarzom oraz wszystkim tym, którzy tworzą atmosferę festiwalową za kolejną świetną edycję Open'era."
	            } else {
	                this._txtArtistName.FontSize="26";
				   this._txtArtistName.Text = "Thank you!"
	            }
	    
	},
	
	dataFailed: function()
	{
	    alert("Loading data failed. Refresh.");
	},
	
	mouseEnterScreen: function()
	{
	    if(this._media.CurrentState=="Paused" || this._media.CurrentState=="Stopped"|| this._media.CurrentState=="Closed")
	    {
	        this._cnvPause.Visibility = "Collapsed";
	        this._cnvPlay.Visibility = "Visible";
	    } else {
	       this._cnvPause.Visibility = "Visible";
	        this._cnvPlay.Visibility = "Collapsed";
	    }
	    this._sbdPlayToPause.Stop();
	    this._sbdPauseToPlay.Stop();
	    this._sbdPlayBtnOut.Stop();
	    this._sbdPlayBtnIn.Stop();
	    this._sbdPlayBtnIn.Begin();
	},
	
	mouseEnterArtistPhoto: function()
	{
	    window.clearInterval(this._intervalId);
	},
	
	mouseLeaveArtistPhoto: function()
	{
	    this._intervalId = window.setInterval(Silverlight.createDelegate(this, this.artistRotator), 4000);
	},
	
	mouseClickArtistPhoto: function()
	{
	    if(this._mode=="gallery")
	    {
	        document.location = "/"+this._language+"/gallery";
	    } else {
	    document.location = "/"+this._language+"/artist/"+this._artists[this._currentArtist].Codename;
	    }
	},
	
	mouseLeaveScreen: function()
	{
	    this._sbdPlayToPause.Stop();
	    this._sbdPauseToPlay.Stop();
	    this._sbdPlayBtnIn.Stop();
	    this._sbdPlayBtnOut.Begin();
	},
	
	showMedia: function(mediaNumber)
	{
	    if(this._mediaTable.length>mediaNumber)
	    {
	        this._currentMedia = mediaNumber;
	        this.setType(this._mediaTable[mediaNumber].MediaType);
	        if(this._mediaTable[mediaNumber].MediaType==1)
	        {
	            this._imgArtistPhoto.Source = this._mediaTable[mediaNumber].Source;
	        } else{
	            this._imgPreview.Source = "/gfx/Media/"+this._mediaTable[mediaNumber].Thumbnail;	            
	            this._bufferingListener = this._media.addEventListener("bufferingProgressChanged", Silverlight.createDelegate(this, this._bufferProgressChanged));
	        }
	        
	    }
	},
	 _bufferProgressChanged: function(sender, eventArgs) {
        
        sender.findName("BufferingText").Text = Math.round(sender.bufferingProgress * 100).toString() + "%";

        var bufferingCanvas = sender.findName("BufferingCanvas");
        var bufferingStoryboard = sender.findName("Buffering");
        if (sender.bufferingProgress == 1.0 || sender.bufferingProgress == 0.0)
        {
            bufferingCanvas.Visibility = "Collapsed";
            bufferingStoryboard.Stop();
        }
        else
        {
            bufferingCanvas.Visibility = "Visible";
            bufferingStoryboard.Begin();
        }
    },
	setType: function(mediaType){
	    switch(mediaType){
	        case 1:{
	             this._playOverlayButton.Visibility = "Collapsed";
	             this._imgPreview.Visibility = "Collapsed";
	             this._media.Visibility = "Collapsed";
	             this._cnvArtistPhoto.Visibility = "Visible";
	        };
	         break;
	        case 2:{
	             this._cnvArtistPhoto.Visibility = "Collapsed";
	             this._imgPreview.Visibility = "Visible";
	             this._playOverlayButton.Visibility = "Visible";
	             this._cnvPlay.Visibility = "Visible";
	             this._media.Visibility = "Visible";
	             this._sbdPlayBtnIn.Begin();
	        };
	        break;
	        default: break; 
	    }
	},
	
	artistRotator: function()
	{
	
	  this._sbdShiftArtistPhoto.Begin();  
	  this._sbdCoversMove.Begin();
	  this._currentArtist++;
	 if(this._currentArtist>=this._artists.length)
	    {
	 	    this._currentArtist = 0;
	    }
	  this.showArtist();
	},
	
	galleryRotator: function()
	{
	
	  this._sbdShiftArtistPhoto.Begin();  
	  this._sbdCoversMove.Begin();
	  this._currentArtist++;
	 if(this._currentArtist>=this._artists.length)
	    {
	 	    this._currentArtist = 0;
	    }
	  
	},
	
	sbdShiftArtistPhotoCompleted: function()
	{
	    

	   
	    this._sbdShiftArtistPhoto.Stop();
	    this.showArtistPhoto();
	},
	
	showArtistPhoto: function()
	{
	    this._imgArtistPhoto.Source = "/gfx/Artists/380/"+this._artists[this._currentArtist].Picture;
	   // if(this._currentArtist<this._artists.length+1)
	   // {
	        this._imgArtistPhoto1.Source = "/gfx/Artists/380/"+this._artists[(this._currentArtist+1) % this._artists.length].Picture;
	   // }
	},
	
	showArtist: function(){
	
	    this.setArtistName(this._artists[this._currentArtist].ArtistName);
	    this._txtLocation.Text = "";	 
	    this._txtDay.Text = "";
	   /* var day;
	     for(var i=0; i<this._artists[this._currentArtist].ShowTimes.length; i++)
	    {
	    var data = this._artists[this._currentArtist];
	        this._txtDay.Text = "";
	    if(data.ShowTimes[i].BeginTime.format("HH").substring(0,1)=="0")
	            {
	            day = data.ShowTimes[i].BeginTime.getDate()-1;
	        switch(this._language)
	        {
	            case "pl" :     
	            switch(data.ShowTimes[i].BeginTime.format("dd"))
	            {
	                
    	            case "01":this._txtDay.Text = "Czwartek"; break;
    	            case "02":this._txtDay.Text = "Czwartek"; break;
    	            case "03":this._txtDay.Text = "Piؤ…tek"; break;
    	            case "04":this._txtDay.Text = "Sobota"; break;
    	            case "05":this._txtDay.Text = "Niedziela"; break;
    	            default: break;
    	            
	            }; break;
	            case "en" :     
	            switch(data.ShowTimes[i].BeginTime.format("dd"))
	            {
    	            case "01":this._txtDay.Text = "Thursday"; break;
    	            case "02":this._txtDay.Text = "Thursday"; break;
    	            case "03":this._txtDay.Text = "Friday"; break;
    	            case "04":this._txtDay.Text = "Saturday"; break;
    	            case "05":this._txtDay.Text = "Sunday"; break;
    	            default: break;
	            }; break;
	            default: break;
	        }
	        } else {
	        day = data.ShowTimes[i].BeginTime.getDate();
	        switch(this._language)
	        {
	            case "pl" :     
	            switch(data.ShowTimes[i].BeginTime.format("dd"))
	            {
	                
    	            case "01":this._txtDay.Text = "Czwartek"; break;
    	            case "02":this._txtDay.Text = "Piؤ…tek"; break;
    	            case "03":this._txtDay.Text = "Sobota"; break;
    	            case "04":this._txtDay.Text = "Niedziela"; break;
    	            case "05":this._txtDay.Text = "Niedziela"; break;
    	            default: break;
    	            
	            }; break;
	            case "en" :     
	            switch(data.ShowTimes[i].BeginTime.format("dd"))
	            {
    	            case "01":this._txtDay.Text = "Thursday"; break;
    	            case "02":this._txtDay.Text = "Friday"; break;
    	            case "03":this._txtDay.Text = "Saturday"; break;
    	            case "04":this._txtDay.Text = "Sunday"; break;
    	            case "05":this._txtDay.Text = "Sunday"; break;
    	            default: break;
	            }; break;
	            default: break;
	        }
	        }
	        //this._txtDay.Text += " "+ day+this._artists[this._currentArtist].ShowTimes[i].BeginTime.format(".MM.yyyy");
	        //misha wykomentowal wyswietlanie sceny
		//this._txtLocation.Text = this._artists[this._currentArtist].ShowTimes[i].BeginTime.format("HH:mm")+"  "+this._artists[this._currentArtist].ShowTimes[i].Stage.StageName+"\n";
	    }*/
		if(this._language=="pl")
	            {
	                   this._txtArtistName.FontSize="26";
					this._txtArtistName.Text = "Dziękujemy!"
	                this._txtLocation["Canvas.Top"]=this._txtArtistName["Canvas.Top"]+this._txtArtistName.ActualHeight+6;
	            this._txtLocation.FontSize="14";
	                this._txtLocation.Text = "Dziękujemy naszej publiczności, artystom, obsługującym imprezę patronom medialnym i pracującym na festiwalu dziennikarzom oraz wszystkim tym, którzy tworzą atmosferę festiwalową za kolejną świetną edycję Open'era."
	            } else {
	                this._txtArtistName.FontSize="26";
				   this._txtArtistName.Text = "Thank you!"
	            }
	},
	
	changeVideo: function(sender, eventArgs)
	{
	    this._currentMedia = eval(sender.Name.substring(sender.Name.length-1,sender.Name.length));
	    this._media.Stop();
	    this._media.Source = null;
	    this._sbdPlayerCurtainDown.Begin();
	    this._imgPreview.Source = this._artists[this._artist][this._currentMedia]["Preview"];
	    this._imgPreview.Visibility= "Visible";
	    this._playOverlayButton.Visibility = "Visible";
	    this.curtainClosed();
	   // this._media.Source = this._artists[this._artist][this._currentMedia]['Video'];
	},
	
	setVolume: function(volume)
	{
	    if(volume>=-25&&volume<=25){
	        this._media.Volume=1-((volume+25)/100)*2;
	        this._volumeAngle["Angle"]=volume;
	    } else {
	        if(volume<-25){
	            this.setVolume(-25);
	        } else {
	            this.setVolume(25);
	        }
	    }
	},

	volumeClicked: function(sender, eventArgs) 
	{
	    this._evntVolumeMouseDown = this._cnvVolume.addEventListener("MouseMove", Silverlight.createDelegate(this, this.volumeSlide));		
        var x = eventArgs.getPosition(this._cnvVolumeReference).x-(this._cnvVolume.Width/2);
	    var y = eventArgs.getPosition(this._cnvVolumeReference).y-(this._cnvVolume.Height/2);
	    this.setVolume(Math.atan2(y,x)*180/Math.PI);
	},
	
	volumeBGClicked: function(sender, eventArgs) 
	{
        var x = eventArgs.getPosition(this._cnvVolumeReference).x-(this._cnvVolume.Width/2);
	    var y = eventArgs.getPosition(this._cnvVolumeReference).y-(this._cnvVolume.Height/2);
	    this.setVolume(Math.atan2(y,x)*180/Math.PI);
	},
	
	volumeUnclicked: function(sender, eventArgs) 
	{
	    this._cnvVolume.removeEventListener("MouseMove", this._evntVolumeMouseDown);		
	    
	},
	
	volumeSlide: function(sender, eventArgs)
	{
	    
	    var x = eventArgs.getPosition(this._cnvVolumeReference).x-(this._cnvVolume.Width/2);
	    var y = eventArgs.getPosition(this._cnvVolumeReference).y-(this._cnvVolume.Height/2);
	    //this._volumeAngle["Angle"]= Math.atan2(y,x)*180/Math.PI;;
	    this.setVolume(Math.atan2(y,x)*180/Math.PI);
	    
	},
	
	setMediaPosition: function(position)
	{
	    if(position>=-25&&position<=25){
	        var b=this._media.Position;
	        b.seconds = (((position+25)/100)*2)*this._media.NaturalDuration.seconds;
	        this._media.Position=b;
	        this.showMediaPosition(position);
	    } else {
	        if(position<-25){
	            this.setMediaPosition(-25);
	        } else {
	            this.setMediaPosition(25);
	        }
	    }
	},

    
    showMediaPosition: function(position)
    {
        this._positionAngle["Angle"]=position;
    },
    
    formatTime:function(e){
        var b=Math.floor(e/(1000*60*60)),c=Math.floor(e/(1000*60))-b*60,d=Math.floor(e/1000)-b*60*60-c*60,a="";
        if(b>0){a=b<10?"0"+b:""+b;a+=":"}a+=c<10?"0"+c:""+c;a+=":";a+=d<10?"0"+d:""+d;return a
    },

    positionChanged: function()
    {
        if(this._media.Position.seconds!=NaN && this._media.NaturalDuration.seconds!=0){
            this.showMediaPosition((this._media.Position.seconds/this._media.NaturalDuration.seconds*100-50)/2);
            var a=Math.max(0,this._media.Position.seconds);a=Math.min(this._media.NaturalDuration.seconds,a)
            
            this._txtMediaPosition.Text = this.formatTime(a*1000)
        }
        window.setTimeout(Silverlight.createDelegate(this,this.positionChanged),1000);        
    },
    
	positionClicked: function(sender, eventArgs) 
	{
	    this._evntPositionMouseDown = this._cnvPosition.addEventListener("MouseMove", Silverlight.createDelegate(this, this.positionSlide));		
        var x = (this._cnvPosition.Width/2)-eventArgs.getPosition(this._cnvPositionReference).x;
	    var y = eventArgs.getPosition(this._cnvPositionReference).y-(this._cnvPosition.Height/2);
	    this.setMediaPosition(Math.atan2(-y,x)*180/Math.PI);
	},
	
	positionBGClicked: function(sender, eventArgs) 
	{
        var x = (this._cnvPosition.Width/2)-eventArgs.getPosition(this._cnvPositionReference).x;
	    var y = eventArgs.getPosition(this._cnvPositionReference).y-(this._cnvPosition.Height/2);
	    this.setMediaPosition(Math.atan2(-y,x)*180/Math.PI);
	},
	
	positionUnclicked: function(sender, eventArgs) 
	{
	    this._cnvPosition.removeEventListener("MouseMove", this._evntPositionMouseDown);			    
	},
	
	positionSlide: function(sender, eventArgs)
	{	    
	    var x = (this._cnvPosition.Width/2)-eventArgs.getPosition(this._cnvPositionReference).x;
	    var y = eventArgs.getPosition(this._cnvPositionReference).y-(this._cnvPosition.Height/2);
	    //this._volumeAngle["Angle"]= Math.atan2(y,x)*180/Math.PI;
	    this.setMediaPosition(Math.atan2(-y,x)*180/Math.PI);
	    
	},
	
	mediaEnded: function(sender, eventArgs)
	{
	    this._sbdPlayerCurtainDown.Begin();
	    sender.position = "00:00:00";
	},
	
	positionPopedIn: function()
	{
	    this._cnvPosition.Visibility="Collapsed";
	},
	
	volumePopedIn: function()
	{
	    this._cnvVolume.Visibility="Collapsed";
	},
	
	curtainOpened: function()
	{
	    this._cnvPosition.Visibility="Visible";
	    this._sbdPositionPopOut.Begin();
	    
	    this._cnvVolume.Visibility="Visible";
	    this._sbdVolumePopOut.Begin();
	    this._positionRectangleBG.Visibility="Visible";
	    this._volumeRectangleBG.Visibility="Visible";
	},
	
	curtainClosed: function()
	{
	    this._sbdVolumePopIn.Begin();
	    this._sbdPositionPopIn.Begin();
	    
	
	    
	    this._positionRectangleBG.Visibility="Collapsed";
	    this._volumeRectangleBG.Visibility="Collapsed";
	},
	
	 _mouseLeftButtonUp: function(sender, eventArgs) {
        //alert(this._media.CurrentState);
        if (this._media.CurrentState == 'Closed') {
            this._media.Source = this._mediaTable[this._currentMedia].Source;
            
            this._sbdPlayerCurtainUp.Begin();            
            this.positionChanged();
        }
        
        if (this._media.CurrentState == 'Paused' || this._media.CurrentState == 'Stop') {
            this._media.Play();
            this._sbdPlayerCurtainUp.Begin();
        } else if (this._media.CurrentState == 'Playing') {
            this._media.Pause();
            this._sbdPlayerCurtainDown.Begin();
            this.curtainClosed();
        }
    },
	
	mediaOpened: function(sender, eventArgs)
    {
    var marker = 
         sender.getHost().content.createFromXaml
         (
              '<TimelineMarker Time="0:0:0.1" Type="Test" Text="Start" />'
         );
    sender.markers.add(marker);

    },
    
    markerReached: function()
    {
        this._imgPreview.Visibility="Collapsed"
    },
    
    playToPauseCompleted: function()
    {
        this._cnvPause.Visibility = "Visible";
	       this._cnvPlay.Visibility = "Collapsed";
    },
    
    pauseToPlayCompleted: function()
    {
           this._cnvPause.Visibility = "Collapsed";
	       this._cnvPlay.Visibility = "Visible";
    },
    
	_onStateChanged: function(sender, eventArgs) {
	     if (this._media.CurrentState === "Playing") {
	       // this._playOverlayButton.Visibility = "Collapsed";
	       this._sbdPlayBtnIn.Stop();
	       this._sbdPlayBtnOut.Stop();	       
	       this._sbdPlayToPause.Begin();
	       this._cnvPause.Visibility = "Visible";
	       this._cnvPlay.Visibility = "Visible";
	     } else if (this._media.CurrentState === "Paused") {
	       // this._playOverlayButton.Visibility = "Visible";

	       this._sbdPlayBtnIn.Stop();
	       this._sbdPlayBtnOut.Stop();
	       this._sbdPauseToPlay.Begin();
	       this._cnvPlay.Visibility = "Visible";
	       this._cnvPause.Visibility = "Visible";
	     }
	}
	
}

function createPlayer(language, codename, mode)
{
    if (!Silverlight.isInstalled('1.0')) {
        return false;
    }
    
	var scene = new SilverlightSite6.Page(language, codename, mode);
	Silverlight.createObjectEx({
		source: "/Xaml/Player.xaml",
		parentElement: document.getElementById("silverlightControlHost"),
		id: "SilverlightControl",
		properties: {
			width: "994",
			height: "276",
			version: "1.0",
			background: "transparent",
			isWindowless: "true"
		},
		events: {
			onLoad: Silverlight.createDelegate(scene, scene.handleLoad),
			onError: function(sender, args) {
			}
		}
	});
	
	return true;
}

function writeNoSilverlight(language, title, description) {
    var nosl = '<div class="noSilverlight{1}"><div class="leftTxt"><span><h2>{2}</h2><p>{3}</p></span><a href="javascript:Silverlight.getSilverlight(\'2.0\');" class="install"></a></div></div>';
    nosl = nosl.replace('{1}', language.toUpperCase());
    nosl = nosl.replace('{2}', title);
    nosl = nosl.replace('{3}', description);
    document.write(nosl);
}

		if (!window.Silverlight) 
			Silverlight = {};

		Silverlight.createDelegate = function(instance, method) {
			return function() {
				return method.apply(instance, arguments);
			}
		}