jQuery.loadingForm = function(form){
	jQuery("div.aviso_carregando").remove();
	jQuery("<div/>").addClass('aviso_carregando').prependTo(form).html( $("#msgloading",form).val() );	
}

jQuery.modal = function(msg,type,log){
	$("<div/>").addClass("form-dialog "+type).html(msg).prependTo("#contato");
}
jQuery.fechaModalTodos  = function(){  };

jQuery.kv.marca = function(P,erro){
	var form = this;
	var camposErro = [];
	$(".form-display").html('');
	jQuery.each(erro, function(i, val){
		var campo = jQuery("*[name='"+val.name+"']",P.form).parents(".form-campo:first");
		campo.addClass(P.erroClass);
		$(".form-display",campo).html(val.erro);
		camposErro.push((jQuery("*[name='"+val.name+"']",P.form).attr("campo")||val.name)+" = "+val.erro);
	});
};

$(function(){
	$("#contato").bind('success',function(json){
		$("#contato").resetForm();
		setTimeout(function(){ $("#contato .form-dialog:last").fadeOut('slow',function(){ $(this).remove(); }); },3000);
		$("#contato #submit").removeAttr("disabled").val("Enviar");
	});
	$("#contato").bind('error',function(json){
		setTimeout(function(){ $("#contato .form-dialog:last").fadeOut('slow',function(){ $(this).remove(); }); },3000);
		$("#contato #submit").removeAttr("disabled").val("Enviar");
	});
	$("#contato").bind('beforeSend',function(){
		$("#contato #submit").attr({disabled:"disabled"}).val("Aguarde...");
	});
});

$.fn.destacaFoto = function(P){
	P = jQuery.extend({
		width: 100,
		height: 100,
		mais: 20,
		eMais: ".foto img",
		opacity: .5
	}, P);
	P.quadro = $(this);
	$(P.eMais,this).mouseover(function(){
		P.thumb = $(this)
		.css({
			position: 'relative',
			margin: -P.mais/2,
			width:P.width+P.mais,
			height:P.height+P.mais,
			zIndex: 100
		});
	}).mouseout(function(){
		P.thumb = $(this)
		.css({
			position: 'static',
			zIndex: '',
			margin: 0,
			width:P.width,
			height:P.height
		})
	});
};
$.destacaFotoVolta = function(e,P){
	$(e).remove();
};
$(function(){
	$("#portfolio-voltar").click(function(){
		$(window).scrollLeft(0);
	});
    /*
    if($(window).width()<$(document).width()){
        var meioTop = ($(window).height()-$("#indicaScroll").height())/2;
        var meioLeft = ($(window).width()-$("#indicaScroll").width())/2;
        $("#indicaScroll").css({top:meioTop}).fadeIn(1000,function(){
            $(this).animate({top:$(window).height()-60}, 800, 'easeOutBounce');
        }).click(function(){
            $(this).fadeOut(800);
        });
    }*/
	$.scrollTimmer;
	$.scroller = function(operador){
		$(window).scrollLeft( parseInt($(window).scrollLeft())+(operador*3) );
		$.scrollTimmer = setTimeout(function(){
			$.scroller(operador);
		},1);
	}
    $(window).mousemove(function(e){
		var x = e.pageX - $(window).scrollLeft();
		var w = $(window).width();
		var borda = 100;
		if( x >= w-borda ){
			clearTimeout($.scrollTimmer);
			$.scroller(3);
		}else{
			clearTimeout($.scrollTimmer);
		}
        if( $("#portfolio-list").length == 0 ){
            if( x <= borda ){
                clearTimeout($.scrollTimmer);
                $.scroller(-3);
            }
        }
        if( x > borda && x < w-borda ){
            clearTimeout($.scrollTimmer);
        }
    });
});

