var imagebuttonlist = new Array();
var mainpictureslist = new Array();
var imgbuttonfuctionset = "onmouseover='javascript:over(-r-)' onmouseout='javascript:out(-r-)' onclick='javascript:clicking(-r-)'";
var buttonfuctionset = "onmouseover='javascript:overstroke(-r-)' onmouseout='javascript:outstroke(-r-)' onclick='javascript:clicking(-r-)' id='strokeID-r-'";
var direktlink = "#";
var testset = "";
var currentID = selected;
var strokeOutColor = "#111111";
var strokeOverColor = "#BBBBBB";
var strokeUpColor = "#990000";
var mainimageID = 0;
var delimiter = "/";

function addDelimiters(){
	if(thumbpath.length > 0 ){
		thumbpath += delimiter;
	}
	
	if(basepath.length > 0){
		basepath +=delimiter;
	}
	
	if(contentpath.length > 0){
		contentpath += delimiter;
	}
	
	if(mainpath.length > 0){
		mainpath += delimiter;
	}
}

function createlist(){
	var name;
	var filecount = 0;
	addDelimiters();
	for(var i = 0; i< itemlist.length; i++){
		name = itemlist[i];
		if(typeof itemlist[i+1] == "number"){
			for(var j=1; j<= itemlist[i+1]; j++){
				addElementToLists(filecount, name + j);
				filecount ++;
			}
		}else if(typeof itemlist[i] == "string"){
			addElementToLists(filecount, name);
			filecount ++;
		}
	}
	mainimageID += filecount;
}



function over(id){
	if(id != currentID){
		document.images[id].src = imagebuttonlist[id][1].src;
	}
}

function out(id){
	if(id != currentID ){
		document.images[id].src = imagebuttonlist[id][0].src;
	}
}

function overstroke(id){
	if(currentID != id){
		document.getElementById("strokeID" + id).style.color = strokeOverColor;
	}
}

function outstroke(id){
	if(currentID != id){
		document.getElementById("strokeID" + id).style.color = strokeOutColor;
	}
}

function nextimage(){
	var tmpID = currentID + 1;
	if(tmpID < imagebuttonlist.length){
		clicking(tmpID);
	}
}

function previmage(){
	var tmpID = currentID - 1;
	if(tmpID >= 0){
		clicking(tmpID);
	}
}


function clicking(id){
		if(currentID >= 0){
			document.images[currentID].src = imagebuttonlist[currentID][0].src;
		}
		currentID = id;
		document.images[id].src = imagebuttonlist[id][1].src;
		if(document.images.length > mainimageID){
			document.images[mainimageID].src = mainpictureslist[id].src;
		}else{
			//document.location.href = itemlist[id] + ".html";
		}
		/*
		changing the Arrowcolors
		*/
		if(currentID < 1){
			document.getElementById("leftarrow").style.color = strokeOverColor;			
		}else{
			document.getElementById("leftarrow").style.color = strokeOutColor;
		}
		
		if(currentID >= imagebuttonlist.length -1){
			document.getElementById("rightarrow").style.color = strokeOverColor;
		}else{
			document.getElementById("rightarrow").style.color = strokeOutColor;
		}
}


function init(){
	var name;
	var filecount = 0;
	if(document.images.length > mainimageID){
		for(var i = 0; i< imagebuttonlist.length; i++){
				mainpictureslist[i] = new Image();
				mainpictureslist[i].src = imagebuttonlist[i][2];
		}
		if(imagebuttonlist.length > 1){
			document.getElementById("leftarrow").style.color = strokeOverColor;
		}
	}
}

function addElementToLists(index, filename){
	if(filename.charAt(0) == "#"){
		var temp= "<img src='" + basepath + contentpath  + thumbpath + filename.substr(1,filename.length-1) + "." + type +"' />";
		imagenavigation += temp.replace(/-r-/g, index);
	}else{
		imagebuttonlist[index] = new Array();
		imagebuttonlist[index][0] = new Image();
		imagebuttonlist[index][0].src = basepath + contentpath + thumbpath + filename + "." + type;
		imagebuttonlist[index][1] = new Image();
		imagebuttonlist[index][1].src = basepath + contentpath  + thumbpath + filename + "_o." + type;
		imagebuttonlist[index][2] = basepath  + contentpath  + mainpath  + filename + "." + type;
		if(imagepagelink === "true"){
			direktlink = itemlist[index] + ".html";
			if(index > 0){
				direktlink = filename + ".html";
			}
		}else{
			if(index == selected){
				addElementToMainPicturesList(index, filename);
				displayimage = "<img src='"+ mainpictureslist[index].src +"' />";
			}
		}
		var pointer = (index == selected ? 1 : 0);
		var temp= "<a href='" + direktlink +"' " + imgbuttonfuctionset + "><img src='" + imagebuttonlist[index][pointer].src + "' /></a>";
		imagenavigation += temp.replace(/-r-/g, index);
		temp = "<a href='#' " + buttonfuctionset + ">|</a>";
		strokenavigation += temp.replace(/-r-/g, index);
	}
}

function addElementToMainPicturesList(index, filename){
	mainpictureslist[index] = new Image();
	mainpictureslist[index].src = basepath  + contentpath  + mainpath  + filename + "." + type;
	
}

function displaying(one){
	      $("#p"+one).toggle();	
		 
}

function displaying2(two){
	      $("#p"+two).toggle();	
		  $("#pp"+two).toggle();	
}
function language(lang) {
	if (lang == "deu") {
		$("#over_d").show();
		$("#over_e").hide();
		
		var time = new Date();
		time = new Date(time.getTime()+1000*60*60);
		document.cookie = 'lang=deu; expires='+time.toGMTString()+';';
	}
	if (lang == "eng") {
		$("#over_e").show();
		$("#over_d").hide();
		
		var time = new Date();
		time = new Date(time.getTime()+1000*60*60);
		document.cookie = 'lang=eng; expires='+time.toGMTString()+';';
	}
}

function startup(){
	
	for(var i = 0; i< list.length; i++){
		var name = list[i];
		list[i] = new Array();
		list[i][0] = new Image();
		list[i][0].src = path + name + "." + type;
		list[i][1] = new Image();
		list[i][1].src = path + name + "_o." + type;

	}
}

function change( image, num, index ){
	document.images[image].src = list[num][index].src;
}

function showadd(layer){
	$("#" + layer).fadeIn("slow");
}

function hideadd(layer){
	$("#" + layer).fadeOut("def");
}

/*immediate List-Creation*/
createlist();
