var blankImg = 'images/ts.gif';


var Accordion = new Class({
	Implements: [Options, Events],
	
	initialize: function(params){
		this.body = params.body;
		this.displays = params.displays;
		this.links = params.links;
		this.events = params.events;
		this.direction = params.direction;

		this.current = null;
		
		this.log = params.log;
		this.temp = null;
		this.items = [];
		this.setup();
       },
       
		setup: function() {
			this.displays.each(
				function (item, key) {
					this.items[key] = new Hash({
							'id'  : key,
							'in'  : '1px',
							'out' : item.getStyle('height')
					});
					item.setStyle('height', this.items[key]['in']);
				}, this // binding to display divs
			); // end each
			this.initLinks();
		}, // end setup function
		
		initLinks: function () {
			this.links.each(
				function(link, counter) {
					link.addEvents({
						
						'click': function (event) {
							event.preventDefault();
							this.allin();
							this.walk(counter);
						}.bind(this),
						
						'mouseenter': function() {
							link.addClass('mov');
						}.bind(this),
						
						'mouseleave': function() {
							link.removeClass('mov');
						}.bind(this)
						
					})
				}, this
			);
		},
		
		walk: function (counter) {
			var goto = (this.displays[counter].getStyle('height') == this.items[counter]['in']) ? this.items[counter]['out'] : this.items[counter]['in'];
 			this.displays[counter].set('tween', { duration: 500 }).tween('height', goto);

			if (this.current == counter) {
				this.links[counter].removeClass('active');
			} else {
				this.links[counter].addClass('active');
				this.current = counter;
			}

		},

		allin: function() {
			var items = this.items;
			if (this.current != null) this.links[this.current].removeClass('active');
			this.displays.each(	
				function(item, index) { 
					item.set('tween', { duration: 500}).tween('height', items[index]['in']); 
				}.bind(this)
			);
		}
		
		
	}); // end class
 


window.addEvent('domready', function() {
});

window.addEvent('load', function() {

	$('loader').fade(0);

	if ($('startseite')!= null) {
		
		$$('img').set('alt', "");
		
		var items = $('startseite').getChildren('div');
		var from  = '-268px';
		var to    = '0px';
		
		var dropdown = function () {
			this.setStyle('position', 'relative');
			this.set('tween',{duration:2500, transition: Fx.Transitions.Elastic.easeOut, onComplete: function() { return this.status=true;}});
			this.tween('top', [from,to]);
		}

		items.each(
			function(item, index) {
				item.addEvents({ 
					'mouseenter': function(){
						if (item.getStyle('top') != to) return;
						item.set('tween', { duration: 500 }).tween('height', '160px');
						items.setStyle('opacity', 0.25);	
						item.setStyle('opacity', 1);
					},
					'mouseleave': function(){
						if (item.getStyle('top') != to) return;
						item.set('tween', { duration: 500 }).tween('height', '40px');
						items.setStyle('opacity', 1);	
					}
				});
				item.dropdown = dropdown.bind(item);
			}
		);
		
		items.each(
			function(item,index) {
				item.dropdown.delay(75*index);
			}
		);

	}

	if ($('accordion')!= null) {
		var accordion = new Accordion({
			body: $('accordion'),
			displays: $$('#accordion .display'),
			links: $$('#accordion h3'),
			events: 'click',
			direction: 'vertical',
			log: $('log')
		});
		
		$$('#accordion').setStyle('height', '368px');
//		accordion.walk(0)
	}




});

/*
window.addEvent('unload', function() {
	$('loader').fade(1);
});
*/

function createBookmark() {

	var title = document.title; 
	var url = "http://" + location.href;

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		alert('Druecken Sie die Tasten "Strg + D"');
	}
	else {
		alert('Druecken Sie die Tasten "Strg + D"');
	}
}

