// JavaScript Document
var automate = true // TO STOP AUTOMATIC SET TO FALSE
var automate_pause = 4000; // SET IN MILLISECONDS (4000)
var speed = 5; // SPEED OF MOVEMENT
var display = 3; //DISPLAY BEFORE RESETING

var item_width = new Array();
var left = 0;
var current = 0;
var slideshow = document.getElementById("inner-wrap");
var slideshow_item = slideshow.getElementsByTagName("h5");
var slideshow_total = slideshow_item.length;
var slideshow_width = 0;
var slideshow_loop = '';
var timeout_auto = '';

for(var x = 0; x<slideshow_total; x++) {
	slideshow_width = slideshow_width+slideshow_item[x].clientWidth;
	item_width[x] = slideshow_item[x].clientWidth;
}

slideshow.style.left = 0;

if(automate==true) automatic('right');


function move_item(value) {
	speed = 5;
	var left = slideshow.style.left;
	current = (value=='left') ? current-1 : current+1;
	if(current>=(slideshow_total-(display-1))) {
		current = 0;
		value = 'left';
	}
	if(current<0) {
		current = (slideshow_total-display);
		value = 'right';
	}
	var target = 0;
	for(x = 0; x<current; x++) {
		target = target+item_width[x];
	}
	animate(left,target,value);
	if(automate==true) automatic('right');
}

function animate(left,target,value) {
	if(slideshow_loop!='') clearTimeout(slideshow_loop);
	left = parseInt(left);
	target = parseInt(target);
	if(left<=0) left = left*-1;
	if(value=='left') {
		if(left>=target) {
			left = (left>speed) ? left-speed : 0;
			speed = speed+1;
			slideshow.style.left = "-"+left+"px";
			slideshow_loop = setTimeout("animate('"+left+"','"+target+"','"+value+"')",35);
		} else {
			slideshow.style.left = "-"+target+"px";
		}
	}
	if(value=='right') {
		if(left<=target) {
			left = left+speed;
			speed = speed+1;
			slideshow.style.left = "-"+left+"px";
			slideshow_loop = setTimeout("animate('"+left+"','"+target+"','"+value+"')",35);
		} else {
			slideshow.style.left = "-"+target+"px";
		}
	}
}

function automatic(value) {
	if(timeout_auto!='') clearTimeout(timeout_auto);
	timeout_auto = setTimeout("move_item('"+value+"')",automate_pause);
}

