﻿$(document).ready(function () {

    //select all the a tag with name equal to modal
    $('#left_boxes img').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        var imgID = $(this).attr('id');
        //Get the A tag
        var id = $(this).attr('src');

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set heigth and width to mask to fill up the whole screen
        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        //transition effect		
        $('#mask').fadeIn(200);
        $('#mask').fadeTo("slow", 0.8);

        //Get the window height and width

        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $("#dialog2").css('top', winH / 5 - $("#dialog2").height() / 5);
        $("#dialog2").css('left', winW / 2 - $("#dialog2").width() / 2);

        //transition effect
        $("#dialog2").fadeIn(500);
        $("#showImage").html('<img src="' + id + '" id="' + imgID + '" width="500" height="340" />');

    });

    // next
    $('#next').click(function (e) {

        var id = $('#showImage img').attr('id');

        if ($("#left_boxes").find('img').length == id)
            id = 1;
        else
            id = parseInt(id) + parseInt(1);

        $("#showImage").html('');
        $("#showImage").html('<img src="' + id + '.jpg" id="' + id + '" width="500" height="340" />').fadeIn(700);

    });

    // prev
    $('#prev').click(function (e) {

        var id = $('#showImage img').attr('id');

        if (id == 1)
            id = 12;
        else
            id = parseInt(id) - parseInt(1);

        $("#showImage").html('');
        $("#showImage").html('<img src="' + id + '.jpg" id="' + id + '" width="500" height="340" />').fadeIn(700);

    });

    //if close button is clicked
    $('.window #hide').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        $('#mask').hide();
        //$('#mask').hide();
        $('.window').hide();
    });

    //if mask is clicked
    $('#mask').click(function () {
        $(this).hide();
        $('.window').hide();
    });

});
