$.productRotator = function(options) {
	
	var defaults = {
		id: "#rotator > ul",
		controller: "#rotator_controller a",
		photoboxId: "#photobox",
		useImage: true,
		buttonSelect: true
	};
	var options = $.extend(defaults, options);
	var on = true;
	
	function initRotator() {
		$(options.id).tabs({fx:{opacity: "toggle"}}).tabs("rotate", 9000, options.buttonSelect);
		
		$(options.photoboxId+"1 img").click(function() {
			if(this.id == "one") {
				$(options.photoboxId+"1 #one").css("z-index", "2");
				$(options.photoboxId+"1 #two").css("z-index", "1");
				$(options.photoboxId+"1 #three").css("z-index", "0");
			} else if(this.id == "two") {
				$(options.photoboxId+"1 #one").css("z-index", "1");
				$(options.photoboxId+"1 #two").css("z-index", "2");
				$(options.photoboxId+"1 #three").css("z-index", "0");
			} else if(this.id == "three") {
				$(options.photoboxId+"1 #one").css("z-index", "0");
				$(options.photoboxId+"1 #two").css("z-index", "1");
				$(options.photoboxId+"1 #three").css("z-index", "2");
			}
			
			$(options.id).tabs("rotate", null, options.buttonSelect);
			$(options.controller).html("<img src='http://www.barry-wehmiller.com/custom/bwc/Accraply/css/images/play.png' title='Start Slideshow' />");
			$(options.controller).unbind("toggle").toggle(stop, start);
		});
		
		$(options.photoboxId+"2 img").click(function() {
			if(this.id == "four") {
				$(options.photoboxId+"2 #four").css("z-index", "2");
				$(options.photoboxId+"2 #five").css("z-index", "1");
				$(options.photoboxId+"2 #six").css("z-index", "0");
			} else if(this.id == "five") {
				$(options.photoboxId+"2 #four").css("z-index", "1");
				$(options.photoboxId+"2 #five").css("z-index", "2");
				$(options.photoboxId+"2 #six").css("z-index", "0");
			} else if(this.id == "six") {
				$(options.photoboxId+"2 #four").css("z-index", "0");
				$(options.photoboxId+"2 #five").css("z-index", "1");
				$(options.photoboxId+"2 #six").css("z-index", "2");
			}
			
			$(options.id).tabs("rotate", null, options.buttonSelect);
			$(options.controller).html("<img src='http://www.barry-wehmiller.com/custom/bwc/Accraply/css/images/play.png' title='Start Slideshow' />");
			$(options.controller).unbind("toggle").toggle(stop, start);
		});
		
		$(options.photoboxId+"3 img").click(function() {
			if(this.id == "seven") {
				$(options.photoboxId+"3 #seven").css("z-index", "2");
				$(options.photoboxId+"3 #eight").css("z-index", "1");
				$(options.photoboxId+"3 #nine").css("z-index", "0");
			} else if(this.id == "eight") {
				$(options.photoboxId+"3 #seven").css("z-index", "1");
				$(options.photoboxId+"3 #eight").css("z-index", "2");
				$(options.photoboxId+"3 #nine").css("z-index", "0");
			} else if(this.id == "nine") {
				$(options.photoboxId+"3 #seven").css("z-index", "0");
				$(options.photoboxId+"3 #eight").css("z-index", "1");
				$(options.photoboxId+"3 #nine").css("z-index", "2");
			}
			
			$(options.id).tabs("rotate", null, options.buttonSelect);
			$(options.controller).html("<img src='http://www.barry-wehmiller.com/custom/bwc/Accraply/css/images/play.png' title='Start Slideshow' />");
			$(options.controller).unbind("toggle").toggle(stop, start);
		});
		
		$(options.controller).css("display", "block");
		
		/* This does not work */
		$(".ui-tabs-nav-item a").click(function() {
			if(on) {
				/* Stop the slideshow. */
				$(options.controller).html("<img src='http://www.barry-wehmiller.com/custom/bwc/Accraply/css/images/play.png' title='Start Slideshow' />");
				$(options.id).tabs("rotate", null, options.buttonSelect);
				$(options.controller).unbind("toggle").toggle(stop, start);
				on = false;
			}
		});
		
		var start = function(eventObj) {
			$(this).html("<img src='http://www.barry-wehmiller.com/custom/bwc/Accraply/css/images/play.png' title='Start Slideshow' />");
			$(options.id).tabs("rotate", null, options.buttonSelect);
			on = false;
		};
		
		var stop = function(eventObj) {
			$(this).html("<img src='http://www.barry-wehmiller.com/custom/bwc/Accraply/css/images/stop.png' title='Stop Slideshow' />");
			var selected = $(options.id).tabs().data("selected.tabs");
			var length = $(options.id).tabs("length");
			if(selected == (length-1)) {
				$(options.id).tabs({fx:{opacity: "toggle"}}).tabs("select", 0);
			} else {
				$(options.id).tabs({fx:{opacity: "toggle"}}).tabs("select", selected+1);
			}
			$(options.id).tabs("rotate", 9000, options.buttonSelect);
			on = true;
		};
		
		$(options.controller).toggle(start, stop);
		
	};
	
	initRotator();
	
};