﻿/*
   Photoscroller
   By : Niels den Otter
   Website : www.n-websites.nl
*/
function photoScroller(itemTag, objectId, itemWidth, itemsToShow, scrollSpeed){	
   this.curItem = 0;
   this.itemTag = itemTag;
   this.objectId = objectId;
   this.itemWidth = itemWidth;
   this.itemsToShow = itemsToShow;
   this.scrollSpeed = scrollSpeed;    
   with(this)
    $(objectId).animate({scrollLeft: 0}, 0);
}
function toLeft(){	
   this.itemMin();
   this.scrollNow();
}
function toRight(){
   this.itemPlus();
   this.scrollNow();
}
function scrollNow(){
   with(this)
    $(objectId).stop().animate({scrollLeft: curItem * itemWidth}, scrollSpeed);
}
/* Handles the item */
function getCurItem(){
   return this.curItem + 1;	
}
function getTotalItems(){
   return $(this.objectId).find(this.itemTag).length;
}
function itemMin(){
   with(this){
       if(getCurItem() > 1)
        curItem--;
       else
        curItem = getTotalItems() - itemsToShow;
   }
}
function itemPlus(){
   with(this){
       if(getCurItem() <= ( getTotalItems() - itemsToShow ) )
        curItem++;
       else
        curItem = 0;
   }
}
photoScroller.prototype.toLeft = toLeft;
photoScroller.prototype.toRight = toRight;
photoScroller.prototype.scrollNow = scrollNow;
photoScroller.prototype.getCurItem = getCurItem;
photoScroller.prototype.getTotalItems = getTotalItems;
photoScroller.prototype.itemMin = itemMin;
photoScroller.prototype.itemPlus = itemPlus;

