function check_length(Object, maxLen){
	if (Object.value.length >= maxLen) {
		Object.value = Object.value.substring(0, maxLen);
	}
}

jQuery(document).ready(function($){
	
	// Agregar clase last a los últimos elementos para evitar un valor en el margen derecho

	$("#tabs li.current").append("<div class='tag'></div>");

	$("#galleryInner #galleryList ul li:last").addClass("last");
	
	$("#buttonList320x90 img:last").addClass("last");

	$("#section2 .section:last").addClass("last");
	
	$("#articlesBigEspecial .newsItem:last").addClass("last");
	
	// Se duplica el valor del campo de búsqueda y se escribe en otro input hidden con la finalidad de resaltar la palabra en los resultados de búsqueda
	$("#searchBox").live('keyup',function(){
		$('#copySearchBox').val($(this).val());
	});
	
	/* Truncate texts to certain length
	$('#tips').jTruncate({  
        length: 40,
        minTrail: 0, 
        ellipsisText: "...",
        moreText:""
    });  */
	
	// Poll manipulation for styling
	$("#easypollform input[type=radio]").each(function(i) {
		var radio = $("<div class='radio'></div>");
		$(this).parent().prepend(radio);
		radio.bind("click",function(e){
			$(this).parent().find("input[type=radio]").click();
			$("#easypollform .encRow .radio").removeClass("on");
			$(this).addClass("on");
		});
	});

	// Horoscope styling
	$("#horoscope ul.zodiacList li:nth-child(6n)").addClass("edge");
	$("#horoscope ul.zodiacList li:gt(5)").addClass("secondRow");
	
	var actual = $('#signoActual').val();
	$('#' + actual).css("display","block");
        
    $('.zodiacPreview').live('click',function(e){
    	e.preventDefault();
    	$('.zintro').css("display","none");
    	var which = $(this).attr('id');
    	var minuswhich = which.toLowerCase();
    	var paragraph = '#' + which + 'Intro';
    	$('#horoscope .linkImg').attr('href','716-horoscopos.html#'+which+'Cont');
    	$('#horoscope img').attr('src','assets/templates/iasa/img/zodiaco/' + minuswhich + '.png');
    	$('#horoscope h3 a').text(which);
    	$('#horoscope h3 a').attr('href','716-horoscopos.html#'+which+'Cont');
    	$(paragraph).css("display","block");
    });
	
	// Other section styling
	$("#section3 .section:nth-child(2n)").addClass("edge");
	$("#section3 .section:gt(1)").addClass("secondRow");

	// Footer styling
	$("#footer ul.sites li:last,#footer ul.contact li:last").addClass("last");
	
	// Tabs de comentarios
	$("#noticiaComentar .comentaContent").hide();
	$("#noticiaComentar #comentaNota").show();

	$("#comentaTabs .comentaTab").each(function(){
		$(this).bind("click",function(){
			// Obtener el índice del elemento seleccionado
			var index = $("#comentaTabs div").index($(this));
			// Esconder todo, inmediatamente mostrar elementos correctos
			$("#comentaTabs .comentaTab").removeClass("selected");
			$(this).addClass("selected");
			$("#noticiaComentar .comentaContent").hide();
			$("#noticiaComentar .comentaContent:nth("+index+")").show();
			//if( $(this).hasClass('facebooktb') ) login();
		});
	});
	
	//Show "Responder" when a comment is published
	$(".responder").hide();
	$(".nav").hide();
	if ($(".comentarios div").hasClass("jot-comment")){
		$(".responder").show();
		$(".nav").show();
	}
	
	// BotÃ³n de 'responder'
	$("#comentarios .responder a")
		.click(function(e) {
			e.preventDefault();
			if (jQuery("#comentaTab1").hasClass("selected")){
				elementClick = $(".anchorLink").attr("href");
				destination = $(elementClick).offset().top;
				jQuery("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100,function() { jQuery("#notaEmail").focus(); } );
			}
			if (jQuery("#comentaTab2").hasClass("selected")){
				jQuery("#comentaTab2").removeClass("selected");
				jQuery("#comentaTab1").addClass("selected");
				jQuery("#comentaFacebook").css({'display':'none'});
				jQuery("#comentaNota").css({'display':'block'});
				elementClick = $(".anchorLink").attr("href");
				destination = $(elementClick).offset().top;
				jQuery("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100,function() { jQuery("#notaEmail").focus(); } );
			}
			if (jQuery("#comentaTab3").hasClass("selected")){
				jQuery("#comentaTab3").removeClass("selected");
				jQuery("#comentaTab1").addClass("selected");
				jQuery("#comentaTwitter").css({'display':'none'});
				jQuery("#comentaNota").css({'display':'block'});
				elementClick = $(".anchorLink").attr("href");
				destination = $(elementClick).offset().top;
				jQuery("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100,function() { jQuery("#notaEmail").focus(); } );
			}
		});
	
	//Colorbox calls for printing and mailing articles
	$(".imprimir").colorbox({width:"820px",height:"550px",maxWidth:820,maxHeight:540,iframe:true,opacity:"0.75"});
	$(".enviar").colorbox({width:"450px",height:"310px",iframe:true,opacity:"0.75"});
	
	$("#back").mouseover(function(){
		$(this).attr('src','assets/templates/iasa/img/regresar_busqueda_b.png');
	});
	$("#back").mouseout(function(){
		$(this).attr('src','assets/templates/iasa/img/regresar_busqueda_a.png');
	});
	$("#next").mouseover(function(){
		$(this).attr('src','assets/templates/iasa/img/avanzar_busqueda_b.png');
	});
	$("#next").mouseout(function(){
		$(this).attr('src','assets/templates/iasa/img/avanzar_busqueda_a.png');
	});
	
	//Obtener la imagen de fondo del Especial, valor de la tv oculto en input hidden
	var fondoEspecial = $("#backEspecial").val();
	$("#especialWrapperTop").css({'background-image' : 'url('+ fondoEspecial + ')'});
	
	//Footer alignment
	$("#footer li:first").addClass("first-link");
	
});

