jQuery(function() {



	var $nav = jQuery('#nav');

	$nav.find('ul').find('ul').hide();

	$nav.find('ul').each(function(){

		var $this = jQuery(this);

		$this.find('li:first').addClass('first');

		$this.find('li:last').addClass('last');

	});

	$nav.find('li').each(function(){

		var $this = jQuery(this);

		if( $this.find('ul').length > 0 ){

			$this.addClass('parent');

		}

	});

	$nav.find('ul li').hover(

	function () {

		var $this = jQuery(this);

		$this.children('ul').show();

		$this.parents('li').children('a').addClass('active');

	}, 

	function () {

		var $this = jQuery(this);

		$this.children('ul').hide();

		$this.parents('li').children('a').removeClass('active');

	}

	);

	

	jQuery(".home #nav li:first").addClass('active');

	$nav.find('.current_page_item').find('a').addClass('active');

	

	jQuery("#loading").bind("ajaxSend", function(){

		jQuery(this).show();

		jQuery('#form_contact fieldset').addClass('layer');

		}).bind("ajaxComplete", function(){

		jQuery(this).hide();

		jQuery('#form_contact fieldset').removeClass('layer');

	});

	

	var action_val = jQuery('#contact_form').attr('action'); 



	jQuery(".submit").click(function() {

		

	 var name = jQuery("#name").val();

		if (name == "") {

      jQuery("#name_error").show();

      jQuery("#name").focus();

      return false;

    }

	

	var name = jQuery("#name").val();

		if (name == "Tu nombre") {

      jQuery("#name_error").show();

      jQuery("#name").focus();

      return false;

    }

		var email = jQuery("#email").val();

		if (email == "") {

      jQuery("#email_error").show();

      jQuery("#email").focus();

      return false;

    }

	

	var email = jQuery("#email").val();

	if( !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) ){

	jQuery("#email_error").show();

	jQuery("#email").focus();

	return (false);

	}

	

	var comments = jQuery("#comments").val();

		if (comments == "") {

      jQuery("#comments_error").show();

      jQuery("#comments").focus();

      return false;

    }

	

	var comments = jQuery("#comments").val();

		if (comments == "Comentario") {

      jQuery("#comments_error").show();

      jQuery("#comments").focus();

      return false;

    }

		

		var dataString = 'name='+ name + '&email=' + email + '&comments=' + comments;

		jQuery.ajax({

		type: "POST",

		url: action_val,

		data: dataString,

		success: function() {

			jQuery('#contact_form').html("<div id='message'></div>");

			jQuery('#message').html("<p>Contact form submitted!</p>")

			.append("<p>We will be in touch soon.</p>");

      }

     });

    return false;

	});

	

	

	  jQuery('.thumb_link').click(function () { 

		varLink = jQuery(this).attr('href');

		jQuery ('#imagen_principal').attr('src',varLink);

		return false;

    });

	  

	  jQuery('.target').attr('target','_blank');
	  
	  
	  jQuery('.list_products li:first').addClass('no_border');
	  



});