// iCarousel is an open source (free) javascript tool for creating carousel like widgets. Copyright (c) 2007 Fabio Zendhi Nagao, http://zend.lojcomm.com.br/icarousel/, MIT Style License.
//eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1;};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p;}('q Z=C z({5:{7:{i:"1x",D:"18",s:1,r:13.12.1I.14,u:1K,l:{i:"1J",R:1X,1z:"G"}},j:{W:"j",p:1T},P:"1Y",S:"1H",T:"21",1d:z.H,1b:z.H,1F:z.H,1t:z.H,1A:z.H},1L:8(1i,1k){4.1N(1k);4.m=$(1i);4.9=$A($$("."+4.5.j.W));4.x=U;d(4.5.P!="10"&&$(4.5.P)){$(4.5.P).17("11",8(1o){C 1a(1o).G();4.1B();4.J("1d",4,20)}.h(4))}d(4.5.S!="10"&&$(4.5.S)){$(4.5.S).17("11",8(1g){C 1a(1g).G();4.15();4.J("1b",4,20)}.h(4))}d(4.5.T!="10"&&$(4.5.T)){$(4.5.T).17("11",8(1e){C 1a(1e).G();4.1r()}.h(4))}q w=4.5.7;K(4.5.7.i.N()){t"L":4.9.Y(8(E){E.e=E.19("B",{u:w.u,r:w.r});E.O("B",0);E.1l({"1n":8(){4.x=1m;d(4.5.7.l.i=="I"){4.v=$1h(4.v)}}.h(4),"1c":8(){4.x=U;d(4.5.7.l.i=="I"){4.v=4.V.X(4.5.7.l.R,4)}}.h(4)})}.h(4));4.y=4.m.1p("y").1q();4.6=0;4.o(4.6);k;M:(2).1R(8(){4.9.Y(8(1f){1f.1V().1U(4.m)}.h(4))}.h(4));4.9=$A($$("."+4.5.j.W));4.9.Y(8(1j){1j.1l({"1n":8(){4.x=1m;d(4.5.7.l.i=="I"){4.v=$1h(4.v)}}.h(4),"1c":8(){4.x=U;d(4.5.7.l.i=="I"){4.v=4.V.X(4.5.7.l.R,4)}}.h(4)})}.h(4));4.e=4.m.1S({u:w.u,r:w.r,1Z:U});4.6=4.9.g/3;4.m.O(w.D,-4.6*4.5.j.p);k}d(4.5.7.l.i=="I"){4.v=4.V.X(4.5.7.l.R,4)}},1P:8(n){K(4.5.7.i.N()){t"L":q 1D=4.6;4.6=1E.1C(n%(4.9.g/3));4.o(4.6,1D);k;M:4.6=1E.1C(n%(4.9.g/3));4.6+=4.9.g/3;4.o(4.6);k}4.J("1A",4,20)},1B:8(){K(4.5.7.i.N()){t"L":q 1G=4.6;4.6-=4.5.7.s;d(4.6<0){4.6=(4.9.g-1)}4.o(4.6,1G);k;M:4.6-=4.5.7.s;d(4.6<4.9.g/3){4.m.O(4.5.7.D,-4.5.j.p*4.9.g*2/3);4.6=4.9.g*2/3-4.5.7.s}4.o(4.6);k}4.J("1F",4,20)},15:8(){K(4.5.7.i.N()){t"L":q 1s=4.6;4.6+=4.5.7.s;d(4.6>=4.9.g){4.6=0}4.o(4.6,1s);k;M:4.6+=4.5.7.s;d(4.6>4.9.g*2/3){4.m.O(4.5.7.D,-4.5.j.p*4.9.g/3);4.6=4.9.g/3+4.5.7.s}4.o(4.6);k}4.J("1t",4,20)},1r:8(){(4.m.1p("y").1q()==0)?4.m.19("y",{u:1u,r:13.12.1y.14}).f(4.y):4.m.19("y",{u:1u,r:13.12.1y.14}).f(0)},V:8(){d(4.5.7.l.1z=="G"&&!4.x){4.15()}},o:8(a,b){K(4.5.7.i){t"L":d($1W(b)){4.9[b].e.f(0).F(8(){4.9[a].e.f(1)}.h(4))}16{4.9[a].e.f(1)}k;t"1Q":q c=4;d(c.5.7.D=="Q"){c.e.f({"Q":-a*c.5.j.p})}16{c.e.f({"18":-a*c.5.j.p})}k;t"1x":q c=4;d(c.5.7.D=="Q"){c.e.f({"B":0.1v}).F(8(){c.e.f({"Q":-a*c.5.j.p}).F(8(){c.e.f({"B":1})})})}16{c.e.f({"B":0.1v}).F(8(){c.e.f({"18":-a*c.5.j.p}).F(8(){c.e.f({"B":1})})})}k}}});Z.1w(C 1O);Z.1w(C 1M);',62,126,'||||this|options|atScreen|animation|function|aItems|||_10|if|fx|start|length|bind|type|item|break|rotate|container||_animate|size|var|transition|amount|case|duration|timer|_6|isMouseOver|height|Class||opacity|new|direction|_7|chain|stop|empty|auto|fireEvent|switch|fade|default|toLowerCase|setStyle|idPrevious|top|interval|idNext|idToggle|false|_autoRotate|klass|periodical|each|iCarousel|undefined|click|Transitions|Fx|easeInOut|_next|else|addEvent|left|effect|Event|onClickNext|mouseleave|onClickPrevious|_5|_8|_4|clear|_1|_9|_2|addEvents|true|mouseenter|_3|getStyle|toInt|_toggle|_d|onNext|1000|75|implement|fadeNscroll|Sine|onMouseOver|onGoTo|_previous|abs|_b|Math|onPrevious|_c|next|Cubic|manual|500|initialize|Options|setOptions|Events|goTo|scroll|times|effects|100|injectInside|clone|defined|5000|previous|wait||toggle'.split('|'),0,{}))
/* ************************************************************************************* *\
 * The MIT License
 * Copyright (c) 2007 Fabio Zendhi Nagao - http://zend.lojcomm.com.br
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this
 * software and associated documentation files (the "Software"), to deal in the Software
 * without restriction, including without limitation the rights to use, copy, modify,
 * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies
 * or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
\* ************************************************************************************* */

var iCarousel = new Class({
	options: {
		animation: {
			type: "fadeNscroll",// fadeNscroll, scroll, fade
			direction: "left",// if type = scroll, set: top || left
			amount: 1,// if type = scroll, set the amount to scroll
			transition: Fx.Transitions.Cubic.easeInOut,
			duration: 500,
			rotate: {
				type: "auto",// auto || manual
				interval: 5000,// if type = auto, set the interval (ms)
				onMouseOver: "stop"// if type = auto, set the onmouseover behavior: stop || proceed
			}
		},

		item: {
			klass: "item",
			size: 100
		},

		idPrevious: "previous",
		idNext: "next",
		idToggle: "toggle",

		onClickPrevious: Class.empty,
		onClickNext: Class.empty,
		onPrevious: Class.empty,
		onNext: Class.empty,
		onGoTo: Class.empty
	},

	initialize: function(container, options) {
		this.setOptions(options);
		this.container = $(container);
		this.aItems = $A($$('.'+ this.options.item.klass));
		this.isMouseOver = false;

		if(this.options.idPrevious != "undefined" && $(this.options.idPrevious))
			$(this.options.idPrevious).addEvent("click", function(event) {
				new Event(event).stop();
				this._previous();
				this.fireEvent("onClickPrevious", this, 20);
			}.bind(this));// check if value is not "undefined" before start search the dom with $()
		if(this.options.idNext != "undefined" && $(this.options.idNext))
			$(this.options.idNext).addEvent("click", function(event) {
				new Event(event).stop();
				this._next();
				this.fireEvent("onClickNext", this, 20);
			}.bind(this));
		if(this.options.idToggle != "undefined" && $(this.options.idToggle))
			$(this.options.idToggle).addEvent("click", function(event) {new Event(event).stop(); this._toggle()}.bind(this));

		var oAn = this.options.animation; // short hand
		switch(this.options.animation.type.toLowerCase()) {
			case "fade":
				this.aItems.each(function(item) {
					item.fx = item.effect("opacity", {duration: oAn.duration, transition: oAn.transition});
					item.setStyle("opacity", 0);
					item.addEvents({
						"mouseenter": function() {
							this.isMouseOver = true;
							if(this.options.animation.rotate.type == "auto") this.timer = $clear(this.timer);
						}.bind(this),
						"mouseleave": function() {
							this.isMouseOver = false;
							if(this.options.animation.rotate.type == "auto") this.timer = this._autoRotate.periodical(this.options.animation.rotate.interval, this);
						}.bind(this)
					});
				}.bind(this));
				this.height = this.container.getStyle("height").toInt();
				this.atScreen = 0;
				this._animate(this.atScreen);
				break;

			default:
				(2).times(function() {
					this.aItems.each(function(item) {
						item.clone().injectInside(this.container);
					}.bind(this));
				}.bind(this));
				this.aItems = $A($$('.'+ this.options.item.klass));
				this.aItems.each(function(item) {
					item.addEvents({
						"mouseenter": function() {
							this.isMouseOver = true;
							if(this.options.animation.rotate.type == "auto") this.timer = $clear(this.timer);
						}.bind(this),
						"mouseleave": function() {
							this.isMouseOver = false;
							if(this.options.animation.rotate.type == "auto") this.timer = this._autoRotate.periodical(this.options.animation.rotate.interval, this);
						}.bind(this)
					});
				}.bind(this));
				this.fx = this.container.effects({duration: oAn.duration, transition: oAn.transition, wait: false});
				this.atScreen = this.aItems.length / 3;
				this.container.setStyle(oAn.direction, - this.atScreen * this.options.item.size);
				break;
		}

		if(this.options.animation.rotate.type == "auto") this.timer = this._autoRotate.periodical(this.options.animation.rotate.interval, this);
	},

	goTo: function(n) {
		switch(this.options.animation.type.toLowerCase()) {
			case "fade":
				var lastIndex = this.atScreen;
				this.atScreen = Math.abs(n % (this.aItems.length / 3));
				this._animate(this.atScreen, lastIndex);
				break;

			default:
				this.atScreen = Math.abs(n % (this.aItems.length / 3));
				this.atScreen += this.aItems.length / 3;
				this._animate(this.atScreen);
				break;
		}

		this.fireEvent("onGoTo", this, 20);
	},

	_previous: function() {
		switch(this.options.animation.type.toLowerCase()) {
			case "fade":
				var lastIndex = this.atScreen;
				this.atScreen -= this.options.animation.amount;
				if(this.atScreen < 0) this.atScreen = (this.aItems.length - 1);
				this._animate(this.atScreen, lastIndex);
				break;

			default:
				this.atScreen -= this.options.animation.amount;
				if(this.atScreen < this.aItems.length / 3) {
					this.container.setStyle(this.options.animation.direction, - this.options.item.size * this.aItems.length * 2 / 3);
					this.atScreen = this.aItems.length * 2 / 3 - this.options.animation.amount;
				}
				this._animate(this.atScreen);
				break;
		}

		this.fireEvent("onPrevious", this, 20);
	},

	_next: function() {
		switch(this.options.animation.type.toLowerCase()) {
			case "fade":
				var lastIndex = this.atScreen;
				this.atScreen += this.options.animation.amount;
				if(this.atScreen >= this.aItems.length) this.atScreen = 0;
				this._animate(this.atScreen, lastIndex);
				break;

			default:
				this.atScreen += this.options.animation.amount;
				if(this.atScreen > this.aItems.length * 2 / 3) {
					this.container.setStyle(this.options.animation.direction, - this.options.item.size * this.aItems.length / 3);
					this.atScreen = this.aItems.length / 3 + this.options.animation.amount;
				}
				this._animate(this.atScreen);
				break;
		}

		this.fireEvent("onNext", this, 20);
	},

	_toggle: function() {
		(this.container.getStyle("height").toInt() == 0) ?
			this.container.effect("height", { duration:1000, transition: Fx.Transitions.Sine.easeInOut }).start(this.height):
			this.container.effect("height", { duration:1000, transition: Fx.Transitions.Sine.easeInOut }).start(0);
	},

	_autoRotate: function() {
		if(this.options.animation.rotate.onMouseOver == "stop" && !this.isMouseOver) this._next();
	},

	_animate: function(a, b) {
		switch(this.options.animation.type) {
			case "fade":
				if($defined(b)) {
					this.aItems[b].fx.start(0).chain(function() {
					this.aItems[a].fx.start(1);}.bind(this));
				} else {
					this.aItems[a].fx.start(1);
				}
				break;

			case "scroll":
				var that = this;
				if(that.options.animation.direction == "top") {
					that.fx.start({"top" : - a * that.options.item.size});
				} else {
					that.fx.start({"left" : - a * that.options.item.size});
				}
				break;

			case "fadeNscroll":
				var that = this;
				if(that.options.animation.direction == "top") {
					that.fx.start({"opacity":0.75}).chain(function() {
						that.fx.start({"top" : - a * that.options.item.size}).chain(function() {
							that.fx.start({"opacity": 1});
						});
					});
				} else {
					that.fx.start({"opacity":0.75}).chain(function() {
						that.fx.start({"left" : - a * that.options.item.size}).chain(function() {
							that.fx.start({"opacity": 1});
						});
					});
				}
				break;
		}
	}
});
iCarousel.implement(new Events); // Implements addEvent(type, fn), fireEvent(type, [args], delay) and removeEvent(type, fn)
iCarousel.implement(new Options);// Implements setOptions(defaults, options)

