    /* Make sure that the global nav hooks into its appropriate location when the window is large enough.

    // Or make it stick to the bottom of the window.

    // Also, check window width and reduce colspan of proof grid if too narrow.*/

    var leftDistance;

    var innovSS = $('#innovation_slideshow');

    var slides = $('#slides');

    var slideFrame = $('#slide_frame');

    var lineDrawingOverlay = $('#line_drawing_overlay');

    var lineDrawing = $('#line_drawing, #line_drawing_overlay');

    var mediaOverlay = $('#media_overlay');

    var mediaContainer = $('#media_container');

    var globalNavBox = $('#global_nav_box');



    function sizeCheck () {

        var windowWidth = $(window).width();

        var viewableTop = $(window).scrollTop();

        var viewableBottom = $(window).height() + viewableTop;

        var gridLeftVal = $('#proof_grid').css('left');

        var leftValFloat = parseFloat(gridLeftVal);

        var proofGrid = $('#proof_grid');

        var gridContainer = $('#grid_container, #grid_overlay');

        var globalNav = $('#global_nav_box');

        var landingHalf = $('div.landing_half');

        var landingHalfWidth = (windowWidth/2)-101;

        var fourthCol = $('#fourth_column');



        /*makes sure that each landing half takes up half the screen width, except for the dividing line*/

        landingHalf.css({'width': landingHalfWidth});



        if (globalNav.css('position') !== 'absolute') {

            if(viewableBottom >= 803) {

                globalNav.css({

                    'position': 'relative',

                    'border': 'none',

                    'margin-bottom': '57px'

                });

            } else if (viewableBottom < 803) {

                if (navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod'){

                    globalNav.css({

                        'position': 'relative',

                        'border': 'none',

                        'margin-bottom': '57px'

                    });

                } else {

                    globalNav.css({

                        'position': 'fixed',

                        'margin-bottom': '0'/*,

                        'border-top':'1px solid #eee'*/

                    });

                }

            }

        }

        if (windowWidth < 1400) {

            $('h3', 'div#promo_1').css({'margin-left': '0'});

            $('h4', 'div#promo_1').css({'text-indent': '0'});

            $('html, body').css({'overflow-x': 'hidden'});

            leftDistance = (windowWidth - 960) / 2;

            fourthCol.hide('100');

            if (gridLeftVal === '-1050px' || gridLeftVal === '-1150px') {

                proofGrid.css({'left': '-900px', 'width': '960px'});

            } else if(leftValFloat > -800 ) {

                proofGrid.css({'left':leftDistance,'width':'960px'});

            }

            gridContainer.css({'width':'960px'});

            if (windowWidth < 800) {

                $('html, body').css({'overflow-x': 'visible'});

            }

        } else {

            $('h4', 'div#promo_1').css({'margin-left': '80px'});

            $('h3', 'div#promo_1').css({'text-indent': '80px'});

            $('html, body').css({'overflow-x': 'hidden'});

            leftDistance = (windowWidth - 1280) / 2;

            gridContainer.css({'width':'1280px'});

            fourthCol.show('100');

            if (gridLeftVal === '-800px' || gridLeftVal === '-900px') {

                proofGrid.css({'left': '-1150px', 'width': '1280px'});

            } else if(leftValFloat > -800) {

                proofGrid.css({'left':leftDistance,'width':'1280px'});

            }

            if (fourthCol.css('width') === '0px') {

                fourthCol.animate({width:'318px'});

            }

        }

        var mediaLeftDistance = (windowWidth - 940) / 2;

        $('#media_container').css({'left': mediaLeftDistance});

        $('#media_overlay').css({'height':$(document).height(),'width':windowWidth});

        if (slideFrame.css('display') === 'block') {

            innovSS.css({'width' : $(window).width()});

            slideFrame.css({'margin-left': (windowWidth - 1580)/2});

        }

    }

    $(window).scroll(sizeCheck)

             .resize(sizeCheck);



    function showProof(){

        var winWidth = $(window).width();

        var innovTab = $('#innovation_side_tab');

        var proofTab = $('#proof_side_tab');

        var proofGrid = $('#proof_grid');

        var splashText = $('.dichotomy_half_content, .dichotomy_half_content p');

        var fourthCol = $('#fourth_column');

        function proofActions(){

            if (splashText.css({'visibility':'visible'})) splashText.css({'visibility':'hidden'});

            if(innovTab.css('display') === 'none'){

                innovTab.fadeIn();

                /*lineDrawing.fadeIn();*/

            }



            if(proofTab.css('display') === 'block'){

                proofTab.fadeOut();

            }



            if (winWidth < 1400) {

                fourthCol.animate({'width':'0px'});

                leftDistance = (winWidth - 960) / 2;

            }else{

                fourthCol.animate({'width':'318px'});

                leftDistance = (winWidth - 1280) / 2;

            }



            proofGrid.animate({left:leftDistance});

            if (proofGrid.css('display') === 'none'){

                proofGrid.fadeIn();

            }

            innovSS.fadeOut();

            $('#grid_overlay').css({visibility:'hidden'});

            slides.css({'margin-left': '0'});

        }

        if(mediaOverlay.css('display') === 'block'){

            mediaOverlay.hide();

            mediaContainer.animate({top: '-640px'},function(){

                proofActions()

            });

        } else {

            proofActions();

        }

    }



    /* Calculating the distance the slider needs to move based upon which slide is clicked and how wide the window is. */

    var distanceToSlide = function(slideClicked){

        var numberIndex;

        var jQSlideClicked = $(slideClicked);

        var jQSlideClickedParent = $(slideClicked+':parent');

        var slideWidth = 1300;

        var screenWidth = $(window).width();

        var screenWidthOffset = (screenWidth - slideWidth) / 2;

        var slideNumber = function(slideClicked){

            if (typeof slideClicked === 'object'){

                if (jQSlideClicked.attr('id')){

                    numberIndex = jQSlideClicked.attr('id').length -= 1

                } else {

                    numberIndex = jQSlideClickedParent.attr('id').length -= 1;

                }

                var slideNumber = jQSlideClicked.attr('id').slice(numberIndex);

                var slideAsNumber =  parseInt(slideNumber);

                return parseInt(slideNumber) > 5 ? slideNumber = '1' : slideNumber;

            } else if (typeof slideClicked === 'number'){

                return slideClicked;

            }

        };

        $('.slide').removeClass('viewing').filter('#slide_'+slideNumber(slideClicked)).addClass('viewing');



        var returnValue = slideNumber(slideClicked) * slideWidth;

        returnValue += 1167 - (2*slideWidth);

        if (slideClicked == 1) {

            return 140;

        } else {

            return returnValue;

        }

    };

    var viewableTop = $(window).scrollTop();

    var viewableBottom = $(window).height() + viewableTop;

    var logoAnimate = viewableBottom < 803?$(window).height() - 140: 500;



    $(document).ready(function(){

        var logo = $('#logo');

        /*var logoAndLanding = $('#logo, #dichotomy_landing');*/

        var proofGrid = $('#proof_grid');

        var gridOverlay = $('#grid_overlay');

        var proofMover = $('#grid_overlay, #proof_side');

        var innovMover = $('#line_drawing_overlay, #innovation_side');

        var proofTab = $('#proof_side_tab');

        var proofLink = $('#proof_side .dichotomy_half_content a');

        var innovLink = $('#innovation_side .dichotomy_half_content a');

        var innovTab = $('#innovation_side_tab');

        var innovTabAndLink = $('#innovation_side .dichotomy_half_content a, #innovation_side_tab');

        var slideFrame = $('#slide_frame');

        var dichotomyHalves = $('.dichotomy_half_content');

        var innovationHalf = $('#innovation_side .dichotomy_half_content');

        var proofHalf = $('#proof_side .dichotomy_half_content');

        var dichotomy = $('div#dichotomy_landing');

        var allButLogo = $('#innovation_slideshow, #global_nav_box, #news_ticker, #footer, #proof_grid, #main');

        var splashHide = $('#innovation_slideshow, #proof_grid, #main, .dichotomy_half_content p');

        var globalNavBox = $('#global_nav_box');

        var splashText = $('.dichotomy_half_content, .dichotomy_half_content p');

        var galleryMore = $('.more_holder');

        var galleryHide = $('.more_holder, .gallery_grid.overlay');



        /*Galleries*/

        var htmlGallery = $('.call_to_action.gallery');

        var videoGallery = $('.call_to_action.video');

        var slideshowGallery = $('.call_to_action.slideshow');



        /* splash logo animation */

        if (window.location.hash === ''){

            dichotomyHalves.hide();

            proofGrid.css({'left':'-1350px'});

            innovSS.css({right: '-450px'});

            $(window).load(function() {

                $('#logo_chaser').delay(500).animate({'height': logoAnimate + 'px'}, 2000, 'swing', function() {

                    $('div#logo h2').fadeIn(500, function() {

                        $('#main').css({'visibility':'visible'});

                        $('div#logo h2').delay(1300).animate({'height': '0'});

                        $('#logo_chaser').delay(1000).animate({'height': '0'}, 2000, function() {

                            splashHide.css({'visibility':'visible'});

                            $(window).width() < 1400 ? proofGrid.animate({'left':'-900px'}) : proofGrid.animate({'left':'-1150px'});

                            innovSS.animate({right: '-220px'});

                            dichotomyHalves.fadeIn();

                        });

                    });

                });

            });

        } /*else if (window.location.hash.indexOf('slide') !== -1) {

            var slideIndex = window.location.hash.slice(window.location.hash.length -= 1);

            slideIndex = parseInt(slideIndex)+1;

            setTimeout(function(){$('#bubble_link_1').click();}, 300);

            innovSS.animate({'right':'0'});

            slides.animate({'margin-left': -(distanceToSlide(slideIndex))});

        }*/ else {

            splashHide.css({'visibility':'visible'});

        }

        sizeCheck();



        globalNavBox.find('a')

                    .live("click", function(event){

                        event.preventDefault();

                        var href = $(this).attr("href");

                        var animDuration = 1000;

                        var animDurationPlus = 1300;

                        var lessWindowHeight = $(window).height()-80;

                        $('#proof_grid').fadeTo(500,0);

                        $('#innovation_slideshow').fadeTo(500,0);

                        $('#footer,#footer_container,#footer_container>div,#news_ticker div,#news_ticker h3,#news_ticker span,#copy_terms').fadeTo(500,0);

                        $('#news_ticker').fadeTo(500,0,function(){

                            globalNavBox.css({'margin-top':'80px'});

                            if (globalNavBox.css('position') === 'fixed') {

                                globalNavBox.animate({'height':lessWindowHeight},1800, function() {

                                window.location = href;

                            });

                            } else {

                                $('#HPtopContent').hide('blind',{},1800, function() {

                                    if (globalNavBox.css('position') === 'fixed') {

                                        globalNavBox.animate({'height':lessWindowHeight},1800, function() {

                                            window.location = href;

                                        });

                                    } else {window.location = href; }

                                });

                            }

                        });

                        /*var scrollBottom = $(window).height();

                        globalNavBox.css({'position': 'absolute','top':scrollBottom*//*,'border-top':'1px solid #eee'*//*});

                        globalNavBox.find('div.container_12').animate({'margin-top': '80px'});

                        globalNavBox.animate({'top':'0','height':$('body').height()},animDuration);

                        $.scrollTo(0,{duration:300});

                        setTimeout(function () {

                            window.location = href;

                        }, animDurationPlus);*/

                        return false; // prevent user navigation away until animation's finished

                    });



        /* check to see if there is a named anchor in the url.  If there is, interpret it. */

        if(window.location.hash === '#innovation'){

            setTimeout(function(){$('#link_area_1').click();}, 300);

            innovSS.animate({'right':'0'});

        }



        if(window.location.hash === '#proof'){

            showProof();

        }



        /* jquery.tooltip startup code*/

        $('area').tooltip({

            track: true,

            delay: 0,

            showURL: false,

            showBody: " - ",

            positionLeft: true

        });



        $('.link_area').mouseover(function(){

            var numberIndex = $(this).attr('id').length -= 1;

            var elementIndex = $(this).attr('id').slice(numberIndex);

            var elementToChange = '#line_drawing_grid_link_'+elementIndex+ ' .slide_link';

            $(elementToChange).css({'background':'url("")'});

        });



        $('.link_area').mouseout(function(){

            var numberIndex = $(this).attr('id').length -= 1;

            var elementIndex = $(this).attr('id').slice(numberIndex);

            var elementToChange = '#line_drawing_grid_link_'+elementIndex+ ' .slide_link';

            $(elementToChange).css({'background':'url("/images/global/transparent_pngs/white_transparency_30.png")'});

        });



        /* News ticker startup code */

        $('#news_items').cycle({

            fx: 'fade',

            speed: '1000',

            pause: true

        });



        /* Slide the slider to the appropriate slide clicked */

        $('.link_area, .slide_content_counter a').click(function(){

            lineDrawing.hide();

            slideFrame.css({'margin-left': ($(window).width() - 1580)/2});

            innovSS.css({'width':$(window).width()});

            slideFrame.show();

            if(proofTab.css('display') === 'none'){

                proofTab.css({display:'block'});

            }

            slides.animate({'margin-left': -(distanceToSlide(this))});

            innovSS.animate({'right':'0'});

            proofGrid.hide();

            return false;

        });



        $('.slide_clickable_prev, .slide_clickable_next').click(function(){

            innovSS.animate({right: '0'});

            slides.animate({'margin-left': -(distanceToSlide(this))});

        });



        innovTabAndLink.click(function(){

            function bringInnov() {

                lineDrawing.css({'display':'block','visibility':'hidden'});

                innovTab.fadeOut();

                proofTab.fadeIn(200,function(){

                    innovSS.css({'right':'0'});

                    $('#link_area_1').click();

                    innovSS.fadeIn();

                });

            }

            if(mediaOverlay.css('display') === 'block'){

                mediaOverlay.hide();

                mediaContainer.animate({top: '-640px'},function(){

                    bringInnov();

                });

            } else {

                bringInnov();

            }

        });



        /* Clicking on the logo should reset everything to the splash display

        (after the logo has done its slide down and back up.) */



        logo.click(function(){

            if (lineDrawing.css({'display':'none'})) lineDrawing.show();

            if (lineDrawing.css({'visibility':'hidden'})) lineDrawing.css({'visibility':'visible'});

            if (splashText.css({'visibility':'hidden'})) splashText.css({'visibility':'visible'});

            slideFrame.hide();

            innovSS.css({'width':'366px'});

            if(mediaOverlay.css('display') === 'block'){

                mediaOverlay.hide();

                mediaContainer.animate({top: '-640px'});

            }

            slides.css({'margin-left': '0'});

            /*Hide the innovation or proof tab*/

            $('.side_tab').css({display:'none'});

            if (innovSS.css('right') != '-220px') {

                innovSS.animate({right: '-220px'});

            }

            if (proofGrid.css('left') != ('-1150px'||'-900px')) {

                if ($(window).width() < 1400){

                    proofGrid.animate({left: '-900px'});

                } else {

                    proofGrid.animate({left: '-1150px'});

                }

                if (gridOverlay.css('visibility') === 'hidden'){

                    gridOverlay.css({visibility:'visible'});

                    $('#main').animate({opacity: '1'});

                }

            }

            if (proofGrid.css('display') === 'none'){

                proofGrid.show();

            }

            if (innovSS.css('display') === 'none'){

                innovSS.show();

            }



            dichotomy.animate({'margin-left': '100px'});

        });



        /* Mousing over the logo should revert to the initial splash display,

        unless we are looking at a slide or the proof grid. */

        logo.mouseover(function(e){

            /* Animate the proof and innovation sections to realign to their original positions

                but only do this if they are peeked, not if they are in full view. */

            if (innovSS.css('right') === '-100px' && lineDrawing.css('display') !== 'none') {

                innovSS.animate({right: '-220px'});

            }

            if (proofGrid.css('left') === '-1050px') {

                proofGrid.animate({left: '-1150px'});

            } else if(proofGrid.css('left') === '-800px') {

                proofGrid.animate({left: '-900px'});

            }



            dichotomy.animate({'margin-left': '100px'},{queue:false});



        });



        /* Clicking on the grid overlay or the proof text should slide the grid front and center,

        hide the splash content (except the logo) and hide the overlay itself to reveal the content of the grid.

        Checks window width and reveals or hides the fourth column. */



        gridOverlay.click(showProof);

        proofTab.click(showProof);

        proofLink.click(showProof);



        /* Proof peek */

        proofMover.mouseover(function(){

            if (proofGrid.css('left') === '-1150px') {//the first two lines in this conditional are repeated because we need all animation to happen simultaneously.

                dichotomy.animate({'margin-left': '200px'},{queue:false});

                innovSS.animate({right:'-220px'},{queue:false});

                proofGrid.animate({left:'-1050px'},{queue:false});

            } else if (proofGrid.css('left') === '-900px') {

                dichotomy.animate({'margin-left': '200px'},{queue:false});

                innovSS.animate({right:'-220px'},{queue:false});

                proofGrid.animate({left:'-800px'},{queue:false});

            }

        });



        /* Innovation peek */

        innovMover.mouseover(function(){

            if(innovSS.css('right') === "-220px"){

                dichotomy.animate({'margin-left': '0px'},{queue:false});

                innovSS.animate({right:'-100px'},{queue:false});

            }

            if (proofGrid.css('left') === '-1050px') {

                dichotomy.animate({'margin-left': '0px'},{queue:false});

                proofGrid.animate({left: '-1150px'},{queue:false});

            } else if(proofGrid.css('left') === '-800px') {

                dichotomy.animate({'margin-left': '0px'},{queue:false});

                proofGrid.animate({left: '-900px'},{queue:false});

            }

        });



        /*Gallery scripts.  These populate the dropdown galleries when a user clicks on the CTA on proof or innovation.*/

        function galleryPopulate(galType, context, innovation){

            var innov;

            var indexSel;

            innovation? innov = '.slide': innov = '';

            $('.'+galType+'.gallery_box').empty()

                                         .append($('.gallery_contents', innov+context).html())

                                         .show();

            if (galType === 'slideshow') {

                $('.slideshow.gallery_box img').each(function(){$(this).removeAttr('title')});

            }

            if (galType === 'video') {

                $('.video.gallery_box iframe').removeAttr('id');

            }

        }



        videoGallery.click (function(){

            var index = videoGallery.index(this);

            var videoContainer = $('.media_button.video iframe');

            galleryHide.hide();

            videoContainer.attr('src', videoContainer.attr('id'));

            if ($('.more_link', this).attr('href') !== '') {

                galleryMore.removeAttr('href')

                           .attr('href', $('.more_link', this).attr('href'))

                           .css({'display':'block'});

            }

            $('.gallery_box, .image_gallery_elements').css({'display':'none'});

            if ($(this).hasClass('slide')){

                index === 0? index : index -= 1;

                galleryPopulate('video', '.call_to_action.video:eq('+index+')', true);

            } else {

                galleryPopulate('video', '.call_to_action.video:eq('+index+')');

            }

        });



        htmlGallery.click (function(){

            var index = htmlGallery.index(this);

            galleryHide.hide();

            $('.gallery_box, .image_gallery_elements').css({'display':'none'});

            if ($(this).hasClass('slide')){

                if (htmlGallery.filter('.slide').length < htmlGallery.length){

                    index === 0 ? index : index -= 1;

                }

                galleryPopulate('html', '.call_to_action.gallery:eq('+index+')', true);

            } else {

                galleryPopulate('html', '.call_to_action.gallery:eq('+index+')');

            }

        });



        slideshowGallery.click (function(){

            var index = slideshowGallery.index(this);

            var images = $('.call_to_action.slideshow:eq('+index+')').find('img');



            galleryHide.hide();

            images.each(function(index){

                var object = $(this);

                if ($(this).attr('src')===""){

                    $(this).attr('src',$(this).attr('title'));

                }

            });

            if ($('.more_link', this).attr('href') !== '') {

                galleryMore.removeAttr('href')

                           .attr('href', $('.more_link', this).attr('href'))

                           .css({'display':'block'});

            }

            $('.gallery_box, .html.gallery_box').css({'display':'none'});

            $('.image_gallery_elements').show();

            if ($(this).hasClass('slide')){

                index === 0 ? index : index -= 1;

                galleryPopulate('slideshow', '.call_to_action.slideshow:eq('+index+')', true);

            } else {

                galleryPopulate('slideshow', '.call_to_action.slideshow:eq('+index+')');

            }

            gallerySwap.initialGallery($('.slideshow.gallery_box'),true,'homepage_');



        });



        $('.call_to_action').bind('click', function(e){

            e.stopPropagation();

            mediaOverlay.show();

            mediaContainer.animate({top: '20px'});

        },false);



        $('#media_close').click(function(){

            mediaOverlay.hide();

            mediaContainer.animate({top: '-640px'});

        });

    });
