// JavaScript Document
// Fix para links externos (rel)
function fix_external_links() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("rel") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
		}
	}
}
window.onload = fix_external_links;



$(document).ready(function(){

	//Funciones del formulario de contacto
	$('#btn-contacto-reset').click(function (evento) { 
		evento.preventDefault();
		$($(this).attr('rel')).resetForm();
	});
	
	$('#btn-contacto-enviar').click(function (evento) { 
		evento.preventDefault();
		test = validarContacto();
		if (test) {
		    $($(this).attr('rel')).submit();
		}
	});
		
	function validarContacto(){
	    if (testearLleno('#nombre')) {
	    	if (testearLleno('#email')) {
	    		var filtro = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@+([_a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]{2,200}\.[a-zA-Z]{2,6}$/;
	    			if(!filtro.test($('#email').val())){
	    				jAlert("El email ingresado no es valido./Email not valid");
	    				$('#email').focus();
	    					return false;	
	    			}
	    			if (testearLleno('#ciudad')) {
	    				if (testearLleno('#pais')) {
	    					if (testearLleno('#empresa')) {
	    						if (testearLleno('#asunto')) {
	    							if (testearLleno('#comentarios')) {
	    								return true;
	    							}
	    						}
	    					}
	    				}
	    			}
	    	}
	    }
	    return false;
	}
		
	function testearLleno(objeto) {
	    if ($(objeto).val() == "") {
	    	jAlert("El campo "+(objeto.substring(1))+" no puede estar vacio.");
	    	$(objeto).focus();
	    	return false;
	    } else { 
	   		return true;
	    }
	}
	
	jQuery.fn.resetForm = function () {
	    $(this).each (function() { this.reset(); });
	}
	
	//Columnas de igual alto
	/*
	if ($("#leftcolumn").height() > $("#rightcolumn").height()) {
		$("#rightcolumn").height($("#leftcolumn").height());
		$("#content").height($("#leftcolumn").height());
	}else{
		$("#leftcolumn").height($("#rightcolumn").height());
		$("#content").height($("#rightcolumn").height()-10);
		
	}
	*/

function equalHeight(group) {
   tallest = 0;
   group.each(function() {
      thisHeight = $(this).height();
      if(thisHeight > tallest) {
         tallest = thisHeight;
      }
   });
   group.height(tallest);
}

equalHeight($(".columna"));

//ACCORDION

	$('#accordion div').hide();
		$('#accordion h3 a').click(function(){
		
		$(this).animate({top:0})
		$('#accordion div').slideUp('slow');
			$(this).parent().next().slideDown('slow');
				return false;
		});

//DROPDOWN
$(function(){

    var config = {    
         sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
         interval: 100,  // number = milliseconds for onMouseOver polling interval    
         over: doOpen,   // function = onMouseOver callback (REQUIRED)    
         timeout: 200,   // number = milliseconds delay before onMouseOut    
         out: doClose    // function = onMouseOut callback (REQUIRED)    
    };
    
    function doOpen() {
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    }
 
    function doClose() {
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    }

    $("#navigation li").hoverIntent(config);
    
    $("#navigation li ul li:has(ul)").find("a:first").append(" &raquo; ");

});




});
