// @font-face causing buggy jog on hover with bold, so reserving for body text
Cufon.replace('#header', {hover: true, fontFamily: "DIN", fontWeight: 500});
    
$(function() {
    
// GA ------------------------------------------------------------------------
    // Correct a/c/ number? Access?
    if (location.hostname == 'www.muirvidler.com') $.geekGaTrackPage('UA-12337288-1');
    
    
    
    
// NAV -----------------------------------------------------------------------
    
    // any topnav with subnav, hide subnav and label topnav
    // (can't use next() since some have subnavs and some don't)
    $('#nav ul.subnav').hide();
    $('.current_page_parent').find('ul').show();
    
    // find if we're in the same section as topnav - if so, show subnav, highlight nav item
    var section_url = location.protocol+ '//' + location.hostname + '/'+$('body').attr('id');
    $('a[href='+section_url+']').css('color', '#000');
    $('a[href='+section_url+']').parent().next().show();
    
    // highlight subsections - uses url plugin
    var url_array = $.url.attr('path').split('/');
    url_array.shift();
    if (url_array.length == 2) { // ie in subsection
        var subsection_url = location.protocol+ '//' + location.hostname+$.url.attr('path');
        $('a[href='+subsection_url+']').css('color', '#000');
    }

    // correct gappy first projects subheader    
    if ($.url.segment[0] == 'folios' || $.url.segment[0] == 'projects' || $.url.segment[0] == 'tearsheets') $('#preloader').show();
    $('.galleryview, #thumbs_gallery, #controls').show(); /*prevent caption flash before load */
    
    $('#aa').click(function(){
       alert($('.current img').width()); 
    });
    
    
    
    // ACCORDION
    var top_link = $('#nav > ul > li:has(ul) > a, #nav > ul > li:has(ul) > h2 > a');
    top_link.attr('href', ''); // knock out link for accordion sections

    top_link.click(function() {
        // ie whether a is wrapped in h2, current section user's in, diff DOM structure
        if ($(this).parent().is('h2')) this_subnav = $(this).parent().parent().find('ul');
        else this_subnav = $(this).parent().find('ul');
        
        this_subnav.slideToggle(500); // since open/close already taken care of
        this_subnav.addClass('this_subnav');
        $('.subnav').not('.this_subnav').slideUp();
        $('.this_subnav').removeClass('this_subnav');
        return false; // prevent blank link linking to top of page 
    });
    
    
    
    
// PRELOADER -----------------------------------------------------------------
    var subsection_name = '';
    if (url_array.length == 2) {
        var subsection_name = $('.current_page_item').text();
        var section_name = $('body').attr('id');
        preloader = '<div id="preloader"><img src="/media/images/preloader.gif">';
        if (subsection_name && !$('body.404').length) preloader += '<span id="preloader_text">loading '+ subsection_name +'</span></div>';
        $('#main').prepend(preloader);
    }
    
    
    
    
// MISC ----------------------------------------------------------------------
    if ($.browser.webkit) {
        $('#root').css('margin-top', '47px');
        $('#main').css('margin-top', '54px');
        $('#nav').css('margin-top', '4px');
        $('#nav > ul > li').css('margin', '0');
        $('body#about #root #main').css('margin-top', '0');
    }
});

