

window.setTimeout("setpic();", 1000);

var pictureID;


picture = function(id){
	if($(id)){
	//Bildinformationen auslesen	
	pictureID = id;
	thumbnail_width = $(id).width;	
	thumbnail_height = $(id).height;
	$(id).removeAttribute("width", 0);
	$(id).removeAttribute("height", 0);
	original_width = $(id).width;
	original_height = $(id).height;
	$(id).setAttribute("width", thumbnail_width);
	$(id).setAttribute("height", thumbnail_height);
	path = $(id).src;
	
	//Maximale Bildgröße festlegen
	if(original_height > 500){
		$('imgpreview_img').setAttribute("height", "500px");	
		original_width = (original_width/100) * ((100/original_height)*500);
	}else{
		$('imgpreview_img').removeAttribute("height", 0);
	}
	picture_buttoncheck();
	//Paramter für großbild setzen
	$("imgpreview_box").style.width= original_width + "px";
	$("imgpreview_bg").style.display="block";
	$("imgpreview_bg2").style.display="block";
	$("imgpreview_img").src=path;
	}
}

picture_close = function(){
	Effect.DropOut('imgpreview_bg2');
	$("imgpreview_bg").style.display="none";
	//$("imgpreview_bg2").style.display="none";
	//$("imgpreview_img").src="";
}



setpic = function(){
	// alle IMG Knoten suchen
	aNodes = document.getElementsByTagName('img');

	// für alle IMG Knoten das onclick Event setzen
	j=1;
	for (var iI=0; iI<aNodes.length; iI++) {
		if(aNodes[iI].id == ""){
			aNodes[iI].id = "imgid#" + j;
			percent = ThumbnailPercent(aNodes[iI].id);
			if(percent>130){
				aNodes[iI].onclick = function(e) {picture(this.id);}
				aNodes[iI].style.cursor="pointer";
				j++;
			}else{
				aNodes[iI].id = "";
			}
		}
	}
}

ThumbnailPercent = function(id){

	thumbnail_width = $(id).width;	
	thumbnail_height = $(id).height;
	style_width = $(id).style.width;
	style_height = $(id).style.height;
	$(id).style.width = "";
	$(id).style.height = "";
	//$(id).removeAttribute("style.width", 0);
	//$(id).removeAttribute("style.height", 0);
	$(id).removeAttribute("width", 0);
	$(id).removeAttribute("height", 0);
	original_width = $(id).width;
	original_height = $(id).height;
	$(id).setAttribute("width", thumbnail_width);
	$(id).setAttribute("height", thumbnail_height);
	//$(id).setAttribute("style.width", style_width);
	//$(id).setAttribute("style.height", style_height);
	$(id).style.width = style_width;
	$(id).style.height = style_height;
	thumbnail = thumbnail_width+thumbnail_height;
	original = original_width + original_height;

	percent = (100/thumbnail)*original;
	if(original<100){
		percent = 100;
	}
	return percent;
}

picture_buttoncheck = function(){
	$('picture_button_previous').style.display="none";
	$('picture_button_next').style.display="none";	
	parts = pictureID.split("#");
	nextID = parseInt(parts[1])+1;
	previousID =  parseInt(parts[1])-1;
	nextPicID = parts[0] + "#" + nextID;
	previousPicID = parts[0] + "#" + previousID;
	//alert(nextPicID + "-" + pictureID);
	if($(nextPicID)){
		$('picture_button_next').style.display="inline";	
	}
	if($(previousPicID)){
		$('picture_button_previous').style.display="inline";	
	}

}

picture_next = function(){
	$('picture_button_previous').style.display="inline";
	parts = pictureID.split("#");
	parts[1]++;
	newPictureID = parts[0] + "#" + parts[1];
	parts[1]++;
	nextPictureID = parts[0] + "#" + parts[1];
	if(!$(nextPictureID)){
		$('picture_button_next').style.display="none";	
	}else{
		$('picture_button_next').style.display="inline";	
	}
	picture(newPictureID);
}
picture_previous = function(){
	$('picture_button_next').style.display="inline";
	parts = pictureID.split("#");
	parts[1]--;
	newPictureID = parts[0] + "#" + parts[1];
	parts[1]--;
	nextPictureID = parts[0] + "#" + parts[1];
	if(!$(nextPictureID)){
		$('picture_button_previous').style.display="none";	
	}else{
		$('picture_button_previous').style.display="inline";	
	}
	picture(newPictureID);
}



