/*
** (c) 2010 rocket-media GmbH & Co KG
** www.rocket-media.de
*/
function initBanner(){
	bannerObj = new bannerClass();
	function recSlide(){
		 bannerObj.slide();
	}
	new PeriodicalExecuter(recSlide, 3);
}

var bannerClass = {};
bannerClass = Class.create();
bannerClass.prototype = {
	initialize: function(){
		this.options = Object.extend({
			container: "banner",
			item: "item",
			loop: true,
			none: true
        }, arguments[0] || { });

		this.hold = false;
		this.mark = 0;
		this.setup();
	},

	setup: function(){
		if($(this.options.container) && $(this.options.container).select("."+this.options.item).length > 1){
			items = $(this.options.container).select("."+this.options.item);

			items.each(function(item, i){
				item.setStyle({
					"zIndex": 10
				});
				item.hide();
				if(i == this.mark){
					item.setStyle({
						"zIndex": 20
					});
					item.show();
				}
			}.bind(this));
		}

		this.domInspect();
	},

	domInspect: function(){
		this.onEnterEvent = this.onEnter.bindAsEventListener(this);
		this.onLeaveEvent = this.onLeave.bindAsEventListener(this);

 		if($(this.options.container) && $(this.options.container).select("."+this.options.item).length > 1){
			items = $(this.options.container).select("."+this.options.item);
			items.each(function(item){
				Event.observe(item, "mouseover", this.onEnterEvent);
				Event.observe(item, "mouseout", this.onLeaveEvent);
			}.bind(this));
		}
	},

	slide: function(){
		if(this.hold) return;
 		if($(this.options.container) && $(this.options.container).select("."+this.options.item).length > 1){
			items = $(this.options.container).select("."+this.options.item);

			this.next = this.mark + 1;
			if(!items[this.next]){
				if(!this.options.loop)
					return;

				this.next = 0;
			}

			items.each(function(item, i){
				item.setStyle({
					"zIndex": 10
				});
				item.hide();
				if(i == this.mark){
					item.setStyle({
						"zIndex": 20
					});
					item.show();
				}
				if(i == this.next){
					item.setStyle({
						"zIndex": 30,
						"left": "265px"
					});
					item.show();
					/*new Effect.Appear(item, {
						form: 0.0,
						to: 1.0,
						duration: 2.0
					});*/
					new Effect.Move(item, {
						x: -205,
						y: 0,
						duration: 0.35,
						transition: Effect.Transitions.linear,
						afterFinish: function(effect){
							new Effect.Move(effect.element, {
								x: -60,
								y: 0,
								duration: 1.00,
								transition: Effect.Transitions.spring
							});
						}
					});
				}
			}.bind(this));

			this.mark = this.next;
		}else{
			//if($(this.options.container))
				//$(this.options.container).hide();
		}
	},

	onEnter: function(){
		this.hold = true;
	},

	onLeave: function(){
		this.hold = false;
	},

	none: function(){
	}
}
