
var index1 = 0;
var index2 = 0;
var index3 = 0;
var index4 = 0;
var index5 = 0;
var index6 = 0;
var index7 = 0;
var index8 = 0;
var singleImages;


var grafiken = new Array();
var actClicked = -1; 


function Rollover (id, path, name) {
  this.id = id;
  this.path = path;
  this.name = name;
  
  this.getFullPath = getFullPath;
}

function getFullPath(state) {
  return this.path+state+this.name;
}

function showOver(id) {
	if (id==actClicked) { return; }
	document.getElementById(id).src=getImageForState('hi', id);	
}

function showOut(id) {
	if (id==actClicked) { return; }
	document.getElementById(id).src=getImageForState('lo', id);	
}

function showClicked(id) {
	if (actClicked != -1) {
		document.getElementById(actClicked).src=getImageForState('lo', actClicked);	
	}
	document.getElementById(id).src = getImageForState('on', id);
	actClicked = id; 
}

function getImageForState(state, id) {
	for (i=0; i<grafiken.length;i++) {
		if (grafiken[i].id==id) { return grafiken[i].getFullPath(state); }
	}
	alert('Fehler: Rollover Grafik '+id+' nicht gefunden!');
}

function getActIndex() {
	if (actList=='liste1') { return index1; }
	if (actList=='liste2') { return index2; }
	if (actList=='liste3') { return index3; }
	if (actList=='liste4') { return index4; }
	if (actList=='liste5') { return index5; }
	if (actList=='liste6') { return index6; }
	if (actList=='liste7') { return index7; }
	if (actList=='liste8') { return index8; }
}

function getActListe() {
	if (actList=='liste1') { return liste1; }
	if (actList=='liste2') { return liste2; }
	if (actList=='liste3') { return liste3; }
	if (actList=='liste4') { return liste4; }
	if (actList=='liste5') { return liste5; }
	if (actList=='liste6') { return liste6; }
	if (actList=='liste7') { return liste7; }
	if (actList=='liste8') { return liste8; }
}

function getActPicture() {
	return getActListe()[getActIndex()]; 
}

function getNextIndex(){
	if (getActIndex()==getActListe().length-1) { return 0; }
	return getActIndex()+1;
}

function getPrevIndex(){
	if (getActIndex()==0) { return getActListe().length-1; }
	return getActIndex()-1;
}

function preload(){
	preloadInc();
	preloadDec();
}

function preloadInc(){
	var tmp = new Image();
	tmp.src = getActListe()[getNextIndex()];
	window.status = "Image "+tmp.src+" preloaded";
}

function preloadDec(){
	var tmp = new Image();
	tmp.src = getActListe()[getPrevIndex()];
	window.status = "Image "+tmp.src+" preloaded";
}


function inc(){
	if (actList=='liste1') { if (index1<liste1.length-1) {index1++;} else {index1 = 0; } }
	if (actList=='liste2') { if (index2<liste2.length-1) {index2++;} else {index2 = 0; } }
	if (actList=='liste3') { if (index3<liste3.length-1) {index3++;} else {index3 = 0; } }
	if (actList=='liste4') { if (index4<liste4.length-1) {index4++;} else {index4 = 0; } }
	if (actList=='liste5') { if (index5<liste5.length-1) {index5++;} else {index5 = 0; } }
	if (actList=='liste6') { if (index6<liste6.length-1) {index6++;} else {index6 = 0; } }
	if (actList=='liste7') { if (index7<liste7.length-1) {index7++;} else {index7 = 0; } }
	if (actList=='liste8') { if (index8<liste8.length-1) {index8++;} else {index8 = 0; } }
	showImages(actList);
	preloadInc();
}

function dec(){
	if (actList=='liste1') { if (index1>0) {index1--;} else {index1 = liste1.length-1; } }
	if (actList=='liste2') { if (index2>0) {index2--;} else {index2 = liste2.length-1; } }
	if (actList=='liste3') { if (index3>0) {index3--;} else {index3 = liste3.length-1; } }
	if (actList=='liste4') { if (index4>0) {index4--;} else {index4 = liste4.length-1; } }
	if (actList=='liste5') { if (index5>0) {index5--;} else {index5 = liste5.length-1; } }
	if (actList=='liste6') { if (index6>0) {index6--;} else {index6 = liste6.length-1; } }
	if (actList=='liste7') { if (index7>0) {index7--;} else {index7 = liste7.length-1; } }
	if (actList=='liste8') { if (index8>0) {index8--;} else {index8 = liste8.length-1; } }
	preloadDec();
	showImages(actList);
}

function showImages(listId) {
	showImagerDiv(true);
	showPreviewDiv(false);
	actList = listId;
	document.getElementById('bild').src=getActPicture();
	document.getElementById('imageCnt').firstChild.nodeValue="Bild "+(getActIndex()+1)+"/"+getActListe().length;
}

function showListImage(listId, aNumber) {
	var number = aNumber - 1;
	if (listId=='liste1') { index1 = number; }
	if (listId=='liste2') { index2 = number; }
	if (listId=='liste3') { index3 = number; }
	if (listId=='liste4') { index4 = number; }
	if (listId=='liste5') { index5 = number; }
	if (listId=='liste6') { index6 = number; }
	if (listId=='liste7') { index7 = number; }
	if (listId=='liste8') { index8 = number; }
	showImages(listId);
	preload();
}

function showPreview() {
	showImagerDiv(false);
	showPreviewDiv(true);
}


function showImagerDiv(doShow){
	var show = 'block';
	if (doShow == false) { show = 'none'; }
	document.getElementById('imager').style.display = show;
}

function showPreviewDiv(doShow){
	var show = 'block';
	if (doShow == false) { show = 'none'; }
	document.getElementById('preview').style.display = show;
}


function showImage(nr) {
	document.getElementById('bild').src=singleImages[nr-1];
}

function showFullImage() {
	var path = document.getElementById('bild').src;
	var x = path.lastIndexOf("/");
	var newPath = path.substr(0,x);
	newPath = newPath + "/t/" + path.substr(x+1, path.length);
	openWindow(newPath);
}
