//	==	spotlight.js	==
;(function($) {
	$.fn.extend({
		spotlightF: function(options) {
			return this.each(function() {
				new $.mySpotlight(this, options);
			});
		}
	});
	$.mySpotlight = function(element, options) {
		var defaults = {
			startIndx: 0
		};
		this.options = $.extend({}, defaults, options || {});
		this.element = $(element);
		this.len = $(element).find(".rotator_info_unit").length;
		this.lastIndx = this.len - 1;
		this.rtrIndx = this.options.startIndx;
		this.controller = '<div class="rotate_control row"><ul class="counter"><li class="arrow" vector="-1"></li><li class="rtr_indx">'+this.rtrIndx+'</li><li>of</li><li class="rtr_len">'+this.len+'</li><li class="arrow rt" vector="1"></li></ul></div>';
		this.setup();
	};
	$.extend($.mySpotlight.prototype, {
		setup: function() {
			$rotatorObj = this.element;
			$rotatorObj.find(".rotator_info").after(this.controller);
			var self = this;
			$rotatorObj.find(".rotate_control .arrow").css("cursor", "pointer").bind("click", function(){
				self.rotate($(this).attr("vector"));
			});
			$rotatorObj.find(".rotator_info_unit").eq(this.rtrIndx).show();
			$rotatorObj.find(".rtr_indx").html(this.rtrIndx+1);
			$rotatorObj.find(".rotator img").each(function(i){
				$(this).css({ width:spotlight[i].w, height:spotlight[i].h, left:spotlight[i].l, top:spotlight[i].t, zIndex:spotlight[i].z });
			});
			$rotatorObj.find(".prods img").css("opacity", 0);
			$rotatorObj.find(".prods img").eq(this.rtrIndx).css("opacity", 1).show();
		},
		rotate: function(dir) {
			var self = this;
			$rotatorObj = this.element;
			$rotatorObj.find(".rotate_control .arrow").css("cursor", "default").unbind( "click" );
			if (dir > 0) {
				$rotatorObj.find(".rotator img").eq(0).appendTo(".rotator");
				$rotatorObj.find(".prods img").eq(0).appendTo(".prods");
				$rotatorObj.find(".rotator img").each(function(i){
					if (i == 5) {
						$rotatorObj.find(".prods img").eq(5).animate(
							{left: "-=40px", opacity: 0},
							200
						);
						$(this).animate(
							{left: "-=40px"},
							200,
							//"swing",
							function(){
								$(this).css("z-index", spotlight[3].z);
							}
						).animate(
							{width: spotlight[1].w, height: spotlight[1].h, top: spotlight[1].t},
							150,
							"linear",
							function(){
							}
						).animate(
							{
								width: spotlight[4].w,
								height: spotlight[4].h,
								top: spotlight[4].t,
								left: spotlight[4].l
							},
							400,
							"swing",
							function(){
								self.stopRotate();
							}
						);
					} else {
						$(this).animate(
							{ 
								width: spotlight[i].w,
								height: spotlight[i].h,
								left: spotlight[i].l,
								top: spotlight[i].t
							},
							300*(i*0.4+1),
							"swing",
							function(){
								self.stopRotate(true);
							}
						)
						.css("z-index", spotlight[i].z);
					}
				});
			} else {	// reverse
				$rotatorObj.find(".rotator img").eq(this.lastIndx).prependTo(".rotator");
				$rotatorObj.find(".prods img").eq(this.lastIndx).prependTo(".prods");
				$rotatorObj.find(".rotator img").each(function(i){
					if (i == 0) {
						$rotatorObj.find(".prods img:visible").fadeTo(100, 0, function(){
							$(this).hide();
						});
						$(this).animate(
							{
								width: spotlight[3].w,
								height: spotlight[3].h,
								top: spotlight[3].t,
								left: "-40px"
							},
							250,
							"swing"
						).animate(
							{
								width: spotlight[0].w,
								height: spotlight[0].h,
								top: spotlight[0].t
							},
							100,
							"linear",
							function(){
								$(this).css("z-index", spotlight[0].z);
							}
						).animate(
							{left: spotlight[0].l},
							100,
							"linear",
							function(){
								self.stopRotate();
							}
						);
					} else {
						$(this).animate(
							{ 
								width: spotlight[i].w,
								height: spotlight[i].h,
								left: spotlight[i].l,
								top: spotlight[i].t
							},
							300*(i*0.4+1),
							"swing"
						)
						.css("z-index", spotlight[i].z);
					}
				});
			}
			$rotatorObj.find(".rotator_info_unit").eq(this.rtrIndx).hide();
			this.rtrIndx += parseInt(dir);
			if (this.rtrIndx >= this.len) {this.rtrIndx = 0;}
			if (this.rtrIndx < 0) {this.rtrIndx = this.lastIndx;}
			$rotatorObj.find(".rtr_indx").html(this.rtrIndx+1);
			$rotatorObj.find(".rotator_info_unit").eq(this.rtrIndx).show();
		},
		stopRotate: function(norebind) {
			if (!norebind) {
				var self = this;
				$rotatorObj.find(".rotate_control .arrow").css("cursor", "pointer").bind("click", function(){
					self.rotate($(this).attr("vector"));
				});
			}
			$rotatorObj.find(".prods img").eq(0).css("left", "52px").show().fadeTo(100, 1);
		}
	});
})(jQuery);

