$(document).ready(function(){
	
	//alert($(window).width());
	

	$(window).resize(function()
	{
		if ( $(window).width() < 1060 )
	 	{ 		
	 		
			$('#html5').fadeOut(1000);
	 	}
	 	else
	 	{
	 		$('#html5').fadeIn(1000);
	 	}
	});
	if ( $(window).width() < 1060 )
	 	{ 		
	 		//alert($(window).width());
			$('#html5').css('display','none');
	 	}
	 	else
	 	{
	 		$('#html5').fadeIn(1000);
	 	}
        
        $('.shadow').click(function(e){
            e.preventDefault();
            
            Shadowbox.open({
                content:    $(this).attr('href'),
                player:     "iframe",
		  width: 710,
		  height: 590
                
            });
        })
	/*
	var formTimer = null;
	$('.form-box input').live('mouseenter',function()
	{	
		$(this).addClass('active');
	});
	$('.form-box input').live('mouseleave',function()
	{	
		$(this).removeClass('active');
	});
	$('.form-box input, .form-box select, .form-box textarea').live('mouseenter focus',function()
	{
		$(this).prev().fadeOut(0);
	});
	
	$('.form-box input, .form-box select, .form-box textarea').live('mouseleave change',function()
	{
		
		if ( ( $(this).val() != '' ) || ( $(this)[0].selectedIndex != 0 ) &&  $(this)[0].selectedIndex != undefined )
		{
			
			$(this).prev().fadeOut(0);
		}
		else
		{
			var th = $(this).prev();
			formTimer = setTimeout(function() {th.fadeIn(0);},300);
		}
	});
	$('.form-box label').live('mouseenter focus',function()
	{
		clearTimeout(formTimer);
		$(this).fadeOut(0);
	});
	
	$('.form-box label').live('mouseleave change',function()
	{
		if ( ( $(this).next().val() != '' ) || ( $(this).next()[0].selectedIndex != 0 ) &&  $(this)[0].selectedIndex != undefined  )
		{
			$(this).fadeOut(0);
		}
		else
		{
			$(this).fadeIn(0);
		}
	});
	*/
	var formTimer = null;
	$('.form-box input').live('focus',function()
	{	
		$(this).addClass('active');
	});
	$('.form-box input').live('focusout',function()
	{	
		$(this).removeClass('active');
	});
	$('.form-box input, .form-box select, .form-box textarea').live('focus',function()
	{
		$(this).prev().fadeOut(0);
	});
	
	$('.form-box input, .form-box select, .form-box textarea').live('focusout change',function()
	{
		
		if ( ( $(this).val() != '' ) || ( $(this)[0].selectedIndex != 0 ) &&  $(this)[0].selectedIndex != undefined )
		{
			
			$(this).prev().fadeOut(0);
		}
		else
		{
			var th = $(this).prev();
			formTimer = setTimeout(function() { th.fadeIn(0); },300);
		}
	});
	$('.form-box label').live('click',function()
	{
		$(this).next().focus();
		//clearTimeout(formTimer);
		$(this).fadeOut(0);
	});

	$('.form-box label').each(function()
	{
		
		if ( $(this).next().val() != '' )
		{
			$(this).css('display','none');
		}
	});
	
	showArrows();
	var headerF = 0;
	$('.arrow_right').click(function()
	{
		var th = $(this).parents('.slider');
		if ( th.attr('semaphore') == 1 ) return;
		th.attr('semaphore',1);
		if ( th.hasClass('headerF') )
		{			
			$('#slider-nav a').removeClass('active-link');
			$('#slider-nav a[data-id='+(++headerF)+']').addClass('active-link');
		}
		var liW =  $(this).parents('.slider').find('li').width();
		
		 $(this).parents('.slider').find('ul').animate(
		{		  
		    left: '-='+liW		   
		 }, 1000, function() 
		 		{
		    	showArrows();
		    	th.attr('semaphore',0)
  				}
  		);
	});
	$('.arrow_left').click(function()
	{
		var th = $(this).parents('.slider');
		if ( th.attr('semaphore') == 1 ) return;
		th.attr('semaphore',1);
		if ( th.hasClass('headerF') )
		{			
			$('#slider-nav a').removeClass('active-link');
			$('#slider-nav a[data-id='+(--headerF)+']').addClass('active-link');
		}
		$(this).parents('.slider').find('ul').stop();
		var liW =  $(this).parents('.slider').find('li').width();
		$(this).parents('.slider').find('ul').animate(
		{		  
		    left: '+='+liW		   
		 }, 1000, function() {
		   showArrows();
		   th.attr('semaphore',0)
  		});
	});
	
	$('.ketchup').ketchup();
	$('.ketchup1').ketchup();
	
	setInterval(slider,5000);
	
	
	$('select').change(function()
	{
		
		$(this).parent().find('span').html($(this).find("option:selected").val());
	});
	$('select').each(function()
	{
		$(this).parent().find('span').html($(this).find("option:selected").val());
	});
	
	$('.login-on').click(function(e)
	{
		e.preventDefault();
		if ( $('.loginF').css('display') == 'none' ) 
		{
			if (  $.browser.msie )
			{
				$('.loginF, .kt_log').css('display','block');
				$('.kt_and').css('display','none');

			}
			else
			{
				$('.loginF, .kt_log').fadeIn(1000);
				$('.kt_and').fadeOut(100);
			}
			
		}		
		else 
		{
			if (  $.browser.msie )
			{
				$('.loginF, .loginFP, .kt_log, .kt_pas').css('display','none');
			}
			else
			$('.loginF, .loginFP, .kt_log, .kt_pas').fadeOut(1000);
			//$('.kt_and').fadeIn(2000);
		}	
		
	});
	
	$('.pf-on').live('click',function(e)
	{
		
		e.preventDefault();
		if ( $('.loginFP').css('display') == 'none' ) 
		{
			if (  $.browser.msie )
			{
				$('.loginFP, .kt_pas').css('display','block');
				$('.kt_and').css('display','none');
			}
			else
			{
				$('.loginFP, .kt_pas').fadeIn(1000);
				$('.kt_and').fadeOut(100);
			}
			
		}		
		else 
		{
			if (  $.browser.msie )
				$('.loginFP, .kt_pas').css('display','none');
			else	
				$('.loginFP, .kt_pas').fadeOut(1000);
			//$('.kt_and').fadeIn(2000);
		}	
		
	});
	
	var count = 0;
	$('#slider-nav a').each(function()
	{
		$(this).attr('data-id',count++);
	});
	$('#slider-nav a').click(function(e)
	{
		e.preventDefault();
		var th = $(this).parents('#featured').find('.slider');
		console.log(th);
		if ( th.attr('semaphore') == 1 ) return;
		th.attr('semaphore',1);
		var id = $(this).attr('data-id'); 
		var liW =  th.find('li').width();
		
		$('#slider-nav a').removeClass('active-link');
		$(this).addClass('active-link');
		
		 th.find('ul').animate(
		{		  
		    left: -id*liW		   
		 }, 1000, function() 
		 		{
		    	showArrows();
		    	th.attr('semaphore',0)
  				}
  		);
	});
	
});

function showArrows()
{
	$('.arrow_left').each(function()
	{		
		if ( $(this).parents('.slider').find('ul').css('left').replace('px','') >= 0 )
		{
			if ( $(this).parents('.slider').attr('id') == 'referenzen' ) {lr = 1;}
			$(this).fadeOut(0);
		} 
		else
		{
			$(this).fadeIn(444);
		}
		
	
	});
	
	$('.arrow_right').each(function()
	{
		
		var liW =  $(this).parents('.slider').find('li').width();
		var liC = 0;
		$(this).parents('.slider').find('li').each(function()
		{
		 	liC++;
		});
		//console.log($(this).parents('.slider').find('ul').css('left').replace('px',''));
		
		var mn = 1;
		if ( $(this).parents('.slider').attr('id') == 'referenzen' )
		{
			mn = 4;
		}
		if ( $(this).parents('.slider').find('ul').css('left').replace('px','') <= (-1)*(liW*liC - liW*mn) )
		{
			if ( mn == 4 ) lr = 0; 
			$(this).fadeOut(0);
		} 
		else
		{
			$(this).fadeIn(444);
		}
		
	
	});
	
	semaphore = 0;

}
var lr = 1;
var semaphore = 0;
function slider()
{
	
	if ( lr == 1 )
	{				
		$('#referenzen .arrow_right').click();
	}
	else
	{
		$('#referenzen .arrow_left').click();
	}	
}



