//////////////////////////////////////////////////////
// Small Preview									//
// Developed by Eng. Mohammed Yehia Abdul Mottalib  //
// http://www.dahabtech.com							//
// Mobile: (+20) 10 3930 361 OR (+20) 14 5325 822	//
// Landline: (+20) 69 3642 312						//
// Address: Masbat - Salah El Din Centre			//
// *************************************************//
// Developed for free use			                //
// Feel free to use this form anywhere in your		//
// in your website									//
// Date: 8th August 2010                            //
// Copyrights 2010 | Dahab TEchnology				//
//////////////////////////////////////////////////////

var smallPrev = {
	
	init: function() {
		
		smallPrev.thumbs    		= Core.getElementsByClass('thumbnailscontainer');
		smallPrev.thumbsContainer   = Core.getElementsByClass('thumbnailsWrraper');
		smallPrev.nextthumb  		 = Core.getElementsByClass("cursornext");
		smallPrev.prevthumb    	 = Core.getElementsByClass("cursorprev");
		
		for(var i = 0, ii = smallPrev.thumbs.length; i<ii; i++) {
			smallPrev.thumbs[i]._childs = smallPrev.thumbs[i].getElementsByTagName('img');
			smallPrev.thumbs[i]._childsWidth = [];
			smallPrev.thumbs[i]._endPos = 0;
			for(var m = 0, mm = smallPrev.thumbs[i]._childs.length; m<mm; m++) {
				smallPrev.thumbs[i]._childsWidth[smallPrev.thumbs[i]._childsWidth.length] = smallPrev.thumbs[i]._childs[m].width;
			}
			for(var j = 0, jj = smallPrev.thumbs[i]._childsWidth.length; j<jj; j++) {
				smallPrev.thumbs[i]._endPos += smallPrev.thumbs[i]._childsWidth[j];
			}
			smallPrev.thumbs[i]._startPos 		= 12;
			smallPrev.thumbs[i]._endPos		 += ((smallPrev.thumbs[i]._childs.length) * 10);
			smallPrev.thumbs[i]._endref	      = smallPrev.thumbs[i]._endPos
			smallPrev.thumbs[i].style.width	  = smallPrev.thumbs[i]._endPos + "px";
			smallPrev.thumbs[i]._endPos		 -= parseInt(Core.getComputedStyle(smallPrev.thumbsContainer[i], "width"), 10) - 30;
			if(smallPrev.thumbs[i]._endPos < parseInt(Core.getComputedStyle(smallPrev.thumbsContainer[i], "width"), 10)) {
				smallPrev.thumbs[i]._endPos = smallPrev.thumbs[i]._endref - 30;
			}
			smallPrev.thumbs[i]._endPos		 *= -1;
			smallPrev.thumbs[i]._tracker 	  = smallPrev.thumbs[i]._startPos;
			smallPrev.thumbs[i]._increment	   = 3;
		}
		
		for(var i = 0, ii = smallPrev.thumbs.length; i<ii; i++) {
			smallPrev.nextthumb[i]._ref = i;
			smallPrev.prevthumb[i]._ref = i;
			Core.addEventListener(smallPrev.nextthumb[i], "click", smallPrev.preventAction);
			Core.addEventListener(smallPrev.prevthumb[i], "click", smallPrev.preventAction);
			Core.addEventListener(smallPrev.nextthumb[i], "mousedown", smallPrev.nextSlideListener);
			Core.addEventListener(smallPrev.prevthumb[i], "mousedown", smallPrev.prevSlideListener);
			Core.addEventListener(smallPrev.nextthumb[i], "mouseup", smallPrev.stopTimer);
			Core.addEventListener(smallPrev.prevthumb[i], "mouseup", smallPrev.stopTimer);
		}
	},
	
	nextSlideListener: function(event) {
		Core.decrease(smallPrev.thumbs[this._ref], smallPrev.thumbs[this._ref]._endPos, smallPrev.thumbs[this._ref]._tracker, smallPrev.thumbs[this._ref]._increment, 100, "left", "px");
	},
	
	prevSlideListener: function(event) {
		Core.increase(smallPrev.thumbs[this._ref], smallPrev.thumbs[this._ref]._startPos, smallPrev.thumbs[this._ref]._tracker, smallPrev.thumbs[this._ref]._increment, 100, "left", "px");
	},
	
	stopTimer: function(event) {
		clearTimeout(smallPrev.thumbs[this._ref]._timer);
		smallPrev.thumbs[this._ref]._timer = null;
		Core.preventDefault(event);
	},
	
	preventAction: function(event) {
		Core.preventDefault(event);
	},
};

Core.start(smallPrev);
