﻿function FormatTop10Item(obj) { 
var link = $(obj).find("a");
var title = $(link).text();$(link).remove();
var url = ""; url = $(link).attr("href");
var img = ""; img = $(obj).find("img");
var text = $.trim($(obj).text());

var html = "";
html+= '<table width="100%" border="0" cellpadding="0" cellspacing="0" class="listingitem" title="' + title + '" onclick="n(\'' + url + '\');">';
html+= '<tr>';
html+= '<td valign="top" class="listingitemcell">';

if ((img != null) && (img != "")) { var src = img.attr("src");if ((src != null) && (src != "")) { 
html+= '<table width="100" border="0" align="left" cellpadding="0" cellspacing="0" class="itemlogo"><tr><td align="center" valign="middle" style="background:#fff;"><img src="' + src + '" alt="' + title + '" /></td></tr></table>';
} else { 
html+= '<table width="100" border="0" align="left" cellpadding="0" cellspacing="0" class="itemlogo"><tr><td align="center" valign="middle">' + title + '</td></tr></table>';
}}
html+= '<table><tr><td class="listingitemtext" valign="middle" align="left">' + text + '</td></tr></table>';
//html+= $(obj).html();
html+='</td>';
html+= '</tr>';
html+= '</table>';

return html;

}

function RenderTop10SportsBooks() { 
var MyItems = $("#sportsbooklistingsleft ul li")
$("#sportsbooklistingsleft ul").after('<table width="100%" border="0" cellpadding="5" id="sportsbooklistingitems"><tr><td width="50%" id="topItemsLeftCell" valign="top"></td><td width="50%" id="topItemsRightCell" valign="top"></td></tr></table>').remove();

var i=0;
$(MyItems).each(function() {

var DestinationCell = "topItemsLeftCell";
if (i % 2 == 0) DestinationCell = "topItemsRightCell";

$("#"+DestinationCell).html($("#"+DestinationCell).html() + FormatTop10Item($(this)));

i++;

});

$(".listingitem").hover(function() { $(this).removeClass("listingitem"); $(this).addClass("listingitemover"); }, function() { $(this).removeClass("listingitemover"); $(this).addClass("listingitem"); }); 

}

function ActivateRSS() { 

$(".rss").each(function() { 
$(this).find("a").prepend('<span class="rssb" title="Click here for RSS feed" onclick="nB(\'' + $(this).attr("data-feed") + '\');return false;"></span>');
});

$(".newsletter").find("a").prepend('<span class="nlsb" title="Click here for more details on subscribing to our newsletter"></span>')

}

$(function() {

var scoreboard = $('#scoreboard');
if ($(scoreboard).attr("data-score") != null) { 
var myScore = $('#scoreboard').attr("data-score").split('|');
$('#scoreboard').html('');
$('#scoreboard').flash({src: '/images/scoreboard.swf?&win=' + myScore[0] + '&loss=' + myScore[1] + '&p1=1&p2=9&p3=4', width: 343,  height:96});
}

$("#sclistright ul li").hover(function() { $(this).addClass("over");}, function() { $(this).removeClass("over"); }); 
$("#sclistright ul li").each(function() { $(this).click(function() { n($(this).find("a").attr("href"));  }); });

$("#articleslistingleft ul li").hover(function() { $(this).addClass("over");}, function() { $(this).removeClass("over"); }); 
$("#articleslistingleft ul li").each(function() { $(this).click(function() { n($(this).find("a").attr("href"));  }); });

$("#newsletter div").html("Click here to receive Live Sports Direct's regular newsletter for information on promotional offers and special deals for fans of the sportsbook written in the trademarked LSPD style. <span style='color:#2b7abf;font-weight:bold;'>[coming soon]</span>");
$("#newsletter div").hover(function() { $(this).addClass("over");}, function() { $(this).removeClass("over"); }); 
$("#newsletter div").click(function() { n('/newsletter/'); }); 

RenderTop10SportsBooks();
ActivateRSS();

});
