var messageObj = new DHTML_modalMessage();

function socialHome() {
  var url = "http://apps.facebook.com/aflfooty/fbml-index.html";
  openSocialIntegrationDialog(url, "Join the Facebook AFL Footy Community", "Join Facebook Footy");
}

function threadComment(forumId, threadId) {
  var url = "http://apps.facebook.com/aflfooty/fbml-view-forum-" + forumId + "-thread-" + threadId + "-page-1.html";
  openSocialIntegrationDialog(url, "Add a Comment", "Add a Comment");
}

function threadReply(forumId, threadId, commentId, posterName) {
  var url = "http://apps.facebook.com/aflfooty/fbml-view-forum-" + forumId + "-thread-" + threadId + "-comment-" + commentId + "-reply-form.html";
  openSocialIntegrationDialog(url, "Reply to " + posterName, "Reply to " + posterName);
}

function postNewTopic(forumId, forumName) {
  var url = "http://apps.facebook.com/aflfooty/fbml-post-new-thread-" + forumId + "-form.html";
  openSocialIntegrationDialog(url, "Add a new topic to the " + forumName + " board", "Add New Topic");
}

function playerReply(playerId, commentId, posterName, playerName) {
  var url = "http://apps.facebook.com/aflfooty/fbml-player-" + playerId + "-comment-" + commentId + "-reply-form.html";
  openSocialIntegrationDialog(url, "Reply to " + posterName + " about " + playerName, "Reply to " + posterName);
}

function playerHome(playerId, playerName) {
  var url = "http://apps.facebook.com/aflfooty/fbml-player-" + playerId + "-details.html";
  openSocialIntegrationDialog(url, "Visit " + playerName + "'s Fan Page", "Go to " + playerName + "'s Fan Page");
}

function playerComment(playerId, playerName) {
  var url = "http://apps.facebook.com/aflfooty/fbml-player-" + playerId + "-details.html";
  openSocialIntegrationDialog(url, "Add a comment on " + playerName, "Add a Comment");
}

function teamReply(teamId, commentId, posterName, teamName) {
  var url = "http://apps.facebook.com/aflfooty/fbml-team-" + teamId + "-comment-" + commentId + "-reply-form.html";
  openSocialIntegrationDialog(url, "Reply to " + posterName + " about the " + teamName, "Reply to " + posterName);
}

function teamHome(teamId, teamName) {
  var url = "http://apps.facebook.com/aflfooty/fbml-team-" + teamId + "-details.html";
  openSocialIntegrationDialog(url, "Visit the " + teamName + " Fan Page", "Go to the " + teamName + " Fan Page");
}

function teamComment(teamId, teamName) {
  var url = "http://apps.facebook.com/aflfooty/fbml-team-" + teamId + "-details.html";
  openSocialIntegrationDialog(url, "Add a comment on the " + teamName, "Add a Comment");
}

function openSocialIntegrationDialog(url, action, shortAction) {
  var html = getHtml(url, action, shortAction);
  messageObj.setShadowOffset(5);
  messageObj.setHtmlContent(html);
  messageObj.setSize(575, 275);
  messageObj.setSource(false);
  messageObj.setShadowDivVisible(false);	
  messageObj.display();
}

function getHtml(url, action, shortAction) {
  var randomnumber = Math.floor(Math.random() * 7) + 1;
  var html = "<table border=0 cellspacing=0 cellpadding=4 class=socialtable>";
  if (shortAction == 'Join Facebook Footy') {
    html += "<tr><td class=socialtitle colspan=2>Join the AFL Footy Community on Facebook!</td></tr>";
  }
  else {
    html += "<tr><td class=socialtitle colspan=2>Join the Footy Discussion on Facebook!</td></tr>";
  }
  html += "<tr>";
  html += "<td rowspan=2 valign=middle align=center><img height=200 width=148 src='/afl/img/largepeep/peep" + randomnumber + ".jpg'/></td>";
  html += "<td>";
  if (shortAction == 'Join Facebook Footy') {
    html += "<p>Interact with thousands of footy fans on <b>Facebook</b> with lively discussion forums and fan pages.";
  }
  else {
    html += "<p>Our lively discussion forums and fan pages are closely integrated with the AFL Footy application on <b>Facebook</b>.";
  }
  html += "<p>You will need to be logged into your <b>Facebook</b> account to <a href='" + url + "'><b>" + action + "</b></a>.";
  html += "<p>Please be assured that:";
  html += "<li>We do <b>NOT</b> have access to your password, email or login details</li>";
  html += "<li>We do <b>NOT</b> have access to your private information or data</li>";
  html += "<p>Come on in and start talking footy!";
  html += "</td></tr>";
  html += "<tr><td align=center>";
  //html += "<p><div class='socialbutton' onclick='window.location=\"" + url + "\"'>Proceed to AFL Footy on Facebook</div>";
  html += "<p><div class='socialbutton' onclick='window.location=\"" + url + "\"'>" + shortAction + "</div>";
  html += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  html += "<div class='socialbutton' onclick='messageObj.close()'>No Thanks</a>";
  html += "</td></tr>";
  html += "</table>"
  return html;
}
