﻿/// <reference path="js/jquery-1.4.2.js" />
/// <reference path="js/galleria.js" />

$(document).ready(function() {

    $("li").mouseenter(MouseEnter);
    $("li").click(Click);

    $(".Group li:eq(0)").mouseenter();
});

function Click()
{
    var link = $(this).find("input").val();
    if (link != null) {
        window.open(link);
    }
}

function MouseEnter() {
    if ($("li.selected").size() > 0) {
        $("li.selected").removeClass("selected");
        $("li").css("top", "0");
    }

    var heightNormal = $(this).height();
    $(this).addClass("selected");
    var height = $(this).height();

    // The changed height of a selected Listitem changes the relative Top value of the 
    // following listitems
    height = height - heightNormal + GetBrowsercorrection();
    
    var index = $("#list li").index($("#list li.selected")) + 1;
    for (var i = index; i < $("#list li").size(); i++)
    {
        $("#list li:eq(" + i + ")").css("top", height * -1);
    }

    var html = $(this).find(".content").html()
    $("#preview").html(html);
    $("#preview .description").css("display", "none");

    Galleria.loadTheme("js/galleria/themes/classic/galleria.classic.js");
    $("#preview .gallery").galleria({
        extend: ShowImageDescription
    });
}

function ShowImageDescription() {
    this.bind(Galleria.IMAGE, function (e) {
        var imagePath = $(e.imageTarget).attr("src");
        var imagePathArray = imagePath.split("/");
        var file = imagePathArray[imagePathArray.length - 1];
        var descriptionName = file.split(".")[0];

        var description = $("#preview .description #" + descriptionName);
        $("#preview .description").children().css("display", "none");

        if (description.size() < 1) {
            $("#preview .description").css("display", "none");
        }
        else {
            $("#preview .description").show();
            description.show();
        }

    });
}

function GetBrowsercorrection() {
    if (navigator.appName == "Microsoft Internet Explorer") {
        return 0;
    } 
    if (navigator.appName == "Opera") {
        return 1;
    }
    return 0;
}
