var colheights = function() {
	
	var height_r = $E('#container_main .rechts').getSize();
	var height_l = $E('#container_main .links').getSize();

	if (height_r.size.y > height_l.size.y) {
		$E('#container_main .links').setStyle('min-height', height_r.size.y);
	}

	else {
		$E('#container_main .rechts').setStyle('min-height', height_l.size.y);
	}
	

}

var Site = function() {
	
	$$('a.external').addEvent('click', function(e) {
	e = new Event(e);
	if (e.alt || e.control || e.shift) return;
	var win = window.open(this.href, '_blank');
	if (win) {
	win.focus();
	e.stop();
	}
	});
	
	
	
	if ($E('.ajax_load')) {
		ajax_reload();
	}
	colheights();
	
	if ($('myGallery')) { 
		startGallery(); 
		if($E('.rechts a').hasClass('open')) {
			Lightbox.init();
		}
	}
	


	var links_navi = $$('#accordion a');
	var togglers = $$('.toggler');
	var stretcher = $$('.stretcher');
	
	var accordion = new Accordion(togglers, stretcher, {
		opacity: false,
		alwaysHide: true,
	
		onActive: function(toggler, el){
			toggler.setStyle('color', '#ffffff');
			toggler.setStyle('background', '#B9122B');
		},
		onBackground: function(toggler, el){
			toggler.setStyle('color', '#ffffff');
			toggler.setStyle('background', '#222222');
		},
		onComplete: function() { 
			var el = $(this.elements[this.previous]);
			if (el.offsetHeight > 0) el.setStyle('height', '');
		}
	});
	
	
	if ($('.toggler2')) {
		var togglers2 = $$('.toggler2');
		var stretcher2 = $$('.stretcher2');
		var accordion2 = new Accordion(togglers2, stretcher2, {
		opacity: false,
		alwaysHide: true,
		
		onActive: function(toggler2, el2){
			//toggler2.setStyle('color', '#ffffff');
			//toggler2.setStyle('background', '#B9122B');
		},
		onBackground: function(toggler2, el2){
			//toggler2.setStyle('color', '#ffffff');
			//toggler2.setStyle('background', '#222222');
		},
		onComplete: function() { 
			var el2 = $(this.elements[this.previous]);
			if (el2.offsetHeight > 0) el.setStyle('height', '');
		}
		});
	}
	
	var links_navi = $$('a');
	
	links_navi.each(function(element) {

		element.addEvent('click',function(evt) {
			
			evt.stop();
			
			var content = $E('#container_main .rechts');
			var content2 = $E('#top');
			content.setStyle('visibility', 'hidden');
			content2.setStyle('visibility', 'hidden');

			element.ajax = new Ajax(element.href, {
				
				method: 'get',
				evalScripts: true,

				onRequest: function(resp) {
					content.setHTML('');
					content.addClass('ajax-loading');
					content2.setHTML('');
					content2.addClass('ajax-loading');
				},


				onComplete: function(resp) {

					element.ajax = null;
					
					var antwort = resp.split("<!--SPLIT-->");

					content.removeClass('ajax-loading');
					content2.removeClass('ajax-loading');

					content.setHTML(antwort[1]);
					content.effect('opacity', {
						duration: 800
					}).start( 0, 1);

					
					content2.setHTML(antwort[0]);
					content2.effect('opacity', {
						duration: 800
					}).start( 0, 1);

					if ($('myGallery')) {
						startGallery();
						
						if($E('.rechts a').hasClass('open')) {
							Lightbox.init();
						}
						
					}

					if ($E('.ajax_load')) {
						ajax_reload(); // fuer ajax nachladen in artikel listen
						$E('#container_main .rechts').setStyle('visibility', 'visible');
						
					}
					
					$$('a.external').addEvent('click', function(e) {
					e = new Event(e);
					if (e.alt || e.control || e.shift) return;
					var win = window.open(this.href, '_blank');
					if (win) {
					win.focus();
					e.stop();
					}
					});
					colheights();
					
					var form = $('Contact');
					if (form) { sendform(); }
					
					
				
				}.bind(element)
				
				
			}).request();

		}.bindWithEvent(element));
	});
	
window.addEvent('load', colheights);

} 
window.addEvent('domready', Site);

