/*-------------Created 09.07 by Rich @digitaria------------------------*/

window.onload=makeWidth;
var move = 0;
var ulWidth;
var totalSlide = 390;
var imageWidth = 127;
var imageMargin = 3;
var animateTime = 10;
var position = 0;
var speed = 15;
var endRight = false;
var endLeft = false;
var animate = new Array();
var storyThumbs;
var imageArray = new Array();
var imageUl;
var storySlider;
var ulWidth;

function makeWidth(){
	storyThumbs = document.getElementById("storyThumbs");
	if (storyThumbs) {
		imageArray = storyThumbs.getElementsByTagName("li");
		imageUl = storyThumbs.getElementsByTagName("ul");
		storySlider = document.getElementById("storySlider");
		ulWidth = ((imageArray.length)*imageWidth)+((imageArray.length)*imageMargin);
		storySlider.style.width = ulWidth+"px";
		imageUl[0].style.width = ulWidth+"px";
	}
}

function imageSlide(direction){
	if (direction == "right"){
		if(-(position-totalSlide) >= (ulWidth)){
			document.getElementById("arrowRight").className="disable";
			endRight=true;
		}else{
			document.getElementById("arrowLeft").className="enable";
			endRight=false;
			moveRight();
		}
	}else{
		if(position >= 0){
			document.getElementById("arrowLeft").className="disable";
			endLeft=true;
		}else{
			document.getElementById("arrowRight").className="enable";
			endLeft=false;
			moveLeft();	
		}
	}
}	
function moveRight(){
	if (animate[0]!=true){
		if ((move-speed) >= -totalSlide && endRight != true && position != ulWidth){
			move=move-speed;
			storySlider.style.left = position+move+"px";
			timerId=setTimeout(moveRight, animateTime);
			animate[1]=true;
		}
		else{
			position=position+move;
			move=0;
			animate[1]=false;
			if(-(position-totalSlide) >= ulWidth){
				document.getElementById("arrowRight").className="disable";
				endRight=true;
			}
		}
	}
}
function moveLeft(){
	if (animate[1]!=true){
		if ((move+speed) <= totalSlide && endLeft != true && position != 0){
			move=move+speed;
			storySlider.style.left = position+move+"px";
			timerId=setTimeout(moveLeft, animateTime);
			animate[0]=true;
		}
		else{
			position=position+move;
			move=0;
			animate[0]=false;
			if(position >= 0){
				document.getElementById("arrowLeft").className="disable";
				endLeft=true;
			}
		}
	}
}


