$(document).ready(function() {
	$("#site-map-link").toggle(
      function () {
        $("#site-map-box").slideDown('slow');
      },
      function () {
        $("#site-map-box").slideUp('slow');
      }
    );
	
	$("#language-link").toggle(
      function () {
        $("#language-box").slideDown('slow');
      },
      function () {
        $("#language-box").slideUp('slow');
      }
    );
	
	
    
     $("#box-contact-send-inquiry").fancybox({
		'scrolling'		: 'no',
		'titleShow'		: false
	 });
    
    $("#contact-box").css({'width' : '530px', 'color' : '#3d3d3d', 'font-size' : '13px', 'background' : '#ffffff',  'padding' : '25px 25px 35px 32px'});
	$("#contact-required").css({'margin' : '5px 0 10px 0'});
    $("#contact-form-title").css({'font-size' : '13px', 'font-weight' : 'bold', 'margin' : '0 0 8px 0'});
	$("#contact-box p").css({'line-height':'150%'});
	$("#contact-box label").css({'display':'block', 'line-height':'150%', 'margin':'8px 0 2px 0'});
    $("#contact-box select").css({'width':'270px', 'height':'22px', 'border':'1px solid #abadb3'});
    $("#contact-email, #contact-phone").css({'width':'268px', 'height':'18px', 'border':'1px solid #abadb3'});
    $("#contact-box #contct-form-type label").css({'dispaly':'inline'});
    $("#contact-form-type").css({'margin':'5px 0 0 0', 'padding':'0', 'list-style-type':'none', 'overflow':'auto'});
	$("#contact-form-type li").css({'float':'left', 'line-height':'35px'});
	$("#contact-form-type input").css({'margin':'0', 'padding':'0'})
	$(".contact-form-type-desc").css({'margin':'0 20px 0 5px'})
    $("#contact-comment").css({'width':'270px', 'height':'75px', 'border':'1px solid #abadb3', 'font-size':'12px', 'font-family':'Arial'})
    $("#contact-form-send").css({'padding':'40px 0 0 270px'});
	$("#contact-form-send-input").css({'display':'block', 'width':'134px', 'height':'25px', 'background':'url("http://www.capitolium.pl/img/layout/button-send-inquiry.png") no-repeat', 'text-indent':'-9999px', 'cursor':'pointer', 'border':'0'});
	$("#contact-form-send-input-deutsch").css({'display':'block', 'width':'147px', 'height':'25px', 'background':'url("http://www.capitolium.pl/img/layout/deutsch/button-send-inquiry.png") no-repeat', 'text-indent':'-9999px', 'cursor':'pointer', 'border':'0'});
    $("#login_error, #email_error").css({'background-color':'#fdb1b1', 'border':'1px solid #fe0000', 'padding':'5px 10px'});
    $("#contact-type-person, #contact-type-firm").css({'margin-top':'10px'});
	
	$("#login_form").bind("submit", function() {
		if ($("#contact-email").val() == "") {
			
			$(this).find(".required-form").each(function(i) {
				if(!$(this).attr("disabled")) {
					if($(this).val() == "") {
						valid = false;
						$(this).css("background-color","#fdb1b1");
					} else {
						$(this).css("background-color","#ffffff");	
					}
				}
			});
			
		    $("#login_error").show();
		    
		    $.fancybox.resize();
		    return false;
    	}
    	else {
    		$("#login_error").hide();
    		$("#email_error").hide();
    		
    		var val = $("#contact-email").val();
    		
    		$(this).find(".required-form").each(function(i) {
				if(!$(this).attr("disabled")) {
					if($(this).val() == "") {
						valid = false;
						$(this).css("background-color","#fdb1b1");
					} else {
						$(this).css("background-color","#ffffff");	
					}
				}
			});
    		
    		if (!validateEmail(val)){
    			$("#login_error").hide();
    			$("#contact-email").css("background-color","#fdb1b1");
    			$("#email_error").show();
    			$.fancybox.resize();
    			return false;
    		}
    	}
    	
    	$.fancybox.showActivity();
    	
		$.ajax({
			type		: "POST",
			cache	: false,
			url		: "http://www.capitolium.pl/contact.php",
			data		: $(this).serializeArray(),
			success: function(data) {
				$.fancybox(data);
			}
    	});
	
		return false;
	});
	
	function validateEmail(address) {
   		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   		var address;
   		if(reg.test(address) == false) {
   		   return false;
   		}
   		else {
			   return true;
   		}
   	}
    
});

