$("document").ready(function () {

	/**
	 * SlideBox v1.0
	 */
	SBCountImage = $("img.SlideBox-Image").length;
	
	for (var i = 1; i <= SBCountImage; i++)
	{
		$("#SlideBox-PagerContent").append('<a rel="'+i+'" class="SlideBoxPager">'+i+'</a>' + "\n");
	}

	$(".SlideBoxPager:first").addClass("SlideBoxPagerActive");
	$(".SlideBox-Image").fadeOut();
	$(".SlideBox-Image:first").fadeIn().addClass("active");

	rotate = function ()
	{	
		var ID = $active.attr("rel") - 1;

		$(".SlideBoxPager").removeClass("SlideBoxPagerActive");
		$active.addClass("SlideBoxPagerActive");

		$(".SlideBox-Image.active").fadeOut().removeClass("active");
		$(".SlideBox-Image:eq("+ID+")").fadeIn().addClass("active");
	
	}; 

	rotateSwitch = function ()
	{		
		play = setInterval(function ()
		{
			$active = $("a.SlideBoxPagerActive").next();

			if ($active.length === 0)
			{
				$active = $(".SlideBoxPager:first");
			}

			rotate();
		}, 5000);
	};

	rotateSwitch();

	$(".SlideBoxPager").hover(
		function () {
			clearInterval(play);
		}
		,
		function () {
			rotateSwitch();
		});

	$(".SlideBoxPager").click(function() {	
		$active = $(this);
		clearInterval(play);
		rotate();
	});	
});
