/******************************\
	Slider Javascript
	Written By David Wilson
\******************************/

/***  GLOBAL Variables  ***/
var bFade = true;						//Include Fade Effect? true(yes)/false(no)
var sMoveStyle = 'SLIDE'		//Manner in which the slider moves left/right: SLIDE(continous smooth motion) / PAGE (slider immediately shift to new group)
var sMoveAction = 'CLICK'		//Only used if sMoveStyle=SLIDE, Functionality of left/right buttons: HOLD(continous slide by iMoveDist in pixels while held) / CLICK (shift slider by iMoveObject * iObjectSize)
var iMoveDist = 5;					//Distance for each SLIDE movement
var iObjectSize = 43;				//Size (in pixels) of each object in the slider (including margins & padding)
var iMoveObject = 5;				//Number of Objects to move is sMoveAction = CLICK.
var iMoveSpeed = 1000;					//Speed of movement in milliseconds.
var iMoveMultiplier;				//Instantiate the Global Variable: Don't Touch
var iShiftDist;							//Instantiate the Global Variable: Don't Touch
var oIntervalID = 0;				//Instantiate the Global Variable: Don't Touch
var oSuperSlider = window.document.getElementById("brand_slide_ctrl_content");	//Instantiate the Global Variable: Don't Touch
var oSuperSlideContainer =  document.getElementById("brand_slide_ctrl");				//Instantiate the Global Variable: Don't Touch
/***  ----------------  ***/


function Nothing() {
	return;
}

function Slide(sAct) {
	oSuperSlider = window.document.getElementById("brand_slide_ctrl_content");
	oSuperSlideContainer =  document.getElementById("brand_slide_ctrl");
	switch (sAct) {
		case 'L': { //Slide Left
			iMoveMultiplier = -1;
			if(bFade){Fade('O')};
			Move_Slider();
			break;
		}
		case 'R': { //Slide Right
			iMoveMultiplier = 1;
			if(bFade){Fade('O')};
			Move_Slider();
			break;
		}
		case 'S': { //Stop Sliding
			if(sMoveAction=='HOLD'){
				window.clearInterval(oIntervalID);
				if(bFade){Fade('I')};
			}
			break;
		}
	}
}

function Move_Slider() {
	var iSliderMargin = oSuperSlider.offsetWidth-oSuperSlideContainer.offsetWidth;
	var iDistRemain = (iMoveMultiplier<0)?iSliderMargin+oSuperSlider.offsetLeft:0-oSuperSlider.offsetLeft;
	if(iSliderMargin>0) {
		switch(sMoveStyle){
			case 'SLIDE': {
				if(sMoveAction=='CLICK'){
					iShiftDist = (iDistRemain>(iMoveObject*iObjectSize))?(iMoveObject*iObjectSize):iDistRemain;
				} else {
					iShiftDist = iDistRemain;
				}
				oIntervalID = window.setInterval("Slide_Control()",iMoveSpeed);
				break;
			}
			case 'PAGE': {
				iShiftDist = (iDistRemain>(iMoveObject*iObjectSize))?(iMoveObject*iObjectSize):iDistRemain;
				oSuperSlider.style.left = oSuperSlider.offsetLeft + (iMoveMultiplier*iShiftDist) + 'px';
				if(bFade){Fade('I')};
				break;
			}
		}
	} else {
		if(bFade){Fade('I')};
	}
}


function Fade(sDir) {
	if(sDir == 'O') {
		//Fade Out
		oSuperSlider.className = 'brand_slide_fade';
	} else {
		//Fade In
		oSuperSlider.className = '';
	}
}

function Slide_Control() {
	if(iShiftDist>=iMoveDist){
		oSuperSlider.style.left = oSuperSlider.offsetLeft + (iMoveMultiplier*iMoveDist) + 'px';
		iShiftDist-=iMoveDist;
	} else {
		oSuperSlider.style.left = oSuperSlider.offsetLeft + (iMoveMultiplier*iShiftDist) + 'px';
		iShiftDist=0;
		if(bFade){Fade('I')};
		window.clearInterval(oIntervalID);
	}
}