
var IB_binderClass = 'glr',
		IB_itemClass = 'itmIB',
		IB_bfrBinders,
		IB_arrBinders = [];

function IB_Class(obj) {
	this.obj = obj,
	this.arrObjImg = [],
	this.ssIndex = 0,
	this.prIndex,
	this.nxIndex,
	this.bfr,
	
	this.Init = function() {
		this.arrObjImg = this.obj.getElementsByClassName(IB_itemClass);
		this.bfr = this.arrObjImg[0].innerHTML;
		this.IB_LoadPrNx(0);
	},
	
	this.IB_LoadPrNx = function(step) {
		if (step > 0) {
			this.ssIndex = (this.ssIndex < (this.arrObjImg.length - step)) ? this.ssIndex + step : this.ssIndex + step - this.arrObjImg.length;
		} else if (step < 0) {
			this.ssIndex = (this.ssIndex > 0 - step - 1) ? this.ssIndex + step : this.arrObjImg.length + step + this.ssIndex;
		}
		this.prIndex = (this.ssIndex > 0) ? this.ssIndex - 1 : this.arrObjImg.length - 1;
		this.nxIndex = (this.ssIndex < this.arrObjImg.length - 1) ? this.ssIndex + 1 : 0;
	}
}

function IB_Preview(objID,step) {
	var objTarget = IB_arrBinders[objID].arrObjImg[0],
			objSource = IB_arrBinders[objID].arrObjImg[(step > 0) ? IB_arrBinders[objID].nxIndex : IB_arrBinders[objID].prIndex];
	objTarget.innerHTML = (objTarget == objSource) ? IB_arrBinders[objID].bfr : objSource.innerHTML;
	IB_arrBinders[objID].IB_LoadPrNx(step);
	return false;
}

window.onload = function() {
	var tmp;
	IB_bfrBinders = document.getElementsByClassName(IB_binderClass);
	for (var i=0; i < IB_bfrBinders.length; i++) {
		tmp = GetIntAfterSymbol(IB_bfrBinders[i].id, '_');
		if (tmp) {
			IB_arrBinders[tmp] = new IB_Class(IB_bfrBinders[i]);
			IB_arrBinders[tmp].Init();
		}
	}
}
