$(function() {
    $('#gototop,#gototop a').click(function() {
        window.scrollTo(0,0);
    });
    
    $('#gototop').hover(function() { $(this).css({background: '#F9FCFD',cursor: 'pointer'}); },
    function() { $(this).css({background: 'transparent',cursor: 'default'}); });
    
    $.getScript('/js/jquery.lightbox-0.5.pack.js',function() {
        $('.photos li a').lightBox({
            imageLoading : '/images/lightbox-ico-loading.gif',
            imageBtnClose : '/images/lightbox-btn-close.gif',
            imageBtnPrev : '/images/lightbox-btn-prev.gif',
            imageBtnNext  : '/images/lightbox-btn-next.gif',
            imageBlank : '/images/lightbox-blank.gif'
        });
        
        $('.photos .enlarge a').lightBox({
            imageLoading : '/images/lightbox-ico-loading.gif',
            imageBtnClose : '/images/lightbox-btn-close.gif',
            imageBtnPrev : '/images/lightbox-btn-prev.gif',
            imageBtnNext  : '/images/lightbox-btn-next.gif',
            imageBlank : '/images/lightbox-blank.gif'
        });
    });
    
    var imgs = [];
    $('.photos img').each(function(i) {
        imgs[i] = parseInt($(this).css('width').replace(/px/,''));
    });
    
    for (var i = 0; i < imgs.length; ++i) {
        $('<div class="enlarge"><a href="'+$('#photos img:eq('+i+')').parent().attr('href')+'"><span>Click To Enlarge</span> <img src="/images/icon_magnify.gif" alt="Click To Enlarge" /></a></div>')
        .css({width: '125px',display: 'inline',marginLeft: (imgs[i]-100)+'px'}).appendTo('#photos .box');
        $('.enlarge img').css('opacity',0.5);
        $('.enlarge span').css('opacity',0);
    }
    
    $('.photos img').hover(function() {
        $('.photos div.enlarge:eq('+$('#photos img').index(this)+') img').css('opacity',1.0);
        $('.photos div.enlarge:eq('+$('#photos img').index(this)+') span').css('opacity',1.0);
    },function() {
        $('.photos div.enlarge:eq('+$('#photos img').index(this)+') img').css('opacity',0.5);
        $('.photos div.enlarge:eq('+$('#photos img').index(this)+') span').css('opacity',0);
    });
    
    $('.photos div.enlarge').hover(function() {
        $(this).children('img,span').css('opacity',1.0);
    },function() {
        $(this).children('img').css('opacity',0.5);
        $(this).children('span').css('opacity',0);
    });
});