    function isLocalHost() {
        var exp = new RegExp('^(192.|local|127.)');
        return exp.test(location.host)?true:false;
    }

    function locationUrl(i,conc) {
        return location.href.split('/')[i]+conc;
    }

    function baseUrl() {
        return isLocalHost()?'http://'+locationUrl(2,'/')+locationUrl(3,'/'):'http://'+location.hostname+'/';
    }
    
    cookie = {
        add:function(name,value,days){
            var expires = "";
            if (days)
            {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                expires = "; expires="+date.toGMTString();
            }
            document.cookie = name+"="+value+expires+"; path=/ ;";
        },
        get:function(name){
            var nameEQ = name + "=";
            var ca = document.cookie.split(';');
            for(var i=0;i < ca.length;i++) {
                var c = ca[i];
                while (c.charAt(0)==' ')
                c = c.substring(1,c.length);
                if (c.indexOf(nameEQ) == 0)
                return c.substring(nameEQ.length,c.length);
            }
            return null;
        },
        del:function(name){
            cookie.add(name,"",-1);
        }
    }
    
    $(function() {

		var ie7 = $.browser.msie && parseInt($.browser.version) >= 7 ? true : false;

		var speed = ie7 ? 0 : 1100;
    	
    	if ($('#slideShow').size() > 0) {
	    	$('#slideShow,#logo,#navegacao').hide();
	    	$('#texto_inicial').css('visibility', 'hidden');
	    	$('#logo').fadeIn(speed, function() {
	    		$('#texto_inicial').hide().css('visibility', 'visible').fadeIn(speed);	
	    	});
    	}
    	
    	
    	var loadImg  = 0;
    	
    	var rodouPaginaInicial = cookie.get('texto_inicial');    	
    	
    	if (rodouPaginaInicial == 1) {
        	var tempoParada  = 3.5 * 1000; //segundos    		
    	}else {
    		var tempoParada  = 10 * 1000; //segundos
    	}    	

    	var tempoInicial = new Date().getTime();
    	
    	var totalImg = $('ul.slides img').each(function() {
	       var img = new Image();
	       $(img).load(function() {
	           loadImg++;
	       }).attr('src',this.src);
	    }).size();    	
    	
    	var ponto  = 0;
    	var stringPonto = '';
    	var timerProjetos3Pontinhos = setInterval(function() {
    		ponto++;
    		stringPonto += '.';
    		if (ponto == 3) {
       			ponto = 0;
    			stringPonto = '.';
    		}    		    		
    		$('#carregando_projetos span').html(stringPonto)
    	}, 300);


    	
    	var timer = setInterval(function() {    		
    		var tempoExecucao = new Date().getTime();
    		if (loadImg == totalImg && (tempoExecucao - tempoInicial) > tempoParada) {
    			cookie.add('texto_inicial', 1);
    			$('#texto_inicial').fadeOut(speed, function() {
    				$('#slideShow').fadeIn(speed, function() {

						$('#navegacao').fadeIn(500);
    					$('#slideShow').slideShow({
    						hoverNavigation: false,
    						interval: 5,
    						transition: {
    							mode: 'fade',
    							speed: speed
    						}
    					});
    				});
    			});
    			clearTimeout(timerProjetos3Pontinhos);
    			clearTimeout(timer);
    		}
    	},100);

    	
  		setTimeout(function(){
            $('.lista_cliente img').hover(function() {
                $(this).fadeTo(100,1);
            },function() {
                $(this).fadeTo(100,0.75);
            }).each(function() {
            	$(this).fadeTo(0,0.75);
            });
        },30);


	    $('#abre_form,#voltar_criacao_site,#bt_finalizar').click(function() {
	        $('#form_orcamento').slideToggle(300,function() {
	            if ($(this).is(':visible')) {
	                $('#abre_form').closest('p').find('span').html('<span>Preencha corretamente nosso formulario e em breve retornaremos o contato.</span>');
	                $('#abre_form').html('');
	            }else {
	                $('#abre_form').closest('p').find('span').html('<span>Caso não queira usar nossa ferramenta de criação,</span>');
	                $('#abre_form').html('<strong>vá para área de orçamento</strong>');
	            }
	            $('#ferramentas,#paleta_cor').slideToggle(300);
	        });
	        return false;
	    });
	
	    $('form').submit(function() {
	        $(this).find('input,textarea').each(function(){
	            if ($(this).attr('title')==$(this).val()) {
	                $(this).val('');
	            }
	        });
	    });
	
	    $('input[type=text],textarea').focus(function(){
	            if (this.value==$(this).attr('title'))
	            $(this).val('');
	            $(this).addClass('selecionado');
	        }).blur(function(){
	            if ($(this).attr('title')==this.value || this.value=='')
	            $(this).val($(this).attr('title'));
	            $(this).removeClass('selecionado');
	        }).each(function(){
	            if (this.value=='')
	                $(this).val($(this).attr('title'));
	    });
	
	
	    //Envio de formulário
	    function notEmpty(value) {
	        return $.trim(value)!=''?true:false;
	    }
	    
	    function isMail(value) {
	        var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	        return emailPattern.test(value);
	    }
	    
	    $('#aba_contato').click(function() {
	        $('#box_contato').toggle(300);
	    });
	
	    $('form.contato').submit(function() {
			var form  = this;
	        var valid = true;
	        var inputs = '';
	
            var campos = $(this).find('input,textarea,select');
	
	        inputs += $(campos).removeClass('erro').each(function() {
	            try {
	                var rules = $(this).attr('rel').split('|');
	                for (var i in rules) {
	                    var erro = eval(rules[i]+'('+this.value+')');
	                    if (!erro) {
	                        valid = false;
	                        $(this).prev().addClass('erro');
	                    }else {
	                        $(this).prev().removeClass('erro');
						}
	                }
	            }catch(e){
	            }
	        }).serialize();
	        if (valid) {
	            $.ajax({
	                url:baseUrl()+'ajax/contato/',
	                data:inputs,
	                type			:'post',
	                dataType	:'json',
					beforeSend : function() {
						$('body').css('cursor', 'wait');
						$(form).find('.bt_enviar_mensagem').fadeOut(150, function() {
							$('#bt_enviando').fadeIn(150);
						});
					},
					complete : function() {
						$('body').css('cursor', 'default');
						campos.each(function() {
							$(this).val('');
						});
						alert("Seu contato foi enviado com sucesso.\nVocê receberá uma resposta dentro de 1 dia útil");
						return true;
					}
	            });
	        }
	        return false;
	    });
	    
	    $('.mostrar_campanhas').click(function() {
	    	var button = this; 
	    	$(this).parent().find('li:hidden').fadeIn(500, function() {
	    		$(button).fadeOut(350);
	    	});
	    	return false;
	    });
	    
	    $('.texto_oculto').hide();
	    $('.ver_depoimento_completo').mouseover(function() {
	    	var link = this;
	    	$('.texto_visivel').html($('.texto_visivel').html().replace('...', ''));
	        $('.texto_oculto').fadeIn(300);
	        $(link).remove();
	    }).click(function() {
	    	return false;
	    });

});

