$(document).ready(function() {

	$('#footer img, #logo img, .slide.fooldal h1').ifixpng(); 

	$('.slide').fadeIn();
    
    $("div.kapcsolat_menu").tabs("div.kapcsolat_form > .form", {
        effect: 'fade'
    });
    
    $("#szolg_menu").tabs("#szolgaltatasok_tabs > .tab", {
        effect: 'fade'
    });
    
    $.validator.methods.equal = function(value, element, param) {
        return value == param;
    };
    
    jQuery.validator.addMethod("phone", function(phone_number, element) {
        phone_number = phone_number.replace(/\s+/g, "");
        return this.optional(element) || phone_number.length > 9 &&
        phone_number.match(/^[-+]?\d*\.?\d*$/);
    }, "Valós telefonszámot adjon meg!");
    
    $.validator.methods.phone = function(value, element, param) {
        return value == param;
    };
    
    
    
    
    $("#altalanos_form").validate({
        wrapper: 'label class="error"',
        errorElement: "span",
        errorPlacement: function(error, element) {
            var hibauzi = '<label class="error"><span>'+error+'</span></label>';
            error.insertAfter(element);
            
        },
        debug:true,
        rules: {
            captcha: {
                required: true,
                equal: 4
            }
        },
        messages: {
            captcha: "Hibás szám",
            email: "Valós e-mail címet adjon meg!"
        },
        submitHandler: function(form) {
            jQuery(form).ajaxSubmit({
                success: showResponse
            });
        }
    });
    
    
    $("#projekt_form").validate({
        wrapper: 'label class="error"',
        errorElement: "span",
        errorPlacement: function(error, element) {
            var hibauzi = '<label class="error"><span>'+error+'</span></label>';
            error.insertAfter(element);
            
        },
        debug:true,
        rules: {
            captcha: {
                required: true,
                equal: 4
            }
        },
        messages: {
            captcha: "Hibás szám"
        },
        submitHandler: function(form) {
            jQuery(form).ajaxSubmit({
                success: showResponse
            });
        }
    });
    
    
    $('p.submit a').click(function(){
        var id = $(this).attr('href');
        $("form"+id).submit();
        return false;
    });
    $('a.easter_egg').click(function(){
        $('html, body').animate({scrollTop:0}, 'slow');
        return false;
    });
    
	$('a.spam_protect').spam_protect();
	
	$('a.tooltip').hover(function() {
		var title = $(this).attr('title');
		$(this).addClass('active');
		$(this).html('<span>'+title+'</span>'); 
		$(this).removeAttr('title');
	}, function() {
		var title = $(this).text();
		$(this).removeClass('active');
		$(this).html('');
		$(this).attr('title',title);
	});


});

function showResponse(responseText, statusText)  {
    $('#formok').slideUp('slow');
    $('#success').slideDown('slow');
}

(function($){

	$.fn.spam_protect = function(options) {
		return this.each(function() {
			obj = $(this);
			href = obj.attr('href');
			href_replaced_1 = href.replace("|", "@");
			href_replaced_2 = href_replaced_1.replace(":", ".");
			obj.attr({ 
				href: 'mailto:'+href_replaced_2,
				title: 'E-mail cím: '+href_replaced_2
          	});
			obj.html(href_replaced_2);
		});
	};
})(jQuery);
