(function () {
	var rotationState = 0;
	var elementAmount = 5;
	
	function getStateValue(elementId)
	{
		if (elementId + rotationState < elementAmount) return(elementId + rotationState );
		else return(elementId + rotationState - elementAmount );
	}
	
	function doBol()
	{
		if (actionBol==0) doMail();
		else
		{
			actionBol=0;
			$("draaiSilverImage").show();
			$("draaiSilverImage2").hide();
			if (initStateSet) $("draaiSilver").setStyle("width:0px; height:0px; top:"+bolTop+"px; left:"+bolLeft+"px");
			else $("draaiSilver").morph("width:"+0.23*mainWidth+"px; height:"+0.3*mainHeight+"px; top:"+bolTop-20+"px; left:"+bolLeft*0.8+"px");
			$("draaiSilver").morph("width:"+0.161*mainWidth+"px; height:"+0.24*mainHeight+"px; top:"+bolTop+"px; left:"+bolLeft+"px",
			{
				delay: 0.5,
				duration: 2,
				  propertyTransitions: {
				    width: 'linear', height: 'linear'
				  }
				});		
			$("draaiSilverImage").morph("width:"+0.161*mainWidth+"px; height:"+0.24*mainHeight+"px",
			{
				delay: 0.5,
				duration: 2,
				  propertyTransitions: {
				    width: 'linear', height: 'linear'
				  }
				});
			$("draaiSilver").setStyle("z-index:1");
		}
		
	}
	
	function doMail()
	{
			open("mailto:harry@stateThis.nl","emailWindow");
	}
	
	function doContact()
	{
		actionBol=1;
		$("draaiSilverImage").hide();
			$("draaiSilverImage2").show();
			
			$("draaiSilver").setStyle("width:"+0.161*mainWidth+"px; height:"+0.24*mainHeight+"px; top:"+bolTop+"px; left:"+bolLeft+"px");
			$("draaiSilverImage2").setStyle("width:"+0.161*mainWidth+"px; height:"+0.24*mainHeight+"px");
			$("draaiSilver").morph("width:"+0.23*mainWidth+"px; height:"+0.3*mainHeight+"px; top:"+bolTop-20+"px; left:"+bolLeft*0.8+"px",
			{
				delay: 0.5,
				duration: 2,
				  propertyTransitions: {
				    width: 'linear', height: 'linear'
				  }
				});		
			$("draaiSilverImage2").morph("width:"+0.23*mainWidth+"px; height:"+0.3*mainHeight+"px",
			{
				delay: 0.5,
				duration: 2,
				  propertyTransitions: {
				    width: 'linear', height: 'linear'
				  }
				});
		$("draaiSilver").setStyle("z-index:10");
		
	}
	
	function setStateMenu()
	{
		for(i=0; i<elementAmount; ++i) 
		{
			menuWidth = 0.1386*enLarger*mainWidth;
			menuHeight = 0.0419*enLarger*mainHeight;
			if (initStateSet) $("menuItem"+i).appear({duration:5});
			else $("menuItem"+i).appear();
			$("menuImage"+i+"On").hide();
			$("menuImage"+i).hide();
			if (i == rotateId)
			{
				$("menuImage"+i).hide();
				$("menuImage"+i+"On").show();
				if (getStateValue(rotateId) == 4)
				{
					$('supernova').hide();
					$('supernova').setStyle("width:"+mainWidth*0.005+"px; height:"+mainHeight*0.008+"px; left: "+(leftArray[getStateValue(i)]*(1.00-(getStateValue(i)/6.2)))+"px;top: "+(topArray[getStateValue(i)]*(0.62+(getStateValue(i)/6)))+"px");
					$('supernovaImage').morph("width:"+mainWidth*0.45+"px; height:"+mainHeight*0.93+"px",
						{
							delay: 2*rounders,
							duration: 0.02,
							  propertyTransitions: {
							    width: 'elastic', height: 'linear'
							  }
							});				
					$('supernova').show();	
				}
			}
			else
			{
				$("menuImage"+i).show();
			}
			$("menuItem"+i).morph("width:"+menuWidth*(0.799+(getStateValue(i)/10))+"px; height:"+menuHeight*(2.5+(getStateValue(i)/10))+"px;left: "+(leftArray[getStateValue(i)]*(1.00-(getStateValue(i)/10)))+"px;top: "+(topArray[getStateValue(i)]*(0.599+(getStateValue(i)/10)))+"px" ,
			{
				delay: 0.5,
			  duration: 1,
			  propertyTransitions: {
			    width: 'easeInCirc', height: 'easeInCirc', top: 'swingFrom',  left: 'swingTo'
			  }
			});
			$("menuImage"+i).setStyle("width: "+menuWidth*(0.799+(getStateValue(i)/10))+"px;height:"+menuHeight*(2.5+(getStateValue(i)/10))+"px");
			$("menuImage"+i+"On").setStyle("width: "+menuWidth*(0.799+(getStateValue(i)/10))+"px;height:"+menuHeight*(2.5+(getStateValue(i)/10))+"px");
			$("menuItem"+i).setStyle("z-index: "+getStateValue(i));
		}
	}
	
	function doStateAction()
	{
		$('header').hide();
		$('infoSurround').hide();
		$('info').hide();
		$('architectuurSurround').hide();
		$('architectuur').hide();
		$('webDevelopmentSurround').hide();
		$('webDevelopment').hide();
		$('projectManagementSurround').hide();
		$('projectManagement').hide();
		$('dia1info').hide();
		$('dia2info').hide();
		$('dia1architectuur').hide();
		$('dia2architectuur').hide();
		$('dia1webDevelopment').hide();
		$('dia2webDevelopment').hide();
		$('dia1projectManagement').hide();
		$('dia2projectManagement').hide();
		switch(rotateId)
		{
			case 4 : 
				$('headerImage').setStyle("width:10px; height:4px");
				$('header').setStyle("top:"+mainHeight*0.1+"px;left:"+mainWidth*0.9+"px;width:"+mainWidth*0.05+"px;height:"+mainHeight*0.05+"px");
				$('header').show();
				$('headerImage').hide();				
				$('headerImage').show();
				$("header").morph("width:"+mainWidth/2.5+"px; height:"+mainHeight/2.2+"px; left:"+(mainWidth/5)+"px; top:"+(mainHeight/1.9)+"px" ,
			{
				delay: .5,
			  duration: 1,
			  propertyTransitions: {
			    width: 'bounce', height: 'linear', top: 'linear',  left: 'easeInCirc'
			  }
			});
				$("header").setStyle("z-index:10");
				$("headerImage").morph("width:"+mainWidth/2.5+"px; height:"+mainHeight/2.2+"px" ,
			{
				delay: .5,
			  duration: 10,
			  propertyTransitions: {
			    width: 'bounce', height: 'bounce'
			  }
			});
				break;
			case 3 : 
				$('infoSurroundImage').setStyle("width:10px; height:4px");
				$('infoSurround').setStyle("top: "+0.3698*mainHeight+"px; left: "+0.3346*mainWidth+"px; width:"+0.45*mainWidth+"px; height: "+0.38*mainHeight +"px"); 
				$('infoSurround').show();
				$('infoSurroundImage').hide()
				$('pagerinfo').hide()
				$('infoSurroundImage').show();
				$("infoSurroundImage").morph("width:"+mainWidth/1.2+"px; height:"+mainHeight/2+"px" ,
			{
				delay: .5,
			  duration: 3,
			  propertyTransitions: {
			    width: 'easeFromTo', height: 'bounce'
			  }
			});
				$("infoSurround").morph("width:"+mainWidth/1.2+"px; height:"+mainHeight/2+"px; left:"+(mainWidth/10)+"px; top:"+(mainHeight/2)+"px" ,
			{
				delay: .5,
			  duration: 3,
			  propertyTransitions: {
			    width: 'easeInOutExpo', height: 'linear', top: 'easeOutBack',  left: 'easeInOutSine'
			  }
			});
				$("infoSurround").setStyle("z-index:8");
				
				$('info').setStyle("top: 10%; left: 5%; font-size:"+mainHeight*0.03+"px");
				$('dia1info').setStyle("width: 20%; height: 65%; top: 18%; left: 50%; font-size:8px");
				$('dia2info').setStyle("width: 15%; height: 50%; top: 20%; left: 80%; font-size:5px");
				$('info').appear({duration:10});
				$('dia1info').appear({duration:20});
				$('dia2info').appear({duration:30});
				$('pagerinfo').appear({duration:40});
				break;
			case 2:
				$('architectuurSurroundImage').setStyle("width:10px; height:4px");
				$('architectuurSurround').setStyle("top: "+0.3698*mainHeight+"px; left: "+0.3346*mainWidth+"px; width:"+0.45*mainWidth+"px; height: "+0.38*mainHeight +"px"); 
				$('architectuurSurround').show();
				$('architectuurSurroundImage').hide()
				$('pagerarchitectuur').hide()
				$('architectuurSurroundImage').show();
				$("architectuurSurroundImage").morph("width:"+mainWidth/1.2+"px; height:"+mainHeight/2+"px" ,
			{
				delay: .5,
			  duration: 3,
			  propertyTransitions: {
			    width: 'easeFromTo', height: 'bounce'
			  }
			});
				$("architectuurSurround").morph("width:"+mainWidth/1.2+"px; height:"+mainHeight/2+"px; left:"+(mainWidth/10)+"px; top:"+(mainHeight/2)+"px" ,
			{
				delay: .5,
			  duration: 3,
			  propertyTransitions: {
			    width: 'easeInOutExpo', height: 'linear', top: 'easeOutBack',  left: 'easeInOutSine'
			  }
			});
				$("architectuurSurround").setStyle("z-index:8");
				$('dia1architectuur').setStyle("width: 20%; height: 65%; top: 18%; left: 50%; font-size:8px");
				$('dia2architectuur').setStyle("width: 15%; height: 50%; top: 20%; left: 80%; font-size:5px");
				$('architectuur').setStyle("top: 10%; left: 5%; font-size:"+mainHeight*0.03+"px");
				$('architectuur').appear({duration:10});
				$('dia1architectuur').appear({duration:20});
				$('dia2architectuur').appear({duration:30});
				$('pagerarchitectuur').appear({duration:40});
				break;
			case 1 : 
				$('projectManagementSurroundImage').setStyle("width:10px; height:4px");
				$('projectManagementSurround').setStyle("top: "+0.3698*mainHeight+"px; left: "+0.3346*mainWidth+"px; width:"+0.45*mainWidth+"px; height: "+0.38*mainHeight +"px"); 
				$('projectManagementSurround').show();
				$('projectManagementSurroundImage').hide()
				$('pagerprojectManagement').hide();
				$('projectManagementSurroundImage').show();
				$("projectManagementSurround").morph("width:"+mainWidth/1.2+"px; height:"+mainHeight/2+"px; left:"+(mainWidth/10)+"px; top:"+(mainHeight/2)+"px" ,
			{
				delay: .5,
			  duration: 3,
			  propertyTransitions: {
			    width: 'easeInOutExpo', height: 'linear', top: 'easeOutBack',  left: 'easeInOutSine'
			  }
			});
				$("projectManagementSurround").setStyle("z-index:10");
				$("projectManagementSurroundImage").morph("width:"+mainWidth/1.2+"px; height:"+mainHeight/2+"px" ,
			{
				delay: .5,
			  duration: 10,
			  propertyTransitions: {
			    width: 'easeFromTo', height: 'sinusoidal'
			  }
			});
				$("projectManagementSurround").setStyle("z-index:8");
				$('projectManagement').setStyle("top: 10%; left: 5%; font-size:"+mainHeight*0.03+"px");
				$('dia1projectManagement').setStyle("width: 20%; height: 65%; top: 18%; left: 50%; font-size:8px");
				$('dia2projectManagement').setStyle("width: 15%; height: 50%; top: 20%; left: 80%; font-size:5px");
				$('projectManagement').appear({duration:10});
				$('dia1projectManagement').appear({duration:20});
				$('dia2projectManagement').appear({duration:30});
				$('pagerprojectManagement').appear({duration:40});
				break;
			case 0 : 
				$('webDevelopmentSurroundImage').setStyle("width:10px; height:4px");
				$('webDevelopmentSurround').setStyle("top: "+0.3698*mainHeight+"px; left: "+0.3346*mainWidth+"px; width:"+0.45*mainWidth+"px; height: "+0.38*mainHeight +"px"); 
				$('webDevelopmentSurround').show();
				$('pagerwebDevelopment').hide();
				$('webDevelopmentSurroundImage').hide()
				$('webDevelopmentSurroundImage').show();
				$("webDevelopmentSurround").morph("width:"+mainWidth/1.2+"px; height:"+mainHeight/2+"px; left:"+(mainWidth/10)+"px; top:"+(mainHeight/2)+"px" ,
			{
				delay: .5,
			  duration: 3,
			  propertyTransitions: {
			    width: 'easeInOutExpo', height: 'linear', top: 'easeOutBack',  left: 'easeInOutSine'
			  }
			});
				$("webDevelopmentSurround").setStyle("z-index:10");
				$("webDevelopmentSurroundImage").morph("width:"+mainWidth/1.2+"px; height:"+mainHeight/2+"px" ,
			{
				delay: .5,
			  duration: 10,
			  propertyTransitions: {
			    width: 'easeFromTo', height: 'sinusoidal'
			  }
			});
				$("webDevelopmentSurround").setStyle("z-index:8");
				$('webDevelopment').setStyle("top: 10%; left: 5%; font-size:"+mainHeight*0.03+"px");
				$('dia1webDevelopment').setStyle("width: 20%; height: 65%; top: 18%; left: 50%; font-size:8px");
				$('dia2webDevelopment').setStyle("width: 15%; height: 50%; top: 20%; left: 80%; font-size:5px");
				$('webDevelopment').appear({duration:10});
				$('dia1webDevelopment').appear({duration:20});
				$('dia2webDevelopment').appear({duration:30});
				$('pagerwebDevelopment').appear({duration:40});
				break;
		}
	}
	
	function doRotate()
	{
		++rounders
		if (rotationState == elementAmount - 1) rotationState=0;
		else 	++rotationState;
		setStateMenu();
		if (getStateValue(rotateId) == 4)	
		{
			doStateAction();
			//doContactData();
			initStateSet = false;
			return;
		}
		doRotate();
	}
	
	function rotating(firedId)
	{
		rotateId = firedId;
		doRotate();
	}
	
	doBol();
	rotating(4);
	
	function rotator(event)
	{
		stripper = Event.element(event).id;
		stripper = stripper.substr(9,1);
		$('supernovaImage').setStyle("width:0px;height:0px");
		rounders = 0;
		rotating(parseFloat(stripper));
	}
	
	function contact(event)
	{
		doContact();
	}
	
	function draaiSilver(event)
	{
		doBol();
	}


$('menuItem0').observe('click', rotator);
$('menuItem1').observe('click', rotator);
$('menuItem2').observe('click', rotator);
$('menuItem3').observe('click', rotator);
$('menuItem4').observe('click', rotator);
$('contact').observe('click', contact);
$('draaiSilver').observe('click', draaiSilver);
})();