function FEGallery(modID, gallery)
{
  this.modID = modID;
  this.images = gallery;
  this.currentIndex = 0;
	this.size = 's';
	
	this.scroll = function(direction){
		this.scrollTo(this.currentIndex + direction);
	}
	
	this.scrollTo = function(index){
		if (this.size == 's'){
			this.scrollSmall(index);
		}
		else {
			this.scrollBig(index);
		}
		
		$("#counter_" + modID).text((this.currentIndex+1) + " / " + this.images.length);
		
		for (var i = this.currentIndex - 10; i<this.currentIndex+10; i++){
			if (i >= 0 && i < this.images.length){
				$("#thumbLeft_" + modID).find("img:eq(" + i + ")").attr("src", this.images[i][0]);
				$("#thumbRight_" + modID).find("img:eq(" + i + ")").attr("src", this.images[i][0]);
				$("#bigThumb_" + modID).find("img:eq(" + i + ")").attr("src", this.images[i][1]);
			}
		}
	}
	
	this.scrollSmall = function(index){
		if (index < 0){
			this.currentIndex = 0;
		}
		else if (index >= this.images.length){
			this.currentIndex = this.images.length - 1;
		}
		else {
			this.currentIndex = index;
		}
		$("#previewImg_" + modID).hide();
		$("#previewImg_" + modID).attr("src", this.images[this.currentIndex][1]);
		$("#previewImg_" + modID).show();
		
		var index1 = (this.currentIndex > 0) ? this.currentIndex - 1 : 0;
		$("#thumbLeft_" + modID).animate({"scrollLeft": 80*index1 }, "fast");

		var index2 = (this.currentIndex < this.images.length-1) ? this.currentIndex + 1 : this.images.length-1;
		$("#thumbRight_" + modID).animate({"scrollLeft": 80*index2 }, "fast");
	}
	
	this.scrollBig = function(index){
		if (index < 0){
			this.currentIndex = 0;
		}
		else if (index >= this.images.length - 1){
			this.currentIndex = this.images.length - 2;
		}
		else {
			this.currentIndex = index;
		}
		if (this.currentIndex < 0){
			this.currentIndex = 0;
		}
		$("#previewImg_" + modID).hide();
		$("#previewImg_" + modID).attr("src", this.images[this.currentIndex][1]);
		$("#previewImg_" + modID).show();
		
		var index1 = (this.currentIndex > 1) ? this.currentIndex - 2 : 0;
		$("#thumbLeft_" + modID).animate({"scrollLeft": 86*index1 }, "fast");

		var index2 = (this.currentIndex < this.images.length-2) ? this.currentIndex + 2 : this.images.length-2;
		$("#thumbRight_" + modID).animate({"scrollLeft": 86*index2 }, "fast");
		
		$("#thumbLeft_" + modID).find("img").css("margin-bottom", "");
		$("#thumbRight_" + modID).find("img").css("margin-bottom", "");
		$("#thumbLeft_" + modID).find("img:eq(" + index1 + ")").css("margin-bottom", "10px");
		$("#thumbRight_" + modID).find("img:eq(" + (index2+1) + ")").css("margin-bottom", "10px");
	}

	this.enlarge = function(popupUrl) {
		dsp_photo(popupUrl + "&coid=" + this.images[this.currentIndex][2], 902, 760);
		return false;
	}
}

