// data player_info

jQuery.data_creator.player_info = function (jElement, options) {
	this.jElement = jElement ;
	this.options = jQuery.extend({}, jQuery.data_creator.player_info.settings, options) ;
	if (this.options.name == '') {
		this.options.name = 'player_info#' + Math.random() ;	
	}
	jQuery.data_creator.player_info.stack[this.options.name]=this ;
	
	this.init() ;
}

jQuery.data_creator.player_info.prototype.init = function() {
	
	this.jElement.find('a').clickable() ;
}

jQuery.data_creator.player_info.prototype.load_info = function(_id) {
	if (_id != this.options.my_id) {
		this.jElement.portlet('disable_button', 'customize') ;	
	} else {
		this.jElement.portlet('enable_button', 'customize') ;	
	}
	player_info_me = this ;
	
	player_info_me.jElement.find('.fetch_pseudo').state({name:'refresh'}) ;
	player_info_me.jElement.find('.fetch_age').state({name:'refresh'}) ;
	player_info_me.jElement.find('.fetch_city').state({name:'refresh'}) ;
	player_info_me.jElement.find('.fetch_avatar img').attr('src', 'Themes/Default/Images/avatar_default.jpg') ;
	
	$.post(this.options.data_dir+'player/player_info/fetch.php', {id: _id}, function(data) {
		try{
			var entry = data.getElementsByTagName('entry')[0] ;
			player_info_me.jElement.find('.fetch_pseudo').html(entry.getAttribute('pseudo')) ;
			player_info_me.jElement.find('.fetch_age').html(entry.getAttribute('age')) ;
			player_info_me.jElement.find('.fetch_city').html(entry.getAttribute('city')) ;
			var avatar = (entry.getAttribute('avatar')=='') ? 'Themes/Default/Images/avatar_default.jpg' : entry.getAttribute('avatar') ;
			player_info_me.jElement.find('.fetch_avatar img').attr('src', avatar) ;
			
			if (player_info_me.options.my_id != _id) {
				player_info_me.jElement.find('.deconnect_link').html('<a href="#">Voir mon profil</a>').unbind('click').click(function() {location.hash=''; eval(player_info_me.options.see_my_profile_script);}).find('a').clickable() ;
			}
			else {
				player_info_me.jElement.find('.deconnect_link').html('<a href="#">D&eacute;connexion</a>').unbind('click').click(function() {location.hash=''; eval(player_info_me.options.deconnect_script);}).find('a').clickable() ;
			}
		}
		catch(e) {
			jQuery.data_creator.error(player_info_me.options.name+' has thrown : '+e) ;	
		}
	}) ;
}

jQuery.data_creator.player_info.settings = {
	my_info:false,
	my_id: -1,
	w_index: -1,
	name: '',
	see_my_profile_script:'',
	deconnect_script:'',
	data_dir:''
}

jQuery.data_creator.player_info.stack = {} ;