// set up some variables

var i = 0;

// Tell browser where to find the image
myImgSrc = "pics/";



function lunchboxOpen(lunchID) {
document.getElementById('lunch_' + lunchID).style.display = "block";
document.getElementById('link_' + lunchID).href = "javascript:lunchboxClose('" + lunchID + "');";

i = 0;

//document.getElementById('imagelink_' + lunchID).href = "javascript:next('" + lunchID + "',bilder_" + lunchID + ");";

bilders (lunchID, eval("bilder_"+lunchID));

}


function bilders(ID, arrayname){
i=0;

document.getElementById('imagelink_' + ID).href = "javascript:next('" + ID + "',bilder_" + ID + ");";

	var img = document.createElement('img');
		img.onload = function (evt) {
		document.getElementById('imgSrc' + ID).src=this.src;
		document.getElementById('imgSrc' + ID).width=this.width;
		document.getElementById('imgSrc' + ID).height=this.height;
		}
		
	nextimg = new Image();
	nextimg.src = myImgSrc + arrayname[1];
	nextimg.onload = function () {
		//alert("ready: " + arrayname[1]);
	}	
		
		
	img.src = myImgSrc + arrayname[0];
	document.getElementById('namnum' + ID).innerHTML= arrayname[0].replace(".jpg","") + "&nbsp;&nbsp;&nbsp;&nbsp;1 / " + arrayname.length;
	//return false;


}

function lunchboxClose(lunchID) {
document.getElementById('lunch_' + lunchID).style.display = "none";
document.getElementById('link_' + lunchID).href = "javascript:lunchboxOpen('" + lunchID + "');";
reset(lunchID)

document.getElementById('imagelink_' + lunchID).href = "javascript:lunchboxOpen('" + lunchID + "');";
document.getElementById('namnum' + lunchID).innerHTML= "&nbsp;";

farbe(document.getElementById("bilder_" + lunchID));

i = 0;


}

function reset(ID){
		document.getElementById('imgSrc' + ID).width = document.getElementById('imgSrc' + ID).width/2.8;		
		document.getElementById('imgSrc' + ID).height = document.getElementById('imgSrc' + ID).height/2.8;
}

// Create link function to switch image forward
function next(ID, arrayname){
document.getElementById('imagelink_' + ID).href = "javascript:next('" + ID + "',bilder_" + ID + ");";
	var img = document.createElement('img');
	img.onload = function (evt) {
		document.getElementById('imgSrc' + ID).src=this.src;
		document.getElementById('imgSrc' + ID).width=this.width;
		document.getElementById('imgSrc' + ID).height=this.height;
	}
if(i>(arrayname.length-2)){
    var l = 0
    i=0
  } else {
    var l = i+=1;
  }
	img.src = myImgSrc + arrayname[l];
	
	nextimg = new Image();
	nextimg.src = myImgSrc + arrayname[(l+1)];
	nextimg.onload = function () {
		//alert("here!: " + arrayname[(l+1)]);
	}
	document.getElementById('namnum' + ID).innerHTML= arrayname[l].replace(".jpg","") + "&nbsp;&nbsp;&nbsp;&nbsp;" + (l+1) + " / " + arrayname.length;
	//return false;
}

function unpubnext(ID, arrayname){
document.getElementById('imagelink_' + ID).href = "javascript:unpubnext('" + ID + "',unpub_" + ID + ");";
	var img = document.createElement('img');
	img.onload = function (evt) {
		document.getElementById('imgSrc' + ID).src=this.src;
		document.getElementById('imgSrc' + ID).width=this.width;
		document.getElementById('imgSrc' + ID).height=this.height;
	}
  if(i>(arrayname.length-2)){
    var l = 0
    i=0
  } else {
    var l = i+=1;
  }
	img.src = myImgSrc + arrayname[l];
	
	nextimg = new Image();
	nextimg.src = myImgSrc + arrayname[(l+1)];
	nextimg.onload = function () {
		//alert("here!: " + arrayname[(l+1)]);
	}
	
	document.getElementById('namnum' + ID).innerHTML= arrayname[l].replace(".jpg","") + "&nbsp;&nbsp;&nbsp;&nbsp;" + (l+1) + " / " + arrayname.length;
	//return false;
}

function layoutnext(ID, arrayname){
document.getElementById('imagelink_' + ID).href = "javascript:layoutnext('" + ID + "',layout_" + ID + ");";
	var img = document.createElement('img');
	img.onload = function (evt) {
		document.getElementById('imgSrc' + ID).src=this.src;
		document.getElementById('imgSrc' + ID).width=this.width;
		document.getElementById('imgSrc' + ID).height=this.height;
	}
  if(i>(arrayname.length-2)){
    var l = 0
    i=0
  } else {
    var l = i+=1;
  }
	img.src = myImgSrc + arrayname[l];
	
	nextimg = new Image();
	nextimg.src = myImgSrc + arrayname[(l+1)];
	nextimg.onload = function () {
		//alert("here!: " + arrayname[(l+1)]);
	}
	
	document.getElementById('namnum' + ID).innerHTML= arrayname[l].replace(".jpg","") + "&nbsp;&nbsp;&nbsp;&nbsp;" + (l+1) + " / " + arrayname.length;
	//return false;
	
if(l>(arrayname.length-1)){
    
    l = 0;
	
}
}


function unpubs(ID, arrayname){
i=0;
document.getElementById('imagelink_' + ID).href = "javascript:unpubnext('" + ID + "',unpub_" + ID + ");";
	var img = document.createElement('img');
	img.onload = function (evt) {
		document.getElementById('imgSrc' + ID).src=this.src;
		document.getElementById('imgSrc' + ID).width=this.width;
		document.getElementById('imgSrc' + ID).height=this.height;
	}
	
	nextimg = new Image();
	nextimg.src = myImgSrc + arrayname[1];
	nextimg.onload = function () {
		//alert("ready: " + arrayname[1]);
	}	
	
	img.src = myImgSrc + arrayname[0];
	document.getElementById('namnum' + ID).innerHTML= arrayname[0].replace(".jpg","") + "&nbsp;&nbsp;&nbsp;&nbsp;1 / " + arrayname.length;
	return false;
}

function layouts(ID, arrayname){
i=0;
document.getElementById('imagelink_' + ID).href = "javascript:layoutnext('" + ID + "',layout_" + ID + ");";
	var img = document.createElement('img');
	img.onload = function (evt) {
		document.getElementById('imgSrc' + ID).src=this.src;
		document.getElementById('imgSrc' + ID).width=this.width;
		document.getElementById('imgSrc' + ID).height=this.height;
	}
	nextimg = new Image();
	nextimg.src = myImgSrc + arrayname[1];
	nextimg.onload = function () {
		//alert("ready: " + arrayname[1]);
	}	
	
	img.src = myImgSrc + arrayname[0];
	document.getElementById('namnum' + ID).innerHTML= arrayname[0].replace(".jpg","") + "&nbsp;&nbsp;&nbsp;&nbsp;1 / " + arrayname.length;
	return false;
}



function Go(select) {
  var wert = select.options[select.options.selectedIndex].value;
  if (wert == "leer") {
   
     top.location.href = "index.php";
    
  } else {
    if (wert == "ende") {
      top.location.href = window.location.href;
    } else {
      window.location.href = wert;
      select.form.reset();
      window.focus();
    }
  }
}




function preloader() 
{

     // counter
     var pre = 0;

     // create object
     imageObj = new Image();

     // set image list
     images = new Array();
     images[0]="image1.jpg"
     images[1]="image2.jpg"
     images[2]="image3.jpg"
     images[3]="image4.jpg"

     // start preloading
     for(pre=0; pre<=3; pre++) 
     {
          imageObj.src=bilder_0[pre];
     }
imageObj.onload = alert(loaded)
} 



function farbe(link)
{
  var allelinks = link.parentNode.childNodes;
  for (var i=0;i<allelinks.length;i++)
    allelinks[i].className=''; //alle Klassen zurücksetzen
  link.className='current'; //geklicktem Link Klasse zuweisen
  return false; //false zurückgeben, damit Linkziel nicht gefolgt wird.
}

