$(document).ready(function() {  

	// Check for hash value in URL  
	var hash = window.location.hash.substr(1);  
	var href = $('a.flirt_w_m').each(function(){  
		var href = $(this).attr('href');  
		if(hash==href.substr(0,href.length-4)){
			var toLoad = hash;
			$('#load_image').load(toLoad)
		}   
	});  

	$('a.flirt_w_m').click(function(){  

		var toLoad = $(this).attr('href');  
		var uid    = $(this).attr('rel');
		$('#load_image_'+uid).hide('fast',loadContent);  
		$('#load').remove();  
		$('#load_image_'+uid).append('<span id="load"></span>');  
		$('#load').fadeIn('normal');  
		
		//window.location.hash = $(this).attr('href');
		
		function loadContent() {
			$('#load_image_'+uid).load(toLoad,'',showNewContent())  
		}  
		function showNewContent() {  
			$('#load_image_'+uid).show('normal',hideLoader());  
		}  
		function hideLoader() {  
			$('#load').fadeOut('normal');
		}
		return false;  
       
	});
	
	$('a.chat_w_o').click(function(){

		var toLoad = $(this).attr('href');
		var uid    = $(this).attr('rel');
		$('#load_image_'+uid).hide('fast',loadContent);  
		$('#load').remove();  
		$('#load_image_'+uid).append('<span id="load"></span>');  
		$('#load').fadeIn('normal');  
		
		//window.location.hash = $(this).attr('href');
		
		function loadContent() {  
			$('#load_image_'+uid).load(toLoad,'',showNewContent())  
		}  
		function showNewContent() {  
			$('#load_image_'+uid).show('normal',hideLoader());  
		}  
		function hideLoader() {  
			$('#load').fadeOut('normal');  
		}
		return false;  
       
	});
	
	$('a.cat_picture_vote').click(function(){
		
		var toLoad = $(this).attr('href');
		var toRefresh = $(this).attr('rel');
		//alert(toRefresh);
		//return false;
		
		$('#cute_msg').hide('slow',loadContent);
		//$('#voting_cute_pictues').hide('slow',loadContent);
		
		$('#load').remove();  
		$('#cute_msg').append('<span id="load"></span>');
		//$('#voting_cute_pictues').append('<span id="load"></span>');
		
		$('#load').fadeIn('normal');				
		
		//window.location.hash = $(this).attr('href');
		
		function loadContent() {  
			$('#cute_msg').load(toLoad,'',showNewContent());
			//$('#voting_cute_pictues').load(toRefresh,'',showNewContent());
		}  
		function showNewContent() {  
			$('#cute_msg').show('normal',hideLoader());
			//$('#voting_cute_pictues').show('normal',hideLoader());
		}
		function hideLoader() {  
			$('#load').fadeOut('normal');  
		}
		return false;  
       
	});
	
	$('a.cat_picture_vote_u').click(function(){
		
		var toLoad = $(this).attr('href');
		var toRefresh = $(this).attr('rel');
		
		$('#ugly_msg2').hide('slow',loadContent);
		//$('#voting_ugly_pictues').hide('slow',loadContent);
		
		$('#load').remove();  
		$('#ugly_msg2').append('<span id="load"></span>'); 
		//$('#voting_ugly_pictues').append('<span id="load"></span>');
		
		$('#load').fadeIn('normal');  
		
		//window.location.hash = $(this).attr('href');
		
		function loadContent() {  
			$('#ugly_msg2').load(toLoad,'',showNewContent())
			//$('#voting_ugly_pictues').load(toRefresh,'',showNewContent());
		}  
		function showNewContent() {  
			$('#ugly_msg2').show('normal',hideLoader());
			//$('#voting_ugly_pictues').show('normal',hideLoader());
		}  
		function hideLoader() {  
			$('#load').fadeOut('normal');  
		}
		return false;  
       
	});		
	
});

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}