/* function to fix the -10000 pixel limit of jquery.animate */
$.fx.prototype.cur = function(){
    if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
      return this.elem[ this.prop ];
    }
    var r = parseFloat( jQuery.css( this.elem, this.prop ) );
    return typeof r == 'undefined' ? 0 : r;
}
$(document).ready(function() {
	$(window).resize();
	$('#descubraMais p').click(function() {
		console.log($('#quemSomos').css("display"));
		if ($('#quemSomos').css("display") == "none") {
			$('#descubra p').fadeOut();
			$('#descubraMais p').css('background', 'url(img/descubraMaisDown.png) no-repeat right center');
			$('#descubra').animate({
				height: '20px',
				'padding-top': 0,
				'padding-bottom': 0,
				'padding-left': 65,
				'padding-right': 65
			}, 1000, 'swing');

			$('#quemSomos').show();
			$('#quemSomos').animate({
	        	height: '490px'
	    	}, 1000, 'swing');
    	} else {
			$('#descubra').animate({
				height: '378px',
				'padding-top': 55,
				'padding-bottom': 55,
				'padding-left': 65,
				'padding-right': 65
			}, 1000,'swing');
			$('#descubra p').fadeIn();
			$('#descubraMais p').css('background', 'url(img/descubraMais.png) no-repeat right center');
			$('#quemSomos').fadeOut('fast');
			$('#quemSomos').animate({
	        	height: '0px'
	    	}, 1000, 'swing');
    	}
	});
	$("input, textarea").each(function() {
		if ($(this).attr("type") == "text" || $(this).attr("type") == "password" || $(this).is("textarea")) {
			var defaultText;
			$(this).is("textarea") ? defaultText = $(this).html() : defaultText = $(this).val();
			$(this).focus( function() {
				if ($(this).val() == defaultText) { $(this).val(""); }
			});
			$(this).blur( function() {
				if ($(this).val() == "") { $(this).val(defaultText); }
			});
		}
	});
	if ($("#portfolio.projetos").length) {
		$('#portfolio').jScrollPane({
			showArrows: true,
			hideFocus: true,
			hijackInternalLinks: true,
			animateScroll: true,
			horizontalDragMinWidth: 37,
			horizontalDragMaxWidth: 37
		});
	} else if ($("#portfolio").length) {
		$('#portfolio').jScrollPane({
			showArrows: true,
			hideFocus: true,
			horizontalDragMinWidth: 37,
			horizontalDragMaxWidth: 37
		});
	}
	$(".jspArrowLeft, .jspArrowRight").css({
        "opacity":"0.3"
    });
    $(".jspArrowLeft, .jspArrowRight").hover(
        function() {
            $(this).stop().animate({"opacity": "1"}, "slow");
        },
        function() {
            $(this).stop().animate({"opacity": "0.5"}, "slow");
    });
    $("#newsletterForm").submit(function() {
    	console.log($('#emailNews').val());
    	$.post('gravanewsletter.php', { 
	    	emailNews: $('#emailNews').val()
	    }, function(data) {
	    	console.log(data);
  			$('#result').html(data);
		});
    	return false;
    });
});

