//variables//
fontGroot 	= 11;
fontKlein 	= 7;
//
arrCount	= 0; 
zindexCount = 2;
//
clicked 	= "no";
//the borderTop, borderBottom and borderSides are to set the layer a bit from the sides of the window
//the smallLyr and bigLyr are the sizes of the small layer and the big layer
var borderTop		=  20;
var borderTopLogo	= 150;
var borderBottom 	= 350;
var borderSides		=  50;
var smallLyr		= 150;
var bigLyr			= 380;
var maxHeight		= 600;

//
var xxx   = borderSides;
//start function which places the layers on random places//

function start() {
	for (i=0;i<=(items.length-1);i++){
		var xPart = (pageWidth()-((borderSides*2)+smallLyr))/items.length;
		//var xxx = Math.floor(Math.random()* (pageWidth()-((borderSides*2)+smallLyr)));
		if(i <= 1){
			var yyy = Math.floor(Math.random()*(((maxHeight-borderTopLogo)-borderBottom)));
			var yyy = yyy+borderTopLogo;	
		}
		else{
			var yyy = Math.floor(Math.random()*(((maxHeight-borderTop)-borderBottom)));
			var yyy = yyy+borderTop;	
		}		
		//var xxx = xxx+borderSides;
		var x = (posLeft()+xxx) + 'px';
		var y = (posTop()+yyy) + 'px';
		moveObjTo(items[i],x,y);
		//the +20 here is set to get the layer a bit from the right side of the window
		if((posLeft()+xxx) >= (pageWidth()-(bigLyr+20))){
			x = (pageWidth()-(bigLyr+20)) + "px";
			moveObjTo(shadowitems[i],x,y);
		}
		else{
			moveObjTo(shadowitems[i],x,y);
		}
		if(i == 0){
			oldY = new Array();
			oldY[i] = y;
		}
		else{
			oldY[i] = y;
		}
		document.getElementById(items[i]).style.fontSize = fontKlein + "px";
		//make layer visible
		setObjVis(items[i],'visible');
		setObjVis(shadowitems[i],'visible');
		setObjVis('logo','visible');
		setObjVis('fade2','visible');
		setObjVis('loading','hidden');
		//change xxx to next place
		xxx = xxx+xPart;
		//
	}
}

function resizeWindow() {
	var xxx = borderSides;
	for (i=0;i<=items.length;i++){
		var xPart = (pageWidth()-((borderSides*2)+smallLyr))/items.length;
		//var xxx = xxx+borderSides;
		var x = (posLeft()+xxx) + 'px';
		var y = oldY[i];
		moveObjTo(items[i],x,y);
		//the +20 here is set to get the layer a bit from the right side of the window
		if((posLeft()+xxx) >= (pageWidth()-(bigLyr+20))){
			x = (pageWidth()-(bigLyr+20)) + "px";
			moveObjTo(shadowitems[i],x,y);
		}
		else{
			moveObjTo(shadowitems[i],x,y);
		}
		//change xxx to next place
		xxx = xxx+xPart;
		//
	}
}

//call start function at loading website//
window.onload = start;
window.onresize = resizeWindow;
//layer functions//
function layerState(links,id,action,pos) {
	//z - index
	zindexCount++;
	//when layer is clicked do this!!//
	if (action == "clickedOFF"){
		if(clicked == "no"){
			//
		}
		if(clicked == "yes"){
			//change class of layer
			a = document.getElementById(memID);
			a.className = 'normal';
			//change font size
			document.getElementById(memID).style.fontSize = fontKlein + "px";
			document.getElementById(memID).style.zIndex = 2;
			//reset position of layer
			document.getElementById(memID).style.left = leftPos;
			//hide photo
			setObjVis('foto','hidden'); 
			//
			clicked = "no";
			//function to change texts back again
			textBack();
		}
	}
	if (action == "clickedON"){
		if(clicked == "yes"){
			//change class of layer
			a = document.getElementById(memID);
			a.className = 'normal';
			//change font size
			document.getElementById(memID).style.fontSize = fontKlein + "px";
			document.getElementById(memID).style.zIndex = 2;
			//reset position of layer
			document.getElementById(memID).style.left = leftPos;
			//hide photo
			setObjVis('foto','hidden'); 
			//
			clicked = "no";
			//function to change texts back again
			textBack();
		}
		//change class//
		a = document.getElementById(id);
		a.className = 'clicked';
		//change font size
		document.getElementById(id).style.fontSize = fontGroot + "px";
		document.getElementById(id).style.zIndex = zindexCount;
		//change position x
		leftPos = document.getElementById(id).style.left;
		replPos = leftPos.replace(/px/,"");
		//memorize id
		memID = id;
		//the +20 here is set to get the layer a bit from the right side of the window
		if (replPos >= (pageWidth()-(bigLyr+20))){
			document.getElementById(id).style.left = (pageWidth()-(bigLyr+20)) + "px";
		}
		//place
		clicked = "yes";
		if (replPos >= 210){
			if (replPos >= (pageWidth()-(bigLyr+20))){
				document.getElementById("foto").style.left = (((pageWidth()-(bigLyr+20)) - 210) + "px");
			}
			else{
				document.getElementById("foto").style.left = ((replPos - 210) + "px");
			}
			if(links != "multiSub"){
			document.getElementById("imageSpan").innerHTML = imagesAr[pos-1];
			}
			else{
			document.getElementById("imageSpan").innerHTML = imagesAr[pos-1][0];
			}
			//alert("hello 210")
			setObjVis('foto','visible'); 
		}
		else{
			document.getElementById("foto").style.left = ((replPos - (-390)) + "px");
			if(links != "multiSub"){
			document.getElementById("imageSpan").innerHTML = imagesAr[pos-1];
			}
			else{
			document.getElementById("imageSpan").innerHTML = imagesAr[pos-1][0];
			}
					//alert("hello !210")
			setObjVis('foto','visible'); 
		}
		//say that clicked is on
		
	}
	if (clicked == "no"){
		//when mouse is over layer do this//
		if (action == "hoverover"){
			document.getElementById(id).style.zIndex = zindexCount;
		}
		//when mouse is of layer do this//
		if (action == "hoverout"){
			document.getElementById(id).style.zIndex = 2;
		}
	}
}

function subImage(pos,posSub) {
	//z - index
	document.getElementById("imageSpan").innerHTML = imagesAr[pos-1][posSub-1];
	//alert("hello !210")
	setObjVis('foto','visible');
	subImageTrack = "YES";
}