// JavaScript Document

$(document).ready(function(){
	/**** PNG FIX ****/
	$(this).pngFix();
	
	
	/**** Scoll Interno ****/
	$settings = {
		scrollbarWidth: 20,
		wheelSpeed: 30,
		scrollbarMargin: 10,
		animateTo: true,
		animateInterval:50,
		animateStep:2,
		reinitialiseOnImageLoad: true
	};
	$('.scroll-pane').jScrollPane($settings);
	
	
	/**** Imagenes de Fondo ****/
	$('#galLeft').mouseleave(
		function(){
			$('#galLeft li').animate({ width: '170px' });
		}
	);
	$('#galRight').mouseleave(
		function(){
			$('#galRight li').animate({ width: '170px' });
		}
	);
    maxWidth = 300;
    minWidth = 40;	

    $("#galLeft li").hover(
      function(){
		$("#galLeft li").attr('rel','out');
		$(this).attr('rel','hover');
		$(this).animate({width: maxWidth+"px"}, { queue:false, duration:400});
        $('#galLeft li[rel="out"]').animate({width: minWidth+"px"}, { queue:false, duration:400 });
      }
    );
    $("#galRight li").hover(
      function(){
		$("#galRight li").attr('rel','out');
		$(this).attr('rel','hover');
		$(this).animate({width: maxWidth+"px"}, { queue:false, duration:400});
        $('#galRight li[rel="out"]').animate({width: minWidth+"px"}, { queue:false, duration:400 });
      }
    );
	
	
	/**** Rotation ****/
	if(!$.browser.msie)
	{
		$('.deco1, .deco2, .deco3').rotate({
			maxAngle:25,minAngle:-55,
			bind:[
				{"mouseover":function(){$(this).rotateAnimation(5);}},
				{"mouseout":function(){$(this).rotateAnimation(-5);}}
			]
		});
	}
	
	
	/**** Send Mail ****/
	$("#submitcontact").click(function(){
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,6})?$/;

		var emailFromVal = $("#emailFromC").val();
		if(emailFromVal == '') {
			$("#emailFromC").before('<span class="error">Ingresa tu email.</span>');
			hasError = true;
		} else if(!emailReg.test(emailFromVal)) {
			$("#emailFromC").before('<span class="error">Ingresa un email valido.</span>');
			hasError = true;
		}

		var subjectVal = $("#subjectC").val();
		if(subjectVal == '') {
			$("#subjectC").before('<span class="error">Ingresa un asunto.</span>');
			hasError = true;
		}

		var nameVal = $("#nameC").val();
		if(nameVal == '') {
			$("#nameC").before('<span class="error">Ingresa tu nombre.</span>');
			hasError = true;
		}

		var messageVal = $("#messageC").val();
		if(messageVal == '') {
			$("#messageC").before('<span class="error">Ingresa un mensaje.</span>');
			hasError = true;
		}
		
		if(hasError == true) {
			$('.scroll-pane').jScrollPane($settings);
		}
		if(hasError == false) {
			$(this).hide();
			$('#tellafriend_form').slideUp(300,function(){$('.scroll-pane').jScrollPane($settings);});
			$("#contactenos").append('<img src="images/loader.gif" alt="Enviando..." id="cargando" />');
			
			$.post("js/contactMail.php",
   				{ name: nameVal, emailFrom: emailFromVal, subject: subjectVal, message: messageVal },
				function(data){
						if(data == 'true')
						{
							$("#contactenos").before('<div class="msgSent error"><h3>Tu mensaje se envi&oacute; satisfactoriamente</h3><p>Gracias por contactarnos.</p></div>'); 
						}
						else
						{
							$("#contactenos").before('<div class="msgSent"><h3>Hay un error enviando su mensaje</h3><p>Disculpe los incomvenientes, por favor intente de nuevo mas tarde.</p></div>');
						}
						//$("#contactenos").before('<div class="msgSent"><p>'+data+'</p></div>');
						$('#cargando').fadeOut('fast',function()
						{
							$('.msgSent').fadeIn();
						});
			});
		}
		
		return false;
	});
	

});