﻿/// <reference path="../../Scripts/jquery-1.3.2-vsdoc.js" />

$(function() {
    BindGalleryList();
    BindGalleryListClick();


    function BindGalleryListClick() {
        $(".GalleryViewItem").click(function(sender) {
            var src = $(sender).children("img").prevObject[0].target.src;
            var imgsrc = src.substring(0, src.indexOf("PictureGallery/") + 15) + "Img/";
            var Filename = src.substring(src.indexOf("PictureGallery/Thumb/") + 21);

            $(".GalleryViewItem").removeClass("GalleryViewItemSelected");
            $(this).addClass("GalleryViewItemSelected");
            $(".PictureSelected").val(Filename);

            var img = new Image();
            img.id = "GalleryViewImage";
            $("#GalleryViewImage").remove();
            $('.GalleryViewImage').addClass("LoadingImage");

            $(img).load(function() {    // when image has loaded...
                $(this).css('display', 'none'); // hide image by default
                $('.GalleryViewImage').removeClass('LoadingImage').append(this);   // remove 'div#loader.loading' class (loading anim gif), then insert our image in 'loader' div
                $(this).fadeIn('slow'); // fade image in

            }).attr('src', imgsrc + Filename);

        })
    }

    function BindGalleryList() {
        $(".PagingLink").click(function() {
            var value = $(this).attr("class");
            value = value.replace('PagingLink paging_', '');
            $(".PageNr").val(value);

            $.post("/Aktiviteter/Bildarkiv/List/" + value, { Id: $(".GalleryId").val(), PictureSelected: $(".PictureSelected").val() }, function(data) {
                $("#GalleryListHtml").html(data);
                BindGalleryList();
                BindGalleryListClick();
            });

        });
    }



});


