function emCarousel(c_id, cn_id, interval) {
	this.carousel   = document.getElementById(c_id)
	this.navigation = document.getElementById(cn_id)
	this.interval   = interval;
	if (this.carousel && this.navigation) {
		this.init();
		this.timer();
	}
}

emCarousel.prototype = {
	init : function() {
		this.items    = this.carousel.getElementsByTagName('LI');
		this.anchors  = this.navigation.getElementsByTagName('A');
		this.width    = this.items[0].clientWidth;
		this.item_ord = 1;
		this.dir      = -1; 
		this.length   = this.items.length;
		this.pause    = false;
		for (var i = 0; i < this.length; i++) {
			this.anchors[i].ord = i;
			YAHOO.util.Event.addListener(this.anchors[i], 'click', this.animateTo, this, true);
		}
		YAHOO.util.Event.addListener(this.carousel, 'mouseover', this.stop, this, true);
		YAHOO.util.Event.addListener(this.carousel, 'mouseout',  this.restart, this, true);
	},

	restart : function(e) {
		if (!YAHOO.util.Dom.isAncestor(this.carousel.parentNode, YAHOO.util.Event.getRelatedTarget(e))) {
			this.pause = false;
			this.timer();
		}
	},

	stop : function(e) {
		clearTimeout(this.timeout);
		if (this.anim) {
			this.pause = true;
			this.anim.stop(true);
		}
	},

	timer : function() {
		var c         = this;
		this.timeout  = setTimeout(function() {c.animate();}, this.interval)
	},

	start : function() {
		if (!this.pause) {
			if (this.item_ord - this.dir < 0) {
				this.dir = -1;
			}
			if (this.item_ord - this.dir == this.length) {
				this.dir = 1;
			}
			this.item_ord = this.item_ord - this.dir;
			this.timer();
		}
	},

	animate : function() {
		for (var i = 0; i < this.length; i++) {
			YAHOO.util.Dom.removeClass(this.anchors[i], 'active');
		}
		YAHOO.util.Dom.addClass(this.anchors[this.item_ord], 'active');
		var to    = (this.width * (-this.item_ord));
		this.anim = new YAHOO.util.Anim(this.carousel, {left: {to: to}}, 1, YAHOO.util.Easing.easeOut);
		this.anim.onComplete.subscribe(this.start, this, true); 
		this.anim.animate();
	},

	animateTo : function(e) {
		if (!this.anim || (this.anim && !this.anim.isAnimated())) {
			var anchor = YAHOO.util.Dom.getAncestorByTagName(YAHOO.util.Event.getTarget(e, true), 'A');
			this.item_ord = anchor.ord;
			clearTimeout(this.timeout);
			this.animate();
		}
		YAHOO.util.Event.stopEvent(e);
	}
}