/*	Script by Fabian Schmidt
	contact : fabian@smowl.com
	or      : info@aimdesignstudio.de

	Thanks go to the guys at mootools.net
	for their awesome javascript-framework  */

var slideList = null;

var createSlideList = function(){

	slideList = $$('.slide');
		
	slideList.each(function(item, index){
	
			
		item.duration = 650 ;
		item.value = (item.hasClass('showcaseMain') || item.hasClass('long') )? 600 : 340 ;
	
		item.slide= new Fx.Tween(item,{
		
			duration: item.duration
		
		});
		
		item.slide.set('height','0');
	
	});
};

var slideInContent = function(list,n){
			
	if(list[list.length-n] == null)
		return;
		
	var s =list[list.length-n] ;
	
	s.slide.start('height',s.value);
	
	if(n>1){
		s.slide.chain( function(){
			slideInContent(list,n-1);
		});
	}
	
};

var buildHeader = function(){

	var header = $('header');
	var url = header.getElement('a').get('href');
	
	
	var obj = new Swiff(url+'../../assets/flash/Krauts_PR_Logo.swf',{
			id: 'Krauts Logo',
			width: 118,
			height: 70,
			vars: {
        		url: url
    		}
	});
	
	var logo = new Element('div');
	logo.setStyles({
		width : 118+'px',
		height : 70+'px'
		//cursor : 'pointer' // conflicts with swf
		//'background-color' : '#000000'
		//'overflow' : 'hidden'
	
	});
	
	if(obj != null){
		
		header.empty();
		
		logo.grab(obj);
		//logo.grab(img);
	}
	else
		return ;
	
	header.grab(logo);
		
	logo.addEvent('click',function(){
	
		window.location.href=url;
	
	});
	
};

var buildFooter = function(){
	var footer = $('footer');
	var tagsImgs = $$('.footerItem img');
	$$('.footerItem').set('target','_blank');
	
	
	tagsImgs.each(function(item, index)
	{
		var imgSrc = item.get('src');
		
		item.addEvents(
		{
			'mouseover': function(e){
				var hoverImg = imgSrc.substr(0,imgSrc.length -4) + "Hover.png";
				item.set('src',hoverImg) ;
				//alert(hoverImg);
				
	
			},
			
			'mouseout': function(e){
	
				item.set('src',imgSrc);
	
			}
		})
	});
};

var isIE = Browser.Engine.trident ;
var isKonquerer = Browser.Platform.linux && Browser.Engine.webkit ;

window.addEvent('domready', function() {//domready
	
	//alert('platform : '+Browser.Platform.name+' , engine is '+Browser.Engine.name);
	
	//-- older KDE-Konquerer (webkit) versions do not support css3 opacity -> compensate with script
	//-- IE only supports non-standard-conform opacity (through filter-property)
	if(isKonquerer || isIE){
		
		var mainNavItms = $$('#mainNav .navItem') ;
		
		mainNavItms.each(function(item, index){
			
			
			var a = item.getElement('a');
			
			var url = a.get('href');
			
			a.dispose();
			
			item.addEvents(
			{
				   
				'click' : function(e){
					e.stop();
					window.location.href = url ;
					
					
				}//-- click end
			
			});
	
	
		});
	}
	//-- IE 6 causes trouble -> no effects for IE 6
	if(true){//! Browser.Engine.trident4
		
		createSlideList();
		buildHeader();
		buildFooter();
		
	}
	//-- Open Client links in new window
	$$('.noLine a').set('target','_blank');
	
	//-- Img Control (used by Showcase sites)
	
	var w = 554;
	var imgStrip = $$('.imgStrip')[0] ;
	if(imgStrip == null){
		return;	
	}
	
	var numImgs = $$('.imgStrip img').length;
	var currentImg = imgStrip.getStyle('margin-left').toInt() / -w;
	
	imgStrip.setStyle('width',numImgs * w);
	// Control buttons
	var picCtrls = $$('.pic');
	picCtrls.set('href','javascript:;') ;
	
	//-- Status display
	var imgStat = $$('.imgStat');
	
	//-- correct margin for IE 7
	if(Browser.Engine.trident5)
		imgStat.setStyle('margin-right','10px');
		
	imgStat.set('html',currentImg+1+'/'+numImgs);
	
	//-- Back Button
	if(picCtrls[0] != null){
		picCtrls[0].addEvent('click',function(){
			
			if(currentImg > 0 ) {
				
				currentImg -- ;
				//alert(currentImg);
				
				imgStrip.morph( { 'margin-left' :  currentImg * -w +'px'});
				
				imgStat.set('html',currentImg+1+'/'+numImgs);
			
			}
		
		});
	}
	//-- Fwd Button
	if(picCtrls[1] != null){
		picCtrls[1].addEvent('click',function(){
			
			
			
			if( currentImg  <  numImgs - 1  ) {
				
				currentImg ++ ;
				//alert(margin);
				
				imgStrip.morph( { 'margin-left' :  currentImg * -w+'px' });
				
				imgStat.set('text',currentImg+1+'/'+numImgs);
			
			}
		
		});
	}
	
	
});

//-- use 'load' instead of 'domready' here to ensure all images are loaded before showing the menu
window.addEvent('load', function() {//domready
	
	//-- IE 6 causes trouble -> no effects for IE 6
	if(true){//! Browser.Engine.trident4
		
		
		//-- items to slide in
		if(slideList == null){
		
			createSlideList();
		}						
		
		slideInContent(slideList,slideList.length);
		
		
	}
	//-- IE 6 also has problems with css :hover -> compensate with script
	if( Browser.Engine.trident4){
		
		
		$$('.navItem').each(function(item, index){
		
			if( item.hasClass('active') ){
				item.addClass('hov');
			}
			
			
			item.addEvents(
			{
				   
				'mouseenter' : function(e){
					e.stop();
					if( !item.hasClass('active') ){
						item.addClass('hov');
					}
					
				},//-- mouseenter end
				
				'mouseleave' : function(e){
					e.stop();
					
					if( !item.hasClass('active') ){
						item.removeClass('hov');
					}
					
					
				}//-- mouseleave end
			
			});
	
		});
	
	}// IE fix end
	
	
	
});
