window.addEvent('domready', function(){ 

	// JavaScript Effekt for Milkbox / Lightbox
	milkbox = new Milkbox();

	// Load PopupBox
	PopupBox = new PopupBox();

	// JavaScript Effect for Top Menu
	$$('#topmenu a').each(function(obj){

		obj.Fx = new Fx.Morph(obj, {duration: 500});

		if (obj.getParent().get('tag') == 'strong')
		{
			obj.Fx.set('.topmenu-nohover-current');
		} else {
			obj.Fx.set('.topmenu-nohover');
		}

		obj.addEvent('mouseenter', function(e) {
			e.stop()
			this.Fx.cancel();
			this.Fx.start('.topmenu-hover');
		}.bindWithEvent(obj));

		obj.addEvent('mouseleave', function(e) {
			e.stop()
			this.Fx.cancel();
			if (this.getParent().get('tag') == 'strong')
			{
				obj.Fx.start('.topmenu-nohover-current');
			} else {
				obj.Fx.start('.topmenu-nohover');
			}
		}.bindWithEvent(obj));

	});

	// JavaScript Effect for Left Menu
	$$('#mainmenu li a').each(function(obj){

		obj.Fx = new Fx.Morph(obj, {duration: 100});

		if (obj.getParent().hasClass('current'))
		{
			obj.Fx.set('.mainmenu-nohover-current');
		} else {
			obj.Fx.set('.mainmenu-nohover');
		}

		obj.addEvent('mouseenter', function(e) {
			e.stop()
			this.Fx.cancel();
			this.Fx.set('.mainmenu-hover');
		}.bindWithEvent(obj));

		obj.addEvent('mouseleave', function(e) {
			e.stop()
			this.Fx.cancel();
			if (this.getParent().hasClass('current'))
			{
				obj.Fx.start('.mainmenu-nohover-current');
			} else {
				obj.Fx.start('.mainmenu-nohover');
			}
		}.bindWithEvent(obj));

	});

	// Load Accordions for each class="accordion"
	$$('.fx-accordion', '.accordion').each(function (obj){
		var accordion_options = {
			alwaysHide: true,
			opacity: false,
			onActive: function(toggler, element){
				if (toggler.hasClass('no-toggler')) {
					obj.Accordion.Fx.cancel();
				} else {
					toggler.addClass('active');
				}
			},
			onBackground: function(toggler, element){
				toggler.removeClass('active');
			}			
		}
		
		if (obj.hasClass('fx-accordion-closed') || obj.hasClass('accordion-closed')) {
			accordion_options.show = -1;
		}
		obj.accordion = new Accordion(obj.getElements('.toggler'), obj.getElements('.element'), accordion_options);
	});

	// Load reduced list for each class="reduced-section"
	$$('.fx-reduced-section', '.reduced-section').each(function(obj){
		var maxHeight = 100;
		if (obj.getSize().y > maxHeight + 20)
		{
			obj.originalHeight = obj.getSize().y;
			obj.set('morph', {duration: 500});
			obj.setStyle('overflow','hidden');
			obj.reduced = true;
			obj.setStyle('height', maxHeight);

			obj.toggle = function() {
				if (this.reduced) {
					this.morph({height: this.originalHeight});
					this.reduced = false;
				} else {
					this.morph({height: maxHeight});
					this.reduced = true;
				}
				return this.reduced;
			}

			obj.reduceLink = new Element('a', {
				'href': '#',
				'html': 'more...',
				'events': {
					'click': function(ev) {
						ev.stop();
						if (this.toggle()) {
							this.reduceLink.set('html','more...');
						} else {
							this.reduceLink.set('html','fold up...');
						}
						return false;
					}.bindWithEvent(obj)
				}
			}).inject(obj, 'after');

		}

	});

	// Load reduced list for each class="reduced-section"
	$$('.fx-table-tabbed').each(function(obj){
		var tickettab;
		var showtab = "";
		var current = "";
		var countTabs = 0;
		var i = 0;
		downloadtabs = new Element('div', {});
		obj.getChildren().each(function(el){
			if (el.tagName == "TBODY")
			{
				i = 0;
				el.getChildren().each(function(el2)
				{
					if (el2.getElement('th') && !(el2.getElement('td')))
					{
						el2.style.display = 'none';
					} else {
						el2.removeClass("even");
						el2.removeClass("odd");
						if (++i%2==0) {
							el2.addClass("even");
						} else {
							el2.addClass("odd");
						}
						if (el2.getElement('a'))
						{
							el2.addEvent("mouseover", function(event) {
								el2.addClass("hover");
							});
							el2.addEvent("mouseout", function(event) {
								el2.removeClass("hover");
							});
							el2.addEvent("click", function(event) {
								location.href = el2.getElement('a').href;
								return false;
							});
						}
					}
				});
				if (showtab == "")
				{
					showtab = el.id;
				}
				thistab = new Element('span', {
					'events': {'click': function() {obj.switchTab(el.id);}},
					'class': 'tab',
					'id': 'tab-' + el.id
				});
				thistab.set('html',el.title + " (" + i + ")");
				countTabs++;
				thistab.inject(downloadtabs);
			}
		});

		obj.switchTab = function(c) {
 			this.getChildren().each(function(el){
				if (el.tagName == 'TBODY')
				{
					if (el.id == c)
					{
						el.style.display = '';
						$('tab-' + el.id).addClass('tab-current');
					}
					else
					{
						el.style.display = 'none';
						$('tab-' + el.id).removeClass('tab-current');
					}
				}
			});
		}.bind(obj);

		if (countTabs > 1) {
			downloadtabs.inject(obj,'before');
			obj.switchTab(showtab);
		}
	});

	// Load dropMenu
	$$('.fx-dropMenu').each(function(obj){
		obj.menu = new DropMenu(obj);
	});

	$$('.fx-fader').each(function(obj){
		obj.fader = new rs_fader(obj)
	});

	$$('.fx-fader-slow').each(function(obj){
		obj.fader = new rs_fader(obj, {speed: 10})
	});

});