var showVideo = Class.create(
{
	initialize: function(obj)
	{
		var self = this;
		this.obj = obj;
		this.currentCase = 0;
		
		this.allVideoContent = $$('.'+this.obj.videomalInnhold);
		this.maxNum = this.allVideoContent.length;
		this.isAni = false;
		
		this.allVideoContent.each(function(elm,i){

			$($(elm).getElementsByClassName('video')[0]).observe('click',function()
			{
				var flashvars = {
					movie: window.videoCollection[i],
					autoPlayMovie: "y",
					flashSkin: "/sitefiles/35/js/ClearOverPlaySeekMute.swf",
					maintainAspect: "n",
					autoHide: "n"
				};
				
				new Effect.Morph('videomal',
				{
					style: 'height: 300px;',
					duration: 0.25,
					afterFinish: function()
					{
						window.swfobject.embedSWF("/sitefiles/35/js/player.swf","flashVideo"+i,"500","280","9.0.0","/sitefiles/35/js/expressInstall.swf",flashvars,false,false);
						$($(elm).getElementsByClassName('videomalTekst')[0]).hide();
						$($(elm).getElementsByClassName('videomalVideo')[0]).show();
					}
				});
			});
			
			$($(elm).getElementsByClassName('closeVideo')[0]).observe('click',function(ev){
				Event.stop(ev);				
				
				new Effect.Morph('videomal',
				{
					beforeStart: function()
					{
						$($(elm).getElementsByClassName('videomalTekst')[0]).show();
						$($(elm).getElementsByClassName('videomalVideo')[0]).hide();
					},
					style: 'height: 180px;',
					duration: 0.75,
					afterFinish: function()
					{
						$('videoContainer'+i).update('<div id="flashVideo'+i+'"><h2>Du må ha adobe flash installert for å se videoen.</h2><p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p></div>');
					}
				});
			});
			
			$($(elm).getElementsByClassName('viewNextCase')[0]).observe('click',function(ev){
				Event.stop(ev);
				self.fader(self.currentCase+1);
			});
		});
		
	},
	
	fader: function(num) {
		var self = this;

		if(!self.isAni)
		{
			self.isAni = true;
			if(self.maxNum == num)
			{
				num = 0;
			}
	
			new Effect.Parallel(
			[
				Effect.Fade($(self.allVideoContent[self.currentCase]), {
					duration: 1
				}),
				
				Effect.Appear($(self.allVideoContent[num]), {
					duration: 1,
					afterFinish: function(){ self.isAni = false;}
				})
			], 
			{ 
				duration: 1
			});
	
			self.currentCase = num;
		}
	}

});

Event.observe(window, 'load', function()
{
	if($('videomal')){
		var newShowVideo = new showVideo(
		{
			videomal : 'videomal', //id
			videomalInnhold : 'videomalInnhold' //class
		});
	}
	
});