/**
 * Benedict Morgan Photography
 * copyright 2010
 *
 */

//CONSTANTS & GLOBALS
var book_size = 0;
var current_image_num = 1;
var active_scroll     = '';
    


function outputBookInfo(position)
{
    $('p.image-info').html('Image ' + position + ' of ' + book_size);
}


function setBookSize()
{
    book_size = $('.active > .pics > img').size();
}


$(document).ready(function() {
    
       
    // Center content
    $('body').css({'display':'block'});
    $('#outer').css({'padding-left': (($(window).width() - 1050) / 2) + 'px'});

    // Book links
    $('#main-nav dt').click(function() {
        
        var book = $(this).attr('class');
        
        if ($('#right-column div.active').hasClass(book)) {
            return;
        }
        
        // add underline to selected book
        $('#main-nav dt').css({'text-decoration':'none'});
        $(this).css({'text-decoration':'underline'});
        
        
        //fade out contact form
        $('#contact-section dd').slideUp('fast');
        
        
        // scroll fade code
        $('#right-column div.active').fadeOut(400, function() {
        
            $(this).removeClass('active');
            
            // reset all to beginning
            var api = $('.scroll').scrollable({api:true});
            api.begin();
            
            $('#right-column div.'+book).fadeIn(400, function() {
                
                $(this).addClass('active');
                    
                $('.nav-arrows').removeClass('show-arrow');
                $('.nextPage-'+book+', .prevPage-'+book).addClass('show-arrow');
                
                setBookSize();
                outputBookInfo(1);
                active_scroll = book;
                
            });    
        });
    });
    
    
   // re-position content on window resize
    $(window).bind('resize', function() {      
        if ($.browser.mozilla) {
            $('#outer').animate({paddingLeft: (($(window).width() - 1050) / 2) + 'px'}, 200);    
        } else {
            $('#outer').css({'padding-left': (($(window).width() - 1050) / 2) + 'px'});  
        }
    });
    
    
    // show contact section
    $('#contact-section dt').click(function() {
        $('#contact-section dd').toggle('fast');
    });
    
    
    // Set the total image size for the first loaded book
    setBookSize();
    
    
    // outputs for active book; Image # of #
    outputBookInfo(1);
    
    
    // underline first book
    $('#main-nav dt:first-child').css({'text-decoration':'underline'});
    
    
    // add crosshair cursor for firefox
    if ($.browser.mozilla) {
        $('.pics > img').css({'cursor':'crosshair'});
    }
    
});