

var m_avatars = {
	offset:  0,
	m_avatar: '',
	
	send: false,
	
	init: function(){
		this.m_avatar	= $('#m_avatar').val();
		this.offset		= $('#offset').val();
		
		$('#box_m_avatars_c .bt_prev2').hide();
		$('#box_m_avatars_c .bt_next2').hide();
		

		this.view();
	},
	
	view: function(){
		if( this.send == true )
			return;
		this.send =false;
		
		$('#box_m_avatars_c .avatars_loading').show();
		
		$.post('m/ajax_list',{'offset': this.offset, 'm_avatar': this.m_avatar },function( data_result ) {																						
	    	
			$('#box_m_avatars_c .avatars_loading').hide();
			$('#ajax_avatars_list').fadeOut( 300, function(){
				$('#ajax_avatars_list').html( data_result );
				if( $('#m_prev').val() == '1' )
					$('#box_m_avatars_c .bt_prev2').fadeIn(300);
				else 
					$('#box_m_avatars_c .bt_prev2').fadeOut(300);
									
				if( $('#m_next').val() == '1' )
					$('#box_m_avatars_c .bt_next2').fadeIn(300);
				else 
					$('#box_m_avatars_c .bt_next2').fadeOut(300);					
											
				$('#ajax_avatars_list').fadeIn(300, function(){ m_avatars.send = false; } );
			 
			});
			
			
			
		});
	},
	
	view_avatar: function( login_alias ) {
		var location = data.baseUrl + "m/" + login_alias + '.html';
		var tmp = '';

		tmp += this.offset  > 0 ?  'offset=' + this.offset + '&' : '';
		tmp += this.m_avatar.length  > 0  ? 'm_avatar=' + this.m_avatar  : '';
			
		/*
		if( tmp.length > 0 )
			location += '/?q=' + encodeURI( tmp );
		*/
		
		window.location = location  ;			
	},
	
	prev: function(){
		if( this.offset > 0 )
			this.offset--;
		this.view();
	},
	
	next: function(){
		this.offset++;
		this.view();
	},
	
	'search':  function() {
		this.m_avatar = $('#m_avatar').val();
		this.offset = 0;
		this.view();
	}
}

$( document ).ready( function() {
	m_avatars.init();							 
});
