function myTimestamp(){
    tstmp = new Date();
    return tstmp.getTime();
}

function avoidcache() {
	return '?avoidcache=' + myTimestamp();
}

$(document).ready(function(){
		$("a.user_thumb_labeled").hover(
	      		function(){
	      			tmp = $(this).attr("id");
					aux = tmp.split("_");
					id = aux[2];
					jQuery("#user_label_thumb_"+id, this).slideDown();
	      		},
	      		function(){
	      			tmp = $(this).attr("id");
					aux = tmp.split("_");
					id = aux[2];
					jQuery("#user_label_thumb_"+id, this).slideUp();
	      		}
      		);
      		
      		
      		setTimeout(function(){
                              $('#flashMessage').slideUp('slow');
                          }, 6000);

			              
            /*$('a.ajax-free').live('click', function() {

    			$.get( $(this).attr('href') + avoidcache(), function(data) {
					$('.status-free').html(data);
    			});

				return false;
			});*/
			
			$(".questions-box span.rft").live('click', function() {
				radiobut = $(this).children('input');
				url = $('form#freeToniteForm').attr("action");
    			$.get( url + '/' + radiobut.val() + avoidcache());
			});
			
      		

			$('a.ajax-link').live('click', function() {
				var tmp = $(this).attr('id');
				var aux = tmp.split('_');
				var update = aux[1];
				var hide = aux[2];
    			$.get( $(this).attr('href') + avoidcache() , function(data) {
					alert(data);
					$('#'+update).html(data).show();
					if(hide == 'fade') {
						setTimeout(function(){
                              $('#'+update).fadeOut();
                          }, 5000);
					}
    			});

				return false;
			});
			
			$('a.ajax-like').live('click', function() {
				var tmp = $(this).attr('id');
				var aux = tmp.split('_');
				var update = aux[1];
				var hide = aux[2];
				$(this).click(function(){return false;});
    			$.get( $(this).attr('href') + avoidcache()  , function(data) {
					$(this).disabled = 0;
					response = JSON.parse(data);
					$('#'+update).html(response.data).show();
					$('#LikeStatusMsg').html(response.message).fadeIn();
						setTimeout(function(){
     					$('#LikeStatusMsg').fadeOut();
                          }, 5000);
    			});
    				
				return false;
			});
			
			
			$('a.ajax-ignore').live('click', function() {
				$.get( $(this).attr('href') + avoidcache(), function(data) {
					$('#IgnoreStatusId').html(data);
    			});

				return false;
			});
			
			$('a.ajax-kiss').live('click', function() {
    			$.get( $(this).attr('href') + avoidcache(), function(data) {
					/*$('#KissStatusId').html(data);*/
					var val = $('#KissRemainingId').html();
					val = val - 1;
					if(val < 0) val = 0;
	            	$('#KissRemainingId').html(val);
     				$('#KissStatusMsg').html(data).fadeIn();
						setTimeout(function(){
     					$('#KissStatusMsg').fadeOut();
                          }, 5000);
    			});

				return false;
			});
			
			
			$('#posts-paging a').live('click', function() {
    			$.get( $(this).attr('href') + avoidcache(), function(data) {
					$('#last-messages').html(data);
    			});
    			
    			return false;
			});
			
        	$('a.ajax-del-msg').live('click', function() {
				var url = $(this).attr('href');
				var tmp = url.split("/");
				var id = tmp[tmp.length-1];
    			$.get( url + avoidcache() , function() {
					$('#msg_'+id).fadeOut('slow');
    			});

    			return false;
			});
			
			$('a.ajax-del-post').live('click', function() {
				var url = $(this).attr('href');
				var tmp = url.split("/");
				var id = tmp[tmp.length-1];
    			$.get( url + avoidcache(), function() {
					$('#post_'+id).fadeOut('slow');
    			});

    			return false;
			});


});


/** utils **/

/** textaera limit **/
function limitChars(textid, limit, infodiv) {

	var text = $('#'+textid).val();
	var textlength = text.length;
	if(textlength > limit){
		$('#' + infodiv).html('0').attr('style','color:red; font-weight: bold');
		$('#'+textid).val(text.substr(0,limit));
		return false;
	} else {
		$('#' + infodiv).html(limit - textlength).attr('style',false);
		return true;
	}

}

function delMsg(id) {

}



