﻿var containerwidth;
var currentitem = 0;
function gotoround(rindex, animateTime) {
    if (!animateTime) animateTime = 1000;
    //if (currentitem >= $(".allmatches > .round").length - 1) return;
    var div1 = $(".allmatches > .round")[currentitem];
    var div2 = $(".allmatches > .round")[rindex];
    $(".allmatches").animate({ left: "-" + ((rindex) * 585) + "px", height: div2.offsetHeight + "px" }, animateTime);
    currentitem = rindex;
}
function next() {
    if (currentitem >= $(".allmatches > .round").length - 1) return;
    var div1 = $(".allmatches > .round")[currentitem];
    var div2 = $(".allmatches > .round")[currentitem + 1];
    $(".allmatches").animate({ left: "-" +((currentitem + 1) * 585) + "px", height: div2.offsetHeight + "px" }, 1000);
    currentitem++;
}

function prev() {
    if (currentitem <= 0) return;
    var div1 = $(".allmatches > .round")[currentitem];
    var div2 = $(".allmatches > .round")[currentitem - 1];
    $(".allmatches").animate({ left: "-" +((currentitem - 1) * 585) + "px", height: div2.offsetHeight + "px" }, 1000);
    currentitem--;

}

function newheiht(x) {
    $(".allmatches").animate({ height: x.toString() + "px" }, 1000) ;
}

function showpopbody() {
    $(".moreinfobody").slideDown("slow");
    $(".moreinfobodyC").css({'display': 'block' });
    $(".moreinfobody").css({'opacity':'0','display':'block','top':'50px'});
    $(".moreinfobody").animate({opacity:"1", marginTop:"100px"});
}

$(document).ready(function() {
    // activate buttons  //
    $(".matchesControls div a").addClass("btndim");
    $(".matchesControls div a:last").removeClass("btndim");
    $(".matchesControls div a").click(function() {
        $(this).parent().children("a").addClass("btndim");
        $(this).removeClass("btndim");
    });
    ///
    var winW = $("body").width();
    var winH = $("body").height();

    //$(".allmatches").css("height", +($(".round")[0].offsetHeight) + "px");
    containerwidth = $(".allmatches > .round").length;
    $(".allmatches").css("width", +(containerwidth * 585) + "px");
    $(".goright").click(function() {
        next(currentitem);
    });
    $(".goleft").click(function() {
        prev(currentitem);
    });
    $(document).bind('keydown', 'left', function() {
        prev(currentitem);
        $(".matchesControls div a").addClass("btndim");
        var yy = $(".matchesControls div a").size() - (currentitem + 1);
        $(".matchesControls div a:eq(" + yy + ")").removeClass("btndim");
    });
    $(document).bind('keydown', 'right', function() {
        next(currentitem);
        $(".matchesControls div a").addClass("btndim");
        var xx = $(".matchesControls div a").size() - (currentitem + 1);
        $(".matchesControls div a:eq(" + xx + ")").removeClass("btndim");
    });
    $(".moreinfopop").click(function() {
        $(this).fadeOut("slow");
        $(".moreinfobodyC").fadeOut("normal");
    });
    $(".moreinfo").click(function() {
        $(".moreinfopop").css({ 'height': winH + 'px', 'width': winW + 'px', 'top': '0px', 'position': 'fixed', 'opacity': '0', 'z-index': '100000', 'background-color': 'black', 'left': '0px' });
        $(".moreinfopop").animate({ width: winW + "px", height: winH + "px", opacity: "0.6", top: "0px", left: "0px" }, 1500);
        $(document).bind('keydown', 'esc', function() {
            $(".moreinfopop").fadeOut("slow");
            $(".moreinfobodyC").fadeOut("normal");
            setTimeout(function() { $(".moreinfobody").css({ 'position': 'relative', 'display': 'none', 'marginTop': '50px' }); }, 750);
        });
        setTimeout("showpopbody()", 750);
    });

    $(".matchroundh").click(function() {
        $(this).parent().children(".matchroundc:eq(0)").slideToggle("normal");
        setTimeout("gotoround(currentitem,500);", 500);
    });

    $(".matchgrouph").click(function() {
        $(this).parent().children(".matchgroupc").slideToggle("normal");
        setTimeout("gotoround(currentitem,500);", 500);
    });
    //// show it on the mat items /////
    $(".moreinfo > *").hide();
});