window.addEvent('domready',function(){
	$$('a').setStyle('-moz-outline',0);
	new Navigation();
	$each($$('.imageTeaser'),function(item){
		new imageTeaser(item);
	});
	
	$each($$('.portfolioTeaser'),function(item){
		new PortfolioTeaser(item);
	});
	
	if($$('.newsItem')[0]){
		new Element('div',{'class':'hr'}).inject($('content').getLast('.newsItem'),'after');
		$each($$('.newsItem'),function(item){
			if(item.getElements('img')[0]){
				item.getElements('p,h3').addClass('floatingParagraph');
			}
		});
	}
	
	$each($$('.toggleText'),function(item){
		item.setStyle('display','none');
		item.getPrevious('p').addClass('toggler').addEvent('click',function(){
			var new_display = this.getNext('.toggleText').getStyle('display') == 'none' ? 'block' : 'none';
			this.getNext('.toggleText').setStyle('display',new_display);
		});
	});
	
});

var PortfolioTeaser = new Class({
	initialize	:	function(el){
		this.el = el;
		this.textEl = new Element('div',{
			'class'	:	'csc-textpic-text'
		}).inject(this.el,'after');
		this.el.getElements('.teaser').addEvents({
			'mouseover'	:	function(el){
				var target = $(el.target).getParent('.teaser').getElements('.text')[0];
				this.textEl
				.setStyle('opacity',0)
				.set('html',target.get('html'))
				.set('morph',{duration:700})
				.morph({opacity:1});
			}.bind(this),
			'mouseleave'	:	function(){
				this.textEl.set('html','');
			}.bind(this)		
		});
	}
});

var imageTeaser = new Class({
	options:{
		duration	:	900,
		transition	:	Fx.Transitions.Elastic,
		elasticity	:	0.3,
		opacity		:	0.7
	},
	initialize	:	function(el){
		this.el = el;
		this.customTransition = new Fx.Transition(this.options.transition,this.options.elasticity);
		this.createThumbnailNavigation();
	},
	createThumbnailNavigation	:	function(){
		var thumbnailNavigation = new Element('div',{
			'class'		:	'thumbnailNavigation'
		}).inject(this.el.getElements('.inner')[0],'after');
		$each(this.el.getElements('.thumb'),function(item){
			item.clone().inject(thumbnailNavigation).setStyle('opacity',this.options.opacity);
		}.bind(this));
		this.el.getElements('.thumbnailNavigation .thumb').addEvents({
			'click'	:	function(el){
				el.target = el.target.hasClass('thumb') ? el.target : el.target.getParent('.thumb');
				if($$('.isactive')[0]){
					$$('.isactive')[0].set('morph',{duration:300}).morph({opacity:this.options.opacity}).removeClass('isactive');						
				}
				this.currentIndex = this.el.getElements('.thumbnailNavigation .thumb').indexOf(el.target);
				el.target.addClass('isactive');
				this.browseItems();
			}.bind(this),
			'mouseover' :	function(el){
				el.target = $(el.target).hasClass('thumb') ? $(el.target) : $(el.target).getParent('.thumb');
				el.target.set('morph',{duration:6000}).morph({opacity:100});	
			},
			'mouseleave':	function(el){
				el.target = el.target.hasClass('thumb') ? el.target : el.target.getParent('.thumb');
				if(!el.target.hasClass('isactive')) el.target.set('morph',{duration:300}).morph({opacity:this.options.opacity});					
			}.bind(this)
		});
		this.el.getElements('.thumbnailNavigation .thumb')[0].setStyle('opacity',100).addClass('isactive');
	},
	browseItems	:	function(){
		this.el.getElements('.inner')[0].set('morph',{
			duration		:	this.options.duration,
			transition		:	Fx.Transitions.Sine.easeInOut
		}).morph({
			'margin-left'	:	this.currentIndex * (-1) * this.el.getElements('.image')[0].getSize().x.toInt()
		});
	}
});


var Navigation = new Class({
	options:{
		duration	:	300
	},
	initialize	:	function(){
		$each($$('#navigation ol li'),function(item){
			if(item.getChildren('ol')[0] && item.getChildren('ol')[0].hasClass('third') != true){
				item.getChildren('ol')[0].setStyles({
					opacity	:	0,
					display	:	'block'
				});
				item.addEvents({
					'mouseover'	:	function(el){
						el.getChildren('ol')[0].set('morph',{
							duration	:	this.options.duration
						}).morph({
							opacity		:	1
						});
						if($$('#navigation .sub ol')[0]){
							if(!el.hasClass('sub') && !el.getParent('.sub')){
								$$('#navigation .sub ol')[0].set('morph',{
									duration	:	this.options.duration
								}).morph({
									opacity		:	0
								});
							}
						}
					}.bind(this,item),
					'mouseleave'	:	function(el){
						if(!el.hasClass('sub') && !el.getParent('.sub')){
							el.getChildren('ol')[0].set('morph',{
								duration	:	this.options.duration
							}).morph({
								opacity		:	0
							});
						}
						if($$('#navigation .sub ol')[0]){
							$$('#navigation .sub ol')[0].set('morph',{
								duration	:	this.options.duration
							}).morph({
								opacity		:	1
							});
						}
					}.bind(this,item)
				});
			}
		}.bind(this));
		if($$('#navigation .sub ol')[0]){
			$$('#navigation .sub ol')[0].setStyle('opacity',1);	
		}
	}
});



/*		
		TYPO3-eigenes JavaScript
		- Spamschutz
										*/
function decryptString(enc,offset){var dec="";var len=enc.length;for(var i=0;i<len;i++){var n=enc.charCodeAt(i);if(n>=0x2B&&n<=0x3A){dec+=decryptCharcode(n,0x2B,0x3A,offset);}else if(n>=0x40&&n<=0x5A){dec+=decryptCharcode(n,0x40,0x5A,offset);}else if(n>=0x61&&n<=0x7A){dec+=decryptCharcode(n,0x61,0x7A,offset);}else{dec+=enc.charAt(i);}}return dec;}
function linkTo_UnCryptMailto(s){location.href=decryptString(s,-1);}
function decryptCharcode(n,start,end,offset){n=n+offset;if(offset>0&&n>end){n=start+(n-end-1);}else if(offset<0&&n<start){n=end-(start-n-1);}return String.fromCharCode(n);}
