/**
 * base JavaScript for Kotex.com
 * requires: jquery.js
 */

// namespace
var KC = {
	debug: false,
	isIE: $.browser.msie,
	isIE6: ($.browser.msie && $.browser.version < 7)
};

// animation classes

			
KC.Carousel = (function () {
	var $c, $s, $d, current = 0, last = 0, timer = null, stopped = false, that;
	return {
		init: function (c) {
			that = this;
			$c = $(c);
			if (!$c.size()) {
				return false;
			}
			$s = $c.find(".slide").css({opacity: 0, zIndex: 1});
			$d = $c.find(".direct");
			$c.hover(function () {
					that.pause();
				}, 
				function () {
					that.play();
				}
			);

			$d.mouseover(function () {
				that.pause();
				stopped = true;
				that.gotoframe($d.index(this));
				this.blur();
				return false;
			});
			last = $s.size() - 1;
			this.show();
			this.play();
		},
		
		show: function () {
			$s.eq(current).css({zIndex: 2}).fadeTo(1000, 0.99, function () { // 0.99 opacity avoids a strange text shift in FF2
				if (KC.isIE) {
					this.style.removeAttribute('filter');
				}
			});
			$c.find(".direct").removeClass("on").eq(current).addClass("on");	
		},
		
		hide: function () {
			$s.eq(current).fadeTo(500, 0).css({zIndex: 1});
		},
		
		pause: function () {
			window.clearInterval(timer);
		},
		
		play: function () {
			if (!stopped) {
				window.clearInterval(timer);
				timer = window.setInterval(that.next, 6000);
			}
		},
		
		gotoframe: function (i) {
			that.hide();
			current = i;
			that.show();
		},
		
		next: function () {
			that.hide();
			current = (current < last) ? current + 1 : 0;
			that.show();
		},
		
		previous: function () {
			that.hide();
			current = (current > 0) ? current - 1 : last;
			that.show();
		}
	};
}) (); // self-invoking!


