// JavaScript Document
			
	function defineMargin(){
		var size=window.getSize();
		var topmargin=0;topmargin=((size.y-850)/2);
		if (topmargin<0) topmargin=0;
		
		$('container').style.top=topmargin+"px";
		return size.y
		}
		
		defineMargin();
		window.addEvent('resize',defineMargin);
		
var morph=new Fx.Morph ($('hover'), {
			duration:200,
			fps: 50
		});	
		
function moveHover(){
	
		if (menuItem==0) {menuClass="&nbsp;&nbsp;HOME"; $('hover').setStyles({'color':'#375e81','top':894,'left':1240});hoverTop=(-6);hoverLeft=340};
		if (menuItem==1) {menuClass="SORTIMENT"; $('hover').setStyles({'color':'#375e81','top':894,'left':1240});hoverTop=(276);hoverLeft=620};
		
		if (menuItem==2) {menuClass="F&Ouml;RETAG"; $('hover').setStyles({'color':'#fcac15','top':896,'left':620}); hoverTop=(446);hoverLeft=170};
		if (menuItem==3) {menuClass="NYHETER"; $('hover').setStyles({'color':'#fcac15','top':896,'left':620});hoverTop=(726);hoverLeft=450};
		if (menuItem==4) {menuClass="PRESENTER"; $('hover').setStyles({'color':'#375e81','top':894,'left':1240});hoverTop=(558);hoverLeft=900};
		$('hover').set('html',menuClass);morph.start({'top':hoverTop,'left':hoverLeft});
				
	}


function hoverGone(){
	
		if (menuItem==0||menuItem==1||menuItem==4){$('hover').set('morph',{duration:150});$('hover').morph({'top':894,'left':1240});}
						else {$('hover').set('morph',{duration:150});$('hover').morph({'top':896,'left':620});}
	}

function rotate(ar,i){
								if(Browser.ie) ar[i].morph({'-ms-transform': ['rotate(-360deg)','rotate(0deg)']});
								else if(Browser.firefox) ar[i].morph({'-moz-transform': ['rotate(-360deg)','rotate(0deg)']});
								else if(Browser.safari) ar[i].morph({'-webkit-transform': ['rotate(-360deg)','rotate(0deg)']});
								else if(Browser.chrome) ar[i].morph({'-webkit-transform': ['rotate(-360deg)','rotate(0deg)']});
								else if(Browser.opera) ar[i].morph({'-o-transform': ['rotate(-360deg)','rotate(0deg)']});
								else ar[i].morph({'transform': ['rotate(-360deg)','rotate(0deg)']});}
								
function swapArticle(){
		if (menuItem==0) {$('articles').tween('top',0);}
		if (menuItem==1) {$('articles').tween('top',-2400);
							divArray=$$('article.sortiment section div');
							divArrayLeft=$$('article.sortiment section div').getStyle('left');
							divArrayTop=$$('article.sortiment section div').getStyle('top');
							divArray.set('morph',{duration:600});
							setTimeout(function(){for (var i=0;i<divArray.length;i++){rotate(divArray,i)};},600);
							}
		
		if (menuItem==2) {$('articles').tween('top',-800);}
		if (menuItem==3) {$('articles').tween('top',-1600);};
		if (menuItem==4) {$('articles').tween('top',-3200);};
			
	}
	
var addEvents = function() {
			//tagname or ID?
			var aArray=$$('nav a[href]');
			
			aArray.addEvents({
							 'mouseover':function(){menuItem=aArray.indexOf(this);moveHover();},
							 'mouseout':function(){hoverGone();},
							 'focus':function(){menuItem=aArray.indexOf(this);moveHover();},
							 'blur':function(){hoverGone();}
							 });
}
							 
	
			var bArray=$$('nav a[href]');
			
			bArray.addEvents({
							 'click':function(){menuItem=bArray.indexOf(this);swapArticle();}
							 });						 
							 
	
	
if (!(Browser.Platform.ios || Browser.Platform.android || Browser.Platform.webos || Browser.ie6 || Browser.ie7 || Browser.ie8)){addEvents();}

if (Browser.Platform.ios||Browser.Platform.android||Browser.Platform.webos){
	$('menu-overlay').setStyle('display','block');
	}
	
var addBrandsEvents = function (){
	
	var brandsArray=$$('article.sortiment div a'); var presentArray=$$('article.presenter div a'); brandsArray.combine(presentArray);
	var brandsNoHref=$$('article.sortiment img !> div');
	
	function showBrand(curBrand){
				
				if ($('brand')) {$('picture').fade('out');setTimeout(function(){$('brand').dispose()},500)};
				//name the picture belonging to the clicked link	
				imageBrand="images/brands/"+curBrand+".jpg";
											 
				//create DIV's for the pictures with links
					//create link
				brandLink=$(curBrand).firstChild.getAttribute('href');
				
				  divBrand = new Element('div', {id:'brand', styles:{'opacity':'0'}});
				  divClick = new Element('div', {id:'clickhere'});
				  divPicture = new Element('img', {id:'picture', 'src':imageBrand});
				  pictureLink = new Element('a', {'href': brandLink, 'target': '_blank'});
				  backToHome = new Element('a', {id:'backToHome', 'html':'<img src="images/close.png"/>', 'href':'#'}); 
				  divPicture.inject(pictureLink);
				  pictureLink.inject(divBrand);
				  divClick.inject(divBrand, 'top');
				  backToHome.inject(divBrand);
				  
				  divBrand.inject($('container'), 'bottom');
				  divBrand.fade('in');
				  brandsNoHref.fade('out');
				  backToHome.addEvent('click', function(){divBrand.fade('out');
				//old browsers prevent clicking on the menu because of the Brand div (z-index bug?) so better get rid of it completely
				 setTimeout(function(){divBrand.dispose();brandsNoHref.fade('in');},500);});
				  
				  
				
			}
		
	brandsArray.addEvents ({
							'click':function(){curBrand=this.getParent().getAttribute("id"); showBrand(curBrand);return false;}
							});
	}
	
	
	
	addBrandsEvents();
	
	
		
