// JavaScript Document

jQuery(document).ready(function(){
	//fancy
	jQuery("a[rel=fancybox]").fancybox({
				'titleShow'		: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});
	
	/**** DROP DOWN MENU ****/
	jQuery("ul.subnav").parent().append("<span></span>");

	jQuery("ul.topnav li span").hover(function() {

		jQuery(this).parent().find("ul.subnav").slideDown('fast').show();

		jQuery(this).parent().hover(function() {
		}, function(){
			jQuery(this).parent().find("ul.subnav").slideUp('slow');
		});

		}).hover(function() {
			jQuery(this).addClass("subhover");
		}, function(){
			jQuery(this).removeClass("subhover");
	});
	
	jQuery("#mycarousel").jcarousel({
        auto: 2,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
	
	/*************************************************************************************************/
jQuery("#submitcontact").click(function(){
		jQuery(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,6})?jQuery/;

		var emailFromVal = jQuery("#emailFromC").val();
		if(emailFromVal == '') {
			jQuery("#emailFromC").before('<span class="error">Ingresa tu email.</span>');
			hasError = true;
		} else if(!emailReg.test(emailFromVal)) {
			jQuery("#emailFromC").before('<span class="error">Ingresa un email valido.</span>');
			hasError = true;
		}

		var subjectVal = jQuery("#subjectC").val();
		if(subjectVal == '') {
			jQuery("#subjectC").before('<span class="error">Ingresa un asunto.</span>');
			hasError = true;
		}

		var nameVal = jQuery("#nameC").val();
		if(nameVal == '') {
			jQuery("#nameC").before('<span class="error">Ingresa tu nombre.</span>');
			hasError = true;
		}
		
		var telVal = jQuery("#phoneC").val();
		
		var webVal = jQuery("#webC").val();
		if(webVal == 'http://')
		{
			webVal = '';
		}
		
		var horarioVal = jQuery("#horarioC").val();
		var paisVal = jQuery("#paisC").val();
		var ciudadVal = jQuery("#ciudadC").val();
		var direccionVal = jQuery("#direccionC").val();		

		var messageVal = jQuery("#messageC").val();
		if(messageVal == '') {
			jQuery("#messageC").before('<span class="error">Ingresa un mensaje.</span>');
			hasError = true;
		}
		
		if(hasError == false) {
			jQuery(this).hide();
			/**/
			jQuery('#tellafriend_form label').hide();
			jQuery('#tellafriend_form input').hide();
			jQuery('#tellafriend_form textarea').hide();
			jQuery('#tellafriend_form select').hide();
			/**/
			jQuery("#tellafriend_form div.buttons").append('<img src="images/loading.gif" alt="Enviando..." id="cargando" />');
			//jQuery.post("http://www.posicionamientowebcali.com/ffd/contactMail.php",
			jQuery.post("js/contactMail.php",
   				{ name: nameVal, emailFrom: emailFromVal, phone: telVal, web: webVal, horario: horarioVal, pais: paisVal, subject: subjectVal, message: messageVal, ciudad:ciudadVal, direccion:direccionVal },
				function(data){
						jQuery('#tellafriend_form div.buttons').hide();
						jQuery("#tellafriend_form").append('<div class="msgSent"><h3>Tu mensaje se envi&oacute; satisfactoriamente</h3><p>Gracias por contactarnos.</p><p><a href="index.php">Volver al Inicio</a></p></div>'); 
			});
			jQuery.post("js/contactMail.php",
			//jQuery.post("http://www.posicionamientowebcali.com/ffd/contactMail.php",
   				{ name: nameVal, emailFrom: emailFromVal, phone: telVal, web: webVal, horario: horarioVal, pais: paisVal, subject: subjectVal, message: messageVal 
			});
		}
		
		return false;
	});

	
	
	/**** PNG FIX ****/
	/*jQuery(this).pngFix();*/
	
});



function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

