var qsWidth=0;
var qsListWidth=0;
var qsLeft=0;
var qsSpeed=0;
var qsScrollTime=0;
var qsScrollValue=false;
var qsScrollDirection="next";
var qsScrollInterval;
var qsElem="";
var qsPosition=0;
var qsListArray = new Array();
var i=0;
var oldPosition=0;

var quicklinkScroller = {
	init: function(_initArray)
	{
		qsElem = _initArray.id;
		
		$(document).ready(function()
		{
			$(qsElem).prepend('<div id="btnLeft" class="disabledLeft" onclick="quicklinkScroller.prev(\'click\')"></div>');
			$(qsElem).append('<div id="btnRight" onclick="quicklinkScroller.next(\'click\')"></div>');
			
			qsWidth = $(qsElem).width()-($("#btnLeft").width()+$("#btnRight").width());
			$(qsElem+" a").each(function(i, elem)
			{
				qsListWidth += $(elem).width();
				qsListArray[i] = $(elem).width();
			});
			$(qsElem+" ul").css({ 'width': (qsListWidth+1)+"px" });
		});
		
		qsSpeed = _initArray.speed;
		qsScrollTime = _initArray.scrollTime * 1000;
		qsScrollValue = _initArray.autoScroll;
		if(_initArray.autoScroll == true) qsScrollInterval = setInterval("quicklinkScroller.next()", qsScrollTime);
		
		$(qsElem).hover(function()
		{
			if(_initArray.pauseOnRoll == true) clearInterval(qsScrollInterval);
		},
		function()
		{
			if(qsScrollValue == true && _initArray.pauseOnRoll == true) qsScrollInterval = setInterval("quicklinkScroller."+qsScrollDirection+"()", qsScrollTime);
		});
	},
	next: function(_method)
	{
		var tempValue = qsListArray.length - qsPosition;
		
		if(_method == "click")
		{
			clearInterval(qsScrollInterval);
			qsScrollValue=false;
		}
		
		if(tempValue > 4)
		{
			$("#qs_buttons ul").stop(true, true).animate({ 'left': '-='+qsListArray[qsPosition]+'px' }, qsSpeed, function()
			{
				qsLeft = $("#qs_buttons ul").css("left");
				qsLeft = qsLeft.replace("px", "");
				qsLeft = qsLeft * (-1);
			});
			qsPosition++;
			
			$("#btnLeft").removeClass('disabledLeft');
		}
		var tempValue = qsListArray.length - qsPosition;
		if(tempValue <= 4 && qsScrollValue == false) $("#btnRight").addClass('disabledRight');
		else if(tempValue <= 4 && qsScrollValue == true)
		{
			$("#btnRight").addClass('disabledRight');
			clearInterval(qsScrollInterval);
			qsScrollDirection = "prev";
			qsScrollInterval = setInterval("quicklinkScroller."+qsScrollDirection+"()", qsScrollTime);
		}
	},
	prev: function(_method)
	{
		if(_method == "click")
		{
			clearInterval(qsScrollInterval);
			qsScrollValue=false;
		}
		
		if(qsLeft != 0)
		{
			qsPosition--;
			$("#qs_buttons ul").stop(true, true).animate({ 'left': '+='+qsListArray[qsPosition]+'px' }, qsSpeed, function()
			{
				qsLeft = $("#qs_buttons ul").css("left");
				qsLeft = qsLeft.replace("px", "");
				qsLeft = qsLeft * (-1);
			});
			
			$("#btnRight").removeClass('disabledRight');
		}
		var tempValue = qsListArray.length - qsPosition;
		if(tempValue == qsListArray.length && qsScrollValue == false) $("#btnLeft").addClass('disabledLeft');
		else if(tempValue == qsListArray.length && qsScrollValue == true)
		{
			$("#btnLeft").addClass('disabledLeft');
			clearInterval(qsScrollInterval);
			qsScrollDirection = "next";
			qsScrollInterval = setInterval("quicklinkScroller."+qsScrollDirection+"()", qsScrollTime);
		}
	}
}