﻿$(document).ready(function () {
    $(".infobox").each(function (i, e) {
        var $e = $(e);
        var link = $e.find(".info a:visible")
        if (link.size() != 0) {
            var img = $e.find("img");
            if (img.size() != 0) {
                img.css({ cursor: "pointer" })
                img.click(function () {
                    location.href = link.attr("href");
                });
            }
        }
    });


    $("#BoxHolder .box").each(function (i, e) {
        var $box = $(this);
        var $boxes = $box.find(".boxHolder");
        if ($boxes.size() > 1) {
            setTimeout(function () { $.fn.ShowNextFrontpageBox($boxes, 0) }, $($boxes.get(0)).data("time") * 1000);
        }
    });
});

$.fn.ShowNextFrontpageBox = function(boxes, index) {
    var $box = $(boxes.get(index)).animate({ opacity: 0 }, 150, function () { $(this).hide(); });

   index = index + 1;
   if (index > boxes.size())
       index = 0;

   $box = $(boxes.get(index)).css({ opacity: 0 }).show().animate({ opacity: 1 }, 300);

   setTimeout(function () { $.fn.ShowNextFrontpageBox(boxes, index) }, $box.data("time") * 1000);
}
