﻿function loadimage(sender)
{
    var itemText = typeof(sender) == 'string' ? sender : $(this).text();
    var allItems = $("div.links > a");
    var item = jQuery.grep(allItems, function(n, i){return ($(n).text() == itemText);})[0];
    var index = jQuery.inArray(item, allItems);
    $("div.links > a:" + (index < 7 ? "lt(7)" : "gt(6)" )).removeClass('und');
    $(item).addClass('und');
    
    $('#waiter')
        .css({
            'display':'block',
            'top':$(document).scrollTop()+$(window).height()/2,
            'left': ($(document).width()-220)/2
            })

    
    var close = function() {$('#waiter').css({'display':'none'});}
    $('#img' + (index < 7 ? 1 : 2))
        .load(close)
        .error(close)
        .attr('src','/res/pic/'+(index + 1)+'.jpg')
}
function enlarge()
{
    var fadeOut = function(){
            $('#largeImage').remove();
            
            $('#overlayBackground').animate({opacity:0.0},500,
                function // callback
                (){  $('#overlayBackground').remove(); } );
            }
            
            
    var newImage = $("<img />")
        .attr('id', 'largeImage')
        .attr('src', $(this).attr('src').replace('min',''))
        .css({'position' : 'absolute','top':$(document).scrollTop(),
        'left':($(document).width()-1098)/2,'opacity' : '.0','filter':'alpha(opacity=0))'})
        .click(fadeOut);
     
    var background = $("<div />")
        .attr('id', 'overlayBackground')
        .css({'position' : 'absolute',
            'left':0,'top':0,'width':$(document).width(),'height':$(document).height(),
            'opacity' : '.0','filter':'alpha(opacity=0))',
            'background':'gray'})
        .click(fadeOut);

    $('body').append(background);
    
    $('#overlayBackground').animate({opacity:0.8}, 500, 
        function //animation complete
        (){
            $('body').append(newImage);
            $('#largeImage').animate({opacity:1.0}, 500);
        }
    );
}
$(document).ready(function()
{  
    $('#link' + cm).css('font-weight','bold')
});
