$(document).ready(function() {
		
		$("#planungs-container a").click( function() {
			$(this).attr('href', '#');
			var image_link = $(this).attr("rel");
			var image_title = $(this).attr("title");
			$("#page-picture > img").css('opacity', 0).attr({
			  alt: image_title,
			  title: image_title,
			  src: image_link
			}).fadeTo(600, 1);
		});
		
		$(".image-color").each(function() {
        if ($(this).attr("src").match(/_color\.png$/i)) {
				$(this).removeClass("hover");
			}
		});
		$(".image-color").hover(function() {
			s = $(this).attr("src").replace(/\.png$/i, "_color.png");
			$(this).attr("src", s);
		}, function() {
			s = $(this).attr("src").replace(/_color\.png$/i, ".png");
			$(this).attr("src", s);
		});


		
		$('form#contactForm').submit(function() {
		$('form#contactForm .error').remove();
		var hasError = false;
		$('.requiredField').each(function() {
			if(jQuery.trim($(this).val()) == '') {
				var labelText = $(this).prev('label').text();
				$(this).css({'border-color': '#FF0000', 'background-color': '#FFEFEF'});
				hasError = true;
			} else if($(this).hasClass('email')) {
				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				if(!emailReg.test(jQuery.trim($(this).val()))) {
					var labelText = $(this).prev('label').text();
					$(this).val('Unkorrekte '+labelText).html();
					hasError = true;
				}
			}
		});
		if(!hasError) {
			$('form#contactForm li.buttons button').fadeOut('normal', function() {
				$(this).parent().append('<img src="/wp-content/themes/vtechnik/images/template/loading.gif" alt="Loading&hellip;" height="31" width="31" />');
			});
			var formInput = $(this).serialize();
			$.post($(this).attr('action'),formInput, function(data){
				$('form#contactForm').slideUp("fast", function() {				   
					$(this).before('<p class="thanks"><strong>Vielen Dank!</strong> Ihre Email wurde erfolgreich versendet. Wir werden uns in K&uuml;rze bei Ihnen melden.</p>');
				});
			});
		}
		
		return false;
		
		});
		
		
		$("div.header-titles").click(
		function()
		{
			window.location = $("a", this).attr("href");
			return false;
		});

		//MENUS IN IE
		if (!$.browser.msie) {
			$('.header-titles').prepend('<span class="hover"></span>').each(function () {
				  var $span = $('> span.hover', this).css('opacity', 0);
				  $(this).hover(function () {
					$span.stop().fadeTo(300, 1);
				  }, function () {
					$span.stop().fadeTo(500, 0);
				  });
			});
		}
		else {
			$('.header-titles').hover(function () {
					$(this).css({
						"background": "url(http://vtechnik.de/wp-content/themes/vtechnik/images/liniemenue.png) repeat-x",
						"background-color": "#0F3F7A"
						});
				  }, function () {
					$(this).css({"background": "url(http://vtechnik.de/wp-content/themes/vtechnik/images/feb_pixel.png) repeat"});
			});
		}
		
		
		//CHECKING WINDOW SIZES
		function checkWindowSizeBig() {
			
			if ( $(window).height() > 800 ) {
				$("#content, #box-container, #referenzen-box-container, #interessantes-content").addClass('large-margin');
				$("#header-menu").addClass('large-margin-top');				
			}
			else {
				$("#content, #box-container, #referenzen-box-container, #interessantes-content").removeClass('large-margin');
				$("#header-menu").removeClass('large-margin-top');				
			}
			
		}
		checkWindowSizeBig();
		$(window).resize(checkWindowSizeBig);
		
		function checkWindowSizeSmall() {
			
			if ( $(window).height() < 580 ) {
				$("html").css({"overflow": "visible"});
			}
			else {
				$("html").css({"overflow": "hidden"});
			}
			
		}
		checkWindowSizeSmall();
		$(window).resize(checkWindowSizeSmall);
		
		function checkWindowWidth() {
			var right = $("div.page-title").css("right");
			if ( $(window).width() < 1090 ) {
				$("div.page-title,div#home-title").css("right","0px");
			}
			else {
				$("div.page-title,div#home-title").css("right",right);
			}
			
		}
		checkWindowWidth();
		$(window).resize(checkWindowWidth);


});
$(window).bind('load', function() {
    var preload = new Array();
    $(".image-color").each(function() {
        s = $(this).attr("src").replace(/\.png$/i, "_color.png");
        preload.push(s)
    });
    var img = document.createElement('img');
    $(img).bind('load', function() {
        if(preload[0]) {
            this.src = preload.shift();
        }
    }).trigger('load');
});
