
$.fn.reverse = function () {
    return $(this.get().reverse());
}
/**
*  GLOBALS
*/
var $max, $maxWidth, $rollShares;

var $rollShareOpen;

var $filterClicked;

var $initialOffset;

/**
*  "Cross" Controls
*/

var showcase_slideWidth = null;
var showcase_numberOfSlides = null;
var showcase_timeoutRef = null;
var showcase_primary_visibleIndex = 1;
var showcase_clone_visibleIndex = 0;
var showcase_stopAnimation = false;

$(function () {
    if ($('#cross').size()) {

        showcase_slideWidth = $('#cross .primary .slides .slide').first().width();
        showcase_numberOfSlides = $('#cross .primary .slides .slide').length;

        //$('#cross .primary .slides .slide .HighlightText').css("background-color", "#111111");
        
        // fade all of the primary slides, apart from last, and all of the clone slides
        setSlideOpacity($('#cross .primary .slides .slide'), false, 0.2);
        //hack for firefox, it stops the strange green text showing when the opacity is lowered
        if (($.browser.mozilla)) {
            $('#cross .primary .slides .slide .HighlightText').css("height", "261px");
            $('#cross .primary .slides .slide .HighlightText').css("background-color", "#DDDDDD");
        }

        setSlideOpacity($('#cross .clone .slides .slide'), false, 0.2);
        //hack for firefox, it stops the strange green text showing when the opacity is lowered
        if (($.browser.mozilla)) {
            $('#cross .clone .slides .slide .HighlightText').css("height", "261px");
            $('#cross .clone .slides .slide .HighlightText').css("background-color", "#DDDDDD");
        }


        // set the controls buttons to the appropriate slide
        $('#cross .controls img').eq(showcase_primary_visibleIndex).css({ 'display': 'block' });

        // set the visible slide to opaque
        setSlideOpacity($('#cross .primary .slides .slide').eq(showcase_primary_visibleIndex), false, 1);
        //hack for firefox, it stops the strange green text showing when the opacity is lowered
        if (($.browser.mozilla)) {
            $('#cross .primary .slides .slide .HighlightText').eq(showcase_primary_visibleIndex).css("height", "");
            $('#cross .primary .slides .slide .HighlightText').eq(showcase_primary_visibleIndex).css("background-color", "");
        }

        $('#cross .primary .slides .slide .HighlightText').eq(showcase_primary_visibleIndex).css("filter", "");

        $('#cross .controls a').click(function () {
            if (showcase_stopAnimation) {
                return false;
            }

            // the class on the link - this points to the class on the slide that will be displayed
            var slideClass = $(this).attr("class");

            // find the target slide, and it's index in the list.
            var targetItem = $('#cross .primary .slides .' + slideClass)
            var targetItemIndex = $('#cross .primary .slides .slide').index(targetItem);

            if (showcase_primary_visibleIndex == targetItemIndex) {
                return false;
            }
            else {
                stopShowcaseTimer();

                $('#cross .primary .slides').stop(true);
                $('#cross .clone .slides').stop(true);

                var positionsToMove = showcase_primary_visibleIndex - targetItemIndex;
                if (positionsToMove < 0) {
                    positionsToMove += showcase_numberOfSlides;
                }

                moveSlides('#cross .primary .slides', positionsToMove, 'left', true);
                moveSlides('#cross .clone .slides', positionsToMove, 'left', false);
            }

            return false;
        });

        startShowcaseTimer();

        rollShares();
        showcaseShares();
    }
});

function autoAnimateSlides() {
    if (!showcase_stopAnimation) {
        // prevent the animation starting again until this animation has finished
        stopShowcaseTimer();

        moveSlides('#cross .primary .slides', 1, 'left', true);
        moveSlides('#cross .clone .slides', 1, 'left', false);
    }
    //moveSlides('#cross .clone .slides', 1, 'left', true);
}

function moveSlides(slideContainer, numberOfSlides, direction, isPrimary) {
    var container = $(slideContainer);
    var moveAmount = showcase_slideWidth * numberOfSlides;
    var currentIndex = isPrimary ? showcase_primary_visibleIndex : showcase_clone_visibleIndex;

    var targetIndex;

    if (direction == 'left') {
        // move in left direction

        // clone as many of the end slides as needed and put to the front
        for (var i = 0; i < numberOfSlides; i++) {
            var slideToClone = $(slideContainer + ' .slide').eq(showcase_numberOfSlides - 1);
            container.prepend(slideToClone.clone(true, true));

            setSlideOpacity($(slideContainer + ' .slide:first'), false, 0.2);
            if (($.browser.mozilla)) {
                $(slideContainer + ' .slide:first .HighlightText').css("height", "261px");
                $(slideContainer + ' .slide:first .HighlightText').css("background-color", "#DDDDDD");
            }
        }

        // move the Left index as much as needed instantly to account for the items added
        var leftAmount = -(numberOfSlides * showcase_slideWidth);
        var newWidth = (showcase_slideWidth * (numberOfSlides + showcase_numberOfSlides));

        container.css({ 'left': leftAmount, 'width': newWidth });

        if (isPrimary) {
            // get the slide that will be the selected one.
            var selectedSlide = $(slideContainer + ' .slide').eq(currentIndex);
            setSlideOpacity(selectedSlide, true, 1);
            if (($.browser.mozilla)) {
                $(slideContainer + ' .slide .HighlightText').eq(currentIndex).css("height", "");
                $(slideContainer + ' .slide .HighlightText').eq(currentIndex).css("background-color", "");
            }
            var selectedSlideClass = selectedSlide.attr('class').split(' ')[1];

            // set the controls to be the last slide
            $('#cross .controls img').hide();
            $('#cross .controls a.' + selectedSlideClass + ' img').css({ 'display': 'block' });
        }

        container.stop().animate({ 'left': 0 }, 350, 'swing', function () {
            for (var i = 0; i < numberOfSlides; i++) {
                $(slideContainer + ' .slide:last').remove();
            }

            container.css({ 'width': showcase_numberOfSlides * showcase_slideWidth });

            if (isPrimary) {
                //restart the animation
                startShowcaseTimer();
            }

            $(slideContainer + ' .slide .HighlightText').css("filter", "");
        });
    }
    else {
        // move in right direction
    }
}

function setSlideOpacity(slides, animate, opacity) {
    // sets/animates the the slides opacity and the parts within it (required for IE7/8)

    var slideParts = $('.inner .enabled img,.inner .HighlightText, .inner .enabled a.more, .shareContainer a.tab', slides);

    if (animate) {
        //slides.animate({ 'opacity': opacity }, 175);
        slideParts.animate({ 'opacity': opacity }, 175);
    }
    else {
        //slides.css({ 'opacity': opacity });
        slideParts.css({ 'opacity': opacity });
    }

    if (opacity < 1) {
        $('a.more', slides).attr('onclick', 'return false;').css("cursor","default");
        $('.shareContainer a.tab', slides).data('disableShareTab', true).css("cursor", "default");
    }
    else {
        $('a.more', slides).attr('onclick', '').css("cursor", "");
        $('.shareContainer a.tab', slides).removeData('disableShareTab').css("cursor", "");
    }
}

function startShowcaseTimer() {
    showcase_stopAnimation = false;
    showcase_timeoutRef = setTimeout("autoAnimateSlides()", 4000);
}
function stopShowcaseTimer() {
    clearTimeout(showcase_timeoutRef);
    showcase_stopAnimation = true;
}


function showcaseShares() {
    $('#showcase .share a.tab').click(function () {
        // if the disableShareTab is set, don't open the share
        if ($(this).data('disableShareTab') == true) {
            return false;
        }
        stopShowcaseTimer();

        // get the parent share div, set the 'open' data to true and open
        var shareContainer = $(this).closest('.share');

        shareContainer.data('open', true);
        shareContainer.animate({ 'top': 108 }, 175, function () {
            // after the animation, show the facebook like.  These are placed in their own 
            // absolute positioned div and shown/hidden when the share tab is opened/closed.
            // This is because having the like control in the carousel slide was causing the
            // animation to become clunky as the like controls were reloaded on each animation.
            var shareClass = $(this).attr("class").substring(6);
            $('#facebookLikes .' + shareClass).show();
        });

        // hide the share tab
        $(this).hide();

        return false;
    });

    $('#showcase .share a.showcaseclose').click(function () {
        // get the parent share div, set 'open' to false and close 
        var shareContainer = $(this).closest('.share');
        var shareClass = shareContainer.attr("class").substring(6);

        $('#facebookLikes .like').hide();

        shareContainer.data('open', false);
        shareContainer.animate({ 'top': 0 }, 175, function () { 
            //restart the animation
            startShowcaseTimer();
        });

        // find the share tab and hide.
        var tab = $('a.tab', shareContainer);
        tab.show();
    });
}

/* Move facebook like buttons from carousel to top of DOM to fix stacking bug - called on doc ready */
function moveAndPositionFBLikes() {
    /* Cache top and left offset of like buttons relative to window */
    var offset = $("#facebookLikes .share0").show().offset();
    $("#facebookLikes .share0").hide();
    var bodyWidth = $("body").width();
    var offsetDifference = 1280 - bodyWidth;
    var posTop = offset.top;
    var posLeft = offset.left + 10;
    initialOffset = posLeft;
    if (offsetDifference > 0) {
        posLeft += offsetDifference;
    }
    /* Move like buttons to top of the DOM */
    $("body").prepend($("#facebookLikes"));
    /* Position each like button by cached left and top position */
    $("#facebookLikes .like").each(function () {
        $(this).css({ 'position': 'absolute', 'top': posTop, 'left': posLeft, 'z-index': '9999' });
    });
    /* Remove position absolute of parent so it doesn't affect new positioning */
    $("#facebookLikes").css('position', 'static');
}

function adjustOffset() {
    var $viewable = $(window).width();
    var $maxOffset = Math.round(($viewable - $maxWidth) / 2) - 15;
    $max.css({ 'margin-left': $maxOffset });
}


function rollShares() {
    $rollShares = $('#roll .share');
    $rollShares.each(function () {
        var $share = $(this);
        var $tab = $(this).children(".tab");
        $('a.tab', $share).click(function () {
            var $tab = $(this);
            $tab.children().hide();
            $share
                .animate({ 'top': 0 }, 350, function () {
                $tab.parent().parent().css('overflow', 'visible');
            })
            .data('open', true);
            $rollShareOpen = true;

            return false;
        });

        $('.clickclose', $share).click(function (e) {
            $tab.children().show();
            $share.animate({ 'top': 156 }, 175).data('open', false);
            $(this).parent().parent().children(".tab").show();
            $tab.parent().parent().css('overflow', 'hidden');
            return false;
        });
    });
}

function positionEdgeFillers() {
    var docHeight = $(document).height();
//    var docHeight;

//    if (($.browser.mozilla) && (window.location.href.toLowerCase().indexOf("insights") != -1)) {
//        docHeight = $(".maincontentwraper").height();
//    } else {
//    docHeight = $(document.body).height();
//    }
    
    var docWidth = $(document).width();
    var fillerWidth = ($(document).width() - 1280) / 2;
    if (fillerWidth > 0) {
        $("#left-edge, #right-edge").height(docHeight).width(fillerWidth);
    } else { $("#left-edge, #right-edge").width(0); }
}

$(window).resize(function () {
    positionEdgeFillers();
});




/**
*  "Countries" Scroller
*/

/**
*  Timed Carousel
*  Adds an alternative bg shade to even items in listings.
*/

$(document).ready(function () {
    var pathname = window.location.href;
    pathname = pathname.toLowerCase();
    if (pathname.search('/united-kingdom/home.aspx') != -1) {
        $("body.IE8 #countries .frame .content h1").css({ height: "47px" });
    }


    if ($('div#countries').size()) {

        var $countryPrev, $countryNext, t;
        var $countries = $('#countries .slides');
        var $countrySlides = $('.slide', $countries);
        var $countryControls = $('#countries .controls a');
        var timer_is_on = 0;

        $countrySlides.css({ 'opacity': 0.2 });

        $countryControls.click(function () {
            scrollCountry($(this), true);
            return false;
        });

        first_slide = $countrySlides.first();

        $('#countries .slides').css({ 'left': -first_slide.position().left });

        function timedCount() {
            t = setTimeout(timedCount, 15000);

            if (timer_is_on > 0) {
                scrollCountry($('.next'), true);
                //alert('test');
            } else {
                //alert('timedCount is being run for the first time');
                timer_is_on = 1;
            }
        }

        function scrollCountry(thisObject, fade) {
            var $clicked = thisObject;
            var $class = $clicked.attr('class');

            //  Next and previous countries to current
            $countryNext = $('li.current', $countries).next();
            $countryPrev = $('li.current', $countries).prev();
            if ($countryPrev.position() == null) {
                // if there is no previous, go somewhere else 
                $countryPrev = $('li.current', $countries).last();
            }
            if ($countrySlides == null) return;
            $countryCurrent = $countrySlides.filter('.current');

            if (fade) {

                $countryCurrent.animate({ 'opacity': 0.2 }, 175);
            }
            $countrySlides.removeClass('current');

            switch ($class) {
                case 'prev':
                    offset = $countrySlides.last().find('img').width();
                    $('#countries .slides').prepend($countrySlides.last().remove());
                    $('#countries .slides').css({ 'left': parseInt($('#countries .slides').position().left - offset - 23) });
                    $countries.stop().animate({ 'left': -$countryPrev.position().left }, 600, 'swing');
                    $countryPrev.addClass('current');
                    break;
                case 'next':
                    offset = $countrySlides.first().find('img').width();
                    $('#countries .slides').append($countrySlides.first().remove());
                    $('#countries .slides').css({ 'left': parseInt($('#countries .slides').position().left + offset - 23) });

                    $countries.stop().animate({ 'left': -$countryNext.position().left }, 600, 'swing');
                    $countryNext.addClass('current');
                    break;
            }

            //after wrapping around refresh collections
            $countrySlides = $('.slide', $countries);

            if (fade) {
                $countrySlides.filter('.current').animate({ 'opacity': 1 }, 425);
            }
            else {
                $countrySlides.filter('.current').css({ 'opacity': 1 });
            }

            if (t != null)
                clearTimeout(t);
            t = setTimeout(timedCount, 15000);
        }

        timedCount();
        scrollCountry($('.prev'), false);
    }



    // Position the background image on thought leadership page
    var bgOffset = $("#sidebar .menu > ul").height();
    $("#corpus.tl-blue").css("background-position", "0 " + bgOffset + "px");
    if ($("#facebookLikes .like").length > 0) {
        moveAndPositionFBLikes();
    }
});

/**
*  Listing Striper
*  Adds an alternative bg shade to even items in listings.
*/
$(function () {
    $('#content ul.listing li:nth-child(odd)').css({ 'background': '#efefe5' });
});

/**
* hero carousel
*/
var hero_timer_ref = null;

$(function () {

    if ($('div#hero-carousel').size()) {
        //  Create collections (much faster performance)
        var $slides = $('.hero-carousel-slides ul li');
        var $controls = $('#hero-carousel .controls a');
        var $highlights = $('#hero-carousel .controls a img');

        //  Setup slider defaults
        $slides.data({ 'current': false }).fadeOut(350);
        $slides.filter(':first').data({ 'current': true }).fadeIn(350);
        $controls.data({ 'current': false });
        $controls.filter(':first').data({ 'current': true });
        //$highlights.css({ 'display': 'none' });
        $highlights.filter(':first').css({ 'display': 'block' });

        $("#roll .controls li:first-child a img").css("display", "block");

        //  Bind slider controls
        $controls.click(function () {
        
            $highlights.css({ 'display': 'none' });
            $controls.data({ 'current': false });

            var $clicked = $(this);
            var $index = $controls.index($clicked);

            $clicked.data({ 'current': true });
            $('img', $clicked).css({ 'display': 'block' });

            $slides.css({ 'z-index': 40 });
            $slides.eq($index).css({ 'z-index': 60 });


            if ($.browser.msie == true) {
                var $outgoing = $slides.not($slides.eq($index));
                $outgoing.hide();

                $slides.eq($index).fadeIn(500);
                $slides.eq($index).data({ 'current': true });

            } else {
                $slides.eq($index).fadeIn(350);
                $slides.eq($index).data({ 'current': true });

                var $outgoing = $slides.not($slides.eq($index));
                $outgoing.fadeOut(350);
            }

            $outgoing.data({ 'current': false });

            if (hero_timer_ref != null)
                clearTimeout(hero_timer_ref);
            hero_timer_ref = setInterval('hero_timer();', 4000);

            //setInterval('$(".hero-carousel-slides ul li h1").css("display", "block");', 350);

            //$(".hero-carousel-slides ul li h1").css("display", "block");

            return false;
        });

        hero_timer_ref = setInterval('hero_timer();', 4000);
    }
});

function hero_timer() {
    controls = $('#hero-carousel .controls');
    next_button = $('img:visible', controls).first().closest('li').next();

    if (!next_button.size())
        next_button = $('li', controls).first();

    next_button.find('a').click();
}


//Global networks filter list

$(document).ready(function () {

    $('ul.switch-filter li a').click(function () {

        go = $(this).attr('href').split('#');

        $('ul.switch-filter li.live').removeClass('live');
        $(this).parent().addClass('live');

        $('.global-address div.live').removeClass('live');
        $('#' + go[1]).addClass('live');

        positionEdgeFillers();

        return false;
    });

    $(".global-address .section .row:last-child").addClass("global-address-footer");

    //Add index value to rel attribute of each global nav anchor
    $(".global-top-nav").each(function () {
        var linkIndex = 0;
        $(this).children("li").children("a").each(function () {
            $(this).attr("rel", linkIndex);
            linkIndex++;
        });

        positionEdgeFillers();
    });

    //When global nav anchor clicked, scroll to corresponding address based on array index
    $(".global-top-nav a").click(function () {
        var locations = $.makeArray($(".section.live div.address-hold"));
        $.scrollTo($(locations[$(this).attr("rel")]), 500, { axis: 'y' });
        return false;

        positionEdgeFillers();
    });

    //Use jquery scroll animation on back to top button
    $(".row .content a.button").click(function () {
        $.scrollTo($(".nav-anchor"), 500, { axis: 'y' });

        positionEdgeFillers();
    });
});

//search results div backgrounds

$(document).ready(function () {
    $("article.search-results div.results-hold:even").addClass('even');

    if ($.browser.msie && $.browser.version == "7.0") {
        var zIndexNumber = parseInt(((Math.pow(2, 32)) / 2));
        $('div').each(function () {
            $(this).css('zIndex', zIndexNumber);
            zIndexNumber -= 10;
        });
    }

    $("#xmlFeedAll").click(function () {
        var $feeds = $('input[type="checkbox"]');

        if ($(this).is(':checked')) {
            for (var i = 0; i < $feeds.length; i++) {
                $feeds[i].checked = true;
            }
        }
    });

    $('input[type="checkbox"]').click(function () {
        if ($(this).attr("id") != 'xmlFeedAll') {
            document.getElementById('xmlFeedAll').checked = false;
        }
    });

});
  

//insights filter

function applyFilter(count, countIncrement) {
    var $feeds = $('input[type="checkbox"]');
    var url = window.location.protocol + '//' + window.location.host + window.location.pathname;

    if (($feeds[0].checked) || ($("#xmlFeedAll").is(":checked"))) {
        url += '?' + $feeds[0].id + '=1';
    } else {
        url += '?' + $feeds[0].id + '=0';
    }

    for (var i = 1; i < $feeds.length; i++) {
        if (($feeds[i].checked) || ($("#xmlFeedAll").is(":checked"))) {
            url += '&' + $feeds[i].id + '=1';
        } else {
            url += '&' + $feeds[i].id + '=0';
        }
    }

    if (count == "") {
        count = 6;
    } else if (countIncrement) {
        count = parseInt(count) + 3;
    }

    if (count == null) {
        window.location = url + '&applyfilter=1';
    } else {
        window.location = url + '&count=' + count + '&applyfilter=1';
    }
}

function applyIndexFilter() {
    var id = $(this).attr("id");
    var $feeds = $('input[type="checkbox"]');
    var $filter = '';
    //id

    for (var i = 0; i < $feeds.length; i++) {
        if (($feeds[i].checked) || ($("#indexAll").is(":checked"))) {
            $filter += $feeds[i].id + ';';
        }
    }

    $(".indexFilterValue").val($filter);

    //$(".indexFilterValue");
}

function applyFilterFromFilterMenu() {
    if ($filterClicked) {
        applyFilter(null, false);
    }
}

function applyFilterFromArticleCount(count) {
    applyFilter(count, true);
}

/*
tabSlideOUt v1.3
    
By William Paoli: http://wpaoli.building58.com
    
*/


(function ($) {
    $.fn.tabSlideOut = function (callerSettings) {
        var settings = $.extend({
            tabHandle: '.handle',
            speed: 300,
            action: 'click',
            tabLocation: 'left',
            topPos: '200px',
            leftPos: '20px',
            fixedPosition: false,
            positioning: 'absolute',
            pathToTabImage: null,
            imageHeight: null,
            imageWidth: null,
            onLoadSlideOut: false
        }, callerSettings || {});

        settings.tabHandle = $(settings.tabHandle);
        var obj = this;
        if (settings.fixedPosition === true) {
            settings.positioning = 'fixed';
        } else {
            settings.positioning = 'absolute';
        }

        $('input[type="checkbox"]').click(function () {
          $filterClicked = true;
        });

        //ie6 doesn't do well with the fixed option
        if (document.all && !window.opera && !window.XMLHttpRequest) {
            settings.positioning = 'absolute';
        }



        //set initial tabHandle css

        if (settings.pathToTabImage != null) {
            settings.tabHandle.css({
                'background': 'url(' + settings.pathToTabImage + ') no-repeat',
                'width': settings.imageWidth,
                'height': settings.imageHeight
            });
        }

        settings.tabHandle.css({
            'display': 'block',
            'outline': 'none',
            'position': 'absolute'
        });

        obj.css({
            'line-height': '1',
            'position': settings.positioning
        });


        var properties = {
            containerWidth: parseInt(obj.outerWidth(), 10) + 'px',
            containerHeight: parseInt(obj.outerHeight(), 10) + 'px',
            tabWidth: parseInt(settings.tabHandle.outerWidth(), 10) + 'px',
            tabHeight: parseInt(settings.tabHandle.outerHeight(), 10) + 'px'
        };

        //set calculated css
        if (settings.tabLocation === 'top' || settings.tabLocation === 'bottom') {
            obj.css({ 'left': settings.leftPos });
            settings.tabHandle.css({ 'right': 0 });
        }

        if (settings.tabLocation === 'top') {
            obj.css({ 'top': '-' + properties.containerHeight });
            settings.tabHandle.css({ 'bottom': '-' + properties.tabHeight });
        }

        if (settings.tabLocation === 'bottom') {
            obj.css({ 'bottom': '-' + properties.containerHeight, 'position': 'fixed' });
            settings.tabHandle.css({ 'top': '-' + properties.tabHeight });

        }

        if (settings.tabLocation === 'left' || settings.tabLocation === 'right') {
            obj.css({
                'height': properties.containerHeight,
                'top': settings.topPos
            });

            settings.tabHandle.css({ 'top': 0 });
        }

        if (settings.tabLocation === 'left') {
            obj.css({ 'left': '-' + properties.containerWidth });
            settings.tabHandle.css({ 'right': '-' + properties.tabWidth });
        }

        if (settings.tabLocation === 'right') {
            obj.css({ 'right': '-' + properties.containerWidth });
            settings.tabHandle.css({ 'left': '-' + properties.tabWidth });
        }

        //functions for animation events

        settings.tabHandle.click(function (event) {
            event.preventDefault();
        });

        var slideIn = function () {

            if (obj.hasClass('open')){
                applyFilterFromFilterMenu();
            }

            if (settings.tabLocation === 'top') {
                obj.animate({ top: '-' + properties.containerHeight }, settings.speed).removeClass('open');
            } else if (settings.tabLocation === 'left') {
                obj.animate({ left: '-' + properties.containerWidth }, settings.speed).removeClass('open');
            } else if (settings.tabLocation === 'right') {
                obj.animate({ right: '-' + properties.containerWidth }, settings.speed).removeClass('open');
            } else if (settings.tabLocation === 'bottom') {
                obj.animate({ bottom: '-' + properties.containerHeight }, settings.speed).removeClass('open');
            }
        };

        var slideOut = function () {

            if (settings.tabLocation == 'top') {
                obj.animate({ top: '-3px' }, settings.speed).addClass('open');
            } else if (settings.tabLocation == 'left') {
                obj.animate({ left: '-3px' }, settings.speed).addClass('open');
            } else if (settings.tabLocation == 'right') {
                obj.animate({ right: '-3px' }, settings.speed).addClass('open');
            } else if (settings.tabLocation == 'bottom') {
                obj.animate({ bottom: '-3px' }, settings.speed).addClass('open');
            }
        };

        var clickScreenToClose = function () {
            obj.click(function (event) {
                event.stopPropagation();
            });

            $(document).click(function () {
                slideIn();
                $('.handle-filter').html('Filter Content');
                 $('#blur-content').removeClass('blur');
            });
        };

        var clickAction = function () {
            settings.tabHandle.click(function (event) {
                if (obj.hasClass('open')) {
                    slideIn();
                     $('#blur-content').removeClass('blur');
                } else {
                    slideOut();
                    $('#blur-content').addClass('blur');
                }
            });

            clickScreenToClose();
        };

        var hoverAction = function () {
            obj.hover(
                function () {
                    slideOut();
                },

                function () {
                    slideIn();
                });

            settings.tabHandle.click(function (event) {
                if (obj.hasClass('open')) {
                    slideIn();
                }
            });
            clickScreenToClose();

        };

        var slideOutOnLoad = function () {
            slideIn();
            setTimeout(slideOut, 500);
        };

        //choose which type of action to bind
        if (settings.action === 'click') {
            clickAction();
        }

        if (settings.action === 'hover') {
            hoverAction();
        }

        if (settings.onLoadSlideOut) {
            slideOutOnLoad();
        };

    };
})(jQuery);

$(document).ready(function(){

		$('#offers-wrapper').css('display','');
        $('#offers-wrapper').tabSlideOut({
            tabHandle: '.handle-filter',                     //class of the element that will become your tab
            pathToTabImage: null, //path to the image for the tab //Optionally can be set using css
            imageHeight: '550px',                     //height of tab image           //Optionally can be set using css
            imageWidth: '63px',                       //width of tab image            //Optionally can be set using css
            tabLocation: 'right',                      //side of screen where tab lives, top, right, bottom, or left
            speed: 300,                               //speed of animation
            action: 'click',                          //options: 'click' or 'hover', action to trigger animation
            topPos: '35px',                          //position from the top/ use if tabLocation is left or right
            leftPos: '20px',                          //position from left/ use if tabLocation is bottom or top
            fixedPosition: false                     //options: true makes it stick(fixed position) on scroll
        });
		
		
		
		
});


//GMaps
function initialize(MapLatitude, MapLongtitude, PinLatitude, PinLongtitude) {

    //var latlng = new google.maps.LatLng(51.520226, -0.135098);
    var latlng = new google.maps.LatLng(MapLatitude, MapLongtitude);
    var myOptions = {
        zoom: 16,
        center: latlng,
        disableDefaultUI: true,
        mapTypeControlOptions: {
            mapTypeId: [google.maps.MapTypeId.ROADMAP, 'phd']
        }
    };

    var styles = [{ featureType: "landscape.man_made", elementType: "all", stylers: [{ visibility: "off"}] }, { featureType: "all", elementType: "all", stylers: [{ hue: "#0066ff" }, { saturation: 0 }, { lightness: -10}] }, { featureType: "road.arterial", elementType: "all", stylers: [{ lightness: 19 }, { gamma: 1.14 }, { hue: "#0033ff" }, { saturation: -39}]}];

    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    // Custom Marker
    var srcImage = '/img/GmapsOverlay.png';

    var phdMarker = new google.maps.Marker({
        //position: new google.maps.LatLng(51.520650, -0.1335),
        position: new google.maps.LatLng(PinLatitude, PinLongtitude),
        map: map,
        icon: srcImage
    });

    //apply style
    var styledMapOptions = {
        name: "phd-map"
    }

    var phdMapType = new google.maps.StyledMapType(
      styles, styledMapOptions);

    map.mapTypes.set('phd', phdMapType);
    map.setMapTypeId('phd');
}


$(document).ready(function () {
    positionEdgeFillers();

    adjustScrollBars();

    adjustHighlightsCarousel();

    AddTimestampToCSS();

    RemoveStylesForDesinger();

    $("h1:empty").remove();

    //positionFBLikes();

    $(window).resize(function () {
        adjustScrollBars();

        adjustHighlightsCarousel();

        //positionFBLikes();
    });

    function RemoveStylesForDesinger() {
        if (top === self) {
            //not in iframe/designer
        } else {
            //in desinger/iframe
            $("#countries").css("height", "100%");

            $("body.IE8 #countries .frame .content h1").css("background", "none;");
            $("body.IE8 #countries .frame .content h1").css("width", "480px;");
            $("body.IE8 #countries .frame .content h1").css("height", "96px;");
            $("body.IE8 #countries .frame .content h1").css("text-indent", "0px");
        }
    }

    function AddTimestampToCSS() {
        var date = new Date()
        var ticks = date.getTime()

        $("#stylesCSS").attr($("#stylesCSS").attr() + '?time=' + ticks);
        $("#mainCSS").attr($("#mainCSS").attr() + '?time=' + ticks);
    }

    function positionFBLikes() {
        var pageWidth = $(window).width();
        //var buttonOffset = (1280 - pageWidth)/4;

        var buttonOffset = $($("#facebookLikes")[1]).offset().left + 10;

        /* Position each like button by cached left and top position */
        $("#facebookLikes .like").each(function () {
            $(this).css({ 'position': 'absolute', 'top': $(this).css("top"), 'left': buttonOffset, 'z-index': '9999' });
        });
    }

    function adjustHighlightsCarousel() {
        //hack for stopping "Highlights" carousel from moving under the "From our network" section
        if ($(window).width() <= 1280) {
            //if the page is smaller than 1280 then the carousel starts to slide under the other section
            var pageOffset = 60 - ((1280 - $(window).width()) / 2);

            //after a while it stops though, so we need need to limit out the offset here
            if (pageOffset < -60) {
                pageOffset = -60;
            }

            //apply the offset
            $('#carousel').css("left", pageOffset);
        } else {
            //if the page is larger than 1280, then do not worry so much
            $('#carousel').css("left", "");
        }
    }

    function adjustScrollBars() {
        if ($(window).width() <= 968) {
            $('html').css('overflow-x', 'visible');
        } else {
            $('html').css('overflow-x', 'hidden');
        }
    }
});

$(document).ready(function () {
    
   // $("body.IE8 #countries .frame .content h1").css({ height: "36px" });
    });


