var font=(function(){var test_string='m/&m#+ilmmmmmmmwwwwwww@%()={';var test_font='"Comic Sans MS"';var notInstalledWidth=0;var testbed=null;var guid=0;return{setup:function(){if($('#fontInstalledTest').length)return;$('head').append('<'+'style> #fontInstalledTest, #fontTestBed { position: absolute; left: -9999px; top: 0; visibility: hidden; } #fontInstalledTest { font-size: 50px!important; font-family: '+test_font+';}</'+'style>');$('body').append('<div id="fontTestBed"></div>').append('<span id="fontInstalledTest" class="fonttest">'+test_string+'</span>');testbed=$('#fontTestBed');notInstalledWidth=$('#fontInstalledTest').width();},isInstalled:function(font){guid++;var style='<'+'style id="fonttestStyle"> #fonttest'+guid+' { font-size: 50px!important; font-family: '+font+', '+test_font+'; } <'+'/style>';$('head').find('#fonttestStyle').remove().end().append(style);testbed.empty().append('<span id="fonttest'+guid+'" class="fonttest">'+test_string+'</span>');return(testbed.find('span').width()!=notInstalledWidth);}};})();

$(document).ready(function() {
	// Font hack
	/*
	font.setup();
	if(!font.isInstalled('Calibri')) {
		//$('body').css('font-size','54.5%');
	}
	*/
	$('a[href="#"]').click(function() {
		if($(this).parent().attr('class')!='pagination') {
			$(this).append('<span class="span_info_box" style="position:relative; z-index:120; display:none;">\
<div style="position:absolute; background:#FFF; color:#000; top:10px; left:0px; padding:5px; -moz-border-radius: 5px; -webkit-border-radius: 5px;">pronto...</div></span>');
			$(this).blur();
			$(this).children('.span_info_box').fadeTo(300,0.95).delay(500).fadeTo(300,0,(function(){$(this).remove()}));
			return false;
		}
	});
	$('#social_links').children().hover(function() {
		$(this).children().stop().fadeTo(500,0);
	}, function() {
		$(this).children().stop().fadeTo(500,1);
	});
	$('#sponsors_ul').children().hover(function() {
		$(this).siblings().stop().fadeTo(500,0.5);
	}, function() {
		$(this).siblings().stop().fadeTo(500,1);
	});
	$('#links').children().hover(function() {
		$(this).siblings().stop().fadeTo(500,0.5);
	}, function() {
		$(this).siblings().stop().fadeTo(500,1);
	});
	$('#comment_form').children('[type!="submit"]').focus(function() {
		if (this.value == this.defaultValue){
        	this.value = '';
    	}
        if(this.value != this.defaultValue){
	    	this.select();
        }
	});
	$('#comment_form').children('[type!="submit"]').blur(function() {
		if (jQuery.trim(this.value) == ''){
        	this.value = (this.defaultValue ? this.defaultValue : '');
    	}
	});
	/* -- Validation -- */
	$('#comment_form').submit(function() {
		$('#form_msg').hide();
		var email  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if($('#comment_form input[name="comment_name"]').val() == 'Nombre') {
			$('#form_msg').html('ingrese un nombre').fadeTo(500,1);
			return false;
		}
		if($('#comment_form input[name="comment_email"]').val() == "Mail (no será publicado)") {
			$('#form_msg').html('ingrese un email').fadeTo(500,1);
			return false;
		}
		if(!jQuery.trim($('#comment_form input[name="comment_email"]').val()).match(email)) {
			$('#form_msg').html('ingrese un email válido').fadeTo(500,1);
			return false;
		}
		if(jQuery.trim($('#comment_form textarea[name="comment_message"]').val()) == 'Comentario') {
			$('#form_msg').html('ingrese un comentario').fadeTo(500,1);
			return false;
		}
		if(jQuery.trim($('#comment_form input[name="comment_spam_protection"]').val()) != '5') {
			$('#form_msg').html('responda correctamente la pregunta anti-spam').fadeTo(500,1);
			return false;
		}
		return true;
	});
	$('#comment_form').children('input[type="submit"]').blur(function() {
		$('#form_msg').fadeTo(500,0);
	});
	/* -- Comments -- */
	$('.comment_content').each(function(i) {
		if($(this).html().length>140) {
			$(this).html(
					$(this).html().substr(0,140) +
					'<span id="comment_full_' + i + '">' +
					$(this).html().substr(140,$(this).html().length) +
					'</span>' +
					'<span id="comment_toggle_' + i + '">... <b>[mostrar]</b></span>'
				);
			$('#comment_full_' + i).hide();
			$('#comment_toggle_' + i).css('cursor', 'pointer');
			$('#comment_toggle_' + i).toggle(function() {
					$('#comment_full_' + i).slideToggle(400);
					$('#comment_toggle_' + i).html(' <b>[ocultar]</b>');
				}, function() {
					$('#comment_full_' + i).slideToggle(400);
					$('#comment_toggle_' + i).html('... <b>[mostrar]</b>');
			});
		}
	});
});
