jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}

jQuery.fn.popup = function(){
	jQuery('body').append('<div id="backgroundPopup" style="display:none; position:fixed; _position:absolute; height:100%; width:100%; top:0; left:0; background:#000000; border:1px solid #cecece; z-index:1;"></div>  ');
	if(jQuery('#backgroundPopup').is(':visible') == true) {
		jQuery("#backgroundPopup").fadeOut("slow");  
		jQuery(this).fadeOut("slow");  
	} else {
		jQuery("#backgroundPopup").css({  
	 		"opacity": "0.7"  
	 	});  
	 	jQuery("#backgroundPopup").fadeIn("slow");  
	 	jQuery(this).fadeIn("slow");
		
		jQuery(this).center();  
	}
    return this;
}

jQuery(document).ready(function(){
	jQuery('.infos .contato').click(function() {
		jQuery('.pop_contato').popup();
		return false;
	});
	
	$('.pop_up .fechar, .pop_up .cancelar').click(function(){
		$(this).closest('.pop_up').popup();
		return false;
	});
	
	$('.l_contato').click(function(){
		$('.pop_contato').popup();
		return false;
	});

	$('.duvida_l').click(function(){
		$('#contato_tipo').val('Duvida');
		$('.pop_contato').popup();
		return false;
	});

	$("#contato_form").validate({
		rules: {
			nome_completo: "required",
			email: {
				required: true,
				email: true
			},
			assunto: "required",
			descricao: "required",
		},
		submitHandler: function(form){
			$('input[type=submit]', $(form)).attr('disabled', 'disabled');
			$(form).ajaxSubmit({
				target: '.pop_contato .content'  
			});
		},
	});

        $(".fazer_login").click(function(){
            $(this).closest('.pop_up').popup();
            $("#usuario").focus();
            return false;
        });

        $(".novo_membro").click(function(){
            $(this).closest('.pop_up').popup();
            window.location = $(this).attr('value');
            return false;
        })

});
