
/**
 * Grid and Baseline grid overlay.
 */
;(function($) { 
    $.fn.gridOverlay = function(options) {
        options = $.extend({
            'gridElement': $('<div />', { 'id':'grid' }),
            'baselineElement': $('<div />', { 'id':'baseline' }),
            'compElement': $('<div />', { 'id':'comp' }),
            'gridKeyCode': 71, // shift+g
            'baselineKeyCode': 66, // shift+b
            'compKeyCode': 67, // shift+c
            'gridImage': '/static/img/grid.png',
            'baselineImage': '/static/img/baseline.png',
            'compImage': '/static/img/comp-home.png',
            'width': this.width(),
            'top': 0,
            'left': 0,
            'zIndex': 100
        }, options);
        
        var grid = $(options.gridElement),
            baseline = $(options.baselineElement),
            comp = $(options.compElement);
            
        $([grid[0], baseline[0], comp[0]]).css({
                'display': 'none',
                'position': 'absolute',
                'width': options.width,
                'height': $(document).height(),
                'top': options.top,
                'left': options.left,
                'z-index': options.zIndex,
                'opacity': .8
            }).appendTo(this);
        grid.css('background', 'transparent url(' + options.gridImage + ') repeat top left');
        baseline.css('background', 'transparent url(' + options.baselineImage + ') repeat top left'); 
        comp.css('background', 'transparent url(' + options.compImage + ') no-repeat top left');
        
        $('body').keyup(function(ev) {
            if (ev.shiftKey) {
                if (ev.keyCode == options.gridKeyCode) {
                    grid.css('height', $(document).height()).toggle();
                } else if (ev.keyCode == options.baselineKeyCode) {
                    baseline.css('height', $(document).height()).toggle();
                } else if (ev.keyCode == options.compKeyCode) {
                    comp.css('height', $(document).height()).toggle();
                }
            }
        });
        
        return this;
    }
})(jQuery);


$(function() {
    
    // Grid overlays
    //$('.page').first().gridOverlay({'width': 960, 'left': 0});
   
  
    
    // Navigation
    $('.nav-t1-item').hoverIntent({
        over: function(ev) {
            $(this).addClass('active');
        },
        out: function(ev) {
            $(this).removeClass('active');
        },
        timeout: 500
    });
    $('.nav-t2-item').hoverIntent({
        over: function(ev) {
            $(this).addClass('active');
        },
        out: function(ev) {
            var el = $(this);
            if (!el.hasClass('selected')) {
                $(this).removeClass('active');
            }
        },
        timeout: 200
    });
    
    
    // Home page feature module
    var captions = {
        'Credentialing Leadership': 'PES draws on exceptional knowledge and expertise to guide clients in the development and maintenance of world-class credentialing programs',
        'Personalized Service': 'PES offers personalized service based on a deep understanding of our clients&rsquo; needs and a rich dialogue around the issues and trends affecting them',
        'Expertise &amp; Experience': 'PES&rsquo;s unmatched expertise and experience comes from decades of service to credentialing organizations across a wide range of professions and industry sectors',
        'Commitment to Integrity': 'PES&rsquo;s approach to credentialing is shaped by a deeply held organizational commitment to the integrity of our clients&rsquo; credentialing programs and assessments',
        'Technological Innovation': 'PES delivers added value and cost savings to clients through the deployment of industry-leading technology solutions',
        'Tailored Solutions': 'PES designs and delivers tailored products and services in support of each client&rsquo;s unique needs, priorities, and mission'
    }
    
    var nav = $('#feature .nav').first();
    var nav_items = nav.find('li');
    var caption = $('#feature figcaption').first();
    
    nav.delegate('li', 'mouseover', function(ev) {
        nav_items.each(function(i, item) {
            $(item).removeClass('active');
        });
        caption.html(captions[$(this).addClass('active').find('a').first().html()]);
    });
    
    if (document.getElementById("location-map")) {
        var latlng = new google.maps.LatLng(30, 0);
        var map = new google.maps.Map(document.getElementById("location-map"), {
            zoom: 1,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        });
        
        jQuery.getJSON('/testing-locations', function(data, textStatus) {
            markers = [];
            for (i=0; i<data.length; i++) {
                var pos = new google.maps.LatLng(data[i][1],data[i][2]);
                var marker = new google.maps.Marker({
                    position: pos,
                    title: data[i][0]
                });
                markers.push(marker);
            }
            var markerCluster = new MarkerClusterer(map, markers);
        });
    }
    
});

