var gGalleries=new Array();

function gGallery(name) {

gGalleries[name]=this;

this.d=2000;
this.name=name;
this.pics=new Array();
this.countPics=this.pics.length;
this.basePath='/gGallery/';
this.srcBig=this.basePath+'big/i';
this.srcThumb=this.basePath+'thumbs/i';
this.srcOriginal=this.basePath+'original/i';
this.noThumb='/i/'+this.basePath+'t.gif';
this.imageEnding='.jpg';
this.b=0;
this.posBig=0;
this.maxPics=3;
this.playing=false;

this.goToUrl=function(url) {
	window.location.href=url;
}

this.loadThumbnails=function() {
	var i;
	for (i=1;i<=this.maxPics;i++) {
		if(this.b+i<=this.countPics) {
			this.cI(this.name+'_i'+i,this.srcThumb+this.pics[this.b+i-1]+this.imageEnding);
		} else {
			this.cI(this.name+'_i'+i,this.noThumb);
		}
	}
	this.writeContent(this.name+'_thumbfrom', (this.b+1));
	this.writeContent(this.name+'_thumbto',(this.b+this.maxPics<this.countPics?this.b+this.maxPics:this.countPics));
	this.writeContent(this.name+'_thumbcount',this.countPics);
	this.setNavigation();
}

this.setNavigation=function() {
	if (this.b>=this.maxPics) {
		this.showNavImg('first');
		this.showNavImg('back');
	} else {
		this.hideNavImg('first');
		this.hideNavImg('back');
	}
	if (this.b+this.maxPics<this.countPics) {
		this.showNavImg('next');
		this.showNavImg('last');
	} else {
		this.hideNavImg('next');
		this.hideNavImg('last');
	}
}

this.showNavImg=function(dir) {
	document.getElementById(this.name+'_'+dir).style['visibility']='visible';
}

this.hideNavImg=function(dir) {
	document.getElementById(this.name+'_'+dir).style['visibility']='hidden';
}

this.cI=function(img, src) {
	document.images[img].src=src;
}

this.writeContent=function(id,text){
	eval('document.getElementById("'+id+'").innerHTML=text');
}

this.setPics=function(newpics) {
	this.pics=newpics;
	this.countPics=this.pics.length;
}

this.goFirst=function() {
	if (this.b>=this.maxPics) {
		this.b=0;
		this.loadThumbnails();
	}
}

this.goBack=function() {
	if (this.b>=this.maxPics) {
		this.b=this.b-this.maxPics;
		this.loadThumbnails();
	}
}

this.goNext=function() {
	if (this.b+this.maxPics<this.countPics) {
		this.b=this.b+this.maxPics;
		this.loadThumbnails();
	}
}

this.goLast=function() {
	if (this.b+this.maxPics<this.countPics) {
		this.b=this.countPics%this.maxPics==0?this.countPics-this.maxPics:this.countPics-(this.countPics%this.maxPics);
		this.loadThumbnails();
	}
}

// Funktionen für Bigimage :-)
this.goFirstBig=function() {
	if (this.posBig > 0) {
		this.setBig(0);
	}
}

this.goBackBig=function() {
	if (this.posBig > 0) {
		this.setBig(this.posBig-1);
	}
}

this.goNextBig=function() {
	if (this.posBig < this.countPics-1) {
		this.setBig(this.posBig+1);
	}
}

this.goLastBig=function() {
	if (this.posBig < this.countPics-1) {
		this.setBig(this.countPics-1);
	}
}

this.closeBig=function() {
	this.stop();
	this.cI(this.name+"_big_img", this.noThumb);
	document.getElementById(this.name+"_big").style.display="none";
}

this.setBig=function(i) {
	if (i<=this.countPics) {	
		this.posBig=i;
		this.cI(this.name+'_big_img', this.srcBig+this.pics[i]+this.imageEnding);
		document.forms['frm_' + this.name + '_big_image'].elements[this.name + '_big_number'].value=this.posBig+1;
		this.writeContent(this.name+'_big_count',this.countPics);
		this.setNavigationBig();
	}
}

this.goBig=function(i) {
	this.stop();
	if (i+this.b<=this.countPics) {
		this.posBig=this.b+i-1;
		
		this.setBig(this.posBig);
		document.getElementById(this.name+'_big').style.display="block";
	
	}
}

this.slide2next=function() {
	if (this.playing&&this.posBig>=0&&this.posBig<this.countPics-1) {
		this.setBig(this.posBig+1);
		setTimeout('gGalleries["' + this.name + '"].slide2next()', this.d);
	} else
		this.stop();
}
this.slideShow=function() {
	this.playing?this.stop():this.play();
}

this.play=function() {
	this.cI(this.name+'_play', this.basePath + 'pause.gif');
	this.playing=true;
	this.slide2next();
}

this.stop=function() {
	this.cI(this.name+'_play', this.basePath + 'play.gif');
	this.playing=false;
}

this.setNavigationBig=function() {
	if (this.posBig > 0) {
		this.showNavImg('big_first');
		this.showNavImg('big_back');
	} else {
		this.hideNavImg('big_first');
		this.hideNavImg('big_back');
	}
	
	if (this.posBig < this.countPics-1) {
		this.showNavImg('big_next');
		this.showNavImg('big_last');
	} else {
		this.hideNavImg('big_next');
		this.hideNavImg('big_last');
	}
}

this.setDelay=function() {
	this.d=document.forms['frm_' + this.name + '_delay'].elements[this.name + '_delay'].options[document.forms['frm_' + this.name + '_delay'].elements[this.name + '_delay'].options.selectedIndex].value;
}


this.selectBigImage=function() {
	n=document.forms['frm_' + this.name + '_big_image'].elements[this.name + '_big_number'].value-1;
	if(n>=0&&n<this.countPics) { 
		this.stop();
		this.setBig(n);
	} else { 
		document.forms['frm_' + this.name + '_big_image'].elements[this.name + '_big_number'].value=this.posBig+1;
	}
}

} // End of gGallery
