jQuery(function($){
	// reset css from JavaScript disabled defaults
	if(jQuery.browser.msie && parseInt(jQuery.browser.version) == 6){
		$(".feature-right").css({
			"margin-left": "40px"
		});
	} else {
		$(".feature-right").css({
			"margin-left": "80px"
		});
	}
	
	$("#featured").css({		// when JS is off, Features scroll inside their view
		"overflow-x": "hidden",
		"overflow-y": "hidden"
	});
	

	

	     
	// top drawer
	// set different heights for the drawer based on the browser
	if($.browser.msie){
		if(parseInt($.browser.version) == 6){
			window.drawerHeight = 201;
		} else {
			window.drawerHeight = 179;
		}
	} else {
		window.drawerHeight = 159;
	}
	$("#hire-me-drawer").css({"top": "-"+window.drawerHeight+"px", "display": "block"});//display it
	$("#drawer-button").click(function(){
		if(parseInt($("#hire-me-drawer").css("top")) == 0){
			$("#hire-me-drawer").animate({"top": "-"+window.drawerHeight+"px"}, 1200, "easeOutQuart");
			$(this).html("Schnellkontakt");
		} else {
			$("#hire-me-drawer").animate({"top": "0px"}, 1000, "easeOutBounce");
			$(this).html("schliessen");
		}
	}).focus(function(){
		$(this).blur();// this removes focus border that looked awful
	});
	
	// crossfades for service icons
	$(".service-icon").each(function (i, element) {
		var src = $(element).find("img").attr("src").replace(".png", "-hover.png");
		$(element).css({background: "url("+src+") no-repeat 1px 1px"});
		$(element).hover(function(){
			$(this).find("img").animate({opacity: 0}, 700);
		}, function(){
			if($(this).find("img:animated").size() == 0){
				$(this).find("img").animate({opacity: 1}, 700);
			} else {
				$(this).find("img").stop().animate({opacity: 1}, 300);
			}
		});
	});
	
	// crossfades for buttons
	// main short buttons
	$(".main-button-short").each(function(i, element){
		var hover = $(element).clone().css({
			"background": "url(images/main-button-short-hover.jpg) no-repeat",
			"position": "relative", 
			"left": "-120px", 
			"z-index": "5", 
			"opacity": "0", 
			"margin-right": "-120px"
		});
		$(element).after(hover);
		$(element).next().hover(function(){
			$(this).animate({opacity: 1}, 300);
		}, function(){
			if($(this).is(":animated")){
				$(this).stop().animate({opacity: 0}, 100);
			} else {
				$(this).animate({opacity: 0}, 300);
			}
		});
	});
	
	// buttons in features
	$(".feature-buttons a").each(function(i, element){
		var hover = $(element).clone().css({
			"background": "url(images/feature-button-hover.jpg) no-repeat",
			"position": "relative", 
			"left": "-120px", 
			"z-index": "5", 
			"opacity": "0", 
			"margin-right": "-120px"
		});
		if($(element).hasClass("feature-button-next")){
			hover.css({"margin-right": "-100px", "left": "-100px"});
		}
		$(element).after(hover);
		$(element).next().hover(function(){
			$(this).animate({opacity: 1}, 300);
		}, function(){
			if($(this).is(":animated")){
				$(this).stop().animate({opacity: 0}, 100);
			} else {
				$(this).animate({opacity: 0}, 300);
			}
		});
	});
	
	// long buttons in main
	$(".main-button-long").each(function(i, element){
		var hover = $(element).clone().css({
			"background": "url(images/main-button-long-hover.jpg) no-repeat",
			"position": "relative", 
			"top": "-65px", 
			"z-index": "5", 
			"opacity": "0", 
			"margin-bottom": "-65px"
		});
		
		$(element).after(hover);
		$(element).next().hover(function(){
			$(this).animate({opacity: 1}, 300);
		}, function(){
			if($(this).is(":animated")){
				$(this).stop().animate({opacity: 0}, 100);
			} else {
				$(this).animate({opacity: 0}, 300);
			}
		});
	});
	


/* Contact.js */

$(document).ready(function(){
	// in kontakt.php
	$("#main-contact-form").submit(function(){
		// 'this' refers to the current submitted form
		var str = $(this).serialize();
		$.ajax({
			type: "POST",
			url: "contact.php",
			data: str,
			success: function(msg){
				$("#note").ajaxComplete(function(event, request, settings){
					if(msg == 'OK'){ // Message Sent? Show the 'Thank You' message and hide the form
						result = '<div class="notification_ok">Ihre Nachricht wurde versendet. Vielen Dank.</div>';
						$("#fields").hide();
					} else {
						result = msg;
					}
					$(this).html(result);
				});
			}
		});
		return false;
	});
	
	// Drawer contact
	$("#drawer-form>form").submit(function(){
		// 'this' refers to the current submitted form
		var str = $(this).serialize();
		$.ajax({
			type: "POST",
			url: "contact.php",
			data: str,
			success: function(msg){
				if(msg.indexOf("notification_ok") > 0){ // Message Sent? Show the 'Thank You' message and hide the form
				    $("#drawer-form>form").html('<div class="drawer_notification_ok">Ihre Nachricht wurde versendet. Vielen Dank.</div>');
				} else {
				    alert(msg.replace("<br />", "\n").replace("<br />", "\n").replace("<div class=\"notification_error\">", "").replace("</div>", ""));
				}
			}
		});
		return false;
	});
})});