$(document).ready(function(){
    old = $('#photo').width()
                  
    if ((old != 850) && (old != 565)) {
        if (old == 700) {
            $('#photo').width(850)
            $('#photo').height(565)
        } else {
            $('#photo').width(565)
            $('#photo').height(850)                  
        }
    }
                  
    $('#projects > ul > li').each(function(i) {
        $(this).click(change_project)
    })
    
    $('#projects > ul > li.current').animate({width: '260px'}, 500)
    
    function change_project() {
        cur = this
        $('#projects > ul > li').each(function(i) {
            $(this).animate({width: '250px'}, 500)        
            $(this).removeClass('current')
        })
        $(cur).addClass('current')
        $('#projects').animate( { 'background-position': '-400px' }, 'slow', function() {
            $(cur).animate({width: '260px'}, 500)
            if ($(cur).attr('link')) {
                $('#projects #link').attr('href', $(cur).attr('link'))
            } else {
                $('#projects #link').attr('href', $(cur).attr('name'))
            }
            $('#projects').removeClass($(this).attr('class'))                                        
            $('#projects').addClass($(cur).attr('name'))
            $(this).animate({'background-position': '250px' }, 'slow')
        });

    }
    
    $('.story > .body').width($('#photo').width()-20)
    $('.story > .body').css('margin-left', Math.round((850-$('#photo').width())/2) + 'px')
    
    $('.story > .image > div').each(function(i) {
        $(this).css('height', $('#photo').height()-100)
        $(this).css('width', $('#photo').width()/2)
        $(this).children('a').css('height', $('#photo').height()-100)
        
        if (!$(this).children('a').attr('href')) {
            $(this).hide();
        }
                                    
        $(this).hover(function() {
            $(this).children('a').animate({opacity: 0.3})
        }, function() {
            $(this).children('a').animate({opacity: 0})
        })                                    
    })

    $('.story > .image > .previous').css('margin-left', Math.round((850-$('#photo').width())/2))
    $('.story > .image > .next').css('margin-left', Math.round((850-$('#photo').width())/2)+Math.round($('#photo').width()/2))
    
    $('.story').hover(function() {
        $('.story > .body').slideDown()
    }, function() {
        $('.story > .body').slideUp()    
    })
        
                  
    $('.gallery a').each(function(i) {
        $(this).attr('rel', 'lightbox-gal')
    })
})

