// JavaScript Document
var filters = {
		requerido: function(el) {return ($(el).val() != '' && $(el).val() != -1 && $(el).val() != 'undefined' || $(el).attr('value') != '');},
		email: function(el) {return /^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/.test($(el).val());},
		telefono: function(el){return /^[0-9]*$/.test($(el).val());},
		categoria: function(el){ return ($('select#mm_categoria option:selected').val());},
		contactDefault: function(el){return $(el).val() != 'Deje su mensaje.';}
	};
	
$.extend({
	stop: function(e){
		if (e.preventDefault) e.preventDefault();
		if (e.stopPropagation) e.stopPropagation();
	}
});

var obj = null;

function checkHover() {
	if (obj) {
		obj.find('ul').hide();	
	} //if
} //checkHover


$(document).ready( function(){
	$("form").bind("submit", function(e){
		if (typeof filters == 'undefined') return;
	    $(this).find("input, textarea, select").each(function(x,el){ 
	        if ($(el).attr("className") != 'undefined') { 
		$(el).removeClass("error");
	        $.each(new String($(el).attr("className")).split(" "), function(x, klass){
	            if ($.isFunction(filters[klass]))
	                if (!filters[klass](el))  $(el).addClass("error");
	        });
	        }
	    });
		if ($(this).find(".error").size() > 0) {
			$.stop(e || window.event);
			jAlert("Necesita completar los campos marcados","El formulario no es valido");
			return false;
		}
	    return true;
	});
	
	$('#Nav > li').hover(function() {
		if (obj) {
			obj.find('ul').hide();
			obj = null;
		} //if
		
		$(this).find('ul').fadeIn('fast');
	}, function() {
		obj = $(this);
		setTimeout(
			"checkHover()",
			400);
	});
	
	$('#Nav li img').css({
		position:'relative',
		top:'-3px'
	});
	
});
