/*
* Lime Flavour
* standard.js
*
* Author: Holger M. Stangl
* Date: September 2010
*/
function openPopUp( thisUrl, width, height ) {
	
	$.fancybox({
		'titleShow' : false,
		'zoomOpacity' : true,
		'overlayShow' : true,
		'overlayColor' : '#9dbd03',
		'overlayOpacity' : 0.8,
		'padding' : 10,
		'zoomSpeedIn' : 500,
		'zoomSpeedOut' : 500,
		'transitionIn' : 'fade',
		'transitionOut'	: 'fade',
		'type' : 'iframe',
		'width' : width,
		'height' : height,
		'href' : thisUrl
		}
	);
}

$(document).ready(function(){

	
	/* JS enable */
	$("html").removeClass("no-js").addClass("js");
	
	
	
	$('#navigation ul li:last').addClass('lastChild');
	
	
	
	var y = 0;
	$(".containerProjects .projectItem").each( function(i, e){
		y++;
		if ( y == 4 ) { 
			$(this).css('margin-right','0');
			y = 0; 
		}
	});

	// $("#content").fadeIn(2000);

	// Main Navigation
	/*
	$('#navigation ul').hoverIntent({
		sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
		interval: 100, // number = milliseconds for onMouseOver polling interval    
		over: function(){
			$("#navigation ul li ul").slideDown(300);
			$("#navigation ul li ul li a").delay(200).animate({
					opacity:1
				},200, function(){}
			);
		},    
		timeout: 300, // number = milliseconds delay before onMouseOut    
		out: function(){
			$("#navigation ul li ul li a").css('opacity','0');
			$("#navigation ul li ul").slideUp(100);
		} 
	});
	*/
	// Main Navigation
	$("#navigation ul li ul").each(function(){
		
		$(this).css("width", $(this).parent().width() );
		
	});
	
	$('#navigation').hoverIntent( {
		sensitivity: 3, 
		interval: 30,    
		over: function(){ 
		
				$("#navigation ul li ul").fadeIn(200);

				$('#header .wrapper').stop().animate({ 
					height: "224px"
				},{
			 		duration: 400
				});
			
		},
		timeout: 300,
		out: function(){
			$("#navigation ul li ul").fadeOut(200);

			$('#header .wrapper').stop().animate({ 
				height: "132px"
			},{
			 	duration: 400
			});
		}
	});
	
	/*
	$("#navigation").hover(function(){
		
		$("#navigation ul li ul").fadeIn(200);
		
		$('#header .wrapper').stop().animate({ 
			height: "260px"
		},{
	 		duration: 400
		});
	}, function(){
		$("#navigation ul li ul").fadeOut(200);
		
		$('#header .wrapper').stop().animate({ 
			height: "132px"
		},{
		 	duration: 400
		});
	});
	*/
	/*
	$("#navigation").hover(function(){
		
		$(this).stop().animate({ 
			height: "247px"
		});
		
		$('#header .wrapper').stop().animate({ 
			height: "247px"
		});
	}, function(){
		$(this).stop().animate({ 
			height: "60px"
		});
		
		$('#header .wrapper').stop().animate({ 
			height: "132px"
		});
	});
	*/
	
	
	/*
	$('#navigation').hoverIntent( {
		sensitivity: 3, 
		interval: 30,    
		over: function(){ 
		
			$("#navigation ul li ul")
			.css("padding","18px 0 27px 0")
			.animate( { 
				height: "132px"
			}, { 
				duration:600, 
				easing:"easeOutQuart", 
				queue:false,
				complete: function() {
					$(this).css("height","auto");
				}
			});
			
		},
		timeout: 300,
		out: function(){
			$("#navigation ul li ul")
			.animate( {
				height:0,
				padding: "0 0 0 0",
				display:"none"
			}, {
				duration: 200,
				easing:"easeOutQuart",
				queue:false,
				complete: function() {
					$(this).css("display","none");
				}
			});
		}
	});
	*/
	
	/* TypeKit FontDisplay */
	/*
	var textDisplayTime = 50;
	$(".containerCenter h1").fadeIn( textDisplayTime );
	$(".containerCenter h2").fadeIn( textDisplayTime );
	$(".containerCenter h3").fadeIn( textDisplayTime );
	$(".containerDetail .headerBox h1").fadeIn( textDisplayTime );
	*/
	

	// Body Height
	$('#content .wrapper').eq(0).css('min-height', $('body').height()-583 );
  	
  	
	/*
	if ( $('body').width() > 1024 ) {
		
		var thisHeight = $('body').height()-100;
		var thisWidth = $('body').width()-100;
		if ( thisWidth < 1000 ) thisWidth = 1000;
		if ( thisWidth > 1100 ) thisWidth = 1100;
		
		$("a.external").click( function(){
			openPopUp( $(this).attr('href'), thisWidth, thisHeight );
			return false;
		});
	
	}
	*/
	
	/* ScrollTo */
	$('a.top').click(function(){
		$.scrollTo( 'body', 800 );
		return false;
	});
	
	
	
	// Self-maximize Textaraes
	$('textarea').elastic();
	
	
	
	// Search Field Hover
	$('#search input').focus(function() {
		if ( $(this).attr('value') == 'Suchbegriff' ) $(this).attr('value','');
	}).blur(function() {
		if ( $(this).attr('value') == '' ) $(this).attr('value','Suchbegriff');
	});
	
	
	$('.containerTeaser').each(function(){				
		
		if ( $(".teaserCol", this).length > 1 ) {
			
			var scrollable = $(".selectionBox", this).scrollable({ 
				easing: 'easeOutQuart',
				speed: 900,
				items:'.wrap',
				prev:'.prev',
				next:'.next'
			});
			var scrollableAPI = $(".thumbImages", this).scrollable({api: true});
		
		} else {
		
			$(".prev", this).hide();
			$(".next", this).hide();
			
		}
		
	});
	
	
	
	$('.containerSlideshow').each(function(){
	
		var scrollable = $(".slideshowBox", this)
		.scrollable({ 
			easing: 'easeInOutExpo',
			speed: 900,
			items:'.wrap',
			prev:'.prev',
			next:'.next',
			circular: true
		}).autoscroll({ 
			autoplay: true,
			interval: 6000
		});
		var scrollableAPI = $(".slideshowBox", this).scrollable({api: true});
		
	});


	// Accordion
	$(".containerAccordion").tabs(".containerAccordion .contentBox", {
		tabs: 'h2',
		effect: 'slide'
	});

	
	$('marquee').marquee({
		repeat: 84
	}).find('a').mouseover(function () {
		$(this).trigger('stop');
	}).mouseout(function () {
		$(this).trigger('start');
	});

});
