function Scroller(obj, clickSize, isHoriz){
	var object;
	var current;
	var child;
	var childHeight;
	var parentHeight;
	var maxClicks;
	var deltaAnimation=500;
	var deltaClick=30;
	var locked=false;
	var self=this;
	var isHorizontal=false;
	var buffer=0;

	if(clickSize>0)
	{
		deltaClick=clickSize;
	}
	if(isHoriz)
	{
		isHorizontal=true;
	}
	else{
		isHorizontal=false;
	}
	this.setHorizontal=function(){
		isHorizontal=true;
		self.init();
	}
	this.setVertical=function(){
		isHorizontal=true;
		self.init();
	}

	this.setClickSize=function(clickSize){
		deltaClick=clickSize;
	}

	this.setAnimationTime=function(animationTime){
		deltaAnimation=animationTime;
	}
	this.setBuffer=function(i){
		if(i>0){
			buffer=i;
		}
	}

	this.clickMath=function(){
		maxClicks=0;
		var deltaPosition=childHeight-parentHeight;
		if(deltaPosition>0){
			maxClicks=Math.ceil(deltaPosition/deltaClick);
//			alert(maxClicks+"="+childHeight+"-"+parentHeight);
		}
		if(buffer>0){
			maxClicks=maxClicks-buffer;
		}
	}

	this.killTriggers=function(){
		object.find('.controls .prev, .controls .next').unbind('click');
	}

	this.init=function(obj){
		object=jQuery(obj);
		self.killTriggers();
		child=object.find('.scroller').children('.scrollerContentContainer');
		if(!isHorizontal){
			parentHeight=object.find('.scroller').outerHeight(true);
			childHeight=child.outerHeight(true);
		}
		else{
			parentHeight=object.find('.scroller').outerWidth(true);
			childHeight=0;

			var elements=child.children();
			elements.each(function(){
				childHeight=childHeight+jQuery(this).outerWidth(true);
			});
//			alert('Width: '+parentHeight);
			child.width(childHeight);
		}
		self.clickMath();
		child.css('position','absolute');
		self.setTriggers();
		current=0;
//		alert(maxClicks);
	}

	this.setTriggers=function(){
		object.find('.controls .prev').click(function(){
			if(current>0){
				self.move('+='+deltaClick);
				current--;
			}
		});
		object.find('.controls .next').click(function(){
			if(current<maxClicks){
				self.move('-='+deltaClick);
				current++
			}
		});
		r_timer=setInterval(
			function(e){
				if(child.outerHeight(true)!=childHeight)
				{
					self.clickMath();
					childHeight=child.outerHeight(true)
				}
			}, 500);
	}



	this.move=function(input){
		if(!locked){
			locked=true;
			if(!isHorizontal){
				child.animate({top: input},deltaAnimation, function(){locked=false});
			}
			else{
				child.animate({left: input},deltaAnimation, function(){locked=false});
			}
		}
//		alert(current);
	}
	self.init(obj);
}

