(function(){

    //Create Namespace
    if (!window.UPS) {
        window['UPS'] = {}
    }
    
    //Helper function to check if an element (i.e. div) exists. Argument is element id
    var exists = function(element){
        if (!document.getElementById(element)) {
            return false;
        }
        else {
            return true;
        }
    }
    window['UPS']['exists'] = exists;
    
    
    //Shows or hides div when element is clicked, depending on action parameter (can be show or hide)
    var divDisplay = function(toggleElement, divToDisplay, action){
    
        if (!action) {
            action == "show";
        }
        
        $(toggleElement).click(function(){
        
            if (action == "show") {
            
                $(divToDisplay).show();
            }
            
            else 
                if (action == "hide") {
                
                    $(divToDisplay).hide();
                }
            
            return false;
            
        }); //end click
    }
    window['UPS']['divDisplay'] = divDisplay;
    
    
    //Displays div when element is clicked with slide down or up animation depending on action (can be up or down)
    var divSlide = function(toggleElement, divToDisplay, speed, action){
    
        if (!speed) {
            speed = 'slow';
        }
        
        if (!action) {
            action == "down";
        }
        
        $(toggleElement).click(function(){
        
            if (action == "down") {
            
                $(divToDisplay).slideDown(speed);
            }
            else 
                if (action = "up") {
                
                    $(divToDisplay).slideUp(speed);
                }
            
            return false;
            
        });
    }
    window['UPS']['divSlide'] = divSlide;
    
    
    //Opens all hrefs with rel="external" attribute in separate window - target=_blank doesn't validate
    var externalLinks = function(){
    
        if (!document.getElementsByTagName) {
            return;
        }
        
        var anchors = document.getElementsByTagName("a");
        var internalDomain = "";
        var internalIp = "209.62.145.148";
        
        for (var i = 0; i < anchors.length; i++) {
            var anchor = anchors[i];
            
            var href = anchor.getAttribute("href");
            
            //Ensure we're only testing external links that start with http or https
            if (href && href.match(/^https?:\/\/.*/)) {
                if ((!href.match(/pressroom\.ups\.com/) && !href.match(/209\.62\.145\.148/)) || anchor.getAttribute("rel") == "external") {
				
					anchor.target = "_blank";
					$(anchor).click(function(){
						if (typeof(dcsMultiTrack) == "function") {
							return dcsMultiTrack("DCS.dcsuri", $(this).attr("href"), "WT.ti", $(this).attr("href"));
						}
						else {
							return true;
						}
					});
				}
            }
            if (anchor.getAttribute("href") && (anchor.getAttribute("href").indexOf(".pdf") > 0)) {
                $(anchor).click(function(){
                    if (typeof(dcsMultiTrack) == "function") {
                        return dcsMultiTrack("DCS.dcsuri", $(this).attr("href"), "WT.ti", $(this).attr("href"));
                    }
                    else {
                        return true;
                    }
                    
                });
            }
        }
    }
    window['UPS']['externalLinks'] = externalLinks;
    
    
    //Opens new window, takes url and size parameters
    var openWindow = function(url, width, height){
    
        var child = window.open(url, 'ups_popup', 'toolbar=0, scrollbars=1, location=0, statusbar=0, menubar=1, resizable=1, width=' + width + ', height=' + height);
        child.focus();
    }
    window['UPS']['openWindow'] = openWindow;
    
    
    //Remove dotted border from selected images with a class of ".link-border" in all browsers - required for IE7
    var removeDottedBorder = function(element){
    
        $(element).focus(function(){
            if ($(this).blur) {
                $(this).blur();
            }
        });
        
    }
    window['UPS']['removeDottedBorder'] = removeDottedBorder;
    
    
    //Creates equal height columns, by finding the width of the tallest element and adjusting the shorter portlet heights 
    var layout = function(className){
    
        if (className == null) {
            className = 'layout-bottom';
        }
        
        var max_height = 0;
        var max_bottom = 0;
        
        //get heights  and bottom coordinates for each box, find max heights and max bottom coordinates
        $('#container div.' + className).each(function(){
            var my_height = $(this).innerHeight();
            var my_bottom = $(this).offset().top + my_height;
            max_height = (my_height > max_height) ? my_height : max_height;
            max_bottom = (my_bottom > max_bottom) ? my_bottom : max_bottom;
        });
        
        //Before setting heights,reset heights to 'auto' in case this function was applied before
        /*$('.'+className).each(function(){
         $(this).css("height","auto");
         });*/
        //Set heights
        $('#container div.' + className).each(function(){
            var my_height = $(this).innerHeight();
            var my_bottom = $(this).offset().top + my_height;
            if (my_bottom != max_bottom) {
                $(this).height((max_bottom - my_bottom) + $(this).height());
            }
            
        });
    }
    window['UPS']['layout'] = layout;
    
    //Switches classes in level-2 left nav li elements to level-3 if the link inside them has a class
    //level 3
    var leftNavLevelSwitch = function(){
    
        $('#left-nav dd').find('a.left-nav-level-3-a').each(function(){
            //find out if parent element li has 'level-2' class and switch it to level-3
            var parentLi = $(this).parent('li');
            if ($(parentLi).hasClass('left-nav-level-2-li')) {
                $(parentLi).removeClass('left-nav-level-2-li');
                $(parentLi).addClass('left-nav-level-3-li');
            }
        });
        
    }
    window['UPS']['leftNavLevelSwitch'] = leftNavLevelSwitch;
    
    //Controls left-nav show/hide functionality
    var leftNavControl = function(){
    
    
    
    
        //For every top-level left-nav item (left-nav-level-0-a - counting starts at 0) do the following
        $("a.left-nav-level-0").click(function(){
        
            //If the first child is hidden, show the child and animate
            if ($(this).parent().next().children(":first").is(":hidden")) {
            
                $("ul li.left-nav-level-1-li").removeClass("down");
                $("ul li.left-nav-level-2-li").removeClass("down");
                $("#left-nav ul:visible").slideUp("fast");
                $("a.left-nav-level-1-a:visible").css("color", "#848862");
                $("a.left-nav-level-2-a:visible").css("color", "#848862");
                $(this).parent().next().children(":first").slideDown("fast");
                
                if ($(this).attr("id") == "level-0-4") {
                    $(this).parent().next().children(":first-child").css("background-image", "url()");
                }
                
            }
            else {
            
                $("#left-nav ul li").removeClass("down");
                $(this).parent().next().children(":first").slideUp("fast");
                $("#left-nav ul li a").css("color", "#848862");
                
            }
            
            return false;
            
        });
        
        //For every second level left-nav item do the following
        $("a.left-nav-level-1-a").click(function(){
        
            //Animation and effects for sub-elements of class 'left-nav-level-1-a'
            if ($(this).next().is("ul:hidden")) {
            
                $("ul.left-nav-level-1 li.left-nav-level-1-li").removeClass("down");
                $(this).parent().addClass("down");
                $("ul.left-nav-level-2").slideUp("fast");
                $("li.left-nav-level-2-li").removeClass("down");
                $("ul.left-nav-level-3:visible").slideUp("fast");
                $("ul.left-nav-level-3:visible").removeClass("down");
                $("a.left-nav-level-1-a:visible").css("color", "#848862");
                $("a.left-nav-level-2-a:visible").css("color", "#848862");
                $(this).css("color", "#1B380C");
                $(this).next().slideDown("fast");
                
            }
            else {
            
                $(this).css("color", "#848862");
                $(this).parent().removeClass("down");
                $(this).next().slideUp("fast");
                
            }
            
            return false;
            
        });
        
        //For every third level left-nav item do the following
        $("a.left-nav-level-2-a").click(function(){
        
            if ($(this).next().is("ul:hidden")) {
            
                $("ul.left-nav-level-2 li.left-nav-level-2-li").removeClass("down");
                $(this).parent().addClass("down");
                $("ul.left-nav-level-3:visible").slideUp("fast");
                $("a.left-nav-level-2-a:visible").css("color", "#848862");
                $(this).css("color", "#1B380C");
                $(this).next().slideDown("fast");
                
            }
            else {
            
                $(this).css("color", "#848862");
                $(this).parent().removeClass("down");
                $(this).next().slideUp("fast");
                
            }
            
            return false;
            
        });
        
        leftNavControl.expandCurrentLink();
    }
    window['UPS']['leftNavControl'] = leftNavControl;
    
    
    leftNavControl.expandCurrentLink = function(){
        //determine the default view ID
        var leftNav = $("#left-nav");
        var defaultView;
        
        //don't proceed if there's no left nav!
        if (leftNav.size() > 0) {
            defaultView = leftNav[0].getAttribute("defaultView");
            
            if (defaultView && defaultView >= 0) {
            
                //setup the rootid for the default view
                var rootId = "level-0-" + defaultView;
                
                var navLinks = document.getElementsByTagName("a");
                if (navLinks) {
                    var location = document.location.href;
                    
                    //strip out vignette mgmt elements for better matching
                    location = location.replace(/[\?&]shownav=1/, "");
                    location = location.replace(/[\?&]vgnextrefresh=1/, "");
                    
                    //finds notes matching the url that are in the default view
                    var navIds;
                    for (var index in navLinks) {
                        var link = navLinks[index];
                        if (link != null) {
                            var linkId = link.id;
                            
                            if (linkId && linkId.indexOf(rootId) >= 0 && link.href == location) {
                                navIds = link.id;
                                
                                //Now let's make it into "not a link"
                                var emptyNode = document.createElement("span");
                                emptyNode.innerHTML = link.innerHTML;
                                emptyNode.className = "currentLink";
                                
                                var parent = link.parentNode;
                                parent.appendChild(emptyNode);
                                parent.className = parent.className + " darkBullet";
                                link.style.display = "none";
                                
                                break;
                            }
                        }
                    }
                    if (!navIds) {
                        navIds = rootId;
                    }
                    navIdsAry = navIds.split("-");
                    
                    //Clicks to deep link starting with first level (so i must start at index of 2)
                    currentId = navIdsAry[0] + "-" + navIdsAry[1];
                    for (var i = 2; i < navIdsAry.length; i++) {
                        currentId += "-" + navIdsAry[i]
                        $("#" + currentId).click();
                    }
                }
            }
            
        }
    }
    
    
    //Function to enable functionality of send page form
    var sendPage = function(){
    
        //Change values to fit Media Kits if this is media kits page, or something more generic if it is another page
        if (UPS.exists('media-kit-template-content')) {
            $('#send-page').addClass('long');
            $('#send-page').children('h3').text('Send this Media Kit');
        }
        else 
            if (!UPS.exists('pressrelease-detail')) {
                $('#send-page').children('h3').text('Send this Page');
            }
        
        //populates subject field with title of page
        var pageTitle = "";
        if (UPS.exists("page-name")) {
            pageTitle = $("#page-name").text();
        }
        else 
            if (UPS.exists("subheader")) {
                pageTitle = $("h3:eq(0)").text();
            }
            else {
                pageTitle = $("h1:eq(0)").text();
            }
        $('#send-subject').attr("value", pageTitle);
        
        //populate hidden input field with current url from browser
        $("input#prURL").attr("value", window.location.href);
        
        //if page has 'send page' button, display send page form with slide down animation
        if ($('#send-page-display')) {
        
            $('#send-page-display').click(function(){
            
                if ($('#send-page').is(':visible')) {
                
                    $('#send-page').hide();
                }
                
                else {
                
                    $('#send-page:hidden').slideDown('normal');
                }
                
                //hide form confirmation
                if ($('#form-confirmation').is(':visible')) {
                    $('#form-confirmation').hide();
                }
                
                return false;
                
            }); //end send-page-display click function
        }
        
        //hide form when 'Cancel' button is clicked
        if ($('#send-page-cancel')) {
        
            UPS.divDisplay('#send-page-cancel', '#send-page', 'hide');
        }
        
        //activate  character counter
        UPS.remainingCharCounter(500, '#send-message', '#char-remaining');
        
        
    }
    window['UPS']['sendPage'] = sendPage;
    
    
    //Strips out suspicious characters from form input fields
    var inputStrip = function(input){
    
        var value = $(input).val();
        
        var stripped = value.replace(/[\;\<\>\{\}\|\ ]/g, ''); //strip out <. >, { } ;
        $(input).val(stripped);
        
    }
    window['UPS']['inputStrip'] = inputStrip;
    
    
    //Characters remaining counter for forms. maxlength is the maximum length allowed, field is the field to count, counter is the element that displays the number 
    var remainingCharCounter = function(maxlength, field, counter){
    
        if (!maxlength) {
            maxlength = "500";
        }
        
        if (!field || !counter) {
            return;
        }
        
        //set initial characters remaining message
        $(counter).text("(" + (maxlength - $(field).val().length) + " characters remaining)");
        
        //change value of characters remaining counter when user types in text area
        $(field).keyup(function(i){
        
            var current = 0;
            var val = $(this).val();
            if (val) {
                current = val.length;
            }
            
            //display counter value
            if (current <= maxlength) {
                $(counter).text("(" + (maxlength - current.toString()) + " characters remaining)");
            }
            //Limit text to maxlength 
            else {
                $(this).val(val.substring(0, maxlength));
            }
            
        });
        
    }
    window['UPS']['remainingCharCounter'] = remainingCharCounter;
    
    //Dropdown function for top navigation and quicklinks
    var topDropDown = function(element){
    
        var classPrefix = "top-nav-";
        
        //change prefix if this is top-links
        if ($(element).parent().is('#header-nav-top-links')) {
            classPrefix = "top-links-";
        }
        
        if ($(element).parent().is('#header-nav-top-links') || $(element).parent().is('#top-nav')) {
            //remove dotted line from last element in list
            $(element).find('ul').children('li:last-child').each(function(){
                $(this).children('a').each(function(){
                    $(this).css({
                        backgroundImage: 'none'
                    });
                });
            });
        }
        
        //add > to menu links that have a secondary or tertiary list
        if ($(element).find('ul').hasClass(classPrefix + 'level-2')) {
            $(element).find('ul.' + classPrefix + 'level-2').parent('li').children('a').append('<span> &gt;</span>');
        }
        
        if ($(element).find('ul').hasClass(classPrefix + 'level-3')) {
            $(element).find('ul.' + classPrefix + 'level-3').parent('li').children('a').append('<span>&gt;</span>');
        }
        
        //show/hide list on hover
        $(element).hover(function(){
            //slide down first level list
            $(this).find('ul:eq(0):hidden').slideDown('normal');
        }, function(){
            $(this).find('ul:visible').slideUp('normal');
        });
        
        enableNextList('ul.' + classPrefix + 'level-1', 'ul.' + classPrefix + 'level-2');
        
        enableNextList('ul.' + classPrefix + 'level-2', 'ul.' + classPrefix + 'level-3');
        
        //shows/hides child lists on hover of parent element
        function enableNextList(parentList, childList){
        
            $(element).find(parentList).each(function(){
            
                $(this).find('li').hover(function(){
                
                    $(this).find(childList + ':hidden').show();
                }, function(){
                
                    $(this).find(childList + ':visible').hide();
                }); //end hover					
            });
            
        } //end enablenNextList
    }
    window['UPS']['topDropDown'] = topDropDown;
    
    
    //Initializes print, send, share, tweet portlet functionality
    var psst = function(){
    
        //activate send page form 
        if (UPS.exists('send-page')) {
            UPS.sendPage();
        }
        
        //activate print button pop-up
        $('#print-page').click(function(){
        
            var href = $(this).attr('href');
            UPS.openWindow(href, 633, 400);
            return false;
            
        });
        
    }
    window['UPS']['psst'] = psst;
    
    
    //Tooltip Functionality for Company History Timeline
    var timelineTooltip = function(){
    
        $("#company-history-timeline ul").children("li").each(function(){
        
            //on mouseover, show tooltip and add class that sets z-index to 1, on mouseout remove class and hide tooltip
            $(this).hover(function(){
                $(this).addClass('z1');
                $(this).find('.tooltip').fadeIn('normal');
            }, function(){
            
                $(this).find('.tooltip').hide();
                $(this).removeClass('z1');
                
            }); //end hover 
        }); //end li.each(function()
    }
    window['UPS']['timelineTooltip'] = timelineTooltip;
    
    //Media Kit landing page hover functionality
    var mediaKitHover = function(){
    
        //For each link on the Media Kit Landing page, do the following
        $('div#media-kit-landing-content li.content-module-visible span.content-module-popup').each(function(){
        
            //Create a popup div, insert content in it, insert it after the link and immediately hide it
            var popup = document.createElement("span");
            popup.className = "popup";
            $(popup).html($(this).parent().next().html());
            $(this).append(popup);
            
            //Hover animation
            $(this).parent().children(":first-child").hover(function(){
            
                $(popup).show();
                
            }, function(){
            
                $(popup).hide();
            });//end hover
        });//end each
    }
    window['UPS']['mediaKitHover'] = mediaKitHover;
    
    
    //Email Updates Form Interactions
    var emailUpdates = function(){
    
        //automatically check boxes when main checkboxes are clicked
        $('.checkbox-column').each(function(){
        
            var listElement = $(this).find('input.checkbox');
            
            $(this).find('.main-checkbox').click(function(){
            
                var checkValue = this.checked;
                
                $(listElement).each(function(){
                
                    this.checked = checkValue;
                    
                }); //end listElement.each
            }); //end main-checkbox.click(function
        });//end checkbox-column
    }
    window['UPS']['emailUpdates'] = emailUpdates;
    
    var animateCarousel = function(elem, numOfItems){
    
        if (!elem) {
            elem = $('#media-carousel .media-carousel-list:eq(0)');
        }
        
        if (!numOfItems) {
            numOfItems = 5;
        }
        
        var mediaListElem = elem;
        
        if (mediaListElem != undefined) {
            $(mediaListElem).jCarouselLite({
                btnNext: ".media-carousel-arrow.right span",
                btnPrev: ".media-carousel-arrow.left span",
                visible: numOfItems,
                //scroll: 2,
                scroll: 1,
                mouseWheel: true,
                circular: false,
                easing: "bounceout",
                speed: 800
            });
            
        }
    }
    window['UPS']['animateCarousel'] = animateCarousel;
    
    //Media Carousel animation
    var mediaCarousel = function(){
    
        var numOfItems = 5;
        
        //If a page containing the Media Carousel has a class of 'media-kit', 7 items should display 
        if ($('#media-carousel').hasClass('media-kit')) {
            numOfItems = 7;
        }
        
        //show first content list
        $('#media-carousel .media-carousel-list:eq(0) ul').show();
        
        UPS.animateCarousel($('#media-carousel .media-carousel-list:eq(0)'), numOfItems);
        
        //populate "topic" field with first topic on pulldown list
        $('#media-carousel-pulldown .current-topic').text($('#media-carousel-pulldown .pulldown-list li:eq(0) a').text());
        
        //remove dotted line from last item in pulldown menu list
        $('#media-carousel-pulldown .pulldown-list').children('li:last-child').each(function(){
            $(this).children('a').each(function(){
                $(this).css({
                    backgroundImage: 'none'
                });
            });
        });
        
        //Activate pulldown menu
        $('#media-carousel-pulldown .pulldown-arrow').click(function(){
            $('#media-carousel-pulldown .pulldown-list').slideToggle('fast');
        });
        
        //Hide pulldown menu when clicking on carousel or on topic
        $('#media-carousel-pulldown .current-topic, #media-carousel .media-carousel-list ul li a, #media-carousel .media-carousel-list ul, #media-carousel .carousel-top h4').click(function(){
            $('#media-carousel-pulldown .pulldown-list:visible').slideUp('fast');
        });
        
        //Show/hide content item lists when a topic is selected from pulldown list
        $('#media-carousel-pulldown .pulldown-list li').each(function(){
            var myIndex = $('#media-carousel-pulldown .pulldown-list li').index(this);
            
            $(this).find('a').click(function(){
            
                //populate current topic field with selected topic
                $('#media-carousel-pulldown .current-topic').text($(this).text());
                
                //show appropriate content list and activate carousel
                $('.media-carousel-list:not(:eq(' + myIndex + ')) ul').hide();
                $('.media-carousel-list:eq(' + myIndex + ') ul').show();
                UPS.animateCarousel($('.media-carousel-list:eq(' + myIndex + ')'), numOfItems);
                
                //hide pulldown list
                $('#media-carousel-pulldown .pulldown-list:visible').slideUp('fast');
                
                return false;
            }); //end click
        });
        
        //remove dotted border from carousel items
        $('.media-carousel-list').find('ul li a').each(function(){
            removeDottedBorder(this);
        });
    }
    window['UPS']['mediaCarousel'] = mediaCarousel;
    
    
    //Request a Speaker Form Interactions
    var requestSpeaker = function(){
    
        //show "other" input field when "other" is selected on speaker dropdown
        if ($("#speaker-requested").val() == "other") {
            $("#other-container").show();
        }
        
        $("#speaker-requested").change(function(){
        
            if ($(this).val() == "other") {
                $("#other-container").show();
            }
            
            else {
                $("#other-container:visible").hide();
            }
            
        });
        //var test = $("#other-toggle")
        //if ($("#other-toggle").is(":checked")) {
        //	$("#other-field").show();
        //} else {
        //	$("#other-field").hide();
        //}
        //$("#other-toggle").click(function() {
        //	$("#other-field").toggle();
        //});
    
    }
    window['UPS']['requestSpeaker'] = requestSpeaker;
    
    
    //Refine search results expand/collapse function
    var refineSearch = function(){
    
        $('#refine-results').find('dt').each(function(){
        
            var myIndex = $('#refine-results dt').index(this);
            var boxToShow = $('#refine-results dl').find('dd:eq(' + myIndex + ')');
            var boxToHide = $('#refine-results dl').find('dd:not(:eq(' + myIndex + '))');
            
            $(this).find('a').click(function(){
            
                $(boxToHide).slideUp('normal');
                $(boxToShow).slideToggle('normal');
                
                return false;
                
            }); //end click
        });
    }
    window['UPS']['refineSearch'] = refineSearch;
    
    var rotateContent = function(){
    
        $('.rotate').each(function(){
        
            var contentArray = new Array();
            var count = 0;
            
            //Hide all content blocks
            $(this).children('.content-block').hide();
            
            $(this).children('.content-block').each(function(){
            
                contentArray.push($(this));
                count++;
                
            });
            
            //Compute a random value
            var randomNumber = Math.floor(Math.random() * count);
            
            //Show only one random content block
            $(this).find('.content-block:eq(' + randomNumber + ')').show();
            
        });
        
    }
    window['UPS']['rotateContent'] = rotateContent;
    
    var calendarPicker = function(){
    
        Date.firstDayOfWeek = 7;
        Date.format = 'mm/dd/yyyy';
        
        $(function(){
            $('.date-pick').datePicker()
        });
        
    }
    window['UPS']['calendarPicker'] = calendarPicker;
    
    //Function to trim preceding / on all images on the delivery environment.
    var trimDoubleSlash = function(){
    
        var imgs = document.getElementsByTagName("img");
        
        for (var i = 0, l = imgs.length; i < l; i++) {
            if (imgs[i].src.indexOf("http://pressroom") > -1) {
                imgs[i].src = imgs[i].src.replace("http://pressroom", "/pressroom")
            }
            else 
                if (imgs[i].src.indexOf("http://test") > -1) {
                    imgs[i].src = imgs[i].src.replace("http://test", "/test")
                }
                else 
                    if (imgs[i].src.indexOf("//pressroom") > -1) {
                        imgs[i].src = imgs[i].src.replace("//pressroom", "/pressroom")
                    }
                    else 
                        if (imgs[i].src.indexOf("//test") > -1) {
                            imgs[i].src = imgs[i].src.replace("//test", "/test")
                        }
        }
        
    }
    window['UPS']['trimDoubleSlash'] = trimDoubleSlash;
    
    //Function for Press Release Archive link switching 
    var archiveLinkSwitch = function(){
    
        function activateLink(spanToEnable, spanToDisable, tableToHide, tableToShow){
            $('#' + spanToDisable + ' a:eq(0)').click(function(){
                $('#' + tableToHide + ':visible').hide();
                $('#' + tableToShow + ':hidden').show();
                
                var disabledText = $('#' + spanToDisable + ' a:eq(0)').text();
                var enabledText = $('#' + spanToEnable).text();
                $('#' + spanToDisable).html(disabledText);
                $('#' + spanToEnable).html('<a href="#">' + enabledText + '</a>');
                
                activateLink(spanToDisable, spanToEnable, tableToShow, tableToHide);
                
                return false;
            });
        }
        
        activateLink('pressReleaseSpan', 'socialMediaReleaseSpan', 'pressReleaseTable', 'socialMediaReleaseTable');
        
    }
    window['UPS']['archiveLinkSwitch'] = archiveLinkSwitch;
    
    var correctRecenltyAddedMargin = function(){
    	var upsLeadershipHeight = $('#ups-leadership').height();
    	var newMarginTop = upsLeadershipHeight + 68;
    	
    	$('#recently-added').css('margin-top', newMarginTop + 'px');
    }
    window['UPS']['correctRecenltyAddedMargin'] = correctRecenltyAddedMargin;
    
    //This is a quick fix. In the future actual functionality may need to be enhanced.
    var fixArchiveYears = function(){
        $('a').each(function(){
            var href = this.href;
            if (href.match(/\/Archive\/\d{4}$/)) {
                href += "/Q1";
                this.href = href;
            }
        });
    }
    
    window['UPS']['fixArchiveYears'] = fixArchiveYears;
    
    var displaySiteGuideError = function(){
    	var displayErrorDiv = getQueryVariable('error');
    	if(displayErrorDiv){
    		$('#display-error').css('display','block');    		
    	}
    	
    	function getQueryVariable(variable) {
    		var query = window.location.search.substring(1);
    		var vars = query.split("&");
    		for (var i=0;i<vars.length;i++) {
    			var pair = vars[i].split("=");
    		    if (pair[0] == variable) {
    		    	return pair[1];
    		    }
    		}
    	} 
    }
    window['UPS']['displaySiteGuideError'] = displaySiteGuideError;
    
})();


//All functions that need to be executed after page load go here
$(document).ready(function(){

    //left-nav behavior
    UPS.leftNavLevelSwitch();
    UPS.leftNavControl();
    
    //remove dotted lines around hrefs with class of "link-border"
    UPS.removeDottedBorder('.link-border');
    
    //rotate content in Featured Media and Recently Added
    UPS.rotateContent();
    
    //tab dropdown
    $("#top-nav dd").each(function(){
        UPS.topDropDown(this);
    });
    
    //quicklinks dropdown (and header links)
    $("#header-nav-top-links li").each(function(){
        UPS.topDropDown(this);
    });
    
    //if page has 'send page' form, activate functionality
    if (UPS.exists('psst')) {
        UPS.psst();
    }
    
    //if page has company history timeline, activate functionality
    if (UPS.exists('company-history-timeline')) {
        UPS.timelineTooltip();
    }
    
    //if page is Media Kit Landing page, enable tooltips and line up columns
    if (UPS.exists('media-kit-landing-content')) {
        UPS.layout('content-module');
        UPS.mediaKitHover();
    }
    
    //if Media Kit template page, change classes of form confirmation
    if (UPS.exists('media-kit-template-content') && UPS.exists('form-confirmation')) {
        $('#form-confirmation').addClass('long');
        $('#form-confirmation').removeClass('mid-col');
    }
    
    //activate email updates form functionality
    if (UPS.exists('email-updates')) {
        UPS.emailUpdates();
    }
    
    //activate email updates form functionality
    if (UPS.exists('request-speaker')) {
        UPS.requestSpeaker();
        UPS.calendarPicker();
    }
    
    if (UPS.exists('media-carousel')) {
        UPS.mediaCarousel();
    }
    
    //activater refine search results
    if (UPS.exists('refine-results')) {
        UPS.refineSearch();
    }
    
    if (UPS.exists('content-types-landing')) {
        //activate dropdown navigation
        $('.content-nav li').each(function(){
            UPS.topDropDown(this);
        });
    }
    
    //function for archive landing page
    if (UPS.exists('archive-landing')) {
        UPS.archiveLinkSwitch();
    }
    
    //open hrefs in external tab/page
    UPS.externalLinks();
    
    //add class 'lower' to 'featured content' if there is a subnavigation on the page
    if (UPS.exists('subheader') && UPS.exists('featured-content')) {
        $('#featured-content').addClass('lower');
    }
    
    //remove 'layout-bottom' class from print/send/share portlet if there is a form confirmation div below it
    if (UPS.exists('psst-contact') && UPS.exists('form-confirmation')) {
        if ($('#psst-contact').hasClass('layout-bottom') && $('#form-confirmation').hasClass('layout-bottom')) {
            $('#psst-contact').removeClass('layout-bottom');
        }
    }
    
    if(UPS.exists('recently-added') && UPS.exists('ups-leadership')){
    	UPS.correctRecenltyAddedMargin();
    }
    
    //add layout-bottom class to template1 div if there is no contact/send/share div below it
    if (!UPS.exists('psst-contact')) {
        $('div.template1').each(function(){
            $(this).addClass('layout-bottom');
        });
    }
    
    //this function makes all bottom modules line up evenly. Only use if editing is off
    var re = new RegExp(/topId/);
    var isEditOn = false;
    $('#container div').each(function(){
        var m = re.exec(this.id);
        if (m != null) {
            isEditOn = true;
        }
    });
    
    if (isEditOn == false) {
        UPS.layout();
    }
    
    //UPS.trimDoubleSlash();
    
    //A quick fix for archive year links. Archive years should always go to Q1 pages, however
    //the vignette system does not offer an easy or obvious way to do this. Instead, this fix
    //finds all archive year links and fixes them
    UPS.fixArchiveYears();
    
    //If query string param 'error' is present and div is present, then error message is displayed in the site guide.
    if(UPS.exists('display-error')){
    	UPS.displaySiteGuideError();
    }
    
    
});










