/* classes */
var ZebraTables = new Class({
	//initialization
	initialize: function(table_class) {

		//add table shading
		$$('table.' + table_class + ' tr').each(function(el,i) {

			//do regular shading
			var _class = i % 2 ? 'even' : 'odd'; el.addClass(_class);

			//do mouseover
			el.addEvent('mouseenter',function() { if(!el.hasClass('highlight')) { el.addClass('mo').removeClass(_class); } });

			//do mouseout
			el.addEvent('mouseleave',function() { if(!el.hasClass('highlight')) { el.removeClass('mo').addClass(_class); } });

			//do click
			el.addEvent('click',function() {
				//click off
				if(el.hasClass('highlight'))
				{
					el.removeClass('highlight').addClass(_class);
				}
				//click on
				else
				{
					el.removeClass(_class).removeClass('mo').addClass('highlight');
				}
			});

		});
	}
});


function fixPNG(myImage) 
{
	try {
		var arVersion = navigator.appVersion.split("MSIE");
		var version = parseFloat(arVersion[1]);
		if ((version >= 5.5) && (version < 7) && (document.body.filters)){
			myImage = $(myImage);
			var vis = myImage.getStyle('display') != 'none';
			if(!vis) myImage.setStyle('display','block');
			var width = $(myImage).offsetWidth;
			var height = $(myImage).offsetHeight;
			if(!vis) myImage.hide();
			var replacement = new Element('span', {
				id:(myImage.id)?myImage.id:'',
				'class':(myImage.className)?myImage.className:'',
				title:(myImage.title)?myImage.title:(myImage.alt)?myImage.alt:'',
				styles: {
					display: 'inline-block',
					width: width,
					height: height,
					filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader (src='" 
						+ myImage.src + "', sizingMethod='scale');"
				}
			});
			if(myImage.style.cssText) {
				try {
					var styles = {};
					var s = myImage.style.cssText.split(';');
					s.each(function(style){
						var n = style.split(':');
						styles[n[0]] = n[1];
					});
					replacement.setStyle(styles);
				} catch(e){}
			}
			if(replacement.cloneEvents) replacement.cloneEvents(myImage);
			myImage.replaceWith(replacement);
		}
	} catch(e) {}
};



var so = new SWFObject("../a_sponsor.swf", "mymovie", "160", "160", "7", "#001620");   
var slideshow = new SWFObject("../slideshow540_240.swf", "slideshow", "537", "237", "7", "#001620");

//var horus = new SWFObject("../palma2009/200_185_2.swf", "horus", "200", "185", "7", "#001620");


var myGallery;


function startGallery() {
	

		
		/* MEDIA GALERY */
		myGallery = new gallery($('myGallery'), {
		timed: 	false,
		embedLinks: false,
		showCarousel: true,
		showArrows: true,
		showInfopane:true,
		delay: 4000,
		fadeDuration: 500,
		preloader: false,
		destroyAfterPopulate: true
		});
		

}


var checkHeight =	function() {

	var height = 0;

	divs = $$('#col1','#col2','#col3');

	divs.each( function(e){
	 if (e.offsetHeight > height){
	  height = e.offsetHeight;
	 }
	});

	divs.each( function(e){
	 e.setStyle( 'height', height + 'px' );
	

	 if (e.offsetHeight > height) {
	  e.setStyle( 'height', (height - (e.offsetHeight - height)) + 'px' );
	 }
	}); 

	}
	


var siteInit = function() {




var myTips = new Tips($$('.Tips'), {
		maxTitleChars: 300,
		opacity: 0.5
	});



if($('NewsTicker')) {
	
	
	var Ticker = new Class({
		setOptions: function(options) {
			this.options = Object.extend({
				speed: 5000,
				delay: 5000,
				direction: 'vertical',
				onComplete: Class.empty,
				onStart: Class.empty
			}, options || {});
		},
		initialize: function(el,options){
			this.setOptions(options);
			this.el = $(el);
			this.items = this.el.getElements('li');
			var w = 0;
			var h = 0;
			if(this.options.direction.toLowerCase()=='horizontal') {
				h = this.el.getSize().size.y;
				this.items.each(function(li,index) {
					w += li.getSize().size.x;
				});
			} else {
				w = this.el.getSize().size.x;
				this.items.each(function(li,index) {
					h += li.getSize().size.y;
				});
			}
			this.el.setStyles({
				position: 'absolute',
				top: 0,
				left: 0,
				width: w,
				height: h
			});
			this.fx = new Fx.Styles(this.el,{duration:this.options.speed,onComplete:function() {
				var i = (this.current==0)?this.items.length:this.current;
				this.items[i-1].injectInside(this.el);
				this.el.setStyles({
					left:0,
					top:0
				});
			}.bind(this)});
			this.current = 0;
			this.next();
		},
		next: function() {
			this.current++;
			if (this.current >= this.items.length) this.current = 0;
			var pos = this.items[this.current];
			this.fx.start({
				top: -pos.offsetTop,
				left: -pos.offsetLeft
			});
			this.next.bind(this).delay(this.options.delay+this.options.speed);
		}
	});

	var hor = new Ticker('TickerVertical',{speed:400,delay:4000,direction:'horizontal'});
	
}

	$$('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();
		}
	});



	/* SPONSOR RIGHT */
   so.addVariable("id", "49"); 
   so.wmode="transparent"; 
   so.write("flashcontent");

    slideshow.wmode="transparent"; 
    slideshow.addVariable("id", "31"); 
    slideshow.write("flashcontent2");

		/*
    horus.wmode="transparent"; 
    horus.write("palma2010");
		*/

	$ES('.lightbox').each(function(el) {
		el.removeClass('lightbox');
		el.addEvent('click', function(e) {
			if (SqueezeBox.click(el)) e.stop();
		}.bindWithEvent(el));
	});




var newsnav = $$('.single_news a');

		if (newsnav)	{
			
			newsnav.each(function(item, i) {
				
				
				
					item.getParent().addEvent('click', function(evt){
						
						evt.stop();
						
						var content = $('news');
						content.setStyle('height', content.scrollHeight + 'px').setHTML('');
						
						this.ajax = new Ajax (this.href, {
							
							method: 'get',
							
								onRequest: function(resp) {
									content.addClass('ajax-loading');	
								},
								onComplete: function(resp) {
										content.removeClass('ajax-loading');
										this.ajax = null;
										content.setStyles({'visibility': 'hidden', 'height': ''}); 
										content.effect('opacity', {duration: 2000}).start(-0.01, 0.99);
										content.setHTML(resp);
										Cufon.replace('h1');
										Cufon.replace('h2');
										Cufon.replace('h3');
								}.bind(item)
							
						}).request();

					}.bindWithEvent(item));
				});
				
		
		}

		var subnav = $$('ul.subnavi li'); 
		var subnav_a = $$('ul.subnavi li a');
		var subnav_rel = $$('ul.subnavi li a').getProperty("rel");
		
		if (subnav) 
		{
					// ALLE NAVS DURCHLAUFEN
					subnav.each(function(ding, i) {
						
						
						if (subnav_rel[i]==active && ding.getParent().getParent()!='footer')
						subnav_a[i].setStyles({'background-color':'#0084D7', 'color':'#fff'});
						subnav[i].addEvent('click', function() {});
					});
		}


}




window.addEvent('domready', function(){
	
	var mySlide = new Fx.Slide('subscriptionform', {
		onComplete : function() {
			
			checkHeight();
			
	}
	});
	
	mySlide.hide();
	
	
	$('toggle').addEvent('click',function() { 
		mySlide.toggle();
	});


var zTables = new ZebraTables('zebra');
new SmoothScroll();
siteInit();
startGallery();
});

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

		if(window.ie6) {

			$$('img.fixPNG').each(function(png){
				fixPNG(png)
			});

		};
		
		checkHeight();


});



