﻿


$(document).ready(function () {


    $(".ssbox a").addClass("thumbnail");
    $('<div class="preview"><a><img class="preview"/><img src="//www.dynatrace.com/images/plusicon.png" class="plusicon"/></a></div><p class="title"></p>').insertBefore(".ssbox .thumbs");
    var count = 0;
    $(".ssbox").each(function () {
        count++;
        // create and set an unique id for this screenshot box
        var id = "ssbox" + count;
        $(this).attr("id", id);
        var preview = $(this).find(".preview");
        var title = $(this).find(".title");


        var allImages = new Array();
        var thumbCount = 0;
        $(this).find(".thumbs a").each(function () {
            thumbCount++;
            var link = $(this);
            var imgSrc = $(this).attr("href");
            var imgSrcMedium = imgSrc.replace(".png", "_medium.png");
            var imgSrcSmall = imgSrc.replace(".png", "_small.png");
            var imgTitle = $(this).attr("title");
            // add to preloader
            allImages.push(imgSrcMedium);
            // add image
            $(this).html("<div class='thumb'><div class='counter'>" + thumbCount + "</div><img src='" + imgSrcSmall + "' alt='' /></div>");

            $(this).hover(function () {
                var targetImage = $(this).attr("href");

                $(this).parent().find(".current").removeClass("current");
                $(this).addClass("current");

                var previewImg = $(preview).find("img.preview");
                previewImg.hide().attr("src", imgSrcMedium).show();

                $(preview).find("a")
                        .attr("href", targetImage)
                        .unbind()
                        .click(function () {
                            link.trigger("click");
                            return false;
                        });
                $(title).html(imgTitle);
            });

            // Videos
            var rel = (link.attr("rel"));
            if (rel != null && rel != "") {
                link.attr("href", rel);
            }
        })


        // Set the shadowbox rel
        $(this).find("div.thumbs a").each(function () {
            var w = "";
            if ($(this).attr("href").indexOf(".flv") > 0) {
                w = "width=700;height=525";
            }
            $(this).attr("rel", "shadowbox[" + id + "]" + w);
        });


        if (thumbCount == 1) {
            $(this).addClass("singleImgGal");
            $(this).parent().addClass("singleImgGal");   
        }
        // Preload all _medium images
        for (var i = 0; i < allImages.length; ++i) {
            $.preLoadImages(allImages[i]);
        }
        $(this).css("visibility", "visible");

        var x = $(this).find("div.thumbs a:first");
        x.hover();

        if (thumbCount == 1)  $(this).find(".thumbs").hide();
    });
});



