/* ================================================================ 
This copyright notice must be untouched at all times.
Copyright (c) 2009 Stu Nicholls - stunicholls.com - all rights reserved.
=================================================================== */
$(document).ready(function(){
current = 1;
button = 1;
images = 5;
width = 240;

$('#p1').animate({"left": "0px"}, 400, "swing");
$('#b1').css("backgroundPosition", "left bottom")
$('#b1 b').css("color","#fff");
$('#loading').css("display","none");


$("#next").click(function() {
		button = current;
		current++
	if (current == (images+1) ) {current = 1}
animateLeft(current,button)
});

$("#previous").click(function() {
		button = current;
		current--
	if (current == 0 ) {current = images}
animateRight(current,button)
});

$("#buttons div").click(function() {
	button=current;
	clickButton = $(this).attr('id');
	current = parseInt(clickButton.slice(1));
	if (current > button) {animateLeft(current,button)}
	if (current < button) {animateRight(current,button)}
});

$("#buttons div b").mouseover(function() { clearTimeout(tss);
	if (($(this).css("color")) == "#d6381b" || ($(this).css("color")) == "rgb(17, 102, 170)") {$(this).css("color","#000");}
});

$("#buttons div b").mouseout(function() { tss = setTimeout('runSlideShow()', SlideShowSpeed);
	if (($(this).css("color")) == "#000" || ($(this).css("color")) == "rgb(0, 0, 0)") {$(this).css("color","#d6381b");}
});

function animateLeft(current,button) {
	$('#p'+current).css("left",width +"px");
	$('#p'+current).animate({"left": "0px"}, 400, "swing");
	$('#p'+button).animate({"left": -width+"px"}, 400, "swing");
	setbutton()
}

function animateRight(current,button) {
	$('#p'+current).css("left",-width+"px");
	$('#p'+current).animate({"left": "0px"}, 400, "swing");
	$('#p'+button).animate({"left": width+"px"}, 400, "swing");
	setbutton()
}

function setbutton () {
	$('#b'+button).css("backgroundPosition", "left top")
	$('#b'+button+' b').css("color","#d6381b");
	$('#b'+current).css("backgroundPosition", "left bottom")
	$('#b'+current+' b').css("color","#fff");
}

});

var SlideShowSpeed = 5000;
//var jss = 1 ;//var jmax = 5;//var jmin = 1;
var tss;
var jwait = 0;
function runSlideShow(){ 
 //var lnk = document.getElementById("next");
 if (jwait==0) { jwait = 1;}
 else { $("#next").trigger('click');  }	
	//lnk.click(); jss = jss + 1; //if (jss>jmax) jss = jmin; //add for check max 7
 tss = setTimeout('runSlideShow()', SlideShowSpeed);
}
