function loadSmileys( input_id ){
	var smileys = [';)', ':(', ':)', ':D', ':p'];
	var html = '<p>';
	for( var i in smileys ){
		html += '<a href="javascript:;" onclick="insertSmiley(this, \'' + input_id + '\')" title="' + smileys[i] + '"><img src="/img/smileys/' + smileys[i] + '.gif"/></a> ';		
	}
	html += '</p>';
	$("#" + input_id).after( html );
}

function insertSmiley( obj, input_id ){
	text = $('#' + input_id).val() + ' ' + $(obj).attr('title') + ' ';
	$('#' + input_id).val( text );
}

function bookmarkthis( op ){
	var title = encodeURIComponent( window.document.title );
	var href = encodeURIComponent( window.document.location.href );
	switch( op ){
		case 'twitter':
			url = 'http://twitter.com/home?status=' + title + ' - ' + href;
		break;
		case 'facebook':
			url = 'http://www.facebook.com/sharer.php?u=' + href;
		break;
	}
	window.open( url );
}

    function getRelativeDate(time_value) {
        var values = time_value.split(" ");
        time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
        var parsed_date = Date.parse(time_value);
        var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
        var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
        delta = delta + (relative_to.getTimezoneOffset() * 60);

        var r = '';
        if(delta < 120) {
            r = 'hace 1 minuto';
        } else if(delta < (45*60)) {
            r = 'hace ' + (parseInt(delta / 60)).toString() + ' minutos';
        } else if(delta < (2*90*60)) { // 2* because sometimes read 1 hours ago
            r = 'hace 1 hora';
        } else if(delta < (24*60*60)) {
            r = 'hace ' + (parseInt(delta / 3600)).toString() + ' horas';
        } else if(delta < (48*60*60)) {
            r = 'hace 1 dia';
        } else if(delta < 1209600){
            r = 'hace '+ (parseInt(delta / 86400)).toString() + ' dias';
        } else{
            r = parsed_date.getDay() + '/' + ( parsed_date.getMonth() + 1 ) + '/' + parsed_date.getFullYear();
        }

        return r;
    }

$().ready(function(){

	// bloquar submit para evitar duplicados
	$('form').submit(function(){
		$('input[type=submit]').attr('disabled', 'disabled');
	});
	
	
	// remarcar comentarios
	var c_obj;
	var c_pos = window.document.location.href.indexOf('#comment-');
	if( c_pos ){
		var c_id = window.document.location.href.substr( c_pos + 9 );
		if( c_obj = $('#comment-'+c_id) )c_obj.css('background', '#FFFFE6');
	}
	
	// autoexpand textareas
	$('textarea').autogrow();
	
	// lightbox
	$('a[rel*=facebox]').facebox();
	
});