
(function($){
function closeIt(){
  $('#contactCont').slideToggleWidth();
}
$.fn.extend({
  slideUp: function() {
    return this.each(function() {
      
      $(this).animate({height: '0px'},"slow","swing", function(){ $(this).hide();});
    });
  },
  slideDown: function() {
    return this.each(function() {
      $(this).show();
      $(this).animate({height: '260px'},"slow","swing");
    });
  },
  slideToggleWidth: function() {
    return this.each(function() {
      var el = jQuery(this);
      if (el.css('height') != '0px') {
        el.slideUp();
      } else {
        el.slideDown();
      }
    });
  }
});
$(document).ready(function(){
    $( "#draggable" ).draggable();
	$('.error').hide();
	$('#contactCont').hide();
	$('#contactCont').height("0px");
	/*$('#contactForm').hide();*/
	$('a.email').each(function(){
		e = this.rel.replace('/','@');
		this.href = 'mailto:' + e;
		$(this).text(e);
	});
	$("#contactLink").click(function(){
		$("#contactCont").slideToggleWidth();
    });
    $("input:[input]").each(function(){
    	this.click(function(){
        $("#contactCont").slideDown();
	    });
    });
    $("#closer").click(function(){
        $("#contactCont").slideToggleWidth();
    });
});

function check_mail( email ){ 
	return (email.indexOf(".") > 2) && (email.indexOf("@") > 0); 
};

$(function() {
    
	$("#CSbutton").click(function() {
		// validate and process form here
		$('.error').hide();
  	  	var name = $("input#name").val();
  		if (name == "") {
        	$("label#name_error").show();
        	$("input#name").focus();
        	return false;
      	}
  		var email = $("input#email").val();
  		if (email == "" || check_mail(email) != true) {
        	$("label#email_error").show();
        	$("input#email").focus();
        	return false;
      	}
  		var phone = $("input#phone").val();
  		/*if (phone == "") {
        	$("label#phone_error").show();
        	$("input#phone").focus();
        	return false;
      	}*/
      	var subject = $("input#subject").val();
      	var site = $("input#site").val();
		  var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&subject=' + subject + '&site=' +site;
		  //alert (dataString);return false;
		  $.ajax({
		    type: "POST",
		    url: "http://www.glasprofi24.de/wp-content/themes/glasprofi24/process.php",
		    data: dataString,
		    success: function() {
		      $('#contactCont').html("<div id='message'></div>");
		      $('#message').html("<h2>Rückrufbitte gesendet!</h2>")
		      .append("<p>Wir werden Sie in Kürze zurückrufen.</p>")
		      .fadeIn(1500, function() {
		        $('#message').append("<img id='checkmark' src='http://www.glasprofi24.de/wp-content/themes/glasprofi24/images/tick.png' />");
		        $('#contactCont').delay(4000).slideToggleWidth();
		        
		      });
		    }
		  });
		  return false;
	});
});
})(jQuery);

