if(typeof agtthumbs == "undefined") var agtthumbs = new Object();

agtthumbs.Instance = function(slider, img, link, descr, left, right) {
	
	this.PerPage = 5;
	this.ItemWidth = 77;
	
	this.ObjSlider = slider;
	this.ObjImage = img;
	this.ObjImageLink = link;
	this.ObjImageDescription = descr;
	this.ObjButtonLeft = left;
	this.ObjButtonRight = right;
	
	this.Items = new Array();
	this.SId = 0;
		
}

agtthumbs.Instance.prototype = {
	
	AddItem: function(item) {
		var instance = this;
		var i = this.Items.length;
		this.Items[i] = item;
		this.Items[i].Obj.onclick = function() { instance.Show(i); }
		this.ObjSlider.appendChild(this.Items[i].Obj);
	},
	
	Display: function() {
		var instance = this;
		for (var i = 0; i < this.ObjButtonLeft.childNodes.length; i++) {
			if (this.ObjButtonLeft.childNodes[i].nodeName == 'A') {
				for (var ii = 0; ii < this.ObjButtonLeft.childNodes[i].childNodes.length; ii++) {
					if (this.ObjButtonLeft.childNodes[i].childNodes[ii].nodeName == 'IMG') {
						if (this.SId > 0) {
							this.ObjButtonLeft.childNodes[i].href = 'javascript://';
							this.ObjButtonLeft.childNodes[i].onclick = function() { instance.PrevItem(); };
							this.ObjButtonLeft.childNodes[i].childNodes[ii].src = '/jk/prev.gif';
						} else {
							this.ObjButtonLeft.childNodes[i].removeAttribute('href');
							this.ObjButtonLeft.childNodes[i].onclick = function() {};
							this.ObjButtonLeft.childNodes[i].childNodes[ii].src = '/jk/prev_.gif';
						}
						break;
					}
				}
				break;
			}
		}
		for (var i = 0; i < this.ObjButtonRight.childNodes.length; i++) {
			if (this.ObjButtonRight.childNodes[i].nodeName == 'A') {
				for (var ii = 0; ii < this.ObjButtonRight.childNodes[i].childNodes.length; ii++) {
					if (this.ObjButtonRight.childNodes[i].childNodes[ii].nodeName == 'IMG') {
						if (this.SId < this.Items.length - 1) {
							this.ObjButtonRight.childNodes[i].href = 'javascript://';
							this.ObjButtonRight.childNodes[i].onclick = function() { instance.NextItem(); };
							this.ObjButtonRight.childNodes[i].childNodes[ii].src = '/jk/next_.gif';
						} else {
							this.ObjButtonRight.childNodes[i].removeAttribute('href');
							this.ObjButtonRight.childNodes[i].onclick = function() {};
							this.ObjButtonRight.childNodes[i].childNodes[ii].src = '/jk/next_.gif';
						}
						break;
					}
				}
				break;
			}
		}
		if (this.ObjSlider.scrollLeft > this.SId * this.ItemWidth) {
			this.ObjSlider.scrollLeft -= this.ItemWidth;
		} else if(this.ObjSlider.scrollLeft + this.ItemWidth * (this.PerPage - 1) < this.SId * this.ItemWidth) {
			this.ObjSlider.scrollLeft += this.ItemWidth;
		}
	},
	
	PrevItem: function() {
		this.Show(this.SId - 1);
	},
	
	NextItem: function() {
		this.Show(this.SId + 1);
	}, 
	
	Show: function(item_id) {
		this.ObjImage.src = this.Items[item_id].SrcLarge;
		if (this.ObjImage.parentNode.nodeName == 'A') {
			this.ObjImage.parentNode.href = this.Items[item_id].SrcPopup;
		}
		this.ObjImageLink.href = this.Items[item_id].SrcPopup;
		this.ObjImageDescription.innerHTML = this.Items[item_id].Descr;
		this.Items[this.SId].Obj.className = false;
		this.Items[item_id].Obj.className = 'selected';
		this.SId = item_id;
		this.Display();
	}
	
}

if(typeof agtthumbsitem == "undefined") var agtthumbsitem = new Object();

agtthumbsitem.Instance = function(src_small, src_large, src_popup, src_popup2, descr) {
	
	this.SrcSmall = src_small;
	this.SrcLarge = src_large;
	this.SrcPopup = src_popup;
	this.Descr = descr;
	
	this.Obj = document.createElement("IMG");
	this.Obj.src = this.SrcSmall;
	this.Obj.alt = '';
	this.Obj.style.width = '75px';
	this.Obj.style.height = '50px';
	
	this.ImageSmall = new Image;
	this.ImageSmall.src = this.SrcSmall;
	
	this.ImageLarge = new Image;
	this.ImageLarge.src = this.SrcLarge;

	this.SrcPopup = src_popup2;
}

var Thumbs = agtthumbs.Instance;
var ThumbsItem = agtthumbsitem.Instance;
