$(document).ready(function(){
    
    nav_access();
    external_links();
    typekit();
    map_tooltips();
    google_map();
    highlight_division();
    thirds_heights();
    colorbox();
    
});
// end document.ready


/* Colorbox listeners
--------------------------------------------------------------------------------- */
function colorbox() {
    $('body#what_we_do div#videos ul li a').colorbox({
        iframe: true,
        width: 743,
        height: 444,
        href: function() { 
            var url = '/components/video/';
            url += $(this).attr('rel');
            return url;
        }
    });
}


/* Highlight a division base on a hash tag
--------------------------------------------------------------------------------- */
function highlight_division(){
    var $body = $('body#what_we_do'),
        division = window.location.hash;
        
    if ( $body.length == 0 || '' == division) return;
        
    $('div'+division, $body).addClass('cur');
    
    
}

/* Make the thirds elements all equal height
--------------------------------------------------------------------------------- */
function thirds_heights(){
    
    var $body = $('body#where_we_do_it');
        
    if ( $body.length == 0) return;
    
    var max_height = 0,
        $thirds = $('#content_pri ul li', $body);
        
    $thirds.each(function(){
        if ( $(this).height() > max_height ) max_height = $(this).height();
    });
    $thirds.height(max_height);
    
}

/* Google map
--------------------------------------------------------------------------------- */
function google_map(){
    
    $body = $('body#contact.landing');
    if ( $body.length == 0 ) return;

    $('#google_map', $body).height($('div.spotlight', $body).outerHeight() - 2);
    
    var map = new GMap2(document.getElementById("google_map"));

    // Set the center point and marker  
    var markers = new Array(
        new GLatLng(52.877244, -1.096817),
        new GLatLng(52.944563, -1.196419)
    );

    map.setCenter(markers[0], 8);

    for ( i=0; i<markers.length; i++ ) {
        marker = new GMarker(markers[i]);
        map.addOverlay(marker);
    }
    

    // Add the map controls
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
}

/* Map tooltips
--------------------------------------------------------------------------------- */
function map_tooltips(){
    var $body = $('body#where_we_do_it.landing');
    if ( $body.length == 0 ) return;
    
    var $points = $('div#map ul li', $body);
        
    $points
        .mouseenter(function(){
            $(this)
                .css('zIndex',99)
                .children('p')
                    .css('opacity', 0.0)
                    .css('top','0')
                    .css('display', 'block')
                    .animate({
                        top: '10px',
                        opacity: 1.0
                    },350);
        })
        .mouseleave(function(){
            $(this).children('p')
                .fadeOut(350)
                .parent('li').css('zIndex',20);
                
        });
}


/* Accessibility navigation enhancements
--------------------------------------------------------------------------------- */
function nav_access(){
    $('ul#nav_access li a')
        .focus(function(){ $(this).addClass('focus'); })
        .blur(function(){ $(this).removeClass('focus'); });
}


/* Open links in an new window and add a class
--------------------------------------------------------------------------------- */
function external_links(){
    $('a[rel="external"]')
      .attr("target", "_blank")
      .addClass('external');
}


/* Typekit!
--------------------------------------------------------------------------------- */
function typekit(){
    try{Typekit.load();}catch(e){}
}

