$(document).ready(function(){
	
	//alert($(window).width());
	
	$('.chk input').each(function()
	{
		$(this).hide();
		
		if ( $(this).attr('checked') == 'checked' ||  $(this).attr('checked') == true )
			$(this).after('<div class="checkbox on"></div>');
		else
			$(this).after('<div class="checkbox off"></div>');
	});
	
	$('.rad input').each(function()
	{
		$(this).hide();
		
		if ( $(this).attr('checked') == 'checked' ||  $(this).attr('checked') == true )
			$(this).after('<div class="radio on"></div>');
		else
			$(this).after('<div class="radio off"></div>');
	});
	
	$('.radio').live('click',function()
	{		
		var name = $(this).prev().attr('name');
		if ( $(this).hasClass('on') ) 
		{			
			//$(this).removeClass('on').addClass('off');			
		}
		else
		{			
			$('input[name='+name+']').next().removeClass('on').addClass('off');
			$(this).removeClass('off').addClass('on');			
		}
		$(this).prev().click();
		$(this).prev().trigger('change');
		
	});
	
	$('.checkbox').live('click',function()
	{
		var dsa = $(this).prev().attr('data-sellectAll')
		if ( dsa  )
		{			
			if ( !$(this).prev().attr('checked') )
			{
				$('[data-selectGroup='+dsa+']').find('.checkbox').addClass('on').removeClass('off');
				$('[data-selectGroup='+dsa+']').find('.checkbox').prev().attr('checked','true');
			}
			else
				{
				$('[data-selectGroup='+dsa+']').find('.checkbox').addClass('off').removeClass('on');
				$('[data-selectGroup='+dsa+']').find('.checkbox').prev().attr('checked','false');
				}
		}
		
		if ( $(this).hasClass('on') ) 
		{
			$(this).removeClass('on').addClass('off');			
		}
		else
		{
			$(this).removeClass('off').addClass('on');			
		}
		$(this).prev().click();
		$(this).prev().trigger('change');
		
	});
	
	$('.hidden').fadeOut();
	
	
	$('[data-triger]').each(function()
	{
		var onE = $(this).attr('data-triger');
		
		if ( $(this)[0].nodeName == 'SELECT' )
		{			
			
			if ( $(this)[0].selectedIndex ==  $(this).attr('data-trigerOn') )
			{
				//console.log(onE);
				$('[data-show='+onE+']').fadeIn(500);
			}
			else
			{
				$('[data-show='+onE+']').fadeOut(500);
			}
		}
		else
		if ( $(this).attr('type') == 'radio'  ) 
		{
		if ( $(this).attr('checked') == true ||  $(this).attr('checked') == 'checked' )
			{
			
			if (  $(this).attr('data-trigerOn') == 'true' )
			{
				console.log($(this));
				$('[data-show='+onE+']').fadeIn(500);
			}
			else
			{
				$('[data-show='+onE+']').fadeOut(500);
			}		
			}
		}
		else
		{
			
			if ( $(this).attr('checked') == true ||  $(this).attr('checked') == 'checked' )
			{				
				
				$('[data-show='+onE+']').fadeIn(500);
			}	
			else
			{
				$('[data-show='+onE+']').fadeOut(500);
			}	
		}
	})
	
	
	$('[data-triger]').live('change',function(e)
	{
		
		var onE = $(this).attr('data-triger');
		
		if ( $(this)[0].nodeName == 'SELECT' )
		{			
			
			if ( $(this)[0].selectedIndex ==  $(this).attr('data-trigerOn') )
			{
				//console.log(onE);
				$('[data-show='+onE+']').fadeIn(500);
			}
			else
			{
				$('[data-show='+onE+']').fadeOut(500);
			}
		}
		else
		if ( $(this).attr('type') == 'radio' ) 
		{
			if (  $(this).attr('data-trigerOn') == 'true' )
			{
				$('[data-show='+onE+']').fadeIn(500);
			}
			else
			{
				$('[data-show='+onE+']').fadeOut(500);
			}
		
		}
		else
		{
			
			if ( $(this).attr('checked') == true ||  $(this).attr('checked') == 'checked' )
			{				
				$('[data-show='+onE+']').fadeIn(500);
			}	
			else
			{
				$('[data-show='+onE+']').fadeOut(500);
			}	
		}
	});

	$(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('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').live('mouseleave change',function()
	{
		if ( ( $(this).next().val() != '' ) || ( $(this).next()[0].selectedIndex != 0 ) &&  $(this)[0].selectedIndex != undefined  )
		{
			$(this).fadeOut(0);
		}
		else
		{
			$(this).fadeIn(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").html());
});
$('select').each(function()
{
$(this).parent().find('span').html($(this).find("option:selected").html());
});	

	
	
	$('#header-login').hide();
	/*
	$('.login-on').click(function(e)
	{
		e.preventDefault();
		if ( $('.loginF').css('display') == 'none' ) 
		{
			$('#header-login').fadeIn(500);
			$('.loginF, .kt_log').fadeIn(1000);
			$('.kt_and').fadeOut(100);
			
		}		
		else 
		{
			$('.loginF, .loginFP, .kt_log, .kt_pas, #header-login').fadeOut(1000);
			//$('.kt_and').fadeIn(2000);
		}	
		
	});
	
	$('.pf-on').live('click',function(e)
	{
		
		e.preventDefault();
		if ( $('.loginFP').css('display') == 'none' ) 
		{
			$('.loginFP, .kt_pas').fadeIn(1000);
			$('.kt_and').fadeOut(100);
			
		}		
		else 
		{
			$('.loginFP, .kt_pas').fadeOut(1000);
			//$('.kt_and').fadeIn(2000);
		}	
		
	});*/
	
	$('.login-on').click(function(e)
	{
		e.preventDefault();
		if ( $('.loginF').css('display') == 'none' ) 
		{
			if (  $.browser.msie )
			{
				$('#header-login').css('display','block');
				$('.loginF, .kt_log').css('display','block');
				$('.kt_and').css('display','none');

			}
			else
			{
				$('#header-login').fadeIn(500);
				$('.loginF, .kt_log').fadeIn(1000);
				$('.kt_and').fadeOut(100);
			}
			
		}		
		else 
		{
			if (  $.browser.msie )
			{
				$('.loginF, .loginFP, .kt_log, .kt_pas, #header-login').css('display','none');
			}
			else
			$('.loginF, .loginFP, .kt_log, .kt_pas, #header-login').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();
	}	
}



