/* Rosetta Starter Store Javascript by Cameron Wardzala */
var Store = Store || {};
Store.Utils = Store.Utils || {};

Store.Utils.LargeRotator = function() {
	
	var currI = 0;
	var current = "#"+jq('.promo').eq(currI).attr("id");
	var rotItems = jq(".rotator-controls").find("li").length-2;
	var intervalTime = 5000;
	// commenting lines below for switching on auto rotate - MS 08/20
	//var t;// = setInterval("Store.Utils.AutoRotate("+currI+")", intervalTime);
	//var pause = true;
	
	// adding lines below for switching on autorotate - MS 08/20
	var t=setInterval("Store.Utils.AutoRotate("+currI+")", intervalTime);
	var pause = false;
	
	if (pause === true) {
		jq(".rotator-controls").find(".pause").hide();
	} else {jq(".rotator-controls").find(".play").hide();}
	
	jq(".promo").not(":eq("+currI+")").hide();
	jq(".rotator-controls li").eq(currI).addClass("active");
	
	jq(".rotator-controls").find("li a").click(function(){
		clearInterval(t);
		if (jq(this).parents("li").hasClass("active")) {return false;}
		jq(".rotator-controls").find(".active").removeClass("active");
		jq(this).parents("li").addClass("active");
		var thrf = jq(this).attr("href");
		Store.Utils.LargeRotator.Rotate(thrf);
		currI = jq(".rotator-controls").find("li a").index(jq(this));
		if (pause === false){
			t = setInterval("Store.Utils.AutoRotate("+currI+")", intervalTime);
		}
		return false;
	});
	
	jq(".rotator-controls").find(".play").click(function(){
		jq(this).hide();
		jq(".rotator-controls").find(".pause").show();
		t = setInterval("Store.Utils.AutoRotate("+currI+")", intervalTime);
		pause = false;
	});
	
	jq(".rotator-controls").find(".pause").click(function(){
		jq(this).hide();
		jq(".rotator-controls").find(".play").show();
		clearInterval(t);
		pause = true;
		
	});
	
	Store.Utils.AutoRotate = function(l){
		if (rotItems > 1 && pause === false){
			if ((currI+1) >= rotItems){currI = 0;} else {currI++;}

			var next = jq(".rotator-controls").find("li a").eq(currI).attr('href');
			Store.Utils.LargeRotator.Rotate(next);
			jq(".rotator-controls").find(".active").removeClass("active");
			jq(".rotator-controls").find("li").eq(currI).addClass("active");
		} else {return;}
	};
	
	Store.Utils.LargeRotator.Rotate = function(file){
		jq(current).hide();
		jq(file).fadeIn();
		jq(file).css({"display": "block", "top":0, "left": 0, "position": "relative"});
		current = file;
	};
};

jq(document).ready(function(){
	Store.Utils.LargeRotator();
});