//-------------------------------
// Class
//-------------------------------

function FeaturedTabsView() {

	var _self = this;

	//-------------------------------
	// Constants
	//-------------------------------
	
		
	//-------------------------------
	// Properties
	//-------------------------------
	
	var _view = $j("#featuredTabs .featuredTabsView");
	var _btnArray = [];

	//-------------------------------
	// Constructor
	//-------------------------------
	
	$j(function() {
		$j("#featuredTabs").append(_view);
		$j("#featuredTabContent").width(($j("body").width() - 100) + "px");
		$j(window).resize(onWindowResize);
	});
	
	//-------------------------------
	// Public Methods
	//-------------------------------
	
	_self.deploy = function(data) {
		var btnAll = new FeaturedTabView({});
		_view.append(btnAll.button);
		_btnArray.push(btnAll);
		$j(btnAll).bind(btnAll.BUTTON_CLICK, onAllClick);
		btnAll.intro();
		
		$j(data).find("item").each(function() {
			var btn = new FeaturedTabView({"data" : $j(this).find("description").text()});
			
			$j(btn).bind(btn.BUTTON_CLICK, onTabClick);
			_view.append(btn.button);
			_btnArray.push(btn);
			
			if(btn.main == "true") $j(btn).trigger(btn.BUTTON_CLICK, [btn.data.page]);
		});
		
	}
	
	//-------------------------------
	// Private Methods
	//-------------------------------
	
	function init() {
	}
	
	//-------------------------------
	// Listeners
	//-------------------------------
	
	function onWindowResize() {
		$j("#featuredTabContent").width(($j("body").width() - 100) + "px");
	}
	
	function onTabClick(event, url) {
		$j(_btnArray).each(function(i, item) {
			item.exit();
		});
		
		event.target.intro();
		
		$j("#featuredContent").fadeOut(function() {
			$j(".content", this).html("");
		});
	
		$j("#featuredTabContent").load(url, function(response, status, xhr) {
			if (status == "error") {
				var msg = "Sorry but there was an error: ";
				alert(msg + xhr.status + " " + xhr.statusText);
			}
			
			$j(".content", this).show();
			if($j(".content", this).height() > 400) $j("#featuredContainer").height($j(".content", this).height() + "px");
		}).show();
	}

	function onAllClick(event) {
		$j("#featuredContainer").height("400px");
		$j(_btnArray).each(function(i, item) {
			item.exit();
		});
		
		event.target.intro();
		
		$j("#featuredTabContent, #featuredContent").fadeOut(function() {
			$j(".content", this).html("");
		});
		
		return false;
	}
}
