$(function(){
	/**
	 * DEFAULTS
	 **/
	
	// Alert/Flash Message
	setTimeout(hideAlert,4000);
	$("#alert-message").click(function(){
	    hideAlert();
	});
	function hideAlert(){
	    if ($("#alert-message")[0]) { $("#alert-message").slideUp('fast'); }
	}
	
	// END
	
	/**
	 * TARGET BLANK
	 */
	$('.target-blank').click(function(){
		$(this).attr('target', '_blank').click();
		return false;
	});
	
	//corner
	//$('.border').corner("8px");
	//$('.borderHighlight').corner("3px");
	
	//retira a prorpiedade do link
	$('a.active').click(function(e){
		e.preventDefault();
	});
	
	//hoverList
	$('.hoverList').css('opacity','0.8');
	$('.hoverList').hover(function(){
		$(this).stop(true,true).animate({
			left:"20px",
			opacity: '1.0'
		}, 'fast');
	}),
	$('.hoverList').stop(true,true).mouseout(function(){
		$(this).animate({
			left:"0px",
			opacity: '0.8'
		},'fast');
	});


	/* Hide Values Default Form Home */
	$('input[type=text]').each(function(index) {
        var valor_previous = $(this).val();
        $(this).focusin(function() {
            var self = $(this);
            var valor = self.val();
            if(valor == valor_previous){
                self.val("");
            }
 
        }).focusout(function() {
            var valor = $(this).val();
            if(valor == ''){
                $(this).val(valor_previous);
            }
        });
    });
    
	$('#fnews').submit(function(){
	
		var base_path = 'http://localhost/projetos/hairfly/';
		var email = $('#email').val();
		var type = $('#option').val();
		
		if(type.length > 0 && email.length > 0){
			$.post(base_path + 'newsletters/', {email: email, type: type}, function(result){
				var result = $.trim(result);
				switch (result){
					case 'success': alert('Casdastro realizado com sucesso');
						$('#email').val('');
						$('#option').val('');	
					break;
					
					case 'already': alert('Esse email já esta cadastrado');
						$('#email').val('');
						$('#option').val('');	
					break;
									
					case 'validate': alert('Todos os campos devem ser preenchidos corretamente'); break;
					
					default: alert('Erro ao realizar cadastro, tente novamente.');
				}
			});
		}else{
			alert('Todos os campos devem ser preenchidos corretamente');
		}
		
		return false;
		
	});
});

