/* Javascript document for Arkaik Clothing by Evan Bartlett (www.evanbartlett.com) */
/* Please don't steal without giving credit where it is due. Word! */

$(document).ready(readyHome);

var current_photo = 0;
var photo_total;
var timer;

function readyHome() {
	photo_total = $(".banneritem").length;
	if (photo_total > 1) {
		$(".bannerbtn").click(setPhotoTo);
		$("#bannerprev").click(setPhotoPrev);
		$("#bannernext").click(setPhotoNext);
		startTimer();
	}
}
function startTimer() {
	clearTimeout(timer);
	timer = setTimeout(ticker, 6000);
}
function stopTimer() {
	clearTimeout(timer);
}
function ticker() {
	startTimer();
	current_photo++;
	if(current_photo > (photo_total-1)) current_photo = 0;
	transitionThePhoto();
}
function setPhotoTo() {
	var num = $(this).attr("id");
	num = num.replace("bannerbtn_","");
	num = num-1;
	clearTimeout(timer);
	timer = setTimeout(ticker, 6000);
	current_photo = num;
	transitionThePhoto();
}
function setPhotoPrev() {
	clearTimeout(timer);
	timer = setTimeout(ticker, 6000);
	current_photo--;
	if(current_photo < 0) current_photo = (photo_total-1);
	current_photo = current_photo;
	transitionThePhoto();
}
function setPhotoNext() {
	clearTimeout(timer);
	timer = setTimeout(ticker, 6000);
	current_photo++;
	if(current_photo > (photo_total-1)) current_photo = 0;
	current_photo = current_photo;
	transitionThePhoto();
}
function transitionThePhoto() {
	$("#bannerslider").css('left', -250-(current_photo*1500)+"px");
	for(i = 0; i < photo_total; i++) {
		if(i == current_photo) {
			$("#bannerbtn_"+(i+1)).addClass("bannerbtnselected");
		} else {
			$("#bannerbtn_"+(i+1)).removeClass("bannerbtnselected");
		}
	}
}
