function startView(nr,RawEncodedGalName,HumanGalName,start)
{
	$("OverlayInputBox").setStyle("display","block");
	el=$("OverlayInputBox").parentNode.removeChild($("OverlayInputBox"));
	if(addOverlay(el)==false) {alert("failure");return false;}
	$("overlay").setStyle("opacity",0.8);
  overlayRePos();
	
	GALCOUNT=(start!=null)?start:GALCOUNT;
	
	$("galDescInput").firstChild.nodeValue=HumanGalName;
	galN=nr;
	galFolder=RawEncodedGalName;
	loadPic(true);	
}

function checkDeleteIt(opt)
{
  ttt=true;
	ips=$("entrys").getElements("input");
	for(i=0;i<ips.length;i++)
	{
  	ite=ips[i];
  	text=(opt=="a")?"Verzeichnis":"Bild";
		if(ite.type=="checkbox") 
  	{
  		if(ite.checked==true) 
    	{
      	check=confirm(unescape("Die%20ausgew%E4hlten%20Objekte%20werden%20eng%FCltig%20vom%20Server%20gel%F6scht%21%20Sind%20Sie%20sicher%3F"));
      	if(check==false) ttt=false;
				else ttt=true;
				return ttt;
    	}	
		}
	}
	return ttt;
}

function nextPic()
{
  GALCOUNT++;
	if(GALCOUNT>pics[galN].length-1) GALCOUNT=0;
	loadPic();
}

function backPic()
{
  GALCOUNT--;
	if(GALCOUNT<0) GALCOUNT=pics[galN].length-1;
	loadPic();
}

function loadPic(start)
{
  //$("imgInput").style.height="auto";
	
	/*if(GAL_ERROR)
	{
  	GAL_ERROR=false; 
  	$$("div.loadInf")[0].getElementsByTagName("p")[0].firstChild.nodeValue="Lade Bild...";
  	$$("div.loadInf")[0].getElementsByTagName("img")[0].style.display="";
	}*/
	
	$("wait").style.display="";
	$("imgDescInput").style.display="none";
	img=new Image();
	descr=pics[galN][GALCOUNT];
	splitA=descr.split("|");
	img.className="prevImgBig";
	//alert("h");
	
	//$("imgInput").style.height="";
	//alert("h");
	img.id="prevImgBig";
	img.style.display="none";
	img.onload=hideLoadInf;
	/*img.onerror=function() 
	{
  	GAL_ERROR=true; 
  	$$("div.loadInf")[0].getElementsByTagName("p")[0].firstChild.nodeValue="Fehler beim Laden des Bildes!";
  	$$("div.loadInf")[0].getElementsByTagName("img")[0].style.display="";
	}*/
	if(start==null) $("imgInput").removeChild($("prevImgBig"));
	$("imgInput").appendChild(img);
	img.src=PATH+galFolder+"/"+splitA[0];
}

function Ausgabe (Ereignis) 
{
  if(Ereignis==null) 
	{
  	Ereignis=window.event;
	}
	key=Ereignis.keyCode || Ereignis.which;
	if(key==27 && $("overlay").style.display!="none") closeView();
	if(key==104 || key==38 || key==37 || key==33 || key==100) backPic()
	if(key==102 || key==39 || key==34 || key==40 || key==98) nextPic()
}

function hideLoadInf()
{
	h=$("prevImgBig").height;
	w=$("prevImgBig").width;
	if(w>=PICDIMENSIONX && w>=h) 
	{
  	$("prevImgBig").width=PICDIMENSIONX;
  	$("prevImgBig").height=(PICDIMENSIONX/w)*h;
	}
	else 
	{
  	$("prevImgBig").height=PICDIMENSIONY;
  	$("prevImgBig").width=(PICDIMENSIONY/h)*w;
	}
	imgDesc=unescape(splitA[1]);
	$("imgDescInput").style.display="";
	//$("imgInput").style.height="auto";
	$("wait").style.display="none";
	$("prevImgBig").style.display="";
	$("imgDescInput").innerHTML=imgDesc;
	$("overlayInput").style.width="auto";
	overlayRePos();
}

function closeView()
{
	$("prevImgBig").parentNode.removeChild($("prevImgBig"));
	var oib=$("OverlayInputBox").cloneNode(true);
	oib.style.display="none";
	$(document.body).appendChild(oib);
	closeOverlay();
}

/* Manager */
function checkUploadImg(field)
{
  if(field.value.substr(field.value.length-3).toLowerCase()!="jpg")
  {
    alert(unescape("Die%20ausgew%E4hlte%20Datei%20ist%20kein%20JPG-Bild%21"));
    field.value="";
  }
  else
  {
    vtest=true;
		empty=false;
		values=new Array();
		 ips=field.parentNode.parentNode.getElementsByTagName("input");
		ipsD=field.parentNode.getElementsByTagName("input");
    for(i=0;i<ips.length;i++) 
		{
  		if(ips[i]==field) continue;
  		if(ips[i].value==field.value) vtest=false;
			if(ips[i].value=="") empty=true;
		}
		if(vtest==false) 
    {
      alert(unescape("Die%20Datei%20wurde%20bereits%20ausgew%E4hlt%21")); 
      field.value="";
			if(ipsD.length==2) field.parentNode.parentNode.removeChild(field.parentNode);
    }
		if(vtest==true && !empty) 
    {
      field.parentNode.parentNode.insertBefore(field.parentNode.cloneNode(true),field.parentNode.parentNode.firstChild);
      field.parentNode.parentNode.getElementsByTagName("input")[0].value="";
		}
		if(ipsD.length<2 && field.value!="")
		{
  		span=new Element('input', 
  		{
        'onclick': "this.parentNode.parentNode.removeChild(this.parentNode);false;",
    		'value': 'x',
				'type': 'submit'
  		});
  		field.parentNode.insertBefore(span,field);
		}
  }
}

function deleteThisUpload(span)
{
  span.parentNode.parentNode.removeChild(span.parentNode);
}