jQuery(function(){
	$('#wrapper').hide();
	$('#footer').hide();

	if(!window.location.hash || window.location.hash == '#beschreibung'){
		jQuery('.beschreibung').show();
		jQuery('.preise').hide();
		classChange('.tab1', '.tab2', 'active');
	}else if(window.location.hash == '#preise'){
		jQuery('.preise').show();
		jQuery('.beschreibung').hide();
		classChange('.tab2', '.tab1', 'active');
	}else if(window.location.hash == '#kontaktadresse'){
		jQuery('#kontakt').hide();
		jQuery('#adresse').show();
		classChange('.tab1', '.tab2', 'active');
	}else if(window.location.hash == '#kontaktformular'){
		jQuery('#kontakt').show();
		jQuery('#adresse').hide();
		classChange('.tab2', '.tab1', 'active');
	};
	
	jQuery('.tab1').bind('click',function(event){
		jQuery('.beschreibung') ? jQuery('.beschreibung').show() : false;
		jQuery('.preise') ? jQuery('.preise').hide() : false;
		jQuery('#adresse') ? jQuery('#adresse').show() : false;
		jQuery('#kontakt') ? jQuery('#kontakt').hide() : false;
		classChange('.tab1', '.tab2', 'active');
	});

	jQuery('.tab2').bind('click', function(event){
		jQuery('.beschreibung') ? jQuery('.beschreibung').hide() : false;
		jQuery('.preise') ? jQuery('.preise').show() : false; 
		jQuery('#adresse') ? jQuery('#adresse').hide() : false;
		jQuery('#kontakt') ? jQuery('#kontakt').show() : false;
		classChange('.tab2', '.tab1', 'active');
	});
	
	jQuery('input[name="vorname"], input[name="nachname"], input[name="email"], input[name="subject"], .message').focus(function() {
			if(jQuery(this).val()=='Vorname' || jQuery(this).val()=='Nachname' || jQuery(this).val()=='Email' || jQuery(this).val()=='Betreff' || jQuery(this).val()=='Ihre Nachricht'){
				jQuery(this).val('');
			}
		});
		
		jQuery('input[name="vorname"], input[name="nachname"], input[name="email"], input[name="subject"], .message').blur(function(){
			if(jQuery(this).val()==''){
				
				if(jQuery(this).hasClass('vorname')){
					jQuery(this).val('Vorname');	
				}else if(jQuery(this).hasClass('nachname')){
					jQuery(this).val('Nachname');
				}else if(jQuery(this).hasClass('email')){
					jQuery(this).val('Email');
				}else if(jQuery(this).hasClass('subject')){
					jQuery(this).val('Betreff');
				}else if(jQuery(this).hasClass('message')){
					jQuery(this).val('Ihre Nachricht');	
				}
				
			}
		});
});

$(document).ready(function(){
	checkWindowSize();
	setTimeout(function(){
		fadeInDiv('#wrapper', 'slow');
		fadeInDiv('#footer', 'slow');
	}, 1200);
});

$(window).resize(function(){
	checkWindowSize();
});

function checkWindowSize(){
	var windowWidth = $(window).innerWidth();
	var windowHeight = $(window).innerHeight();
	$('#wrapper').width(windowWidth);
	$('#wrapper').height(windowHeight);
	$('#stage').width(windowWidth);
	$('#footer').width(windowWidth);
	$('.contentElement').width(windowWidth);
	$('#mainMenu').width(windowWidth);
	if(windowHeight <= 650){
		jQuery('#mainMenu').css({
			'position':'static'
		});
		jQuery('#footer').css({
			'position':'static'
		});
		jQuery('#stage').css({
			'position':'static'
		});
		jQuery('body').css({
			'overflow':'auto'
		});
	}else if(windowHeight > 650){
		jQuery('#mainMenu').css({
			'position':'absolute'
		});
		jQuery('#footer').css({
			'position':'absolute'
		});
		jQuery('#stage').css({
			'position':'absolute'
		});
		
	
	}
	
	if(windowWidth < 960){
		jQuery('body').css({
			'overflow':'auto'
		});
		
		jQuery('#wrapper').css({
			'width':'960px'
		});
		jQuery('#stage').css({
			'width':'960px'
		});
		
		jQuery('#footer').css({
			'width':'960px'
		});

	}else if(windowWidth > 960){
		
		jQuery('#wrapper').css({
			'width': windowWidth
		});
		jQuery('#stage').css({
			'width':windowWidth
		});
		
		jQuery('#footer').css({
			'width':windowWidth
		});
	
	}
};

function fadeInDiv(id, speed){
	jQuery(id).fadeIn(speed);
};

function classChange(first, secnd, cClass){
	jQuery(first).addClass(cClass);
	jQuery(secnd).removeClass(cClass);
};

jQuery(function(){
	jQuery('#kontakt').submit(function(event){
		var formData = decodeURIComponent(jQuery('#kontakt').serialize());
		jQuery.getJSON('kontakt.php?'+formData, function(data) {
			var error = new Array();
			jQuery.each(data, function(key, val){
				if(val.condition === false){
					changeFalse(val.cClass);
					alert(val.message);
					error.push(false);
				}else if(val.condition === true) {
					changeTrue(val.cClass);
			        error.push(true);
				}
			});
			//console.log(error);
			if(jQuery.inArray(false, error) == '0'){
				
			}else {
				jQuery.getJSON('kontakt.php?'+formData+'&cmd=send', function(data) {
					jQuery.each(data, function(key, val){
						if(val.cClass == 'send'){
							jQuery('#kontakt div').last().append(val.message);
						}
					});
						
				});
			}
  		});
  		
		event.preventDefault();
		return false;
	});
});

function changeFalse(cClass){
	jQuery('#kontakt input[name="'+cClass+'"]').css({
		'background':'#F00',
		'color':'#FFF'
	});
};

function changeTrue(cClass){
	jQuery('#kontakt input[name="'+cClass+'"]').css({
		'background':'#dadada',
		'color':'#000'
	});
};
