var aCurPos = 0;
var userStop = false;
var selectStop = false;

function autoRotate() {
	userStop = false;
	$("#attract_waitbar").animate({width: "592px"}, 8000, function() {
		if (!userStop) {
			aCurPos++;
			if (aCurPos > 3) {
				aCurPos = 0;
			}
			
			attractTo(aCurPos);
			$("#attract_waitbar").animate({width: "1px"}, 300, function () {
				autoRotate();
			});
		}
	});
}

function stopRotate() {
	userStop = true;
	$("#attract_waitbar").stop(true, true);
	$("#attract_waitbar").css({opacity: 1, width: "1px"});
}

function selectorTo(pos) {
	if (!selectStop) {		// Stop the user from clicking items too quickly, messing with the animation
		selectStop = true;
		stopRotate();
		attractTo(pos);
		setTimeout('autoRotate()', 100);
		setTimeout('selectStop = false', 1900);
	}
}

function attractTo(pos) {
	aCurPos = pos;
	
	for (var i = 0; i < 4; i++) {
		$('#attract_i' + i).css("border", "2px solid #777");
	}
	$('#attract_i' + pos).css("border", "2px solid black");
	$('#a_ol_1').css({opacity: 1});
	$('#a_ol_2').css({opacity: 0.1});
	$('#text_holder').animate({opacity: 0, marginLeft: "-40px"} , 500);
	//$('#a_ol_1').animate({opacity: 1}, 600);
	$('#attract_wipe').animate({marginLeft: "0px"}, 600, function () {
			$('#a_ol_1').animate({opacity: 0.25}, 500);
			$('#a_ol_2').animate({opacity: 0.85}, 500).delay(200);
			$("#attract_slide").css("background", "url(" + feat_items[aCurPos][0] + ")");
			$("#attract_link").attr("href", feat_items[aCurPos][1]);
			$("#info_header").html(feat_items[aCurPos][2]);
			$("#info_description").html(feat_items[aCurPos][3]);
			$("#attract_wipe").animate({width: "0px"}, 1000, function () {
					$("#attract_wipe").css({marginLeft: "590px", width: "590px"});
					$("#text_holder").css({marginLeft: "70px"});
					$("#text_holder").animate({opacity: 1, marginLeft: "0px"}, 300);
			   });
		});
}
