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

	/**
	* ### HEADERFADER ###
	**/
	var headergallery = new IhcFadeGallery( $$('.ct_bild_header').getFirst() );	
	

	/**
	* ### BILD FADEGALLERY ###
	**/
	$$('.ct_bild_fadegallery').each(function(item,index){
		var fadegallery = new IhcFadeGallery( item );
		fadegallery.fadeNext = function(){ this.fade(this.getNext()); };
		fadegallery.fadePrev = function(){ this.fade(this.getNext()); };
		var navi = new Element('div',{'class':'ct_bild_fadegallery_navi'});
		item.addEvents({
					'mouseover':function(){
						this.getElement('.ct_bild_fadegallery_navi').set('tween', {duration: 300});
						this.getElement('.ct_bild_fadegallery_navi').tween('opacity',1);
					},
					'mouseout':function(){
						this.getElement('.ct_bild_fadegallery_navi').set('tween', {duration: 300});
						this.getElement('.ct_bild_fadegallery_navi').tween('opacity',0);
					}
				});
		var next  = new Element('div',{'class':'ct_bild_fadegallery_navi_next','events':{
					'mouseover':function(){
						this.set('tween', {duration: 300});
						this.tween('opacity',1);
					},
					'mouseout':function(){
						this.set('tween', {duration: 300});
						this.tween('opacity',0.4);
					},
					'click':function(){
						fadegallery.fadeNext();
					}
				}});
		next.setStyle('opacity',0.4);
		var prev  = new Element('div',{'class':'ct_bild_fadegallery_navi_prev','events':{
					'mouseover':function(){
						this.set('tween', {duration: 300});
						this.tween('opacity',1);
					},
					'mouseout':function(){
						this.set('tween', {duration: 300});
						this.tween('opacity',0.4);
					},
					'click':function(){
						fadegallery.fadePrev();
					}
				}});
		prev.setStyle('opacity',0.4);
		
		navi.adopt(prev);
		navi.adopt(next);
		navi.setStyle('opacity',0);
		item.adopt(navi);
	});
	
	/**
	* ### MEDIABILDER ###
	**/
	$$('a[rel*=lightbox]').each(function(item, index){
		var box = item.getParent('div');
    		box.setStyle('position','relative');
		var bild = box.getElement('img');
		bild.setStyle('position','relative');
		bild.setStyle('z-index',1);
		item.adopt( new Element('div',{
				'class':'ct_bild_overlay',
				'styles':{
					'width':bild.getSize().x,
					'height':bild.getSize().y,
					'top':box.getStyle('padding-top'),
					'left':box.getStyle('padding-left'),
					'opacity':0
				}
			}) );
	});
	$$('a[rel*=lightbox]').addEvents({
    		'mouseenter': function(){
			var overlay = this.getElement('.ct_bild_overlay');
			//overlay.set('tween', {duration: 300});
			//overlay.tween('opacity',0.3);
			overlay.setStyle('opacity',1);
		},
		'mouseleave': function(){
			var overlay = this.getElement('.ct_bild_overlay');
			//overlay.set('tween', {duration: 500});
			//overlay.tween('opacity',0);
			overlay.setStyle('opacity',0);
		}
	});


	/**
	* ### LINKBOX ###
	**/
	$$('.ct_linkbox').addEvents({
    		'mouseenter': function(){
			this.set('tween', {duration: 300});
			this.tween('background-color','#727272');
		},
		'mouseleave': function(){
			this.set('tween', {duration: 500});
			this.tween('background-color','#636363');
		},
		/*'click': function(){
			var link = this.getElement('.ct_linkbox_bild a');
			if( link != null){
				window.location.href = '/'+link.getProperty('href');
			}
		}*/
		'click': function(){
			var link = this.getElement('.ct_linkbox_bild a');
			if( link != null){
				var href = link.getProperty('href');
				if( href.substring(0,7) == 'http://' ){
					var newWindow = window.open(href, '_blank');
					newWindow.focus();
					return false;
				}
				window.location.href = '/'+href;
			}
		}
	});


	/**
	* ### BOX ###
	**/
	$$('.ct_box').addEvents({
    		'mouseenter': function(){
			this.set('tween', {duration: 300});
			this.tween('background-color','#dcd5cf');
		},
		'mouseleave': function(){
			this.set('tween', {duration: 500});
			this.tween('background-color','#e9e5e2');
		}
	});


	/**
	* ### BILDERGALLERY ###
	**/
	$$('.ct_bildergallery_border').addEvents({
    		'mouseenter': function(){
			var bilder = this.getElements('img');
			bilder.set('tween', {duration: 500});
			bilder.tween('opacity',0.7);
		},
		'mouseleave': function(){
			var bilder = this.getElements('img');
			bilder.set('tween', {duration: 500});
			bilder.tween('opacity',1);
		}
	});
	$$('.ct_bildergallery_border a').addEvents({
    		'mouseover': function(){
			var bilder = this.getElements('img');
			bilder.set('tween', {duration: 300});
			bilder.tween('opacity',1);
		},
		'mouseleave': function(){
			var bilder = this.getElements('img');
			bilder.set('tween', {duration: 300});
			bilder.tween('opacity',0.7);
		}
	});
});
