var host = window.location.host
var baseURL = (host != 'localhost') ? 'http://scottpattinsonart.com' : 'http://localhost/scottpattinsonart/www'

jQuery(document).ready(function($) {
    adjustFooter()
    $(window).resize(function() {
        adjustFooter()
    })
    
    // Typography
    $('blockquote p').wrapAll('<div class="quote"></div>')
    
    $('.ceebox').ceebox()
    
    $('nav.main a.active').append('<span>*</span>')
    
    $('#thumbs .thumb').live('mouseover', function() {
        swapArtwork($(this))
    })
    
    $('.gallery #thumbs .thumb:first-child').trigger('mouseover')
    
    $('#artnav a').live('click', function() {
        //var index = $('#thumbs .thumb').index($('#thumb .selected'))
        //alert(index)
        if ($(this).attr('rel') == 'next') {
            
            $('#thumbs .selected').next('.thumb').trigger('mouseover')
        } else if ($(this).attr('rel') == 'prev') {
            $('#thumbs .selected').prev('.thumb').trigger('mouseover')
        }
    })
    
    $('a[rel=external]').attr('target', 'display')
});

adjustFooter = function() {
    $('#content').css('minHeight', $(document).height() - 150)
}

swapArtwork = function( thumb ) {
    if ( ! $(thumb).hasClass('selected')) {
        
        // fade out current art
        $('#artwork').fadeOut(500)
        
        $('#artwork').load(baseURL + '/bits/series/details/', { work_id: $(thumb).attr('rel') }, function(data) {
            $('#artwork').stop(true,true).delay(500).fadeIn(500)
        })
        /*
        var index = $('#thumbs .thumb').index($('#thumbs .selected'))
        var prevTitle = ''
        if (index == 0)
            prevTitle = $('#thumbs .thumb').last().find('a').attr('title')
        else
            prevTitle = $('#thumbs .selected').prev('.thumb').find('a').attr('title')

        prevLink = prevTitle.substring(prevTitle.indexOf('#') - 1, prevTitle.indexOf(':'))
        $('#artnav a[rel=prev]').attr('href', prevLink)
         
         if (index == $('#thumbs .thumb').length)   
            var nextTitle = $('#thumbs .thumb').first().find('a').attr('title')
        else
            var nextTitle = $('#thumbs .selected').next('.thumb').find('a').attr('title')
            
        nextLink = nextTitle.substring(nextTitle.indexOf('#') - 1, nextTitle.indexOf(':'))
        $('#artnav a[rel=prev]').attr('href', nextTitle)
        */
        $('#thumbs .thumb').removeClass('selected')
        $(thumb).addClass('selected')

    }
}

