
jQuery.fn.siteRotator = function() {
	
	
	$(this).find("li").addClass("small");
	
	$("#siteRotator").find("li:gt(1)").css("display", "none");
	
	var $rotatorList = $(this).find("ul");
	var $featured = $rotatorList.find("li:first");
	$("#featureBox").html($featured.html());
	
	$featured.remove();
	$rotatorList.append($featured);
	
	if (!jQuery.support.opacity)
	{
		$("#siteRotator ul").css("display", "none");
		$("#featureBox div").css("width", "410px");
		$("#featureBox").css("width", "595px");
		$("#featureBox img").css("float", "right");
	}
	
	var rotateFn = (jQuery.support.opacity) ? "rotate()" : "rotateOldBrowsers()";
	var intId = window.setInterval(rotateFn, 5000);

};

function rotateOldBrowsers()
{
	$("#featureBox").fadeOut("slow", function() {
		
		var $rotatorList = $("#siteRotator").find("ul");
		var $featured = $rotatorList.find("li:first");
		
		$("#featureBox").html($featured.html());
		$("#featureBox div").css("width", "410px");
		$("#featureBox").css("width", "595px");
		$("#featureBox img").css("float", "right");
		$("#featureBox").fadeIn();
		
		var $moveToBack = $rotatorList.find("li:eq(0)");
		$moveToBack.remove();
		$moveToBack.attr("style", "");
		$moveToBack.find("img").attr("style", "");	
		
		$rotatorList.attr("style", "");
		$rotatorList.append($moveToBack);
		
	});
}

function rotate() {
	var $list = $("#siteRotator").find("ul");
	var $onDeck = $list.find("li:first");
	
	var $featureBox = $("#featureBox");
	
	$onDeck.find("img").animate({
		height: 131
	}, 1000);
	
	$featureBox.animate({
		top: "+=50px",
		opacity: 0
	}, 1000);
	
	$list.animate({
		top: "-=60px"
	}, 1000, "swing");
	
	$onDeck.animate({
		left: "-=202px",
		top: "+=50px"
	}, 1000, "linear", function() {
		
		$featureBox.css("top", 0);
		$featureBox.html($(this).html());
		$featureBox.animate({
			opacity: 1
		}, 1000, "linear", function() {
			var $moveToBack = $list.find("li:eq(0)");
			$moveToBack.remove();
			$moveToBack.attr("style", "");
			$moveToBack.find("img").attr("style", "");	
			
			$list.attr("style", "");
			$list.append($moveToBack);
			$list.find("li:gt(1)").css("display", "none");
			$list.find("li:lt(2)").attr("style", "");
			
			var $onDeck2 = $list.find("li:eq(1)");
			$onDeck2.css("opacity", 0);
			$onDeck2.animate({
				opacity: 1
			}, 1000);
			
		});
	});
	
}
