﻿$(window).load(function() {

    $('#image-container').mousemove(function(e) {
        var relativeX = e.clientX - $('#image-container').offset().left;
        if (relativeX < 200) {
            $('#image-container #previous-image').addClass('hover');
            $('#image-container #next-image').removeClass('hover');
        }
        else if (relativeX > $('#image-container').width() - 200) {
            $('#image-container #next-image').addClass('hover');
            $('#image-container #previous-image').removeClass('hover');
        }
        else {
            $('#image-container #next-image').removeClass('hover');
            $('#image-container #previous-image').removeClass('hover');
        }

        e.stopPropagation();
    });

    $(document.body).mousemove(function(e) {
        $('#image-container #next-image').removeClass('hover');
        $('#image-container #previous-image').removeClass('hover');
    });


    $('#sidebar-b img.gallery-thumbnail').click(function(o) {
        $('#image-container').addClass('loading');
        $('#full-image').attr('src', this.src.replace('/thumbnails/', '/images/'));
        $('#full-image').get(0).imageNode = this;
    });
    $('#image-container #previous-image').click(function(o) {
        var current = $('#full-image').get(0).imageNode;
        if (current && $(current).prev('img.gallery-thumbnail').length > 0) {
            $('#image-container').addClass('loading');
            $('#full-image').attr('src', $(current).prev('img.gallery-thumbnail').attr('src').replace('/thumbnails/', '/images/'));
            $('#full-image').get(0).imageNode = $(current).prev('img.gallery-thumbnail').get(0);
        }
    });
    $('#image-container #next-image').click(function(o) {
        var current = $('#full-image').get(0).imageNode;
        if (current && $(current).next('img.gallery-thumbnail').length > 0) {
            $('#image-container').addClass('loading');
            $('#full-image').attr('src', $(current).next('img.gallery-thumbnail').attr('src').replace('/thumbnails/', '/images/'));
            $('#full-image').get(0).imageNode = $(current).next('img.gallery-thumbnail').get(0);
        }
    });

    $('#sidebar-b img.gallery-thumbnail:first').click();

});
