// awards notifications for the stream, v2
// NOTE: this must match the numbers in BlazeSource.php.  Also maintained in stream_config.php in platform :-(
var INBOX_MSG_TYPE = 11;
var TOURNAMENT_PLACE_MSG_TYPE = 19;

var PROSHOP_PURCHASE_MSG_TYPE = 1278;

var GOLFER_PROGRESSION_MSG_TYPE = 2052;
var CUTLINE_MSG_TYPE = 2060;
var NOW_WATCHING_MSG_TYPE = 2061;

var AWARD_MSG_TYPEv1 = 5782;
var IGC_MSG_TYPEv1 = 5783;
var ONLINEPASS_MSG_TYPE = 5784;
var AWARD_MSG_TYPE = 5785;
var IGC_MSG_TYPE = 5786;
var FRIENDS_LB_MSG_TYPE = 5787;
var MILESTONE_MSG_TYPE = 5788;
var USER_MSG_TYPE = 5789;
var ACHIEVEMENT_MSG_TYPE = 5790;


// global data
var perPage = 10; // For "My Recent Activity"
var shown   = 1; // do not edit.
var totalEntries = 0;
var recentActivityCount = 0;
var deferredMessages = 0;

var DEFAULT_ICON = '/img/placeholder/feed_icon.gif';

function showNextPage (e) {
    if (e) { e.preventDefault(); }
    shown *= perPage;
    if ($('.timeago').length !== 0) {
          jQuery(function($) { $('.timeago').easydate(); });
          }

    $('#Activity_Feed li.entry:lt(' + shown + ')').fadeIn();

    if (shown >= totalEntries || totalEntries === perPage) {
        $('#view_more_activity').hide();
    }
}

// Function: parseCutLine
function parseCutLine (s) {
    var arrValues = s.split(';');
    var ret       = {};

    if (arrValues.length !== 5) {
        return null;
    }

    ret.madeCut = parseInt(arrValues[0], 10);
    ret.streak  = parseInt(arrValues[1], 10);
    ret.cutline = parseInt(arrValues[2], 10);
    ret.score   = parseInt(arrValues[3], 10);
    ret.xp      = parseInt(arrValues[4], 10);

    return ret;
}

//Function: parsePersonaInfo
function parsePersonaInfo (s) {
	
    var arrValues = s.split(';');
    var ret       = {};

    // at least need persona id and name
    if (arrValues.length < 2) 
    {
        return null;
    }

    ret.id = parseInt(arrValues[0], 10);
    ret.name  = arrValues[1];
    if (arrValues.length > 2)
    {
    	ret.email = arrValues[2]; // optional -- used by welcome bonus/referral messages
    }
    else
    {
    	ret.email = '';
    }

    return ret;
}

// Function: parseTournamentAward
function parseTournamentAward (s) {
    var arrValues = s.split(';');
    var ret       = {};

    if (arrValues.length !== 5) {
        return null;
    }

    ret.tournamentName = arrValues[0];
    ret.tournamentId = parseInt(arrValues[1], 10);
    ret.score = parseInt(arrValues[2], 10);
    ret.rank = parseInt(arrValues[3], 10);
    ret.winnings = parseInt(arrValues[4], 10);

    return ret;
}

// Function: parseGroupTournamentAward
function parseGroupTournamentAward (s) {
    var arrValues = s.split(';');
    var ret       = {};

    if (arrValues.length < 6) {
        return null;
    }

    ret.tournamentName = arrValues[0];
    ret.groupName = arrValues[1];
    ret.tournamentId = parseInt(arrValues[2], 10);
    ret.score = parseInt(arrValues[3], 10);
    ret.rank = parseInt(arrValues[4], 10);
    ret.groupId = parseInt(arrValues[5], 10);
	
	if (arrValues.length == 7)
	{
		ret.winnings = parseInt(arrValues[6], 10);
	}
	else
	{
		ret.winnings = 0;
	}

    return ret;
}

function parseAward (msgType, source) {
    var ret       = {};

    // after this version, we're passing a full JSON reward structure in the first parm
    if( msgType < ONLINEPASS_MSG_TYPE )
	{
        ret.awardType = $('entry[key=0]', source).text();
        ret.awardValue = $('entry[key=1]', source).text();
		ret.awardName = 'prize';
		ret.awardIcon = '/img/home/feed_ea.png' 
	}
    else
    {
		var rewardStr = $('entry[key=0]', source).text();

    	//TODO: Fix this!  For message type IGC_MSG_TYPE, IGCHAL_INGAME_REPLACE_LEADER (and others)
    	// doesnt follow the format (i.e. not JSON), so if its the non-json string, we
    	// wont try to parse it as json.  i could have done a try/catch but thats probably
    	// bad too...  this is coming out anyway, so no troubles, no worries...
    	// I would recommend a different message type for this, since it has a unique
    	// format...
    	if (rewardStr != '0')
    	{
    		try
    		{
	    		var reward = eval('(' + rewardStr + ');');
	    		
				ret.awardType = reward.type;
			    ret.awardValue = reward.value;
			    ret.awardName = reward.meta['displayName'];
			    ret.awardIcon = reward.meta['icon'].replace(/\\/g, '/');
    		}
    		catch(err)
    		{
    			// bad data, handle it so we don't break the entire stream
    			ret.awardType = 'Invalid';
        		ret.awardValue = 0;
        		ret.awardName = 'prize';
        		ret.awardIcon = '/img/home/feed_ea.png'
    		}
    	
    	}
    	else
    	{
    		ret.awardType = 'Invalid';
    		ret.awardValue = 0;
    		ret.awardName = 'prize';
    		ret.awardIcon = '/img/home/feed_ea.png' 
    	}
    }
    
    ret.awardDisplay = $('entry[key=2]', source).text();
    ret.awardDisplay = ret.awardDisplay.replace(/\(r\)/g, "<sup>&reg;</sup>");
	ret.awardName = ret.awardName.replace(/\(r\)/g, "<sup>&reg;</sup>");
    
    ret.header = 'Congratulations!  You\'ve been awarded ' + ret.awardName;
    ret.icon = '/img/home/feed_ea.png';
    ret.image = ret.awardIcon;
    ret.message = ret.awardValue;
    
    switch(ret.awardType)
    {
        case 'TYPE_CASH':
        case 'TYPE_POINTS':
        case 'TYPE_OFBPOINTS':
        {
        	ret.feedDescription = 'Upgrade your golfer with your ' + ((ret.awardType == 'TYPE_CASH') ? 'cash' : 'points') + ' now!';
        	ret.feedLinkClass = 'launchGame';
            ret.feedLink = 'javascript:void(0);';
            ret.feedLinkLocation = 'Pro Shop';
        }
        break;
        
        case 'TYPE_OFB':
        {
        	ret.feedDescription = 'Equip your new gear now!';
        	ret.feedLinkClass = 'launchGame';
            ret.feedLink = 'javascript:void(0);';
            ret.feedLinkLocation = 'My Gear';
        }
        break;
    }
    
    return ret;
}

function extractEventName(s)
{
    var arrValues   = s.split(';');
    if (arrValues.length < 1)
    {
        return null;
    }

    return  arrValues[0];
}

function parseIngameChalAwardsMetaData(s)
{
    var arrValues   = s.split(';');
    var ret         = {};

    if (arrValues.length < 4)
    {
        return null;
    }
    ret.eventName 		= arrValues[0];
    ret.tournamentName 	= arrValues[1];
    ret.courseName 		= arrValues[2];
    ret.hole 			= parseInt(arrValues[3]);
    ret.leaderName   	= arrValues.length >= 5 ? arrValues[4] : 'Your friend'; // NEW field, handle grandfathering of old data
    ret.courseId   		= arrValues.length >= 6 ? parseInt(arrValues[5]) : 0; // NEW field, handle grandfathering of old data
    
    return ret;
}

function getGolferProgressionLevels(level){
	if(level >= 50)
		return "Legend";
	else if(level >= 45)
		return "Master";
	else if(level >= 40)
		return "World Champion";
	else if(level >= 30)
		return "Champion";
	else if(level >= 25)
		return "Tour Pro";
	else if(level >= 20)
		return "Pro";
	else if(level >= 15)
		return "Semi Pro";
	else if(level >= 10)
		return "Rookie";
	else if(level >= 5)
		return "Amateur";
	else
		return "Beginner";
}

function popNewLevel () {
    var striped = true;

    callGetWS(true, "/messaging_service/mystream/50/0", // NOTE: no paging, just getting first page
	        WSRequestTimeout,
	        null,
	        function(xml, TextStatus) {
	            totalEntries = $('notification', xml).length;

	            if ($('notification', xml).length >= perPage) {
	                $('#view_more_activity').show();
	                $('#view_more_activity').bind('click', showNextPage);
	            }

	            // need to clean this up some
	            var found = false;
	            var objCutLine = null;

	            $('notification', xml).reverse().each(function() {
	                var header = '';
	                var message = ' ';
					var messageCopy = ' ';
	                var icon = '';
	                var image = '';
	                var feedLink = '';
	                var feedLinkClass = '';
	                var feedClass = '';
	                var feedLinkLocation = '';
	                var timestamp = parseInt($('timestamp', this).text(), 10);
	                var msgId = parseInt($('messageid', this).text(), 10);
	                var msgType = parseInt($('type', this).text(), 10);
	                var msgStatus = parseInt($('status', this).text(), 10);
	                
	                var date = new Date(timestamp * 1000);

	                var dateString = date.toLocaleDateString() + ' ' + date.toLocaleTimeString();
	                
	                recentActivityCount++;

	                if (msgType === CUTLINE_MSG_TYPE) 
	                {
	                    header = '';
	                    feedLink = '/friends/sponsorships';
	                    feedLinkLocation = 'The Cut Details';
	                    feedClass = 'thecut';
	                    icon = '/img/home/feed_madecut.png';
	                    // ---------------------
	                    // Cut Line Notification
	                    // ---------------------
	                    var customType = parseInt($('entry[key=4]', this).text(), 10);
	                    if (customType === 1) {
	                        objCutLine = parseCutLine($('entry[key=65282]', this).text());

	                        if (objCutLine.madeCut) {
	                            // Made the cut
	                            if (objCutLine.streak < 2) {
	                                message += '<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img src="' + icon + '" alt="' + feedLinkLocation + '" /></a></div><div class="copy"><h3><a class="' + feedLinkClass + '" href="' + feedLink + '">Congratulations! &nbsp;You\'ve Made The Cut!</a></h3><p>You\'ve started a new streak! The final cut was ' + objCutLine.cutline + ' and you shot a ' + objCutLine.score + ', earning you ' + formatLargeNumbers(objCutLine.xp) + ' XP. Play a full round today and keep your streak going!</p><span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' + feedLinkLocation + '</a></span></div>';
	                            } else {
	                                message += '<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img src="' + icon + '" alt="' + feedLinkLocation + '" /></a></div><div class="copy"><h3><a class="' + feedLinkClass + '" href="' + feedLink + '">Congratulations! &nbsp;You\'ve Made The Cut!</a></h3><p>You\'ve made the cut for the ' + ordinal(objCutLine.streak) + ' day in a row! The final cut was ' + objCutLine.cutline + ' and you shot a ' + objCutLine.score + ', earning you ' + formatLargeNumbers(objCutLine.xp) + ' XP. Play a full round today and keep your streak going!</p><span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' + feedLinkLocation + '</a></span></div> ';
	                            }
	                        }
	                        else {
	                            // Did not make the cut
	                            message += 'Yesterday\'s final cut was' + objCutLine.cutline + ' and you shot ' + objCutLine.score + '. Unfortunately, you missed the cut, but you can play a full round today to try and start a new streak. Good Luck!';
	                        }
	                    }
	                    else {
	                        var money = $('entry[key=65282]', this).text();
	                        money = '$' + formatLargeNumbers(money);

	                        header = 'You\'ve Earned ' + money + ' From Sponsorships!';
	                        feedLink = '/friends/sponsorships';
	                        feedLinkLocation = 'Sponsorship Details';
	                        feedClass = 'sponsorships';
	                        icon = '/img/home/feed_sponsorship.png';

	                        // Sponsor made the cutline
	                        message += '<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img src="' + icon + '" alt="' + feedLinkLocation + '" /></a></div><div class="copy"><h3><a class="' + feedLinkClass + '" href="' + feedLink + '">' + header + '</a></h3><p>Players you were sponsoring have made the cut, earning you ' + money + '. Visit your sponsorships to view details of your earnings and predict who will win tomorrow!</p><span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' + feedLinkLocation + '</a></span></div>';
	                    }

	                    updateRecentActivity(header, message, striped, dateString, icon, feedLink, feedLinkLocation, feedClass);
	                }
	                // someone is now watching you (either by manually from user or by auto-fan/friend on referral...)
	                else if (msgType === NOW_WATCHING_MSG_TYPE) 
	                {
	                    feedClass = 'newfan';

	                    var customType = parseInt($('entry[key=4]', this).text(), 10);
	                    if (customType === 0) // FANMANAGER_NEW_FAN_NOTIFICATION
	                    {
	                        var watcherPersonaInfo = parsePersonaInfo($('entry[key=6]', this).text()); // semicolon delimited <personaid>;<personaname>
	                        message += '<div class="image"><img src="/img/home/feed_friend.png" /></div><div class="copy"><img src="/img/spacer.gif" /><span><a href="/profiles/' + watcherPersonaInfo.name + '">' + watcherPersonaInfo.name + '</a> sent you a friend request!</span></div>';
	                        updateRecentActivity(header, message, striped, dateString, icon, feedLink, feedLinkLocation, feedClass);
	                    }
	                    else if (customType === 1) // FANMANAGER_NEW_FRIEND_NOTIFICATION
	                    {
	                    	// we already show the friend request in the referral bonus message, so no need for anything to display
	                    }
	                    else 
	                    {
	                        header = 'Fan Manager';
	                        feedClass = 'newfan';
	                        message += 'Unhandled customType ' + customType;
	                        updateRecentActivity(header, message, striped, dateString, icon, feedLink, feedLinkLocation, feedClass);
	                    }
	                }
	                else if (msgType === INBOX_MSG_TYPE) 
	                {
	                    var subtype = $('subtype', this).text();
	                    if (subtype == 'tournamentnews') {
	                        var tournamentNewsType = $('tournamentnewstype', this).text();

	                        var tournamentId = $('tournamentid', this).text();
	                        var tournamentName = $('tournamentname', this).text();
	                        var groupId = $('groupid', this).text();
	                        var groupName = $('groupname', this).text();

	                        feedLink = '/groups/profile_overview/' + groupId;
	                        feedLinkLocation = 'Group Details';
	                        feedClass = 'tournaments';

	                        if (tournamentNewsType === 'create') {
	                            header = 'New Group Tournament';
	                            icon = '/img/home/feed_new_group_tournament.png';

	                            message = "A new tournament has been created for the " + groupName + " group.";

	                            messageCopy = '<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img alt="' + feedLinkLocation + '" src="' + icon + '"/></a></div><div class="copy"><h3><a class="' + feedLinkClass + '" href="' + feedLink + '">' + header + '</a></h3><p>' + message + '</p><span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' + feedLinkLocation + '</a></span></div>';
	                            updateRecentActivity(header, messageCopy, striped, dateString, icon, feedLink, feedLinkLocation, feedClass);
	                        }
	                    }
	                    else {
	                        feedClass = 'group_request';

	                        // messages are localized in blaze in the etc/framework/localize.csv
	                        var customMsg = $('entry[key=65282]', this).text();
	                        message += '<div class="copy"><img src="/img/spacer.gif" /><span>' + customMsg + '</span></div>';

	                        updateRecentActivity(header, message, striped, dateString, icon, feedLink, feedLinkLocation, feedClass);
	                    }
	                }

	                // level-up popup
	                else if (msgType === GOLFER_PROGRESSION_MSG_TYPE) 
	                {

	                    var customType = parseInt($('entry[key=4]', this).text(), 10);
	                    if (customType == 0) // level up!
	                    {
	                        var newLevel = parseInt($('entry[key=3]', this).text(), 10);

	                        // only show popup for level 2 and up...
	                        if (newLevel > 1) 
	                        {
	                            var tillNextLevel = $('entry[key=2]', this).text();
								
								feedLink = '/myProfile';
	                            feedLinkLocation = 'My Golfer';
	                            feedClass = 'levelup';
	                            icon = '/img/home/feed_levelup.png';
	                            title = getGolferProgressionLevels(newLevel);

	                            messageCopy = '<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img alt="' + feedLinkLocation + '" src="' + icon + '"/></a></div><div class="copy"><h3><a class="' + feedLinkClass + '" href="' + feedLink + '">Congratulations! &nbsp;You\'ve Reached Level ' + newLevel + ' ' + title + '!</a></h3><p>You are now a level ' + newLevel + ' ' + title + '.</p><span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' + feedLinkLocation + '</a></span></div>';

	                            // ---------------------
	                            // Level-up notification
	                            // ---------------------

	                            message += '<div class="modal_heading"><h2>Congratulations, You Leveled!</h2></div>';
	                            message += '<div class="modal_body"><div class="modal_info modal_background notification"><div class="modal_message message_background"> <div id="global_modal_icon" class="modal_icon"><img src="/img/globals/modal_levelup.png" /></div><div class="modal_copy"><h2>You Are Now A Level ' + newLevel + ' ' + title + '</h2>'
								
								if (newLevel != 250) {
									if( tillNextLevel <= 0)
										message += '<p>You have to complete the title requirements to reach the next level.</p>';
									else
										message += '<p> ' + formatLargeNumbers(tillNextLevel) + ' XP required to reach the next level.</p>';
								}
								
								message += '</div></div></div>';

	                            // var strPublishMessage = "Sign up now to hit the links with [#name#]! [#name#] is climbing the ranks in Tiger Woods PGA TOUR&reg; Online! [#name#] is now a level " + newLevel + " " + title + " Golfer.";
	                            var strPublishMessage = "[#name#] is now a level " + newLevel + " " + title + " Golfer. Sign up now to hit the links with [#name#]!";
	                            // status 0 means unread, only popup if unread!!!
	                            if (msgStatus == 0) 
	                            {
	                                found = true;
	                                ModalQueue.add(message, null, null, { show_publish: true, message: strPublishMessage });
	                            }
	                        }
	                        else {
		                        feedLinkClass = 'launchGame';
	                           	feedLink = 'javascript:void(0);';
	                            feedLinkLocation = 'Play Now!';
	                            feedClass = 'levelup';
	                            icon = '/img/home/feed_firstlevel.png';
	                            header = "Start Your Career Today!";
	                            messageCopy = '<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img alt="' + feedLinkLocation + '" src="' + icon + '"/></a></div><div class="copy"><h3><a class="' + feedLinkClass + '" href="' + feedLink + '">' + header + '</a></h3><p>You are a level 1 Beginner.</p><span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' + feedLinkLocation + '</a></span></div>';
	                        }
	                    }
	                    else if (customType == 1) // welcome!
	                    {
	                    	var welcomeMsgType = parseInt($('entry[key=65281]', this).text());
	                    	var messageText = '';
	                    	switch (welcomeMsgType)
	                    	{
	                    		default: // by default (original welcome msgs e.g.), use the old welcome msg
	                    		case 0:
		                    		feedLinkClass = 'launchGame';
	                               	feedLink = 'javascript:void(0);';
	    	                        feedLinkLocation = 'Play now';
	    	                        feedClass = 'welcome';
	    	                        icon = '/img/home/feed_ea.png';
	    	                        image = '/img/home/feed_welcome.png';
	    	                        header = "Welcome to Tiger Woods PGA TOUR&reg; Online!";
	    	                        messageText = 'Get started playing in no time with the PLAY NOW link in the top right of your screen, or check out the links below to learn all the tips and tricks to start beating your friends right away.';
	                    			break;
	                    		case 2:
	                    			feedLink = '/users/membershipOffer';
	    	                        feedLinkLocation = 'Become a Member today';
	    	                        feedClass = 'welcome';
	    	                        icon = '/img/home/feed_ea.png';
	    	                        image = '/img/home/feed_membership.png';
	    	                        header = "Membership has its benefits!";
	    	                        messageText = 'Members never pay greens fees on any course, get exclusive access to Pro Shop items + much more!';
	                    			break;
	                    		case 1:
	                    		case 3:
	                    			feedLinkClass = 'launchGame';
	                                feedLink = 'javascript:void(0);';
	    	                        feedLinkLocation = 'Shop now';
	    	                        feedClass = 'welcome';
	    	                        icon = '/img/home/feed_ea.png';
	    	                        image = '/img/home/feed_proshop.png';
	    	                        header = "Improve your golfer in the Pro Shop";
	    	                        messageText = 'Stop by the Pro Shop to pick up gear to give your game a boost. Get the latest name brand gear like Nike, TaylorMade, Callaway + more.';
	                    			break;
	                    		case 4:
	                    			feedLink = '/groups';
	    	                        feedLinkLocation = 'Join a group now';
	    	                        feedClass = 'welcome';
	    	                        icon = '/img/home/feed_ea.png';
	    	                        image = '/img/home/feed_groups.png';
	    	                        header = "Join a group with people that share your interests";
	    	                        messageText = 'Get your friends together and join a group to share common interests and aggregate statistics.';
	                    			break;
	                    	}
	                    	
	                    	messageCopy = '<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img alt="' + feedLinkLocation + '" src="' + icon + '"/></a></div><div class="copy has_image"><h3><a class="' + feedLinkClass + '" href="' + feedLink + '">' + header + '</a></h3><div class="feed_image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img class="image_contest" src="' + image + '" alt="' + feedLinkLocation + '" /></a></div><p>' + 
	                    					messageText + 
	                    					'</p><span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' + feedLinkLocation + '</a></span></div>';
	                    }
	                    else if (customType == 2) // Invitee Stream Message
	                    {
	                        var referrerPersonaInfo = parsePersonaInfo($('entry[key=8]', this).text()); // semicolon delimited <personaid>;<personaname>;<email>
	                        var money = $('entry[key=7]', this).text();
	                        money = '$' + formatLargeNumbers(money);
	                        var referrerEmail =  referrerPersonaInfo.email;
	                        if (referrerEmail.length != 0) // its possible to get blank for old messages
	                        {
	                        	referrerEmail = ' (' + referrerEmail + ')';  // format for display with parenthesis
	                        }
	                        var referrerHtml = '<a href="/profiles/' + referrerPersonaInfo.name + '">' + referrerPersonaInfo.name + '</a>';

	                        //feedLink = referralType == 'email' ? '#" onclick="popupInviteFriendsByEmail();return false;"'; : '#" onclick="TWOFace.popupInviteFriends();return false;"';
	                        feedLink = '#" onclick="popupInviteFriendsByEmail();return false;"';

	                        feedLinkLocation = 'Invite friends now';
	                        feedClass = 'newfan';
	                        icon = '/img/home/feed_ea.png';
	                        
	                        header = 'Thank you for registering!';
	                        
	                        messageCopy =
                            	'<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img src="' + icon + '" alt="' + feedLinkLocation + '" /></a></div><div class="copy"><h3><a class="' + feedLinkClass + '" href="' + feedLink + '">' + header + '</a></h3><p>' +
                            	
                            		'Here is an extra ' + money + ' in-game cash from ' + referrerHtml + referrerEmail + ' for signing up. Earn $50,000 in-game cash for each of your own friends you invite.' +
                            		
                            	'</p><span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' + feedLinkLocation + '</a></span></div>';
	                    }
	                    else if (customType == 3) // Inviter Stream Message
	                    {
	                        var referreePersonaInfo = parsePersonaInfo($('entry[key=8]', this).text()); // semicolon delimited <personaid>;<personaname>;<email>
	                        var money = $('entry[key=7]', this).text();
	                        money = '$' + formatLargeNumbers(money);
	                        //var referralType =  $('entry[key=65281]', this).text();
	                        var referreeEmail = referreePersonaInfo.email;
	                        if (referreeEmail.length != 0) // its possible to get blank for old messages
	                        {
	                        	referreeEmail = ' (' + referreeEmail + ')';  // format for display with parenthesis
	                        }
	                        var referreeHtml = '<a href="/profiles/' + referreePersonaInfo.name + '">' + referreePersonaInfo.name + '</a>';

	                        //feedLink = referralType == 'email' ? '#" onclick="popupInviteFriendsByEmail();return false;"'; : '#" onclick="TWOFace.popupInviteFriends();return false;"';
	                        feedLink = '#" onclick="popupInviteFriendsByEmail();return false;"';

	                        feedLinkLocation = 'Invite friends now';
	                        feedClass = 'newfan';
	                        icon = '/img/home/feed_ea.png';
	                         
	                        header = referreeHtml + ' accepted your invite!';
	                        
	                        /*if (referralType == 'facebook' || referralType == 'Referral Bonus!') // capitalize and handle backwards compatibility with original welcome msg
	                        {
	                        	referralType = 'Facebook'; //capitalize to prettify it, don't capitalize 'email'
	                        }*/
	                        
	                        messageCopy =
                            	'<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img src="' + icon + '" alt="' + feedLinkLocation + '" /></a></div><div class="copy"><h3><a class="' + feedLinkClass + '" href="' + feedLink + '">' + header + '</a></h3><p>' +
                            	
                            		'You have a pending <a href="/messages/notifications">friend request</a> from ' + referreeHtml + referreeEmail + '. Here is ' + money + ' in-game cash for this referral. Earn more by inviting your <a class="' + feedLinkClass + '" href="' + feedLink + '">Friends Now!</a>' +
                            		
                            	'</p><span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' + feedLinkLocation + '</a></span></div>';
	                    }
	                    else 
	                    {
	                        header = "Unknown Type" + customType;
	                        messageCopy = "<h3>" + header + "</h3><p>Unknown error occur.  Please report via the 'Report a Bug' feature under Settings.</p>";
	                    }

	                    updateRecentActivity(header, messageCopy, striped, dateString, icon, feedLink, feedLinkLocation, feedClass);
	                }

	                else if (msgType === PROSHOP_PURCHASE_MSG_TYPE)
	                // ---------------------
	                // Proshop Purchase notification
	                // ---------------------
	                {
	                    var referrerPersonaInfo = parsePersonaInfo($('entry[key=1]', this).text()); // semicolon delimited <personaid>;<personaname>
	                    var trophy = $('entry[key=0]', this).text();
	                    var updateScreen = true;
	                    var displayName = '';
	                    var profileLink = '/profiles/' + referrerPersonaInfo.name + '/prestige';
	                    var thisOne = recentActivityCount;
	                    
	                    deferredMessages++;
	                    
	                    callGetWS(true, "/pro_shop_service/productByName/" + trophy + "/1/5",
	                    WSRequestTimeout,
	                    null,
	                    function(data, textStatus) {//Success
	                        if ($("error", data).length == 0) {
	                            image = $("product attributes attribute[name='Thumbnail_60x60URI']", data).attr("value");
	                            displayName = $("product attributes attribute[name='Product Name']", data).attr("value");
	                            feedLink = '/myProfile/prestige';
								feedLinkLocation = 'Go to My Prestige Items';
	                            icon = '/img/home/feed_ea.png';
	                            messageCopy = 
								'<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img src="' + icon + '" alt="' + feedLinkLocation +
	                            '" /></a></div><div class="copy has_image"><h3>' + referrerPersonaInfo.name +
	                            ' has just bought a new Prestige Item!</h3><p>Check out <a class="capitalTxt" href="' + profileLink + '"><strong>' + referrerPersonaInfo.name +
	                              '\'s Collection</strong></a> or <a href="/myProfile/prestige"><strong>get your own from My Prestige Items</strong></a></p><span class="feed_meta"><abbr class="timeago" title="' +
	                                dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' +
	                                feedLinkLocation + '</a></span></div>';
	                            $("#RECENT_ACTIVITY_" + thisOne).html( messageCopy );
	                            
	                            deferredMessages--;
	                            if( deferredMessages == 0 )
	                                showNextPage();
	                        }
	                        else
	                        {
	                            deferredMessages--;
	                            if( deferredMessages == 0 )
	                                showNextPage();
	                        }
	                    },
	                    function(XMLHttpRequest, textStatus) {
                                 deferredMessages--;
                                 if( deferredMessages == 0 )
	                                showNextPage();
	                    },
	                    null);
	                    displayName = 'temp';
	                    image = '/img/home/feed_ea.png';
                        updateRecentActivity(header, "", striped, dateString, icon, feedLink, feedLinkLocation, feedClass );
	                }

                    else if ( (msgType === AWARD_MSG_TYPEv1) || (msgType === AWARD_MSG_TYPE) )
                    {
		                // ---------------------
		                // Awards notification - generic 'catch all' notification
		                // ---------------------
                    	var awardData = parseAward(msgType, this);
                    	
                    	// hotfix for trophies directing the user to the wrong spot
                    	// TODO - this NEEDS to be done as a custom message type (but the hotfix will not go away)
                    	if(awardData.awardType == 'TYPE_OFB' && awardData.awardValue.indexOf('trophies') == 0 )
                    	{
                        	awardData.feedDescription = 'View all of your trophies now!';
                            awardData.feedLink = '/myProfile/prestige?#c=-1&sn=76261&p=1&s=-price&f=';
                            awardData.feedLinkLocation = 'Trophies';
                    	}
                    	
                        awardData.feedClass = 'something';
                        
                        messageCopy = 
    						'<div class="image"><a class="' + awardData.feedLinkClass + '" href="' + awardData.feedLink + '"><img src="' + awardData.icon + '" alt="' + awardData.feedLinkLocation + '" /></a></div>' +
                            '<div class="copy has_image"><h3>' + awardData.header + '</h3>' +
                            	'<div class="feed_image_lg"><a class="' + awardData.feedLinkClass + '" href="' + awardData.feedLink + '"><img src="' + awardData.image + '" alt="' + awardData.feedLinkLocation + '" /></a></div>' +
                            	'<p>' + awardData.awardDisplay + '<br/><a class="capitalTxt ' + awardData.feedLinkClass + '" href="' + awardData.feedLink + '">' + awardData.feedDescription + '</a></p>' +
                            	'<span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + awardData.feedLinkClass + '" href="' + awardData.feedLink + '">' + awardData.feedLinkLocation + '</a></span>' +
                            '</div>';

                        updateRecentActivity(header, messageCopy, striped, dateString, icon, feedLink, feedLinkLocation, feedClass);
                    }
                    else if (msgType === MILESTONE_MSG_TYPE)
                    {
	                    // ---------------------
	                    // Milestone notification - specifically catered for milestone awards
	                    // ---------------------
                    	var awardData = parseAward(msgType, this);
                    	
                    	// override the title bar
                    	awardData.header = 'Congratulations! ' + awardData.awardDisplay;

                    	// override the feed to always deep-link to milestone page
                        awardData.feedClass = 'something';
                        
                        awardData.feedLink = '/myProfile';
                        
                        awardData.feedLinkLocation = 'Milestones';
                        awardData.feedDescription = 'Check out all of your milestone awards now!';
                        //awardData.icon = '/swappables/companylogos/milestones.png';
                        
                        messageCopy = 
						'<div class="image"><a class="' + awardData.feedLinkClass + '" href="' + awardData.feedLink + '"><img src="' + awardData.icon + '" alt="' + awardData.feedLinkLocation + '" /></a></div>' +
                        '<div class="copy has_image"><h3>' + awardData.header + '</h3>' +
                        	'<div class="feed_image_lg"><a class="' + awardData.feedLinkClass + '" href="' + awardData.feedLink + '"><img src="' + awardData.image + '" alt="' + awardData.feedLinkLocation + '" /></a></div>' +
                        	'<p><a class="capitalTxt ' + awardData.feedLinkClass + '" href="' + awardData.feedLink + '">' + awardData.feedDescription + '</a></p>' +
                        	'<span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + awardData.feedLinkClass + '" href="' + awardData.feedLink + '">' + awardData.feedLinkLocation + '</a></span>' +
                        '</div>';

                        updateRecentActivity(header, messageCopy, striped, dateString, icon, feedLink, feedLinkLocation, feedClass);
                    }
                    else if (msgType === ACHIEVEMENT_MSG_TYPE)
                    {
	                    // ---------------------
	                    // ACHIEVEMENT notification - specifically catered for ACHIEVEMENTS
	                    // ---------------------
                   	    var achievementData = {};
	                   	achievementData.key = $('entry[key=0]', this).text(); // used to get the icon eventually
	                   	achievementData.title = $('entry[key=1]', this).text();
	                   	achievementData.desc = $('entry[key=2]', this).text();
                   	    achievementData.points = $('entry[key=3]', this).text();
                    	
                    	// override the title bar
                    	achievementData.header = 'Congratulations! You\'ve been awarded the \"' + achievementData.title + "\" achievement!";

                    	// override the feed to always deep-link to milestone page
                        achievementData.feedClass = 'something';
                        achievementData.feedLink = '/myProfile/achievements';
                        achievementData.feedLinkLocation = 'Achievements';
                        achievementData.feedDescription = 'View all of your Achievements now!';
                        achievementData.image ='/swappables/achievements/'+achievementData.key+".png";
                        achievementData.icon = '/img/home/feed_tournament_award.png';
                        
                        messageCopy = 
						'<div class="image"><a href="' + achievementData.feedLink + '"><img src="' + achievementData.icon + '" alt="' + achievementData.feedLinkLocation + '" /></a></div>' +
                        '<div class="copy has_image"><h3>' + achievementData.header + '</h3>' +
                        	'<div><a href="' + achievementData.feedLink + '"><img class="image_contest" src="' + achievementData.image + '" alt="' + achievementData.feedLinkLocation + '" /></a></div>' +
                        	'<p><a class="capitalTxt" href="' + achievementData.feedLink + '">' + achievementData.feedDescription + '</a></p>' +
                        	'<span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link" href="' + achievementData.feedLink + '">' + achievementData.feedLinkLocation + '</a></span>' +
                        '</div>';

                        updateRecentActivity(header, messageCopy, striped, dateString, icon, feedLink, feedLinkLocation, feedClass);
                        
                        
                        // status 0 means unread, only popup if unread!!!
                        if (msgStatus == 0) 
                        {
                        	var strModalHtml = "";
                        	var modalHeader = achievementData.title + " Achievement Earned!";
                        	var modalLink = '/myProfile/achievements';
                        	var modalDesc = 'Congratulations on completing this achievement!<br/>View more Achievements on the My Golfer Page.';
                        	
                        	strModalHtml += '<div class="modal_heading"><h2>' + modalHeader + '</h2></div>';
                        	strModalHtml += '<div class="modal_body"><div class="modal_info modal_background notification"><div class="modal_message message_background">'; 
                        	strModalHtml += '<div id="global_modal_icon" class="modal_icon"><img src="' + achievementData.image  + '" /></div><div class="modal_copy"><h3>';
                        	strModalHtml += '<p><a class="capitalTxt" href="' + modalLink + '">' + modalDesc + '</a></p>';
                        	strModalHtml += '</h3></div></div></div>';
							
							var strPublishMessage = '[#name#] has been awarded the &quot;' + achievementData.title + '&quot; achievement!  Sign up now to hit the links with [#name#]!';
							
                            found = true;
                            ModalQueue.add(strModalHtml, null, null, { show_publish: true, message: strPublishMessage });
                        }
                    }
                    else if (msgType === USER_MSG_TYPE)
                    {
	                    // ---------------------
	                    // User award - general-purpose notification involving another user
	                    // ---------------------
                    	var awardData = parseAward(msgType, this);
                        var payLoad = unescape($('entry[key=3]', this).text());
                        var arrValues   = payLoad.split(';');
                        
                        // default to anonymous test and a link to my own page (this should really never happen)
                        var userStr = 'your friend';
                        userLink = '/profiles/' + personaName;
                        if (arrValues.length > 1)
                        {
                            userStr = arrValues[1];
                            userLink = '/profiles/' + userStr;
                        }
                        userMessage = '<strong><a href="' + userLink + '">'+userStr+'</a></strong>';
                        awardData.awardDisplay = awardData.awardDisplay.replace("[user]", userMessage);
                        
                        // same copy as basic awards message, but with the modified awardDisplay from above
                        messageCopy = 
    						'<div class="image"><a class="' + awardData.feedLinkClass + '" href="' + awardData.feedLink + '"><img src="' + awardData.icon + '" alt="' + awardData.feedLinkLocation + '" /></a></div>' +
                            '<div class="copy has_image"><h3>' + awardData.header + '</h3>' +
                            	'<div class="feed_image_lg"><a class="' + awardData.feedLinkClass + '" href="' + awardData.feedLink + '"><img src="' + awardData.image + '" alt="' + awardData.feedLinkLocation + '" /></a></div>' +
                            	'<p>' + awardData.awardDisplay + '<br/><a class="capitalTxt ' + awardData.feedLinkClass + '" href="' + awardData.feedLink + '">' + awardData.feedDescription + '</a></p>' +
                            	'<span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + awardData.feedLinkClass + '" href="' + awardData.feedLink + '">' + awardData.feedLinkLocation + '</a></span>' +
                            '</div>';

                        updateRecentActivity(header, messageCopy, striped, dateString, icon, feedLink, feedLinkLocation, feedClass);
                    }
	                // ---------------------
	                // Awards notification
	                // ---------------------                    
	                else if ( (msgType === IGC_MSG_TYPEv1) || (msgType === IGC_MSG_TYPE) )
                    {
	                	if(msgType === IGC_MSG_TYPEv1)
	                	{
	                        var awardType = $('entry[key=0]', this).text();
	                        var awardValue = $('entry[key=1]', this).text();
	                	}
	                	else  // (msgType === IGC_MSG_TYPE)
	                	{
	                		// with this version, we're passing a full JSON reward structure in the first parm
	                    	var rewardStr = $('entry[key=0]', this).text();
	                    	var reward = eval('(' + rewardStr + ');');

	                    	//TODO: Fix this!  For message type IGC_MSG_TYPE, IGCHAL_INGAME_REPLACE_LEADER (and others)
	                    	// doesnt follow the format (i.e. not JSON), so if its the non-json string, we
	                    	// wont try to parse it as json.  i could have done a try/catch but thats probably
	                    	// bad too...  this is coming out anyway, so no troubles, no worries...
	                    	// I would recommend a different message type for this, since it has a unique
	                    	// format...
	                    	if (rewardStr != '0')
	                    	{
		                    	var awardType = reward.type;
		                        var awardValue = reward.value;
		                        var awardName = reward.meta['displayName'];
		                        var awardIcon = reward.meta['icon'];	                    		
	                    	}
	                	}
	                	
                        var awardDisplay = $('entry[key=2]', this).text();
                        var payLoad = unescape($('entry[key=3]', this).text());
                        var eventName = extractEventName(payLoad);
                        header = awardDisplay;
                        
                        var skipDisplay = false;
                        switch(eventName)
                        {
	                        // tournament (normal & group) end of day Closest of Pin winner
	                        case 'IGCHAL_CP_EOD_WIN_A':
	                        case 'IGCHAL_CP_EOD_WIN_NA':
	                        {
	                            var metaData = parseIngameChalAwardsMetaData(payLoad);
	
	                            feedClass = 'something';
	                            icon = '/img/home/feed_tournament_award.png';
	                            image = '/img/icons/icon_winner_cttp.png';
	                            message = awardValue;
	                            
	                            header = 'Closest to Pin Contest Won!';
								feedLinkClass = 'launchGame';
	                            feedLink = 'javascript:void(0);';
                        		//feedLink = '/tournaments';
                        		feedLinkLocation = 'Play a Tournament Today';
	                            if(metaData == null)
								{
									messageText = 'You have won the Closest to Pin Contest and have won $'+ formatLargeNumbers(message) + '.   Play a new tournament today for another chance to win.';
								}
	                            else
								{
	                            	var course        = metaData.courseName;
	                            	var courseName 	  = course.replace("_and_", "&");

                                	messageText = 'You have won the Closest to Pin Contest of Hole ' + (metaData.hole + 1) + ' on ' + courseName + ' during the ' + metaData.tournamentName + ' and have won $' + formatLargeNumbers(message) + '.  Play a new tournament today for another chance to win.';
								}
	                            
	                            messageCopy = '<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img alt="' + feedLinkLocation + '" src="' + icon + '"/></a></div><div class="copy has_image"><h3><a class="' + feedLinkClass + '" href="' + feedLink + '">' + header + '</a></h3><div class="feed_image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img class="image_contest" src="' + image + '" alt="' + feedLinkLocation + '" /></a></div><p>' + 
				                            		messageText + 
				                            		'</p><span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' + feedLinkLocation + '</a></span></div>';
	                        }
	                        break;
	                        
	                        // tournament (normal & group) end of day Longest Drive winner
	                        case 'IGCHAL_LD_EOD_WIN_A': // affiliated (group)
	                        case 'IGCHAL_LD_EOD_WIN_NA': // non-affiliated (normal tournament)
	                        {
	                            var metaData = parseIngameChalAwardsMetaData(payLoad);
	
	                            feedClass = 'something';
	                            icon = '/img/home/feed_tournament_award.png';
	                            image = '/img/icons/icon_winner_ld.png';
	                            message = awardValue;
								
	                            header = 'Longest Drive Contest Won!';
	                            
	                            feedLinkClass = 'launchGame';
	                            feedLink = 'javascript:void(0);';
                            	//feedLink = '/tournaments';
                            	feedLinkLocation = 'Play a Tournament Today';
								
	                            if(metaData == null)
								{
									messageText = 'You have won the Longest Drive Contest and have won $' + formatLargeNumbers(message) + '.   Play a new tournament today for another chance to win.';
								}
	                            else
								{
	                            	var course        = metaData.courseName;
	                            	var courseName 	  = course.replace("_and_", "&");

                                	messageText = 'You have won the Longest Drive Contest of Hole ' + (metaData.hole + 1) + ' on ' + courseName + ' during the ' + metaData.tournamentName + ' and have won $' + formatLargeNumbers(message) + '.  Play a new tournament today for another chance to win.';
								}
	                            
	                            messageCopy = '<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img alt="' + feedLinkLocation + '" src="' + icon + '"/></a></div><div class="copy has_image"><h3><a class="' + feedLinkClass + '" href="' + feedLink + '">' + header + '</a></h3><div class="feed_image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img class="image_contest" src="' + image + '" alt="' + feedLinkLocation + '" /></a></div><p>' + 
						                    		messageText + 
						                    		'</p><span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' + feedLinkLocation + '</a></span></div>';
	                            
	                        }
	                        break;
                            // tournament in-game challenge notifications
                            case 'IGCHAL_INGAME_BEAT_NA':
                            case 'IGCHAL_INGAME_MEET_NA':
                            case 'IGCHAL_INGAME_CLOSE_NA':
                            case 'IGCHAL_INGAME_SET_NA':
                            // group affiliated e.g.	
                            case 'IGCHAL_INGAME_BEAT_A':
                            case 'IGCHAL_INGAME_MEET_A':
                            case 'IGCHAL_INGAME_CLOSE_A':
                            case 'IGCHAL_INGAME_SET_A':
                            case 'IGCHAL_INGAME_CLOSE':
                            case 'IGCHAL_INGAME_MEET':
                           	{
                           		// nothing for now?
                           		skipDisplay = true;
                          	}
                           	break;
                           	
                            // non-tournament end of day in-game challenge notifications
                            case 'IGCHAL_EOD_WIN':
                            {
                            	//parse data differently here
                            	if(payLoad)
                            	{
                            		var params = payLoad.split(";");
                            			
                            		if(params != null && params.length >= 7)
                                	{
	                                	var challengeType = params[1]; //params[0] is event name
	                                	var course    		= params[2];
	                                	var hole          = Number(params[3]) + 1;
	                                	var tee			  = Number(params[4]);
	                                	var pin			  = Number(params[5]);
	                                	var leaderName    = params[6];
	                                	var courseId      = params[7];
	                                	var courseName 	  = course.replace("_and_", "&");
                        				feedClass = 'something';
                        				feedLinkClass = 'launchGame';
	                                	feedLink = 'javascript:void(0);';
                        				//feedLink = '/play/playRedirect/'+courseId+'/singleplayer/0/' + tee + '/' +pin;
                                        feedLinkLocation = 'Win More Challenges'; 
                                        
                                        icon = '/img/home/feed_tournament_award.png';
                                    	header = challengeType + ' Contest Won!' ;
                                    	
                                    	var messageText = "";
                                   		if(challengeType == "Longest Drive")
                                        {
                                   			messageText = 'You have won the the ' + challengeType + ' Contest on the ' + getTeeDisplay(tee) + ' Tees of Hole ' + (hole) + ' on ' + courseName + ' and have won $' + formatLargeNumbers(Number(awardValue)) + '.  Play again today for another chance to win.';
                                        	image = '/img/icons/icon_winner_ld.png';
                                        }
                                        else
                                        {
                                        	messageText = 'You have won the the ' + challengeType + ' Contest on the ' + getTeeDisplay(tee) + ' Tees and ' + getPinDisplay(pin) + ' Pin of Hole ' + (hole) + ' on ' + courseName + ' and have won $'+ formatLargeNumbers(Number(awardValue)) + '.  Play again today for another chance to win.';
                                        	image = '/img/icons/icon_winner_cttp.png';
                                        }
                                    	messageCopy = '<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img alt="' + feedLinkLocation + '" src="' + icon + '"/></a></div><div class="copy has_image"><h3><a class="' + feedLinkClass + '" href="' + feedLink + '">' + header + '</a></h3><div class="feed_image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img class="image_contest" src="' + image + '" alt="' + feedLinkLocation + '" /></a></div><p>' + 
					                                		messageText +  
					                                		'</p><span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' + feedLinkLocation + '</a></span></div>';
                                	}
                            	}
                            }
                            break;
                            // non-tournament in-game challenge notifications
                            case 'IGCHAL_INGAME_BEAT':
                            case 'IGCHAL_INGAME_SET':
                           	{
                            	//parse data differently here
                            	if(payLoad)
                            	{
                            		var params = payLoad.split(";");
                            			
                            		if(params != null && params.length >= 7)
                                	{
	                                	var challengeType = params[1];
	                                	var course    	  = params[2];
	                                	var hole          = Number(params[3]) + 1;
	                                	var tee			  = Number(params[4]);
	                                	var pin			  = Number(params[5]);
	                                	var leaderName    = params[6];
	                                	var courseId      = params[7];
	                                	var courseName 	  = course.replace("_and_", "&");
	                                	
	                                	feedClass = 'something';
	                                	feedLinkClass = 'launchGame';
	                                	feedLink = 'javascript:void(0);';
	                                	//feedLink = '/play/playRedirect/'+courseId+'/singleplayer/0/' + tee + '/' +pin;
                                        feedLinkLocation = 'Beat Your Record';
                                        
                                        icon = '/img/home/feed_tournament_award.png';
                                    	header = 'New ' + challengeType + ' Record Set!' ;
            
                                    	var messageText = "";
                                        if(challengeType == "Longest Drive")
                                        {
                                        	image = '/img/icons/icon_record_ld.png';
                                        	messageText = 'You have been awarded $'+ formatLargeNumbers(Number(awardValue)) + ' for setting the ' + challengeType + ' Contest record on Hole ' + hole + ' from the ' + getTeeDisplay(tee) + ' Tees on ' + courseName + '.'; 
                                        }
                                        // closest to pin
                                        else
                                        {
                                        	image = '/img/icons/icon_record_cttp.png';
	                                    	messageText = 'You have been awarded $'+ formatLargeNumbers(Number(awardValue)) + ' for setting the ' + challengeType + ' Contest record on Hole ' + hole + ' from the ' + getTeeDisplay(tee) + ' Tees and ' + getPinDisplay(pin) + ' Pin on ' + courseName + '.'; 
                                        }
                                        messageCopy = '<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img alt="' + feedLinkLocation + '" src="' + icon + '"/></a></div><div class="copy has_image"><h3><a class="' + feedLinkClass + '" href="' + feedLink + '">' + header + '</a></h3><div class="feed_image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img class="image_contest" src="' + image + '" alt="' + feedLinkLocation + '" /></a></div><p>' + 
					                                		messageText +  
					                                		'</p><span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' + feedLinkLocation + '</a></span></div>';
                                	}
                            	}
                            	
                          	}
                           	break;
                            case 'IGCHAL_INGAME_REPLACE_LEADER':
                            {
                            	//parse data differently here
                            	if(payLoad)
                            	{
                            		var params = payLoad.split(";");
                            			
                            		if(params != null && params.length >= 7)
                                	{
                                		var newLeaderName = params[1];
	                                	var challengeType = params[2];
	                                	var course    	  = params[3];
	                                	var hole          = Number(params[4]) + 1;
	                                	var tee			  = Number(params[5]);
	                                	var pin			  = Number(params[6]);
	                                	var courseId	  = parseInt(params[8]);
	                                	var courseName 	  = course.replace("_and_", "&");
	                                	feedClass = 'something';
	                                	feedLinkClass = 'launchGame';
	                                	feedLink = 'javascript:void(0);';
                                        //feedLink = '/play/playRedirect/'+courseId+'/singleplayer/0/' + tee + '/' +pin;
                                        feedLinkLocation = 'Challenge Now';
                            				
                                        icon = '/img/home/feed_tournament_award.png';
                            			header = 'Your ' + challengeType + ' Record Has Been Beaten!' ;

                            			var messageText = '';
	                                	if(challengeType == "Longest Drive")
	                                	{
                                			var yards		  = Number(params[7]);
                                			var yardMsg		  = "by inches";
                                			if(yards > 1)
                                			{
                                				yardMsg = "by " + yards + " yds ";
                                			}
	                                		header = 'Your ' + challengeType + ' Record Has Been Beaten ' + yardMsg + '!' ; 
                                        	image = '/img/icons/icon_beaten_ld.png';
                                        	
                                        	messageText = '<a href="/profiles/' + newLeaderName  + '">' +newLeaderName + '</a> has beaten your ' + challengeType + ' Contest record on Hole '+ hole + ' from the ' + getTeeDisplay(tee) + ' Tees on ' + courseName + '. Get on the ' + courseName + ' and win back this challenge now!';
	                                	}
	                                	// closest to pin
                                        else
                                        {
                                        	image = '/img/icons/icon_beaten_cttp.png';
                                        	
                                        	messageText = '<a href="/profiles/' + newLeaderName  + '">' +newLeaderName + '</a> has beaten your ' + challengeType + ' Contest record on Hole '+ hole + ' from the ' + getTeeDisplay(tee) + ' Tees and ' + getPinDisplay(pin) + ' Pin on ' + courseName + '. Get on the ' + courseName + ' and win back this challenge now!';
                                        }
	                            		messageCopy = '<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img alt="' + feedLinkLocation + '" src="' + icon + '"/></a></div><div class="copy has_image"><h3><a class="' + feedLinkClass + '" href="' + feedLink + '">' + header + '</a></h3><div class="feed_image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img class="image_contest" src="' + image + '" alt="' + feedLinkLocation + '" /></a></div><p>' + 
		                            		messageText + 
		                            		'</p><span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' + feedLinkLocation + '</a></span></div>';
                                	}
                            	}
                            }
                           	break;
                           	
                           	//
                           	// Friends notifications (your friend won!)
                           	//
                           	
                            // tournament (normal & group) end of day Closest of Pin winner
                            case 'IGCHAL_CP_EOD_WIN_A_FRIENDWON':
                            case 'IGCHAL_CP_EOD_WIN_NA_FRIENDWON':
                            {
                                var metaData = parseIngameChalAwardsMetaData(payLoad);

                                if(metaData)
                                {
	                                feedClass = 'something';
	                                icon = '/img/home/feed_tournament_award.png';
	                                image = '/img/icons/icon_winner_cttp.png';
	                                message = awardValue;
	                                
	                                header = 'Closest to Pin Contest Won!';
									
									feedLinkClass = 'launchGame';
	                            	feedLink = 'javascript:void(0);';
	                           		//feedLink = '/tournaments';
	                           		feedLinkLocation = 'Play a Tournament Today';
	                                        
	                                messageText = '<a href="/profiles/' + metaData.leaderName  + '">' + metaData.leaderName + '</a> has won the Closest to Pin Contest of Hole ' + (metaData.hole + 1) + ' on ' + metaData.courseName + ' during the ' + metaData.tournamentName + ' and has won $'+ formatLargeNumbers(message) + '.  Play a tournament today for a chance to win.';
	                                messageCopy = '<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img alt="' + feedLinkLocation + '" src="' + icon + '"/></a></div><div class="copy has_image"><h3><a class="' + feedLinkClass + '" href="' + feedLink + '">' + header + '</a></h3><div class="feed_image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img class="image_contest" src="' + image + '" alt="' + feedLinkLocation + '" /></a></div><p>' + 
					                            		messageText + 
				                            		'</p><span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' + feedLinkLocation + '</a></span></div>';
                                }
                            }
                            break;
                            
                            // tournament (normal & group) end of day Longest Drive winner
                            case 'IGCHAL_LD_EOD_WIN_A_FRIENDWON': // affiliated (group)
                            case 'IGCHAL_LD_EOD_WIN_NA_FRIENDWON': // non-affiliated (normal tournament)
                            {
                                var metaData = parseIngameChalAwardsMetaData(payLoad);
                                
                                if(metaData)
                                {
	                                feedClass = 'something';
	                                icon = '/img/home/feed_tournament_award.png';
	                                image = '/img/icons/icon_winner_ld.png';
	                                message = awardValue;
									
	                                header = 'Longest Drive Contest Won!';
									
									feedLinkClass = 'launchGame';
	                            	feedLink = 'javascript:void(0);';
	                          		//feedLink = '/tournaments';
	                           		feedLinkLocation = 'Play a Tournament Today';
	                                        
	                                messageText = '<a href="/profiles/' + metaData.leaderName  + '">' + metaData.leaderName + '</a> has won the Longest Drive Contest of Hole ' + (metaData.hole + 1) + ' on ' + metaData.courseName + ' during the ' + metaData.tournamentName + ' and has won $'+ formatLargeNumbers(message) + '.  Play a tournament today for a chance to win.';
	                               
	                                messageCopy = '<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img alt="' + feedLinkLocation + '" src="' + icon + '"/></a></div><div class="copy has_image"><h3><a class="' + feedLinkClass + '" href="' + feedLink + '">' + header + '</a></h3><div class="feed_image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img class="image_contest" src="' + image + '" alt="' + feedLinkLocation + '" /></a></div><p>' + 
						                        		messageText + 
						                        		'</p><span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' + feedLinkLocation + '</a></span></div>';
                                }
                            }
                            break;
                            // non-tournent (course) challenge win
                            case 'IGCHAL_EOD_WIN_FRIENDWON':
                            {
                            	//parse data differently here
                            	if(payLoad)
                            	{
                            		var params = payLoad.split(";");
                            			
                            		if(params != null && params.length >= 7)
                                	{
	                                	var challengeType = params[1]; //params[0] is event name
	                                	var course    	  = params[2];
	                                	var hole          = Number(params[3]) + 1;
	                                	var tee			  = Number(params[4]);
	                                	var pin			  = Number(params[5]);
	                                	var leaderName    = params[6];
	                                	var courseId      = params[7];
	                                	var courseName 	  = course.replace("_and_", "&");
	                                	
                        				feedClass = 'something';
                        				feedLinkClass = 'launchGame';
	                                	feedLink = 'javascript:void(0);';
                                    	//feedLink = '/play/playRedirect/'+courseId+'/singleplayer/0/' + tee + '/' +pin;
                                        feedLinkLocation = 'Challenge Now';
                                        
                                        icon = '/img/home/feed_tournament_award.png';
                                    	header = challengeType + ' Contest Won!' ;
                                    	
                                   		if(challengeType == "Longest Drive")
                                        {
                                        	image = '/img/icons/icon_winner_ld.png';
                                        }
                                        else
                                        {
                                        	image = '/img/icons/icon_winner_cttp.png';
                                        }
                                   		var messageText = '<a href="/profiles/' + leaderName  + '">' + leaderName + '</a> has won the ' + challengeType + ' from the ' + getTeeDisplay(tee) + ' Tees of Hole ' + (hole) + ' on ' + courseName + ' and has won $'+ formatLargeNumbers(Number(awardValue)) + '.  Play today for a chance to win.';                                   		
                                   		messageCopy = '<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img alt="' + feedLinkLocation + '" src="' + icon + '"/></a></div><div class="copy has_image"><h3><a class="' + feedLinkClass + '" href="' + feedLink + '">' + header + '</a></h3><div class="feed_image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img class="image_contest" src="' + image + '" alt="' + feedLinkLocation + '" /></a></div><p>' + 
				                                		messageText +
				                                		'</p><span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' + feedLinkLocation + '</a></span></div>';
                                	}
                            	}
                            }
                            break;                            
							default:
							{
								var messageText = "unhandled case" + eventName;
								messageCopy = '<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img alt="' + feedLinkLocation + '" src="' + icon + '"/></a></div><div class="copy has_image"><h3><a class="' + feedLinkClass + '" href="' + feedLink + '">' + header + '</a></h3><div class="feed_image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img class="image_contest" src="' + image + '" alt="' + feedLinkLocation + '" /></a></div><p>' + 
				                                		messageText +
				                                		'</p><span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' + feedLinkLocation + '</a></span></div>';
							}

                        }

                        if(!skipDisplay)
                        {
                        	updateRecentActivity(header, messageCopy, striped, dateString, icon, feedLink, feedLinkLocation, feedClass);
                        }
                    }
                    else if (msgType === ONLINEPASS_MSG_TYPE) // online pass notifications
                    {
                    	var awardData = parseAward(msgType, this);
                        var payLoad = unescape($('entry[key=3]', this).text());
                        var eventName = extractEventName(payLoad);

                    	// parse the event name for the game
                    	game = eventName.replace(/ONLINEPASS_(.*)\d\d_.*/, "$1");
                    	
						/* turn off background image for now... at least until we can make them look better
                    	if(game)
                    	{
							awardData.bgImage = '/img/backgrounds/bg_onlinepass_'+game.toLowerCase()+'.jpg';
	                    	awardData.feedClass = 'onlinePass'+game.toUpperCase();
                    	}
                    	else
                    	{
	                    	// TODO - this needs to account for each online pass type
							awardData.bgImage = '/img/backgrounds/bg_onlinepass_ncaa.jpg';
							awardData.feedClass = 'onlinePassNCAA';
                    	}
						*/
						
                        messageCopy = 
    						'<div class="image"><a class="' + awardData.feedLinkClass + '" href="' + awardData.feedLink + '"><img src="' + awardData.icon + '" alt="' + awardData.feedLinkLocation + '" /></a></div>' +
                            '<div class="copy has_image"><h3>' + awardData.header + '</h3>' +
                            	'<div class="feed_image_lg"><a class="' + awardData.feedLinkClass + '" href="' + awardData.feedLink + '"><img src="' + awardData.image + '" alt="' + awardData.feedLinkLocation + '" /></a></div>' +
                            	'<p>' + awardData.awardDisplay + '<br/><a class="capitalTxt" class="' + awardData.feedLinkClass + '" href="' + awardData.feedLink + '">' + awardData.feedDescription + '</a></p>' +
                            	'<span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + awardData.feedLinkClass + '" href="' + awardData.feedLink + '">' + awardData.feedLinkLocation + '</a></span>' +
                            '</div>';
    
                        updateRecentActivity(awardData.header, messageCopy, striped, dateString, awardData.icon, awardData.feedLink, awardData.feedLinkLocation, awardData.feedClass);
                    }
	                
	                //
	                // daily leaderboard winner
	                //
                    else if (msgType === FRIENDS_LB_MSG_TYPE)
					{
					   // with this version, we're passing a full JSON reward structure in the first parm
	                   var rewardStr = $('entry[key=0]', this).text();
	                   var reward = eval('(' + rewardStr + ');');

	                   //TODO: Fix this!  For message type IGC_MSG_TYPE, IGCHAL_INGAME_REPLACE_LEADER (and others)
	                   // doesnt follow the format (i.e. not JSON), so if its the non-json string, we
	                   // wont try to parse it as json.  i could have done a try/catch but thats probably
	                   // bad too...  this is coming out anyway, so no troubles, no worries...
	                   // I would recommend a different message type for this, since it has a unique
	                   // format...
	                    if (rewardStr != '0')
	                    {
		                    var awardType = reward.type;
		                    var awardValue = reward.value;
		                    var awardName = reward.meta['displayName'];
		                    var awardIcon = reward.meta['icon'];	                    		
	                    }
							
						var awardDisplay = $('entry[key=2]', this).text();
                        var payLoad = unescape($('entry[key=3]', this).text());
                        var eventName = extractEventName(payLoad);
                        header = awardDisplay;
                        
                        var skipDisplay = false;

                        // parse our metadata to know rank, value, beaten, played, etc...
                    	if (payLoad)
                    	{
                    		var params = payLoad.split(";");
                    		if (params != null && params.length >= 5)
                        	{
								// param[0] is reserved for EventName.
                            	var leaderboardType = params[1];
								var rank = params[2]; 
								var value = params[3];
								var beaten = params[4];
								var played = params[5];
								
		                        var eventStr = eventName;
		                        var valueStr = value;
		                        switch(eventName)
		                        {
									// non-tournament end of day in-game challenge notifications
		                            case 'FRIENDS_LB_MONEY_EARNED':
		                            case 'FRIENDS_LB_MOST_EARNED': // deprecated
		                            {
		                            	eventStr = 'Highest Earnings';
		                            	valueStr = '$' + formatLargeNumbers(Number(value));
		                            }
		                            break;
		                            case 'FRIENDS_LB_BIRDIES':
		                            case 'FRIENDS_LB_MOST_BIRDIES': // deprecated
		                            {
		                            	eventStr = 'Most Birdies';
		                            	valueStr = value + ' ' + pluralize(value, 'birdie');
		                            }
		                            break;
		                            case 'FRIENDS_LB_ROUNDS':
		                            case 'FRIENDS_LB_MOST_ROUNDS': // deprecated
		                            {
		                            	eventStr = 'Most Rounds Played';
		                            	valueStr = value + ' ' + pluralize(value, 'round');
		                            }
		                            break;
		                            case 'FRIENDS_LB_LONGEST_DRIVE':
		                            {
		                            	eventStr = 'Longest Drive';
		                            	valueStr = (Math.round(value*100)/100) + ' ' + 'yards';
		                            }
		                            break;
									case 'FRIENDS_LB_LEVEL':
		                            {
		                            	eventStr = 'Highest Level';
		                            	valueStr = value;
		                            }
		                            break;
		                            case 'FRIENDS_LB_ACHIEVEMENT_POINTS':
		                            {
		                            	eventStr = 'Highest Achievement Score';
		                            	valueStr = formatLargeNumbers(value); // + ' ' + pluralize(value, '???');
		                            }
		                            break;
		                            
		                            // shouldn't hit this!
									default:
									{
										eventStr = eventName;
										valueStr = value;
									}
									break;
								}
																		
                				feedClass = 'something';
                				feedLinkClass = 'launchGame';
	                            feedLink = 'javascript:void(0);';
                                feedLinkLocation = 'Compete Today';
                                
                                icon = '/img/home/feed_tournament_award.png';
								header = 'Daily ' + eventStr + ' Results';
                            	
                            	var messageText = 'Congratulations! You have finished ' + ordinal(rank) +  ' in the Daily ' + eventStr + ' Leaderboard with ' + valueStr + '. Here\'s $' + formatLargeNumbers(Number(awardValue)) + ' for playing against ' + played + ' friend(s). More opportunities to win today!';
                            	// NOTE: no custom icon for winning friends lb right now
                                //image = '/img/icons/icon_winner_ld.png';
							
                            	messageCopy = '<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img alt="' + feedLinkLocation + '" src="' + icon + '"/></a></div><div class="copy has_image"><h3><a class="' + feedLinkClass + '" href="' + feedLink + '">' + header + '</a></h3><p>' + 
                            				  //  no image right now '<div class="feed_image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img class="image_contest" src="' + image + '" alt="' + feedLinkLocation + '" /></a></div><p>' + 
		                                		messageText +  
		                                		'</p><span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' + feedLinkLocation + '</a></span></div>';
                        	}
                    		// not enough params in payload
                    		else
                    		{
                    			header = eventName;
                    			messageCopy = "Error: Message has incorrect payload param cnt: eventName = " + eventName + " params: " + params.length;
                    			icon = '/img/home/feed_tournament_award.png';
                    			feedLinkClass = 'launchGame';
	                            feedLink = 'javascript:void(0);';
    							feedLinkLocation = 'Compete Today';	
    							feedClass = 'something';
                    		}
                    	}
                    	// no payload set
						else
						{
							header = eventName;
							messageCopy = "Error: Message has no payload: eventName = " + eventName;
							icon = '/img/home/feed_tournament_award.png';
							feedLinkClass = 'launchGame';
	                        feedLink = 'javascript:void(0);';
							feedLinkLocation = 'Compete Today';	
							feedClass = 'something';           
						}
						
						updateRecentActivity(header, messageCopy, striped, dateString, icon, feedLink, feedLinkLocation, feedClass);
					}	                
	                else if (msgType === TOURNAMENT_PLACE_MSG_TYPE) 
	                {
	                    // ---------------------
	                    // Tournament Award notification
	                    // ---------------------
	                    var customType = parseInt($('entry[key=4]', this).text(), 10);
	                    if (customType === 0)  // Tournament Award Notification
	                    {
	                        objTournamentAward = parseTournamentAward($('entry[key=9]', this).text());

	                        if (objTournamentAward !== null) {
	                            header = 'Your Tournament Results';
	                            
	                            feedLinkClass = 'launchGame';
	                            feedLink = 'javascript:void(0);';
	                            //feedLink = '/tournaments/detail/' + objTournamentAward.tournamentId;
	                            feedLinkLocation = 'Tournament Details';
	                            feedClass = 'tournaments';
	                            icon = '/img/home/feed_tournament_award.png';

	                            var money = '$' + formatLargeNumbers(objTournamentAward.winnings);
	                            var score = formatRelativeScore(objTournamentAward.score);
	                            message = "You\'ve ranked " + ordinal(objTournamentAward.rank) + " place in the " + objTournamentAward.tournamentName + " tournament with a score of " + score + ".  You\'ve earned " + money + " in prize money!";
	                            messageCopy = '<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img alt="' + feedLinkLocation + '" src="' + icon + '"/></a></div><div class="copy"><h3><a class="' + feedLinkClass + '" href="' + feedLink + '">' + header + '</a></h3><p>' + message + '</p><span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' + feedLinkLocation + '</a></span></div>';
	                            updateRecentActivity(header, messageCopy, striped, dateString, icon, feedLink, feedLinkLocation, feedClass);
	                        }
	                    }

	                    // ---------------------
	                    // Group Tournament Award notification
	                    // ---------------------
	                    var customType = parseInt($('entry[key=4]', this).text(), 10);
	                    if (customType === 1)  // Group Tournament Award Notification
	                    {
	                        objTournamentAward = parseGroupTournamentAward($('entry[key=10]', this).text());

	                        if (objTournamentAward !== null) {
	                            header = 'Your Group Tournament Results';
	                            feedLink = '/groups/profile_overview/' + objTournamentAward.groupId;
	                            feedLinkLocation = 'Group Details';
	                            feedClass = 'tournaments';
	                            icon = '/img/home/feed_tournament_award.png';

	                            var money = '$' + formatLargeNumbers(objTournamentAward.winnings);
	                            var score = formatRelativeScore(objTournamentAward.score);
	                            message = "You\'ve ranked " + ordinal(objTournamentAward.rank) + " place in the " + objTournamentAward.groupName + " group tournament with a score of " + score + ".  You\'ve earned " + money + " in prize money!";
	                            messageCopy = '<div class="image"><a class="' + feedLinkClass + '" href="' + feedLink + '"><img alt="' + feedLinkLocation + '" src="' + icon + '"/></a></div><div class="copy"><h3><a class="' + feedLinkClass + '" href="' + feedLink + '">' + header + '</a></h3><p>' + message + '</p><span class="feed_meta"><abbr class="timeago" title="' + dateString + '">' + dateString + '</abbr>&nbsp;&#183;&nbsp;<a class="feed_link ' + feedLinkClass + '" href="' + feedLink + '">' + feedLinkLocation + '</a></span></div>';
	                            updateRecentActivity(header, messageCopy, striped, dateString, icon, feedLink, feedLinkLocation, feedClass);
	                        }
	                    }
	                }

	                // non custom handling of the message, debug text (shouldn't ever fall thru to this unformatted data)
	                else 
	                {
	                    header = 'Msg Type: ' . msgType;

	                    // if the message has a exp update type and hasnt been touched
	                    $(this).find('entry').each(function() {
	                        message += '<h3>' + $(this).text() + '</h3>';
	                    });

	                    updateRecentActivity(header, message, striped, dateString, DEFAULT_ICON);
	                }


	                striped = !striped; // flip bit

	                // touch this message, so it doesnt get shown again
	                if (msgStatus == 0) { 
	                    callPostWS(true, "/messaging_service/touchmessage/" + msgId + "/0/1/1/",
                            WSRequestTimeout,
                            null,
                            function(xml, TextStatus) {
                            },
                            function(XMLHttpRequest, textStatus) {

                            },
                            null);
	                }

	            });
	            
                if( deferredMessages == 0 )
                    showNextPage();

	            if (found) {
	                ModalQueue.play();
	            }
	            
	            // done adding stream messages, handle new special click handlers for feed links (vs simple url redirection)
	            $(".launchGame").click(function(){
	        		teeOff();		
	        	});

	        },
	        function(XMLHttpRequest, textStatus) {

	        },
	        null);
}

function updateRecentActivity(header, message, striped, timestamp, icon, feedLink, feedLinkLocation, feedClass)
{
    var liActivity = '';

    if (striped) {
        liActivity += '<li class="entry ' + feedClass + '" style="display: none;">';
        //liActivity += '<li class="entry DoubleBorder ' + feedClass + ';">';
    }
    else {
        liActivity += '<li class="entry ' + feedClass + '" style="display: none;">';
        //liActivity += '<li class="entry DoubleBorder striped ' + feedClass + '";">';
    }

    liActivity = liActivity + '<div class="inner" id="RECENT_ACTIVITY_'+recentActivityCount+'">' + message + '</div></li>';

    // add it to the DOM
    $("#Activity_Feed ul.feedList").prepend(liActivity);
}


