/*
** (c) 2010 rocket-media GmbH & Co KG
** www.rocket-media.de
*/
document.observe("dom:loaded", function(){
	$$("body")[0].addClassName("jsEnabled");

	bannerObj = new bannerClass();
	function recSlide(){
		 bannerObj.slide();
	}
	new PeriodicalExecuter(recSlide, 6.0);
});

var bannerClass = {};
bannerClass = Class.create();
bannerClass.prototype = {
	initialize: function(){
		this.options = Object.extend({
			container: "news1",
			wrapper: "items",
			item: "item",
			loop: true,
			height: "resize",
			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);

			var tmpMaxHeight = 0;

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

				if(this.options.height == "resize"){
					if(tmpMaxHeight < item.getHeight()){
						tmpMaxHeight = item.getHeight();
					}
				}

			}.bind(this));

			if(this.options.height == "resize"){
				$(this.options.container).down("."+this.options.wrapper).setStyle({"height": tmpMaxHeight+"px"});
				items.each(function(item, i){
					item.setStyle({"height": tmpMaxHeight+"px"});
				}.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();
					item.setOpacity(1.0);
					item.fade({ duration: 2.0 });
				}
				if(i == this.next){
					item.setStyle({
						"zIndex": 30
					});
					item.setOpacity(0.0);
					item.show();
					new Effect.Appear(item, {
						form: 0.0,
						to: 1.0,
						duration: 2.0
					});
				}
			}.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(){
	}
}
