ProcessCasinoBlock("gi-top-casino", "badgecorner");
ProcessCasinoBlock("gi-top-bonuses", "badgecorner2");
ProcessSlotsBlock("group-slotgames2");

function LimitString(str, strlength) { if (str.length > strlength) { str = str.substring(0, strlength) + ' <span style="color:#a50e1d;">&raquo;&raquo;</span>'; } return str; }

function ProcessSlotsBlock(slotsBlockID) {

    var title = "";
    var img = "";
    var rating = "";
    var description = "";
    var linkhref = "";
    var linktitle = "";
    var software = "";
    var releasedate = "";

    var mySlotsBlock = $("#" + slotsBlockID);
    var mySlotsBlockHTML = '<table width="100%" border="0"><tr><td valign="top">';
    var mySlotsBlockItems = $(mySlotsBlock).find("ul.slotsitems li");
    var totalItems = $(mySlotsBlockItems).length;
    var itemcount = 0;
    var IsInserted = false;

    $(mySlotsBlockItems).each(function () {

        itemcount++;

        img = $(this).attr("i");
        rating = $(this).attr("r");
        var l = $(this).find("a");
        var linktitle = $(l).html();
        linkhref = $(l).attr("href");
        description = $.trim($(this).text().replace(linktitle, ""));

        mySlotsBlockHTML += '<table width="100%" style="padding-right:10px;border-bottom:1px solid silver;margin-bottom:10px;" title="Click here for more details." onclick="n(\'' + linkhref + '\');" class="group-box slotitem">';
        mySlotsBlockHTML += '<tr>';
        mySlotsBlockHTML += '<td width="80" align="center" valign="middle" class="img"><img title="' + linktitle + '" align="absmiddle" src="' + img + '" /></td>';
        mySlotsBlockHTML += '<td valign="top">';
        mySlotsBlockHTML += '<img src="/images/rs' + rating + '.gif" height="15" title="Our Casino Slot Game Rating - ' + rating + '" align="absmiddle" class="sgf" />';
        mySlotsBlockHTML += '<strong><a href="' + linkhref + '">' + linktitle + '</a></strong><br />';
        mySlotsBlockHTML += '<div style="margin-top:10px;">';
        mySlotsBlockHTML += LimitString(description, 90);
        mySlotsBlockHTML += '<br /><br />';
        mySlotsBlockHTML += '<span style="font-size:11px;color:#770000;font-style:italic;">';
        mySlotsBlockHTML += 'By ' + $(this).attr("s") + '. ';
        mySlotsBlockHTML += '    ';
        mySlotsBlockHTML += 'Released: ' + $(this).attr("d");
        mySlotsBlockHTML += '    ';
        mySlotsBlockHTML += '</span>';
        mySlotsBlockHTML += '</div>';
        mySlotsBlockHTML += '</td>';
        mySlotsBlockHTML += '</tr>';
        mySlotsBlockHTML += '</table>';

        if (itemcount >= (totalItems / 2) && !IsInserted) { IsInserted = true; mySlotsBlockHTML += '<td valign="top">'; } else if ((itemcount == totalItems) && IsInserted) { mySlotsBlockHTML += "</td>"; }

    });

    mySlotsBlockHTML += "</td></tr></table>";

    $(mySlotsBlock).find("ul.slotsitems").after(mySlotsBlockHTML).remove();

}

function ProcessCasinoBlock(casinoblockID, badgeClassID) {

    var title = "";
    var img = "";
    var rating = "";
    var description = "";
    var linkhref = "";
    var linktitle = "";

    var myCasinoBlock = $("#" + casinoblockID);
    var myCasinoBlockHTML = '<table width="375" border="0" class="group-box" cellpadding="0" cellspacing="0">';
    var myCasinoBlockItems = $(myCasinoBlock).find("ul li");
    var totalItems = $(myCasinoBlockItems).length;
    var itemcount = 0;

    $(myCasinoBlockItems).each(function () {

        itemcount++;

        img = $(this).attr("i");
        rating = $(this).attr("r");
        var l = $(this).find("a");
        var linktitle = $(l).html();
        linkhref = $(l).attr("href");
        description = $.trim($(this).text().replace(linktitle, ""));

        myCasinoBlockHTML += '<tr><td>';
        myCasinoBlockHTML += '<table width="100%" class="groupboxitem" onclick="n(\'' + linkhref + '\');">';
        myCasinoBlockHTML += '<tr>';
        
        myCasinoBlockHTML += '<td class="groupboximage" rowspan="2" align="center" valign="middle">';
        myCasinoBlockHTML += '<div class="' + badgeClassID + '"><div><span>#' + itemcount + '</span></div></div>';
        myCasinoBlockHTML += '<div style="display:absolute;z-index:100;width:55px;">';
        if (img.indexOf(".jpg") > 0) {
            myCasinoBlockHTML += '<img class="fhth" border="0" src="' + img + '" title="' + linktitle + '" />';
        } else { myCasinoBlockHTML += '<div class="flimgbox" fl="' + img + '" style="width:55px;" id="flGroupBox' + itemcount + '"></div>'; }
        myCasinoBlockHTML += '</div>';
        myCasinoBlockHTML += '</td>';
        
        myCasinoBlockHTML += '<td class="groupboxtitle" valign="bottom" style="padding-bottom:5px;"><a href="' + linkhref + '">' + linktitle + '</a></td>';
        myCasinoBlockHTML += '<td align="right" class="group-rating">';
        myCasinoBlockHTML += '<img src="/images/rs' + rating + '.gif" height="15" alt="Our Casino Rating - ' + rating + '" align="absmiddle" />';
        myCasinoBlockHTML += '</td></tr>';
        myCasinoBlockHTML += '<tr>';
        myCasinoBlockHTML += '<td colspan="2" class="groupboxdesc" valign="top">' + LimitString(description, 90) + '</td>';
        myCasinoBlockHTML += '</tr>';
        myCasinoBlockHTML += '</table>';
        myCasinoBlockHTML += '</td></tr>';

    });

    myCasinoBlockHTML += '</table>';

    $(myCasinoBlock).find("ul").after(myCasinoBlockHTML).remove();

    $(".groupboxitem").hover(function () { $(this).addClass("over"); }, function () { $(this).removeClass("over"); });
}

function ActivateGroupFlashObjectsGroups() {
    $(".flimgbox").each(function () {
        try {
            var fo = new SWFObject($(this).attr("fl"), "movie_player", 45, 45, 7, "#FFFFFF");
            fo.addParam("wmode", "transparent");
            fo.write($(this).attr("id"));
            $(this).parent().html($("#" + $(this).attr("id")).html());
        } catch (e) { }
    });
}

$(document).ready(function () { ActivateGroupFlashObjects(); });
