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.votes=true;
this.voteinfo=new Array();
this.basePath='http://www.live-style.it/gGallery/';
this.srcBig='http://www.live-style.it/img.php?i=';
this.srcThumb='http://www.live-style.it/img.php?s=t&i=';
this.srcBig='http://www.live-style.it/i/big/';
this.srcThumb='http://www.live-style.it/i/small/';
//this.srcThumb=this.basePath;
this.srcOriginal='http://www.live-style.it/gGallery/original/i';
this.noThumb='http://www.live-style.it/t.gif';
//this.imageEnding='.jpg';
this.imageEnding='';
this.b=0;
this.posBig=0;
this.maxPics=3;
this.playing=false;

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

this.getImgPath=function(id,big) {
    var dir=Math.floor(id/1000);
    if (big==1) {
        return this.srcBig+dir+'/'+id+'.jpg';
    } else {
        return this.srcThumb+dir+'/'+id+'.jpg';
    }
}

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.getImgPath(this.pics[this.b+i-1],0));
		} 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.writeVoteinfo=function(i) {
	this.writeContent('quote', this.voteinfo[i]['vote']);
	this.writeContent('cntvote', this.voteinfo[i]['count']);
}

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";
	if ( this.votes ) { document.getElementById(this.name+'_frm').style['display']='none'; }
	//document.getElementById(this.name+'_vote').style['display']='none';
}

this.setBig=function(i) {
	if (i<=this.countPics) {	
		this.posBig=i;
        this.cI(this.name+'_big_img', this.getImgPath(this.pics[i],1));
		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();
		if (this.votes) { this.writeVoteinfo(this.pics[i]); }
	}
}

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.go2Thumbnail=function(i)  {
	var xy=Math.floor(i/this.maxPics);
	this.b=xy*this.maxPics;
	this.loadThumbnails();
}

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;
	}
}


this.showForm=function() {
	if (this.votes) { document.getElementById(this.name+'_vote').style['display']='none'; }
	document.getElementById(this.name+'_frm').style['display']='block';
	document.getElementById('test').value=this.pics[this.posBig];
}

this.showVote=function() {
	document.getElementById(this.name+'_frm').style['display']='none';
	if (this.votes) { document.getElementById(this.name+'_vote').style['display']='block'; }
}


} // End of gGallery
