(function ($) {
    // VERTICALLY ALIGN FUNCTION
    $.fn.vAlign = function() {
            return this.each(function(i){
            var ah = $(this).height();
            var ph = $(this).parent().height();
            var mh = Math.ceil((ph-ah) / 2);
            $(this).css('padding-top', mh);
            });
    };
})(jQuery);

$(document).ready(function () {
    $('.mainPage .photo_item a').click(function () {
        var url = $(this).attr('href');
        var id = $(this).attr('id');
        $('.photo-plate a').hide();
        $('.photo-plate a#' + id).show();
        $('.navigation_photo-plate .prev').hide();
        $('.navigation_photo-plate .next').hide();
        if ($('.photo-plate a#' + id).prev().length != 0)
        {
            $('.navigation_photo-plate .prev').show();
            $('.navigation_photo-plate .prev').css('visibility', 'visible');
        }
        if ($('.photo-plate a#' + id).next().length != 0)
        {
            $('.navigation_photo-plate .next').show();
            $('.navigation_photo-plate .next').css('visibility', 'visible');
        }
        $('.mainPage .photo-plate a:visible').vAlign();
    });
    
});

$(window).load(function () {
    $('.mainPage .photo-plate a:visible').vAlign();
});
