window.addEvent('domready',function(){
	$('loading').setStyle('display','none');
	$('sites').setStyle('display','block');
	$('eng-slide').setStyle('display','inline');
	$('sv-slide').setStyle('display','inline');
	$('nl-slide').setStyle('display','inline');
	$('de-slide').setStyle('display','inline');
	
	defineMargin();
	
	$('languages').setStyle('visibility','visible');
	$$('*').set('tween',{duration:2000});
	
	var language='-en';
	var dur=50000;
	
	function sitesMouseOverOut(dur){
		$('sites').get('tween').cancel();
		calcdur=dur/(1910/(1910+($('sites').getStyle('left').toInt())+1));
		$('sites').set('tween',{duration:calcdur,transition:Fx.Transitions.linear,complete:function(){this.fireEvent('complete')}});
		HSstart=$('sites').getStyle('left');horizontalSlide(HSstart,HSend);setTween(dur)}
		
	function sitesMouseOut(){sitesMouseOverOut(50000)};
	function sitesMouseOver(){sitesMouseOverOut(17000)};
	
	var myTween3=new Fx.Tween('slide',{duration:2000});
	var myTween4=new Fx.Tween('languages',{duration:500});
	var mySlideshow=new Fx.Tween('picture-slideshow',{duration:2000});
	
		mySlideshow.set('opacity',0);
	
	var myContainer=new Fx.Tween('container',{duration:2000});
	var myColumnContainer=new Fx.Tween('columncontainer',{duration:2000});
	var sitesCopy=$('sites').clone(true);
	
		sitesCopy.inject('sites');
	
	$('sites').set('tween',{duration:50000,transition:Fx.Transitions.linear});
	
	var HSstart=0, HSend=-1910;
	
	var setTween=function(dur){$('sites').get('tween').addEvent('complete',function(){$('sites').set('tween',{complete:function(){this.fireEvent('complete')},duration:dur,transition:Fx.Transitions.linear});HSstart=0;HSend=-1910;horizontalSlide(HSstart,HSend)})};
	
	function horizontalSlide(HSstart,HSend){$('sites').tween('left',HSstart,HSend)};
	
		horizontalSlide(HSstart,HSend);
		
		setTween(50000);
		
	function closeSlideshow(){myColumnContainer.set('display','block');$('close').setStyle('display','none');mySlideshow.start('opacity',1,0);myTween4.start('top',2);myTween3.start('top',50);backToText();myContainer.start('width',750,1002)}
	
	function languagesAway(){$('col1'+language).tween('left',0,-490);$('col2'+language).tween('left',490,1002)}
	
	function backToText(){$('col1'+language).tween('left',-490,0);$('col2'+language).tween('left',1002,490)}
	
	function startSlide(){myTween3.start('top',530).chain(function(){myTween4.start('top',600);mySlideshow.start('opacity',0,1);myContainer.start('width',1002,750);myColumnContainer.set('display','none');$('close').setStyle('display','block')});$('picture-slideshow').setStyle('display','block')}
	
	function startSlideshow(){languagesAway();startSlide()};
	
	var pos=[];pos["-nl"]=90;pos["-en"]=15;pos["-de"]=190;pos["-sv"]=269;
	
	$$('area').addEvent('click',function(){if(language!==('-'+this.getAttribute('id'))){languagesAway();language='-'+this.getAttribute('id');$('vinkje').setStyle('left',pos[language]);backToText()}});
	
	$('closeSlideshow').addEvent('click',function(){closeSlideshow()});
	
	$$('a.slide').addEvent('click',function(){if(playslide==false){playSlide()};startSlideshow()});
	
	var calcdur;
	$('sites').addEvent('mouseover',function(){sitesMouseOver()});
	$('sites').addEvent('mouseout',function(){sitesMouseOut()});
	
	function screenSize(){
			var size=[0,0];
			if(typeof window.innerWidth!='undefined'){size=[window.innerWidth,window.innerHeight]}
			else if(typeof document.documentElement!='undefined'&&typeof document.documentElement.clientWidth!='undefined'&&document.documentElement.clientWidth!=0){size=[document.documentElement.clientWidth,document.documentElement.clientHeight]}
			else{size=[document.getElementsByTagName('body')[0].clientWidth,document.getElementsByTagName('body')[0].clientHeight]}
			
			return size}
			
	function defineMargin(){
		var size=screenSize();
		var topmargin=0;topmargin=((size[1]-511)/2)-25;
		if(topmargin<5)topmargin=5;
		$('container').style.top=topmargin+"px";
		$('jatte').style.top=(topmargin-50)+"px";
		}
		
	var playslide=false;
	function playSlide(){
			var data={
			'animals01.jpg':{caption:'Animal photography - Moose, Stora Bl&aring;sj&ouml;n '},
			'animals02.jpg':{caption:'Animal photography - Reindeer, Stekenjokk '},
			'animals03.jpg':{caption:'Animal photography - Goats (Jeppe and Oscar), Svanseleg&aring;rd '},
			'animals04.jpg':{caption:'Animal photography - Rabbit, Svanseleg&aring;rd '},
			'animals05.jpg':{caption:'Animal photography - Woodpecker, Stavtorpet - Gr&auml;smark '},
			'animals06.jpg':{caption:'Animal photography - Cat (Pippi), Erik Bengtstorp - Gr&auml;smark '},
			'animals07.jpg':{caption:'Animal photography - Sheep, Tiskaretj&auml;rn '},
			'animals08.jpg':{caption:'Animal photography - Cows, Tiskaretj&auml;rn '},
			'animals09.jpg':{caption:'Animal photography - '},
			'animals10.jpg':{caption:'Animal photography - Husky, Lowlandssleddogs '},
			'animals11.jpg':{caption:'Animal photography - Reindeer, Svansele '},
			'animals12.jpg':{caption:'Animal photography - '},
			
			'landscapes01.jpg':{caption:'Landscape photography - Svansele '},
			'landscapes02.jpg':{caption:'Landscape photography - Gaustafallet, Stekenjokk '},
			'landscapes03.jpg':{caption:'Landscape photography - Tiskaretj&auml;rn '},
			'landscapes04.jpg':{caption:'Landscape photography - Herbergsdalen '},
			'landscapes05.jpg':{caption:'Landscape photography - Gr&auml;smark '},
			'landscapes06.jpg':{caption:'Landscape photography - Svansele '},
			'landscapes07.jpg':{caption:'Landscape photography - Fatmomakke '},
			
			'people01.jpg':{caption:''},
			'people02.jpg':{caption:''},
			
			'products01.jpg':{caption:'Product photography - Jojo! '},
			'products02.jpg':{caption:'Product photography - Jojo! '},
			'products03.jpg':{caption:'Product photography - Fyra H&auml;nder '},
			'products04.jpg':{caption:'Product photography - Jojo! '},
			'products05.jpg':{caption:'Product photography - Helens Kl&auml;der '},
			'products06.jpg':{caption:'Product photography - Helens Kl&auml;der '},
			'products07.jpg':{caption:'Product photography - Fyra H&auml;nder '}
			};
			
			var myShow=new Slideshow('picture-slideshow',data);
			
			playslide=true}
			
});
