// JavaScript Document

//Formular check
function check_input(cont)
{
	inputs = new Array('name', 'betreff', 'email');
	text = new Array('Dein Name', 'Der Betreff', 'Deine E-Mail Adresse');
	x = 0;
	while ( x != inputs.length )
	{
		if ( cont != inputs[x] )
		{
			if ( $('input#' + inputs[x]).val() ==  '' )
			{
				$('input#' + inputs[x]).val(text[x]);
			}
		}
		if ( inputs[x] == cont & $('input#' + inputs[x]).val() == text[x] )
		{
			$('input#' + cont).val('');	
		}
		x++;
	}
}	

//Formular change
function change(cont)
{
	$('img#valid_' + cont).remove();
	if ( cont == 'email')
	{
		$.get("inc/test_email.php",
		{
			email: $('input#email').val()
			},
			function(data)
			{
				if ( data == 'true' )
				{
					$('li#email_li').append('<img class="valid" id="valid_' + cont + '" src="Bilder/win.png" />');
				}
				else
				{
					$('li#email_li').append('<img class="valid" id="valid_' + cont + '" src="Bilder/fail.png" />');
				}				
			});
	}
	else
	{
		$('li#' + cont + '_li').append('<img class="valid" id="valid_' + cont + '" src="Bilder/win.png" />');
	}
}

function send()
{
	alert('Fehler');
	$.get("inc/email_test.php",
	{
		email: $('input#email').val()
	},
		function  ajax(data)
		{	
			if ( data == 'true' )
			{
				if ( $('textarea#nachricht').val() != '' & $('input#name').val() != 'Dein Name' & $('input#betreff').val() != 'Der Betreff' & $('input#name').val() != '' & $('input#betreff').val() != '' & $('input#email').val() != 'Deine E-Mail Adresse' )
				{
					send_mail( $('input#name').val() , $('input#betreff').val() , $('input#email').val() , $('textarea#nachricht').val() );
				}
			}
		});
}
	
function send_mail(name, betreff, email, nachricht)
{
	$.ajax(
	{
		type: "POST",
		url: "mail.php",
		data: 'name=' + name + '&betreff=' + betreff + '&email=' + email + '&nachricht=' + nachricht
	});
	alert('Das verschicken von Nachrichten über das Formular ist derzeit nicht möglich. Schreib mir einfach eine E-Mail an: moritz.k@gmail.com');
}
	
$(document).ready(
function()
{	

	check_input();

	var speed = 510
	
	//Scrollbar Ein-/Ausblenden
	$(window).bind('resize', 
	function ()
	{ 
		if (window.innerWidth < 840)
		{
			$('body').css('overflow-x','scroll');
		}
		else
		{
			$('body').css('overflow-x','hidden');
		}
  	});
	
	// Select all links with lightbox class
	$(function() 
	{
		$('a.lightbox').lightBox(); 
	});
	
	// Menue Hover
	$('div#view img').hover( 
	function()
	{
		$(this).css('opacity','0.6');
	},
	function()
	{
		$(this).css('opacity','0.2');
	});
		
	// Portfolio Switcher
	$('div#view img').click( 
	function()
	{
		if ( $('ul#list_portfolio li div.portfolio_desc_wrapper').is(':visible') == true ) 
		{
			$('div#view img').attr('src', 'Bilder/view_info.gif');
			$('ul#fix li').css('height','256px');
			$('ul#list_portfolio li div.portfolio_desc_wrapper').fadeOut(speed);
			$('ul#list_portfolio').fadeOut(speed);
			$('ul#list_portfolio').fadeIn(speed);
			
		}
		else
		{
			$('div#view img').attr('src', 'Bilder/view_square.gif');
			$('ul#fix li').css('height','512px');
			$('ul#list_portfolio').fadeOut(speed,
			function() 
			{
				$('ul#list_portfolio li div.portfolio_desc_wrapper').show();
			});
			$('ul#list_portfolio').fadeIn(speed);
		}
	});

	//Portfolio Thumb Hover
	$('ul#list_portfolio li div.list_portfolio_img').hover( 
	function()
	{
		if ( $('ul#list_portfolio li div.portfolio_desc_wrapper').is(':visible') != true ) 
		{
			$(this).find('div.list_portfolio_img_slider_bg').stop().animate(
			{
				top: '118px'
			}, 150);
			$(this).find('div.list_portfolio_img_slider_text').stop().animate(
			{
				top: '118px'
			}, 150);
		}		
	},
	function()
	{
		$(this).find('div.list_portfolio_img_slider_bg').stop().animate(
		{
			top: '178px'
		}, 150);
		$(this).find('div.list_portfolio_img_slider_text').stop().animate(
		{
			top: '178px'
		}, 150);
	});

	// Menue Hover
	$('div#menue li').hover( 
	function()
	{
		if ( $('div#menue_overlay').css('display') == 'none')
		{
			var id = $(this).attr('id').substring(6);
			if ( $(this).hasClass('menue_active') == false)
			{
				$(this).children('div.menue_top').stop().animate(
				{ 
					height: '105px'
				}, 150);
			}
		}
	},
	function()
	{
		if ( $('div#menue_overlay').css('display') == 'none')
		{
			if ( $(this).hasClass('menue_active') == false )
			{
				$(this).children('div.menue_top').stop().animate(
				{ 
					height: '85px'
				}, 150 );
			}
		}
	});
	
	//Menue Click
	$('div#menue ul li').click( 
	function()
	{
		$(this).stop();
		var old_class = $('li.menue_active').attr('class');
		var old_id = $('li.menue_active').attr('id').substring(6);
		var new_class = $(this).attr('class');
		var new_id = $(this).attr('id').substring(6);
		
		$('div#menue_overlay').css({'display' : 'block'});
		
		$('li#menue_' + old_id).children('div.menue_top').animate(
		{ 
			height: '85px'
		},
		function()
		{
			$('li#menue_' + old_id).removeClass();
		});
		
		$('li#menue_' + new_id).children('div.menue_top').animate(
		{ 
			height: '125px'
		},
		function()
		{
			$('li#menue_' + new_id).addClass('menue_active');
			$('div#menue_overlay').css({'display' : 'none'});
		});
		
		var x = 1;
		
		$('div.content').fadeOut('speed',
		function()
		{
			
			if ( x == 4 )
			{
				$('div#' + new_id).fadeIn('speed');	
			}
			
		x = x+1;
		});	
	});
		

 });