$(document).ready(function() {
	$(".current-menu-item > a").removeAttr('href');
	$.backstretch("http://www.accionchile.cl/images/fondos/fondo"+$.randomBetween(1, 12)+".jpg");
	$(".menu-item-type-custom").hover(function(){
		$(this).children(".sub-menu").fadeIn();
	}, function(){
		$(this).children(".sub-menu").fadeOut();
	});
	$('.item').each(function(){
		$(this).children('#example1').hover(function(){
			$(this).children('.gris').hide();
			$(this).children('.item_normal').show();
		}, function(){
			$(this).children('.gris').show();
			$(this).children('.item_normal').hide();
		});
	});
	$(".defaultText").focus(function(){
			if ($(this).val() == $(this)[0].title)
        	{
            	$(this).val("");
				$(this).css('color','#FFF');
        	}
	});
	$(".defaultText").each(function(){
			if ($(this).val() == "")
        	{
           		$(this).val($(this)[0].title);
				$(this).css('color','#727272');
        	}
	});
	$(".defaultText").blur(function(){
		$(".defaultText").each(function(){
				if ($(this).val() == "")
        		{
            		$(this).val($(this)[0].title);
					$(this).css('color','#727272');
        		}
		});
	});
	$('#contacto').submit(function(){
		$(".defaultText").each(function(){
			if ($(this).val() == $(this)[0].title)
        	{
            	$(this).val("");
				$(this).css('color','#FFF');
        	}
		});
		var aux1=true;
		var aux2=true;
		var aux3=true;
		var aux4=true;
		if($('#input_nombre').val().length<1){
			aux1=false;
			$("#nombre").fadeIn();
		}
		if($('#input_email').val().length<1){
			aux2=false;
			$("#email").fadeIn();
		}
		if($('#input_asunto').val().length<1){
			aux3=false;
			$("#asunto").fadeIn();
		}
		if($('#input_mensaje').val().length<1){
			aux4=false;
			$("#mensaje").fadeIn();
		}
		if(aux1&&aux2&&aux3&&aux4){
			$.ajax({
            type: 'POST',
            url: $(this).attr('action'),
            data: $(this).serialize(),
            success: function(data) {
                $('#result').html(data);
            }
			});
		}else{
			$(".defaultText").each(function(){
				if ($(this).val() == "")
        		{
            		$(this).val($(this)[0].title);
					$(this).css('color','#727272');
        		}
			});
		}
		return false;
	});
	$('#input_nombre').keyup(function(){
		$('#nombre').fadeOut();
	});
	$('#input_email').keyup(function(){
		$('#email').fadeOut();
	});
	$('#input_asunto').keyup(function(){
		$('#asunto').fadeOut();
	});
	$('#input_mensaje').keyup(function(){
		$('#mensaje').fadeOut();
	});
	$(document).ajaxStart(function() {
		$('#result').html("Procesando");
    }).ajaxStop(function() {
		$('.aux').each(function(){
			$(this).val($(this)[0].title);
			$(this).css('color','#727272');
		});
    });
	$(".img_tooltip[title]").tooltip({

   		// tweak the position
  		offset: [-25, 0],
		position: 'center left',
		tipClass: 'tooltip2',
   		// use the "slide" effect
  		effect: 'slide'

		// add dynamic plugin with optional configuration for bottom edge
		//}).dynamic({ bottom: { direction: 'down', bounce: true } 
	});
});

function aparece(){
	$("#loader").fadeOut('slow');
	$("#contenedor").fadeIn('slow');
	$("#logo").stop().animate({ paddingLeft: '280px'}, {queue: false, duration: 800 });
	$("#video_prem").stop().animate({ paddingRight: '360px'}, {queue: false, duration: 800 });
}
