(function () {
	longPics = Array();
	durationsArray = Array();
	pictureArray = Array(1,2,3,4,23, 24, 25, 26, 27, 28, 29, 30);
        for (x=1; x<30; ++x) durationsArray[x] = 0.4;
	cnt = 1;
        var gbRotateId = 0;
	var rotationState = 0;
	var elementAmount = 7;


	function getStateValue(elementId)
	{
		if (elementId + rotationState < elementAmount) return(elementId + rotationState );
		else return(elementId + rotationState - elementAmount );
	}

	function setStateMenu()
	{
		for(i=0; i<7; ++i)
		{
			//menuWidth = 0.1386*enLarger*mainWidth;
			//menuHeight = 0.0419*enLarger*mainHeight;
			$("menuItem"+i).appear();
			$("menuImage"+i+"On").hide();
			$("menuImage"+i).hide();
			$("menuItem"+i).setStyle("top:23%");
			if (i == rotateId)
			{
				//alert(i);
				$("menuImage"+i).hide();
				$("menuImage"+i+"On").show();
				$("menuItem"+i).setStyle("top:27.35%");
			}
			else
			{
				$("menuImage"+i).show();
			}
		}
	}

	function setgbStateMenu()
	{
          for(i=0; i<gastenBoekEntries-gbRotateId; ++i)
          {
             $("gbEntry"+(gbRotateId+i)).morph("width:"+(50-i)+"%;height:"+(60-i)+"%;top:" + (35-i) + "%;left:" + (i*3) + "%;z-index:" + (gastenBoekEntries-i+8) + ";",
               {
		  delay: 0.5,
		  duration: 1,
		  propertyTransitions: {
		    width: 'easeInCirc', height: 'easeInCirc', top: 'swingFrom',  left: 'swingTo'
		  }
	         });
          }
          for(i=0; i<gbRotateId; ++i)
          {
             $("gbEntry"+(gbRotateId-i-1)).morph("width:"+(50-(gastenBoekEntries-i))+"%;height:"+(60-(gastenBoekEntries-i))+"%;top:" + (35-(gastenBoekEntries-i-1)) + "%;left:" + (gastenBoekEntries-i-1)*3 + "%;z-index:" + (gastenBoekEntries-(gastenBoekEntries-i-1)+8) + ";",
               {
		  delay: 0.5,
		  duration: 1,
		  propertyTransitions: {
		    width: 'easeInCirc', height: 'easeInCirc', top: 'swingFrom',  left: 'swingTo'
		  }
	        });
          }
        }

	/*function pictureMoviePlay(inputNr, srcString)
	{
		++cnt;
		if (rotateId == 0)
		{
			if (cnt<30)
			{
				$('pictureMovie'+inputNr).hide();
				$('pictureMoviePlayer'+inputNr).hide();
				$('pictureMovie'+inputNr).src = srcString;
				$('pictureMovie'+inputNr).setStyle("height:"+mainHeight/1.65+"px; border:0px solid black");
				tmpNr = 0;
				if (inputNr == 2) tmpNr = 3;
				else tmpNr = 2;
				$('pictureMoviePlayer'+tmpNr).setStyle("z-index:1");
				$('pictureMoviePlayer'+inputNr).setStyle("width:40%; height:50%; left:23%; top:25%; z-index:2");
				$('pictureMoviePlayer'+inputNr).appear({duration:durationsArray[cnt]});
				$('pictureMovie'+inputNr).appear({duration:durationsArray[cnt], delay:5, after: function() {pictureMoviePlay(tmpNr, "./images/DSCN" + cnt + ".jpg");}});
			}
			else
			{
				cnt = 1;
				pictureMoviePlay(2, "./images/DSCN1.jpg");
			}
		}
	}
	*/

	function setImagesSize()
        {
                 $('headerImage').setStyle("height:" + mainHeight / 8.1875 + "px; width:" +mainWidth / 5.6412+ "px;");
                 $('homeImage1').setStyle("height:" + mainHeight / 4.679 + "px");
                 $('homeImage2').setStyle("height:" + mainHeight / 4.679 + "px");
                 $('homeImage3').setStyle("height:" + mainHeight / 4.679 + "px");
                 for (imgC = 0; imgC < 7; ++imgC)
                 {
                   if (imgC == 0) lc = 38;
                   if (imgC == 1) lc = 19;
                   if (imgC == 2) lc = 19;
                   if (imgC == 3) lc = 19;
                   if (imgC == 4) lc = 28;
                   if (imgC == 5) lc = 21;
                   if (imgC == 6) lc = 31;
                   $('menuImage' + imgC).setStyle("height:" + mainHeight / 65.5 + "px; width:" +mainWidth / lc + "px;");
                   $('menuImage' + imgC + 'On').setStyle("height:" + mainHeight / 65.5 + "px; width:" +mainWidth / lc+ "px;");
                 }
                 $('homeImage').setStyle("height:" + mainHeight / 2.3905 + "px; width:" +mainWidth / 4.0382+ "px;");
                 $('activiteitenImage').setStyle("height:" + mainHeight / 2.3666 + "px; width:" +mainWidth / 7.39+ "px;");
                 $('zalenverhuurImage').setStyle("height:" + mainHeight / 2.62 + "px; width:" +mainWidth / 4.438+ "px;");
                 $('historyImage').setStyle("height:" + mainHeight / 1.6375 + "px; width:" +mainWidth / 7.5+ "px;");
                 $('bestuurImage').setStyle("height:" + mainHeight / 1.93541 + "px; width:" +mainWidth / 6.343+ "px;");
                 $('contactImage').setStyle("height:" + mainHeight / 2.3905 + "px; width:" +mainWidth / 4.093+ "px;");
                 $('gastenboekImage').setStyle("height:" + mainHeight / 4.367 + "px; width:" +mainWidth / 7.39+ "px;");
				 //$('adHome').setStyle("height:" + mainHeight / 4.5 + "px; width:" +mainWidth / 7.6+ "px;");
        }

	function doStateAction()
	{
		setImagesSize();
		var browserDec = 0;
        if (navigator.appName!="Netscape") browserDec = 0.3;		
		$('home').hide();
		$('history').hide();
		$('bestuur').hide();
		$('ff').hide();
		$('zalenverhuur').hide();
        $('gastenboek').hide();
        $('activiteiten').hide();
        $('contact').hide();
		$('content').hide();
		var p1, p2, p3;
                p1 = Math.floor(Math.random()*12);
                p2 = p1;
                while (p2 == p1) p2 = Math.floor(Math.random()*12);
                p3 = p2;
                while (p3 == p2 || p3 == p1) p3 = Math.floor(Math.random()*12);
                document.getElementById("homeImage1").src="./code/tools/retrieveImage.php?component=home&id=" + pictureArray[p1];
		document.getElementById("homeImage2").src="./code/tools/retrieveImage.php?component=home&id=" + pictureArray[p2];
		document.getElementById("homeImage3").src="./code/tools/retrieveImage.php?component=home&id=" + pictureArray[p3];
		for (var gbE = 0; gbE<gastenBoekEntries; ++gbE)
                {
                   $("gbEntry"+gbE).hide();
                }
		switch(rotateId)
		{
			case 0 :							
				$('home').setStyle("width:24.9%; left:22.16%; top:30.6%; z-index:7; background-color:#e7e7e7;");
				$('homeImageDiv').setStyle("left:"+(51+browserDec)+"%; top:"+(0.059*mainHeight)+"px; z-index:4;");
				$('contentImageBlur').setStyle("width:"+ mainWidth * 0.03+"px; left:"+(50.8+browserDec)+"%; top:"+(0.059*mainHeight)+"px; height:"+ mainHeight * 0.42+"px; z-index:8;");
				$('home').appear({duration:durationsArray[cnt], delay:0.5});
				$('ff').appear({duration:10, delay:3});
				$('content').setStyle("height:57.5%");
				$('content').appear({duration:durationsArray[cnt], delay:0});							
			break;
			case 1:
				$('activiteiten').setStyle("width:37.6%; left:22.16%; top:30.6%; z-index:7; background-color:#e7e7e7;");
				$('activiteitenImageDiv').setStyle("left:"+(75.7+browserDec)+"%; top:"+(0.059*mainHeight)+"px; z-index:4;");
				$('contentImageBlur13').setStyle("width:"+ mainWidth * 0.03+"px; left:"+(75.5+browserDec)+"%; top:"+(0.059*mainHeight)+"px; height:"+ mainHeight * 0.23+"px; z-index:8;");
                $('activiteiten').appear({duration:durationsArray[cnt], delay:0.5});
				$('content').appear({duration:durationsArray[cnt], delay:0});
				$('content').setStyle("height:57.5");				
			break;
			case 2 :								
				$('zalenverhuur').setStyle("width:24.9%; left:22.16%; top:30.6%; z-index:7;background-color:#e7e7e7;");
				$('zalenverhuurImageDiv').setStyle("left:"+(51+browserDec)+"%; top:"+(0.06*mainHeight)+"px; z-index:4;");
				$('contentImageBlur11').setStyle("width:"+ mainWidth * 0.03+"px; left:"+(50.8+browserDec)+"%; top:"+(0.06*mainHeight)+"px; height:"+ mainHeight * 0.38+"px; z-index:8;");
				$('zalenverhuur').appear({duration:durationsArray[cnt], delay:0.5});
				$('content').appear({duration:durationsArray[cnt], delay:0});				
				$('content').setStyle("height:57.5%");
			break;
			case 3 :
				$('history').setStyle("width:37.6%; left:22.16%; top:30.6%; z-index:7;background-color:#e7e7e7;");
				$('historyImageDiv').setStyle("left:"+(76.1+browserDec)+"%; top:"+(0.059*mainHeight)+"px; z-index:4;");
				$('contentImageBlur9').setStyle("width:"+ mainWidth * 0.03+"px; left:"+(75.9+browserDec)+"%; top:"+(0.059*mainHeight)+"px; height:"+ mainHeight * 0.61+"px; z-index:8;");
				$('history').appear({duration:durationsArray[cnt], delay:0.5});
				$('content').appear({duration:durationsArray[cnt], delay:0});
				$('content').setStyle("height:57.5");				
			break;
			case 4 :
			    $('bestuur').setStyle("width:24.9%; left:22.16%; top:30.6%; z-index:7;background-color:#e7e7e7;");
				$('bestuurImageDiv').setStyle("left:"+(71.7+browserDec)+"%; top:"+(0.059*mainHeight)+"px; z-index:4;");
				$('contentImageBlur10').setStyle("width:"+ mainWidth * 0.03+"px; left:"+(71.5+browserDec)+"%; top:"+(0.059*mainHeight)+"px; height:"+ mainHeight * 0.517+"px; z-index:8;");
				$('bestuur').appear({duration:durationsArray[cnt], delay:0.5});				
				$('content').appear({duration:durationsArray[cnt], delay:0});
				$('content').setStyle("height:57.5");				
			break;
            case 5 :
				bdT = 0;
                if (browserDec == 1) bdT = 0.1;
				$('content').setStyle("height:57.5%");
				$('contentImageBlur12').setStyle("width:"+ mainWidth * 0.03+"px; left:"+(80.4-bdT)+"%; top:"+(67-bdT)+"%; height:"+ mainHeight * 0.228+"px; z-index:8;");
				$('gastenboek').setStyle("width:48%; left:25%; top:35%; height:45%; z-index:7;");
				$('content').appear({duration:durationsArray[cnt], delay:0});
				$('gastenBoekImageDiv').setStyle("left:"+(80.45-bdT)+"%; top:"+(67-bdT)+"%; z-index:4;");
				$('gastenboek').appear({duration:durationsArray[cnt], delay:0.5});
				for (var gbE = 0; gbE<gastenBoekEntries; ++gbE)
				{
				   if (gbE%2 == 0) $("gbEntry"+gbE).setStyle("text-align:left;position:absolute;border:1px solid #f7a608;background-color:#dadada;padding:15px;width:"+(50-gbE)+"%;height:"+(60-gbE)+"%;top:" + (35-gbE*1) + "%;left:" + (gbE*3) + "%;z-index:" + (gastenBoekEntries-gbE+8) + ";");
				   else
				   {
					 if (gbE%3 == 0) $("gbEntry"+gbE).setStyle("text-align:left;position:absolute;border:1px solid #f7a608;background-color:#0857f7;padding:15px;width:"+(50-gbE)+"%;height:"+(60-gbE)+"%;top:" + (35-gbE*1) + "%;left:" + (gbE*3) + "%;z-index:" + (gastenBoekEntries-gbE+8) + ";");
					 else $("gbEntry"+gbE).setStyle("text-align:left;position:absolute;border:1px solid #0857f7;background-color:#f7a608;padding:15px;width:"+(50-gbE)+"%;height:"+(60-gbE)+"%;top:" + (35-gbE*1) + "%;left:" + (gbE*3) + "%;z-index:" + (gastenBoekEntries-gbE+8) + ";");
				   }
				   $("gbEntry"+gbE).appear({duration:durationsArray[cnt], delay:0.5});
				}
			break;
			case 6:
				$('contact').setStyle("width:24.9%; left:22.16%; top:30.6%; z-index:7; background-color:#e7e7e7;");
				$('contactImageDiv').setStyle("left:"+(51+browserDec)+"%; top:"+(0.059*mainHeight)+"px; z-index:4;");
				$('contentImageBlur14').setStyle("width:"+ mainWidth * 0.03+"px; left:"+(50.8+browserDec)+"%; top:"+(0.059*mainHeight)+"px; height:"+ mainHeight * 0.42+"px; z-index:8;");
				$('contact').appear({duration:durationsArray[cnt], delay:0.5});
				$('content').appear({duration:durationsArray[cnt], delay:0});
				$('content').setStyle("height:57.5%");
			break;
	}
}

	function doRotate()
	{
		++rounders
		if (rotationState == elementAmount - 1) rotationState=0;
		else 	++rotationState;
		setStateMenu();
		if (getStateValue(rotateId) == 0)
		{
			doStateAction();
			initStateSet = false;
			return;
		}
		doRotate();
	}

	function rotating(firedId)
	{
		rotateId = firedId;
		doRotate();
	}

	function gbRotating(stripper)
	{
		if (stripper == "nextArrow") 
                {
                  if (gbRotateId < gastenBoekEntries-1)
                  {
                    ++gbRotateId;
                    setgbStateMenu();
                  }
                }
		else
                {
                  if (gbRotateId>0)
                  {
                    --gbRotateId;
                    setgbStateMenu();
                  }
                }
	}

	function rotator(event)
	{
		stripper = Event.element(event).id;
		stripper = stripper.substr(9,1);
		rounders = 0;
		rotating(parseFloat(stripper));
	}

        function gbRotator(event)
	{
		stripper = Event.element(event).id;
		gbRotating(stripper);
	}
	
	function adRotator(event)
	{
		rotating(1);
	}

	function zoomFireEvent()
	{
		var newWidth = screen.width;
		if (newWidth != pageWidth)
		{
			pageWidth = newWidth;
			alert("resizing, adjusting resolutions");
			window.location.reload(false);			
		}
	}
	
	$('menuItem0').observe('click', rotator);
	$('menuItem1').observe('click', rotator);
	$('menuItem2').observe('click', rotator);
	$('menuItem3').observe('click', rotator);
	$('menuItem4').observe('click', rotator);
	$('menuItem5').observe('click', rotator);
	$('menuItem6').observe('click', rotator);
	$('nextArrow').observe('click', gbRotator);
	$('backArrow').observe('click', gbRotator);
	//$('adHomeDiv').observe('click', adRotator);
    rotating(0);
	setInterval(zoomFireEvent, 100);	

})();
