/******************************\
	Slider Javascript
	Written By David Wilson
\******************************/

/***  GLOBAL Variables  ***/
var iMoveDist = 50;					//Distance for each SLIDE movement
var iMoveObject = 4;				//Number of Objects to move is sMoveAction = CLICK.
var iObjectSize = 193;				//Size (in pixels) of each object in the slider (including margins & padding)
var iObjectCount = 0;				//default number of slider items;
var iCurrentPosLeft = 0;		//To reduce the object lookup.
var oSSTray = window.document.getElementById("brand_slide_ctrl_content");	//Instantiate the Global Variable: Don't Touch
var oSSContainer =  window.document.getElementById("brand_slide_ctrl");				//Instantiate the Global Variable: Don't Touch
/***  ----------------  ***/

function Nothing() {
	return;
}

jQuery(document).ready(function(){
	oSSTray = jQuery("#brand_slide_ctrl_content");	//Instantiate the Global Variable: Don't Touch
	oSSContainer =  jQuery("#brand_slide_ctrl");				//Instantiate the Global Variable: Don't Touch
	if(!oSSTray||!oSSContainer||oSSTray.length<1||oSSContainer.length<1) return;
	iObjectSize = jQuery(".brand_slide_ctrl_item").outerWidth(true);
	iObjectCount = (jQuery(".brand_slide_ctrl_item")).length;
	iCurrentPosLeft = oSSTray.position().left;

	prepSlider();
	
	jQuery("#brand_slide_ctrl_previous").click(function(){
		iMoveDist = (iMoveObject*iObjectSize);
		if(iCurrentPosLeft >= 0)return;
		if(iCurrentPosLeft+iMoveDist >= 0) iMoveDist = (iCurrentPosLeft*-1);
		iCurrentPosLeft += iMoveDist;
		//oSSTray.fadeTo("normal", 0.4)
		oSSTray.animate( { left: "+="+iMoveDist+"px" }, "slow" )
		//.fadeTo("normal", 1);
	});

	jQuery("#brand_slide_ctrl_next").click(function(){
		iMoveDist = (iMoveObject*iObjectSize);
		var iSlideDist = oSSTray.width() - oSSContainer.innerWidth();
		if(iCurrentPosLeft >= iSlideDist||iSlideDist<=0)return;
		if(iSlideDist+iCurrentPosLeft <= iMoveDist) iMoveDist = (iSlideDist+iCurrentPosLeft);
		if(iMoveDist<=0)return;
		iCurrentPosLeft -= iMoveDist;
		//oSSTray.fadeTo("normal", 0.4)
		oSSTray.animate( { left: "-="+iMoveDist+"px" }, "slow" )
		.fadeTo("normal", 1);
	});
});

function prepSlider() {
		oSSTray.width(iObjectCount*iObjectSize);
		if(jQuery("#itemBrandSel").length==0)return;
		if(oSSTray.width()<=oSSContainer.innerWidth())return;
		var iSelBrandPos = jQuery("#itemBrandSel").position().left;
		var iCenterPos = (oSSContainer.innerWidth()-iObjectSize)/2;
		if(iSelBrandPos<iCenterPos) return;
		iMoveDist = iSelBrandPos-iCenterPos;
		if(iMoveDist > (oSSTray.width()-oSSContainer.innerWidth())) iMoveDist = (oSSTray.width()-oSSContainer.innerWidth());
		iCurrentPosLeft-=iMoveDist;
		//oSSTray.fadeTo("normal", 0.4)
		oSSTray.animate( { left: "-="+iMoveDist+"px" }, "fast" )
		//.fadeTo("normal", 1);
}

function queueStop(oSSTray) {
//	iCurrentPosLeft = oSSTray.position().left;
//	var iSlideDist = oSSTray.width() - oSSContainer.innerWidth();
//	if((iSlideDist+iCurrentPosLeft)<=0) oSSTray.stop(true,true);
}
