var onSlide = 1;
var lastSlide = 0;
var isPaused = true;
var inTransition = false;
var interval;
$(document).ready(function() {
	$("#ShowRotator-Item1").show().css("left",0);
	$("#ShowRotator-Pagination1").addClass("Selected");
	// Stop rotator on user interaction
	$("#ShowRotator-Pagination").hover(function(){
		stopRotator();
	},function(){
		startRotator();
	});
	// Content Rotator Pagination
	$(".ShowRotator-Pagination").click(function(){
		if (onSlide != $(this).html()) goToRotator($(this).html());
		return false;
	});
	$(".ShowRotator-Pagination").hover(function(){
		$(".ShowRotator-Pagination").removeClass("Hover");
		$(this).addClass("Hover");
	},function(){
		$(".ShowRotator-Pagination").removeClass("Hover");
	});
	// Make slide linkable
	$(".ShowRotator-Item").click(function() {
	    if ($(this).find(".ShowRotator-Image").attr("target") == "_blank") {
            var day = new Date();
            var id = day.getTime();
            eval("page" + id + " = window.open($(this).find('.ShowRotator-Image').attr('href'), '" + id + "');");
		}else{
		    window.location = $(this).find(".ShowRotator-Image").attr("href");
		}
		return false;
	});
	// remove the focus lines
	$('a').focus( function() { $(this).blur(); } );
	// Start the rotator
	$(window).load(function() {
		startRotator();
	});
});
function startRotator() {
	if (isPaused) {
		isPaused=false;
		window.clearInterval(interval);
		interval = window.setInterval('goRightRotator();',5000);
	}
}
function stopRotator() {
	isPaused=true;
	window.clearInterval(interval);
}
function goRightRotator(newSlide) {
	if (!inTransition) {
		inTransition = true;
		lastSlide = onSlide;
		if (newSlide) {
			onSlide = newSlide;
		}else{
			if (onSlide < maxSlide && onSlide >= 1) {
				onSlide++;
			}else{
				onSlide = 1;
			}
		}
		$("#ShowRotator-Item"+(lastSlide)+" .ShowRotator-Image img").fadeOut(750,function(){
			$("#ShowRotator-Item"+(onSlide)).show();
			$("#ShowRotator-Item"+(onSlide)+" .ShowRotator-Image img").hide();
			$("#ShowRotator-Item"+(lastSlide)).hide();
			$("#ShowRotator-Item"+(onSlide)+" .ShowRotator-Image img").fadeIn(750,function(){
				inTransition = false;
			});
		});
		$(".ShowRotator-Pagination").removeClass("Selected");
		$("#ShowRotator-Pagination"+(onSlide)).addClass("Selected");
	}
}
function goLeftRotator(newSlide) {
	if (!inTransition) {
		inTransition = true;
		lastSlide = onSlide;
		if (newSlide) {
			onSlide = newSlide;
		}else{
			if (onSlide <= maxSlide && onSlide > 1) {
				onSlide--;
			}else{
				onSlide = maxSlide;
			}
		}
		$("#ShowRotator-Item"+(lastSlide)+" .ShowRotator-Image img").fadeOut(750,function(){
			$("#ShowRotator-Item"+(onSlide)).show();
			$("#ShowRotator-Item"+(onSlide)+" .ShowRotator-Image img").hide();
			$("#ShowRotator-Item"+(lastSlide)).hide();
			$("#ShowRotator-Item"+(onSlide)+" .ShowRotator-Image img").fadeIn(750,function(){
				inTransition = false;
			});
		});
		$(".ShowRotator-Pagination").removeClass("Selected");
		$("#ShowRotator-Pagination"+(onSlide)).addClass("Selected");
	}
}
function goToRotator(newSlide) {
	if (onSlide > newSlide) {
		goLeftRotator(newSlide);
	}else{
		goRightRotator(newSlide);
	}
}

