$(function(){
    
    // Blend
    if(jQuery.browser.msie && (document.documentMode < 7)) {} else{
        $("a.socialIcon, a.playgame").blend({ speed: jsBlendSpeed });
    }

    $("div.newsAccordianWrap, div.newsAccordian").css({ "overflow": "hidden" }).children().children("h3:first").css("border-top", "solid 0px #fff");
    $(".gameTabContent").css("margin-bottom", 0);
    $(".newsAccordian").accordion({ fillSpace: true });
    
    // Setup Tabs
    
    var initialRoundabout = 0;
    
    $("#games").addClass("ui-tabs ui-widget ui-widget-content");
    
    var hash = window.location.hash;
    
    if(hash != "" && $(hash) != null)
    {
        initialRoundabout = $('#games a[href$="' +hash+ '"]').parent('li').index();
        if(initialRoundabout < 0)
        {
            initialRoundabout = 0;
            $("#games>table>tbody>tr>td>#game-fader").children(".gameTabContent").addClass("ui-tabs-panel ui-widget-content ui-tabs-hide").filter(":first").removeClass("ui-tabs-hide");
        }
        else
        {
            $("#games>table>tbody>tr>td>#game-fader").children(".gameTabContent").addClass("ui-tabs-panel ui-widget-content ui-tabs-hide").filter(hash).removeClass("ui-tabs-hide");
            $('html,body').scrollTop(0);
        }
    }
    else
    {
        $("#games>table>tbody>tr>td>#game-fader").children(".gameTabContent").addClass("ui-tabs-panel ui-widget-content ui-tabs-hide").filter(":first").removeClass("ui-tabs-hide");
    }
    
    // Roundabout
    var $roundabout = $("#gameRoundabout");

    $roundabout.append($roundabout.html())
    .roundabout({ tilt: -4, maxScale: 1, minScale: 0.4, minOpacity: 0.1, startingChild: initialRoundabout})
    .children().children("a").click(function (e) 
        {
            var hash = $(this).attr("hash");

        // Fade out div, switcheroo the tabs, fade back in
        $("#game-fader").fadeOut("500", function () {
        $("#game-fader>" + hash).removeClass("ui-tabs-hide").siblings().addClass("ui-tabs-hide");
        }).fadeIn("500");
        $('.contextBox').css("display", "block");
        // Prevent Default
        e.preventDefault();
        }
    );
});
