﻿
var imageFile = "";

$(document).ready(function () {
    $("#main").find("img").css("cursor", "pointer");
    $("#main").find("img").mousedown(function () {
        if (imageFile.length > 0 && imageFile == $(this).attr("src")) {
            $("#dynPic").hide("fast");
            $("#bigPic").remove();
            imageFile = "";
        }
        else {
            if (imageFile.length > 0) {
                $("#dynPic").hide("fast");
                $("#bigPic").remove();
                imageFile = "";
            }
            $("<img/>", { id: "bigPic", "src": $(this).attr("src").replace("_small", "_big"), alt: "" }).appendTo("#dynPic");
            imageFile = $(this).attr("src");
            $("#dynPic").css("cursor", "pointer").css("top", event.clientY - 200).css("left", event.clientX - 200).fadeIn(500);
            $("#dynPic").click(function () {
                $("#dynPic").hide("fast");
                $("#bigPic").remove();
                imageFile = "";
            });
            isOpen = true;
        }
    });
});

function explode(photo) {
    if (isOpen) {
        $("#dynPic").fadeOut(300);
        $("#bigPic").remove();
        isOpen = false; 
    }
    else{
        $("<img/>", { id: "bigPic", "src": photo.src.replace("_small", "_big"), alt: "" }).appendTo("#dynPic");
        $("#dynPic").css("cursor", "pointer").css("top", event.clientY).css("left", event.clientX).fadeIn(500);
        $("#dynPic").click(function () {
            $("#dynPic").hide(400);
            $("#bigPic").remove();
        });
        isOpen = true;
    }
}
