/* ================================================================ 
This copyright notice must be untouched at all times.
Copyright (c) 2009 Stu Nicholls - stunicholls.com - all rights reserved.
=================================================================== */
onload = function() {

/* default variable settings */
timer=0;
current = 1;
button = 1;
animatespeed = 1000;

/* delay in miliiseconds */
showTime=6000;

/* automatic variable settings */
pictures = $('.button_a').length;
width = 838;

/* initial set up */
$('#buttons a').css("color","#6A6A6A");
$('#buttons #b1 a').css("color","#ed1a3b");

$('#p1').animate({"left": "0px"}, animatespeed, "easeInOutCubic");
$('#loading').css("display","none");

/* start the timer */
timer = setTimeout ("autoPlay()", showTime);


$("#next").click(function() {
		button = current;
		current++
	if (current == (pictures+1) ) {current = 1}
animateLeft(current,button)
});

$("#previous").click(function() {
		button = current;
		current--
	if (current == 0 ) {current = pictures}
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)}
});



function animateRight(current,button) {
	$('#p'+current).css("left",-width+"px");
	$('#p'+current).animate({"left": "0px"}, animatespeed, "easeInOutCubic");
	$('#p'+button).animate({"left": width+"px"}, animatespeed, "easeInOutCubic");
	setbutton()
}

$("#wrap").mouseover(function() {clearTimeout(timer);});
$("#wrap").mouseout(function() {timer = setTimeout ("autoPlay()", showTime);});

}

function autoPlay () {
	button = current;
	current++
	if (current == (pictures+1) ) {current = 1}
	animateLeft(current,button)

timer = setTimeout ("autoPlay()", showTime);
}

function animateLeft(current,button) {
	$('#p'+current).css("left",width +"px");
	$('#p'+current).animate({"left": "0px"}, animatespeed, "easeInOutCubic");
	$('#p'+button).animate({"left": -width+"px"}, animatespeed, "easeInOutCubic");
	setbutton()
}

function setbutton () {
	$('#b'+button+' a').css("color","#444");
	$('#b'+current+' a').css("color","#ed1a3b");
}
