if(location.href.split('#')[1]) window.location = location.href.split('#')[1];	
var loaded = new Array();
var gallery;

function gallery() {
	this.ajaxRoot;
	this.photoId;

	this.displayPhoto = function (Id, Album) {
		gallery=this;
		var load = new Array;
		
		if(Id == this.photoId) return;

//		Altes Bild ausblenden und Loading anzeige einblenden	
		if(document.getElementById("img"+this.photoId)) document.getElementById("img"+this.photoId).style.visibility = "hidden";			
		if(document.getElementById("photoWait")) document.getElementById("photoWait").style.visibility = "visible";

//		Referenz URL
		if(location.href.split('#')[1]) var Url = location.href.split('#')[1];
		else var Url = location.href;
		location.hash=Url.replace("p="+this.photoId,"p="+Id);
		
//		Neues Bild
		this.photoId = Id;

//		Aktuelles Bild
		ajax(this.ajaxRoot+"?ajax=greenishGallery:createImage&a="+Album+"&photoId="+this.photoId, this.photoId, this.showPhoto);
		
//		Preload
		if(this.photoId < (Anzahl-1)) load[0] = parseFloat(this.photoId)+1;
		else load[0] = 1;
		if(this.photoId>1) load[1] = parseFloat(this.photoId) - 1;
		for(var x = 0; x<load.length; x++) if(!loaded[load[x]]) ajax(this.ajaxRoot+"?ajax=greenishGallery:createImage&a="+Album+"&photoId="+load[x], load[x], this.preload);
	}
	
	this.showPhoto = function (photoInfo, Id) {
		var addContent,buttons="";		
		photoInfo=eval("("+photoInfo+")");

		var Next = parseFloat(Id)+1;
		var Prev = parseFloat(Id)-1;

//		Bild Generieren wenn nicht vorher schon generiert		
		if(!document.getElementById("img"+Id)) {
			addContent = "<img src=\""+relPath+photoInfo.photoSrc+"\" class=\"photo "+photoInfo.direction+"\" id=\"img"+Id+"\" alt=\"Photo\"";
			if(Anzahl>=Next) addContent += "onClick=\"javascript:gallery.displayPhoto("+Next+",'"+Album+"');\"";
			addContent += ">\n";
			document.getElementById("showPhoto").innerHTML += addContent;
		}

		
//		Buttons Generieren
		var buttonForward=document.getElementById("showPhotoButtonsForward");
		var buttonBack=document.getElementById("showPhotoButtonsBack");
		if(Id > 1) {
			buttonBack.href="javascript:gallery.displayPhoto("+Prev+",'"+Album+"');";
			buttonBack.style.display="block";
		}
		else buttonBack.style.display="none";
		if(Anzahl>=Next) {
			buttonForward.href="javascript:gallery.displayPhoto("+Next+",'"+Album+"');";
			buttonForward.style.display="block";
		}
		else buttonForward.style.display="none";

		

//		Alles Einblenden
		if(document.getElementById("showPhotoButtons")) document.getElementById("showPhotoButtons").style.visibility = "visible";			
		if(document.getElementById("photoWait")) document.getElementById("photoWait").style.visibility = "hidden";
		document.getElementById("img"+Id).style.visibility = "visible";
	
	}
	this.preload = function(photoInfo, Id) {
		photoInfo=eval("("+photoInfo+")");
//		Iniziert Image Object wenn noch nicht vorhanden.
		if(!loaded[Id] || loaded[Id].src != photoInfo.photoSrc) {
			loaded[Id] = new Image();
			loaded[Id].src = photoInfo.photoSrc;
		}
	}
}
