
Sphere = {}
Sphere.FO = new function() {
	
	// INIT
	this.selectedUrl = "";
	
	var sportFullName = {
		'mlb':'Professional Baseball',
		'nfl':'Professional Football',
		'nhl':'Professional Hockey',
		'nba':'Professional Basketball',
		'cfootball':'Collegiate Football',
		'cbasketball':'Collegiate Basketball',
		'all':'All Sports' };
	
	//--------
	
	
	// PUBLIC
	
	this.loadArticle = function( ele ) {
		
		// TODO - move logic to server
		if( window.location.hostname.indexOf("sphere") >= 0 || window.location.hostname=="192.168.1.102" ) { 
			var base = "/widgets/fo/";
		} else {
			var base = "/sphere/";
		}
		
		ele.blur(); // remove selection grid around link text
		selectedUrl = ele.href; // set Sphere.FO object's stored URL

		$.get(base+"content.php?url="+escape(selectedUrl), renderArticle);
		$("div#storyBucket").fadeTo( 1, .15);
		$("div#loadingState").css("top", ($("td.rightColumn").height()/2)-($("div#loadingState").height()/2)+"px" );
		$("div#loadingState").css("left", ($("td.leftColumn").width()+$("td.rightColumn").width()/2)-($("div#loadingState").width()/2)+"px" );
		$("div#loadingState").css("visibility", "visible");
				
		$("ol#breakingStories li").each(function (i) { 
			if( $(this).find("a").attr("href") == selectedUrl ) {
				$(this).addClass("selected");
			} else { 
				$(this).removeClass("selected");
			}
		});
		
		return false;
	}

	this.loadCategory = function( ele, cat ) {
		this.hideCategories();
		ele.blur();
		
		if( !cat) return false; // nothing to do!

		if( window.location.hostname.indexOf("sphere") >= 0 || window.location.hostname=="192.168.1.102" ) { 
			var base = "/widgets/fo/";
		} else {
			var base = "/sphere/";
		}		
		
		
		$.get(base+"content?cat="+escape(cat), renderCategory);

		$("#sphereFoModule .sportsBuzzLabel").each(function(i) {
			this.innerHTML = ('Sports Buzz : '+sportFullName[cat] );
		});
		
		$("ol#breakingStories").fadeTo( 1, .15);
		$("div#storyBucket").fadeTo( 1, .15);
		$("div#loadingState").css("top", ($("td.rightColumn").height()/2)-($("div#loadingState").height()/2)+"px" );
		$("div#loadingState").css("left", ($("td.leftColumn").width()+$("td.rightColumn").width()/2)-($("div#loadingState").width()/2)+"px" );
		$("div#loadingState").css("visibility", "visible");
		
		return false;
	}
	
	this.showCategories = function() {
		$('#sphereFoModule #menuHeader').show();
		$('#sphereFoModule #subHeader').css("visibility", "hidden");
		$("div#storyBucket").hide();
		$("div#storyBucket").show();
	}
	
	this.hideCategories = function() {		
		$('#sphereFoModule #menuHeader').hide();
		$('#sphereFoModule #subHeader').css("visibility", "visible");
		$("div#storyBucket").hide();
		$("div#storyBucket").show();
	}
	
	
	//-------
	
	
	
	// PRIVATE 
	
	function renderArticle( txt ) {
		$("div#loadingState").css("visibility", "hidden");
		$("div#storyBucket").html( txt );
		$("div#storyBucket").fadeTo("fast", 1);
	}
	
	function renderCategory( txt ) {
		$("div#loadingState").css("visibility", "hidden");
	 	$("div#mainTableWrapper").html( txt );
		
		$("ol#breakingStorier").fadeTo("fast", 1);
		$("div#storyBucket").fadeTo( "fast", 1);
		
	}
	
	//-------

}