//-------------------------------
// Class
//-------------------------------

function FeaturedBarApp() {

	
	var _self = this;

	//-------------------------------
	// Constants
	//-------------------------------
	
	var XML_PATHS	= 	[	{"type" : "players", "url" : "http://www.iamatrailblazersfan.com/DesktopModules/Iama/PlayerFeed.aspx"}, 
							{"type" : "dancers", "url" : "http://www.iamatrailblazersfan.com/DesktopModules/Iama/DancerFeed.aspx"}, 
							{"type" : "games", "url" : "http://www.iamatrailblazersfan.com/DesktopModules/Iama/GameFeed.aspx"}
						];
	
	//-------------------------------
	// Properties
	//-------------------------------
	
	var _featuredContentDataModel;
	
	var _playerNavigationView;
	var _dancerNavigationView;
	var _gamesView;
	var _startingFiveView;
	
	var _counter = 0;
	
	//-------------------------------
	// Constructor
	//-------------------------------
	
	$j(function() {
		_featuredContentDataModel = new FeaturedContentDataModel();
		_playerNavigationView = new PlayerNavigationView();
		_gamesView = new GamesView();
		_dancerNavigationView = new DancerNavigationView();
		//_startingFiveView = new StartingFiveView();
		
		$j(_featuredContentDataModel).bind(_featuredContentDataModel.DATA_COMPLETE, onContentDataComplete);
		$j(_playerNavigationView).bind(_playerNavigationView.DISPLAY, onNavDisplay);
		$j(_playerNavigationView).bind(_playerNavigationView.PLAYER, onPlayerClick);
		$j(_dancerNavigationView).bind(_dancerNavigationView.DISPLAY, onNavDisplay);
		//$j(_startingFiveView).bind(_startingFiveView.DISPLAY, onNavDisplay);
		
		init();
	});
	
	//-------------------------------
	// Public Methods
	//-------------------------------
	
	//-------------------------------
	// Private Methods
	//-------------------------------
	
	function init() {		
		loadData();
		
		//_startingFiveView.deploy();
	}
	
	function loadData() {
		_featuredContentDataModel.loadJSON(XML_PATHS[_counter]);
	}
	
	//-------------------------------
	// Listeners
	//-------------------------------
	
	function onContentDataComplete(event, data, path) {
		switch(path.type) {
			case "players" :
				_playerNavigationView.deploy(data);
				break;
			case "dancers" :
				_dancerNavigationView.deploy(data);
				break;
			case "games" :
				_gamesView.deploy(data);
				break;
			case "player" :
				_playerNavigationView.deployContent(data);
				break;
		}
		
		if(_counter < XML_PATHS.length - 1)	_counter++;
		else return false;
		
		loadData();
	}
	
	function onNavDisplay(event) {
		switch(event.target.DISPLAY) {
			case "player_display" :
				_dancerNavigationView.exit();
				//_startingFiveView.exit();
				break;
			case "dancer_display" :
				_playerNavigationView.exit();
				//_startingFiveView.exit();
				break;
			case "startingfive_display" :
				_playerNavigationView.exit();
				_dancerNavigationView.exit();
				break;
		}
	}
	
	function onPlayerClick(event, id) {
		var path = {"type" : "player", "url" : "http://www.iamatrailblazersfan.com/DesktopModules/Iama/Iama_VisualFeed.aspx?Feed=Featured&FeaturedProfileType=player&FeaturedProfileId=" + id}
		_featuredContentDataModel.loadJSON(path);
	}
}
