var socialMedia = {
	//location of HTML files to be loaded into the content div
	contentUrls: {
		twitter: "/ui_components/v1/social_media/twitter_inc.php",
		twittertalent: "/assets/includes/twitter/talent_v1.html",
		twitterhockey: "/assets/includes/twitter/hockey_v1.html",
		twitternba: "/assets/includes/twitter/nba_v1.html",
		twittersoccer: "/assets/includes/twitter/soccer_v1.html",
		twittermma: "/assets/includes/twitter/mma_v1.html",
		facebook: "/assets/includes/facebook.php"
	},		
	oldHtml: '', //container for the current content - reverts to this on error
	loadingHtml: '<div class="v1-ajax-loading" style="height:{height}px;"></div>',
	errorMessage: 'Sorry...\nWe\'re experiencing technical difficulties. Please try again later.',

    retweet: function(id) {
        var aTweet = $("li#tweet_"+id+" span.tweet").html().replace(/<\/?[^>]+>/gi, '');
        var aTwit = $("li#tweet_"+id+" span.twit").html();

        var tURL = "http://twitter.com/home?status=" + encodeURIComponent('RT @'+aTwit+' '+aTweet);
        var w = window.open(tURL, "twitterWindow");
        return false;
    },

	loadContent: function(siteId){
		//valid siteId's are the propery names of contentUrls
		socialMedia.showLoading();
		$.ajax({
			url: socialMedia.contentUrls[siteId],
			cache: false,
			success: socialMedia.onLoad,
			error: socialMedia.onLoadError
		});
	},
	
	showLoading: function(){
		var curContentDiv = $("div.socialMediaWidget div.contentHolder");
		socialMedia.oldHtml = curContentDiv.html();
		
		var contentHeight = curContentDiv.height();
		var curLoadingHtml = socialMedia.loadingHtml.replace("{height}", contentHeight);
		curContentDiv.html(curLoadingHtml);
	},
	
	onLoad: function(responseHtml){
		$("div.socialMediaWidget div.contentHolder").html(responseHtml);
	},
	
	onLoadError: function(xhr, status, exception){
		//alert("error; status: " + status + "; exception: " + exception);
		alert(socialMedia.errorMessage);
		$("div.socialMediaWidget div.contentHolder").html(socialMedia.oldHtml);
	}
};

