// Rotator Variables
var Old = 0;
var New = 0;
var Interval;

// When: Page Load
$(function() {
	// Show First Rotator Item
	$(".rotator_item").css("opacity","0");
	$(".rotator_item:first").css("opacity","1");	
	var RotateCount = $(".rotator_item").length;
	// Run Interval
	Duration = $(".rotator_item:first .rotator_hidden").attr("value");
	Interval = setTimeout("NextPage("+RotateCount+");", Duration);
});

// Move to Next Page
function NextPage(RotateCount) {
	if (New==(RotateCount-1)) {		
		Page = 0;
	} else {
		Page = New+1;
	}
	Duration = $(".rotator_item:eq("+Page+") .rotator_hidden").attr("value");
	Interval = setTimeout("NextPage("+RotateCount+");", Duration);
	RotateItem(Page);
}

// When: Click Rotator Selector
function RotateItem(id) {
	Old = New;
	New = id;
	$(".rotator_item:eq("+Old+")").stop();
	$(".rotator_item").css({"z-index": 1});
	$(".rotator_item:eq("+Old+")").css({"opacity":"1", "z-index": 2});
	$(".rotator_item:eq("+New+")").css({"opacity":"0", "z-index": 3});
	$(".rotator_item:eq("+New+")").stop().animate({
		opacity:1
	}, {queue:false, duration:1000});
}
