// JavaScript Document

if(selectedCulture = "da")
{
	var translations = new Hash({close: "Klik her for at afslutte video ", play: "Klik her for at afspille video "});
}

if(selectedCulture = "en")
{
	var translations = new Hash({close: "Click here to close video ", play: "Click here to play video"});
}

if(selectedCulture = "de")
{
	var translations = new Hash({close: "Click here to close video ", play: "Click here to play video"});
}

onYouTubePlayerReady = function()
{
	fp.videoReady = true;
	$('flashPlayer').addEventListener('onStateChange','onytplayerStateChange');
};

function onytplayerStateChange(state)
{

	if(state == 0)
	{	
		Cookie.write('hasE46vidPlayed', true, { duration: 90, path: "/" });
	}
}

frontPageVideo = new Class({
	Implements: Options,
    options: {
       videooverlay: null
    },
	initialize: function(options){
			this.setOptions(options);
    		//this.videoReveal = new Fx.Reveal(this.options.videocontainer,{'heightOverride':401,'widthOverride':710});
			// Video visibility
			this.videoShow = true;
			this.videoReady = false;
			this.videoPlayer = null;
			this.videoContainer = null;
			this.stopImage = null;
			this.playImage = null;
			this.videoBtn = null;
			this.videoBtnText = null;
			
						
			this.videoBtn = new Element('div',{
				'id':'videoBtn'			
			});
			
			this.videoBtnText = new Element('span',{
				'id':'videoBtnText'
			});
			
			this.stopImage = new Element('img',
    		{'id':'stopimage',
			  'src': staticSite + '/images/video-player-stop-icon.png'
    		});
			
			this.playImage = new Element('img',
    		{'id':'playimage',
			  'src': staticSite + '/images/video-player-play-icon.png'
    		});			
			
			this.stopImageHover = new Element('img',
    		{'id':'stopimagehover',
			  'src': staticSite + '/images/video-player-stop-icon-hover.png'
    		});
			
			this.videoBtn.inject(this.options.videooverlay); 
			this.videoBtnText.inject(this.videoBtn,'bottom');
			
			this.videoBtnText.set('text',translations.close);	
			
			this.stopImage.inject(this.videoBtn,'bottom');
			
			this.createVideo();			
			
			this.videoBtn.addEvent('click', function(){
				if(this.videoReady)
				{
					if(this.videoShow)
					{
						this.videoShow = false;
						this.videoBtnText.set('text',translations.play);
						this.playImage.inject(this.videoBtn,'bottom');
						this.videoContainer.setStyles({'display':'none'});						
						this.playImage.inject(this.videoBtn,'bottom');
						$('stopimage').dispose();
						Cookie.write('hasE46vidPlayed', true, { duration: 90, path: "/" });
						this.destroyVideo();
					}
					else
					{
						this.videoShow = true;
						this.videoBtnText.set('text',translations.close);
						this.stopImage.inject(this.videoBtn,'bottom');
						this.videoContainer.setStyles({'display':'block'});	
						$('playimage').dispose();
						this.createVideo();
					}
				}
				
			}.bind(this));	
		
			
			this.videoBtnText.addEvents({
    			'mouseenter': function(){        			
						this.videoBtnText.setStyle('color','#FDFDFD');
						//this.stopImageHover.inject(this.videoBtn,'bottom');
						//$('stopimage').dispose();					
    			}.bind(this),
   				 'mouseleave': function(){        			
						this.videoBtnText.setStyle('color','#CCCCCC');
						//this.stopImage.inject(this.videoBtn,'bottom');
						//$('stopimagehover').dispose();						
    			}.bind(this)
			});

			
    	},
    	createVideo: function()
    	{
    		
    		this.videoContainer = new Element('div',
    		{'id':'videoContainer',
    			'styles': {
    	        	'width': '710px',
    	        	'height': '410px'
    	    	}
    		});
    		
    		this.videoContainer.inject(this.options.videooverlay);
    		
    		if (Browser.Plugins.Flash.version > 8){
    	  		this.videoPlayer =  new Swiff('http://www.youtube.com/v/c-sQ_tdvFo4&version=3&color1=0xb1b1b1&color2=0xcfcfcf&fs=1&hd=1&enablejsapi=1&autoplay=1',{
    			    id: "flashPlayer",
                    width: 710,
                    height: 401,                    
    				container: this.videoContainer,
       				params:
    				{
    						AllowFullScreen: true,
    						allowScriptAccess : "always"
    					
    				}			
    			});
    	  		        		
    		}
    		
    	},
    	destroyVideo: function()
    	{    		    		
    		this.videoContainer.destroy();
			$('videoBtn').dispose(); 		
    	}
});



window.addEvent('domready', function(){
	
	 function hasVideoPlayed() {
        var videoPlayed = Cookie.read('hasE46vidPlayed');
        if (videoPlayed == null) {
        	if(videoPlayed != false)
			{
				fp = new frontPageVideo({videooverlay: $('videoOverlay')});
			}				    
		}
    };	
	
	$('E46SCHCOMP').fade(0.6)
	
	$('E46SCHCOMP').addEvents({
    			'mouseenter': function(){        			
					this.fade(1.0);
				},
   				'mouseleave': function(){        			
				  	this.fade(0.6);
    			},
				'click': function()
				{
					
					fp = new frontPageVideo({videooverlay: $('videoOverlay')});
				}
			});
	
	hasVideoPlayed();

});

