// 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').focus();
	    					return false;	
	    			}
	    			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"));


$("#main-slider").easySlider({
	auto: true,
	continuous: true,
	controlsShow: false,
	speed: 800,
	pause: 8000
});

//$('ul#categorias.submenu').hide();
$('ul#colaboradores.submenu').hide();

$('#columnas.column-box .titulo_area').click(function() {
  $('ul#categorias.submenu').slideToggle('slow', function() {
    // Animation complete.
  });
});

$('#colaboradores.column-box .titulo_area').click(function() {
  $('ul#colaboradores.submenu').slideToggle('slow', function() {
    // Animation complete.
  });
});

DD_roundies.addRule('.post', '10px');
DD_roundies.addRule('.column-box', '10px');
DD_roundies.addRule('.btn-leer-mas a', '10px');

});