//-------------------------------
// Class
//-------------------------------

function PlayerNavigationView() {

	var _self = this;

	//-------------------------------
	// Constants
	//-------------------------------
	
	PlayerNavigationView.prototype.DISPLAY = "player_display";
	PlayerNavigationView.prototype.PLAYER = "player_clicked";
	
	//-------------------------------
	// Properties
	//-------------------------------
	
	var _playerContentView;
	
	var _button = $j("<li class='button players'><a href='#'>Players</a></li>");
	var _view = $j("<ul class='playerNavContainer'></ul>");
	
	//-------------------------------
	// Constructor
	//-------------------------------
	
	$j(function() {
		_playerContentView = new PlayerContentView();
		
		$j("#featuredBar").append(_button);
		$j("#featuredBar").append("<li class='divider'></li>");
		
		$j(_button).bind("click", onButtonClick);
		$j(_button).bind("mouseover", onButtonOver);
		$j(_button).bind("mouseout", onButtonOut);
	});
	
	//-------------------------------
	// Public Methods
	//-------------------------------
	
	_self.deploy = function(data) {
		//$j(_view).append("<span>");
		
		var content = $j("<span></span>");
		$j(data).find("info").each(function(i, item) {
			var btn = new PlayerNavigationButton({"data" : item});
			$j(btn).bind(btn.BUTTON_CLICK, onPlayerClick);
			content.append(btn.button);
		});
		
		content.append("<div class='clear'></div>");
		$j(_view).html(content);
		$j("#featuredPlayerContainer").append("<div class='stripe'></div>");
		$j("#featuredPlayerContainer").append(_view);
	}
	
	_self.deployContent = function(data) {
		_playerContentView.activity(data);
	}
	
	_self.intro = function() {
		$j("#featuredPlayerContainer .playerContentView").css("top", $j("#featuredContainer").height() + "px");
		$j("#featuredPlayerContainer").show().css("height", $j("#featuredContainer").height() + "px");
		$j(_view).animate({"top" : ($j("#featuredContainer").height() - _view.height() - 9) + "px"});
		$j("#featuredPlayerContainer .stripe").animate({"top" : ($j("#featuredContainer").height() - _view.height() - 9) + "px"});
		$j(_self).trigger(_self.DISPLAY);
		$j(_button).css({"background-position" : "0 -45px"});
		$j("a", _button).addClass("selected");
		_button.enabled = true;
	}
	
	_self.exit = function() {
		$j("#featuredPlayerContainer .stripe").animate({"top" : $j("#featuredContainer").height() + "px"});
		$j(_view).animate({"top" : $j("#featuredContainer").height() + "px"}, function() {
			$j("#featuredPlayerContainer").hide();
		});
		_playerContentView.exit();
		$j(_button).css({"background-position" : "0 0"});
		$j("a", _button).removeClass("selected");
		_button.enabled = false;
	}
	
	//-------------------------------
	// Private Methods
	//-------------------------------
	
	//-------------------------------
	// Listeners
	//-------------------------------

	function onButtonClick(event) {
		if($j(_view).is(":visible")) {
			_self.exit();
		} else {
			var title = "/homepage/players";
			pageTracker._trackPageview(title);
			s.linkTrackVars="None";
			s.linkTrackEvents="None";
			s.tl(this, "o", title);
			s.t();
			
			_self.intro();
		}
		
		
		
		return false;
	}
	
	function onButtonOver() {
		if(!_button.enabled) $j(_button).css({"background-position" : "0 -45px"});
	}
	
	function onButtonOut() {
		if(!_button.enabled) $j(_button).css({"background-position" : "0 0"});
	}
	
	function onPlayerClick(event, data, id) {
		_playerContentView.deploy(data);
		$j(_self).trigger(_self.PLAYER, [id]);
	}
}
