﻿//uses jquery
var currGalleryImage;
var inAnimation = false;
function galleryInit(e, loc)
{

    currGalleryImage = e;
 
  $("#overlay").css("display", "block");

    $("#previewimageHolder>img").bind('load readystatechange', function (e) {
        if (this.complete || (this.readyState == 'complete' && e.type == 'readystatechange')) {
            if (inAnimation == false) {
                    $("#galleryDisplayHolder").css({ opacity: 0.5});
    
                    $("#galleryDisplayHolder").css("left", ( ($(currGalleryImage).offset().top + ($(currGalleryImage).height()/2)) - ($("#previewimageHolder").height() / 2) ));
                    $("#galleryDisplayHolder").css("top",  ( ($(currGalleryImage).offset().top + ($(currGalleryImage).height()/2)) - ($("#previewimageHolder").height() / 2) ));
                   // $("#galleryDisplayHolder").css("display", "" );
                    $("#previewimageHolder>img").unbind('load readystatechange');

            }
            
        }
    });
    $("#previewimageHolder>img").attr("src", "makeimage.aspx?size=600&url="+loc);
    $("#previewImageDescription").text($(currGalleryImage).attr("alt"));
}
function showImagePreview(e, loc)
{

    currGalleryImage = e;
    inAnimation = false;
    $("#galleryDisplayHolder").css("display", "");
    
   $("#overlay").css("display", "block");
    //$(e).addClass("selected");

    $("#previewimageHolder>img").bind('load readystatechange', function (e) {
        if (this.complete || (this.readyState == 'complete' && e.type ==
'readystatechange')) {
            if (inAnimation == false) {
                animateInPreview();
            }
            inAnimation = true;
        }
    });
    
    $("#previewimageHolder>img").attr("src", "makeimage.aspx?size=600&url="+loc);
    $("#previewImageDescription").text($(currGalleryImage).attr("alt"));
    
 

}
function animateInPreview(e) {
//    alert($("#previewimageHolder").outerWidth())
    $("#galleryDisplayHolder").animate({
        opacity: 1,
        top: ($(currGalleryImage).offset().top + ($(currGalleryImage).height()/2)) - ($("#previewimageHolder").height() / 2),
        left: $("#igallery").offset().left - ($("#previewimageHolder").width()+20)

    }, 800, jQuery.easing.easeOutBounce, function () {
        // Animation complete.
    });

}
function animateOutPreview(e) {
    $("#galleryDisplayHolder").animate({
        opacity: 0
    }, 400, jQuery.easing.easeOutQuad, function () {
        // Animation complete.
        $("#galleryDisplayHolder").css("display", "none");
    });

}
function hideImagePreview() {
    animateOutPreview();
  //  prevSel.className = "previewNormal";
 //   prevSel.style.backgroundColor = prevSel.oldBG;
}

 
