/* Generic functions*/
var m3xPage = function () { /* private methods */


    function isIE() {
        return $.browser.msie;
    }
    function browserVersion() {
        return parseInt($.browser.version);
    }
    function checkQueryParams() {
        var queryParms = window.location.href.split('?');
        if (queryParms.length > 1 && queryParms[1].substring(0, 8) == "conf=rcb") {
            var queryParmsX = queryParms[1].split('&');
            var cName = queryParmsX[1].substring(2);
            $('#requestCallBackSent').click();
            document.getElementById("contName").innerHTML = 'Dear ' + cName;
        }
    }
    function hasId(elementId) {
        if ($("#" + elementId).length > 0) {
            return true;
        } else {
            return false;
        }
    }
    function hasLightbox() {
        return $("a.lightbox").length > 0;
    }
    function isHomePage() {
        return $("#flashVideo").length > 0;
    }
    function isNewsPage() {
        return $("#newsExtraLinks").length > 0;
    }
    function isAboutPage() {
        return $("#ctl00_Main_aboutSlate").length > 0;
    }
    function isHubPage() {
        return $("#ctl00_Main_hubSlate").length > 0;
    }
    function isCsrPage() {
        return $("#ctl00_Main_csrSlate").length > 0;
    }
    function isMapPage() {
        return $("#ctl00_Main_locationsSlate").length > 0;
    }
    function isCurrentPartners() {
        return $(".currentPartnersLogo").length > 0;
    }
    function isVehiclePage() {
        return $(".vehiclePage").length > 0;
    }
    function isntPartnerPage() {
        return $("div.partnerLogo").length == 0;
    }
    function generateMap() {
        m3xMap.init();
    }
    function fixDownArrows() {
        $("h3.myAccHeader span.arrowHolder").mouseover(function () {
            if ($(this).parent().hasClass("selected") == false) {
                $(this).css("background", "#fff url(/content/images/visitor/ros/downArrowsPink.gif) no-repeat right 50%");
            }
            $(this).css("text-decoration", "underline");
        });
        $("h3.myAccHeader span.arrowHolder").mouseout(function () {
            if ($(this).parent().hasClass("selected") == false) {
                $(this).css("background", "#fff url(/content/images/visitor/ros/downArrows.gif) no-repeat right 50%");
            }
            $(this).css("text-decoration", "none");
        });
        $("h3.selected span.arrowHolder").mouseover(function () {
            $(this).css("background", "#fff url(/content/images/visitor/ros/upArrowsPink.gif) no-repeat right 50%");
            $(this).css("text-decoration", "underline");
        });
        $("h3.selected span.arrowHolder").mouseout(function () {
            $(this).css("background", "#fff url(/content/images/visitor/ros/upArrowsPink.gif) no-repeat right 50%");
            $(this).css("text-decoration", "none");
        });
        $("h3.myAccHeader span.arrowHolder").click(function () {
            $("h3.myAccHeader span.arrowHolder").css("background", "#fff url(/content/images/visitor/ros/downArrows.gif) no-repeat right 50%");
            $(this).css("background", "#fff url(/content/images/visitor/ros/upArrowsPink.gif) no-repeat right 50%");
        });
        $("#rosContentRight div.newsXtraRhsLinkContainer").mouseover(function () {
            $("#rosContentRight div.newsXtraRhsLinkContainer").css("background", "transparent url(/content/images/visitor/ros/rosRightNewsXtra.gif) no-repeat right -204px");
        });
        $("#rosContentRight div.newsXtraRhsLinkContainer").mouseout(function () {
            $("#rosContentRight div.newsXtraRhsLinkContainer").css("background", "transparent url(/content/images/visitor/ros/rosRightNewsXtra.gif) no-repeat right 0");
        });
    }
    function publicInit() { /* Setup other objects*/
        if ($("#enterLogin").length > 0) {
            m3xLogin.init();
        }
        m3xMenu.init();
        m3xSearch.init();
        m3xRotateImages.init();
    } /* public */
    return {
        init: publicInit,
        fixDownArrows: fixDownArrows,
        generateMap: generateMap,
        browserVersion: browserVersion,
        checkQueryParams: checkQueryParams,
        isIE: isIE,
        hasId: hasId,
        hasLightbox: hasLightbox,
        isHomePage: isHomePage,
        isNewsPage: isNewsPage,
        isAboutPage: isAboutPage,
        isCsrPage: isCsrPage,
        isHubPage: isHubPage,
        isMapPage: isMapPage,
        isCurrentPartners: isCurrentPartners,
        isVehiclePage: isVehiclePage,
        isntPartnerPage: isntPartnerPage
    };
} ();        /* Drop down menu show and hide functions*/
var m3xMenu = function () { /* private methods*/


    function show(whichElementParent, whichElement) { /* Ensure consistent widths of menu elements*/
        if ($(whichElementParent).width() > 140) {
            $(whichElement).css("width", $(whichElementParent).width() + "px");
        }
        $(whichElement).toggle();
    }
    function hide(whichElement) {
        $(whichElement).toggle();
    }
    function publicInit() { /* Fix issues with li spacing in <= IE 7*/
        if ($.browser.msie && parseInt(jQuery.browser.version) <= 7) {
            $("ul.topMenu li.dropFix").addClass("dropFixIE");
        } /* Define hover in/out events for top menu*/
        $("li.dropHover").mouseenter(function () {
            show($(this), $("#" + $(this).attr("id") + " > ul"));
        }).mouseleave(function () {
            hide($("#" + $(this).attr("id") + " > ul"));
        });
    } /* public methods */
    return {
        init: publicInit
    };
} (); /*Filtering of search results into predefined sections.*/
var m3xSearch = function () { /* private*/
    var config = {
        sections: ["all", "news", "product", "sector", "customer", "other"]
    };

    function filter(whichSection) { /* Hide all sections and show specific section*/
        $("div.allPages").hide();
        $("div." + whichSection + "Pages").show(); /* Stylise the text links*/
        $("div#searchOptions a").css({
            fontWeight: "normal",
            textDecoration: "none"
        });
        $("div a#" + whichSection + "PagesLink").css({
            fontWeight: "bold",
            textDecoration: "underline"
        }); /* Determine number of results returned*/
        var lengthOfQuery = $("div." + whichSection + "Pages").length ? $("div." + whichSection + "Pages").length : "0";
        $("#searchDigit").html(lengthOfQuery);
    }
    function publicInit() {
        $('input#searchBox').blur(function () {
            if (!$(this).attr("value") || $(this).attr("value") == "undefined" || $(this).attr("value") == "") {
                $(this).attr("value", "Search").css("color", "#b3b3b3");
            }
        });
        if ($("#searchOptions").length > 0) {
            $.each(config.sections, function (index, section) {
                $("#" + section + "PagesLink").click(function () {
                    filter(section);
                    return false;
                });
            });
        }
    } /* public */
    return {
        init: publicInit
    };
} (); /* Login box Focusing, pre-filling etc */
var m3xLogin = function () { /* private */


    function passwordFocus() { /* swap readable (fake) and real password boxes */
        $("input#textPasswordBox").hide();
        $("input#password").show().focus();
    }
    function passwordBlur() {
        if (!$("input#password").attr("value") || $("input#password").attr("value") == "undefined" || $("input#password").attr("value") == "") {
            $("input#password").hide();
            $("input#textPasswordBox").show().attr("value", "Password").blur();
        }
    }
    function checkEnter() { /* Legacy keypress code to submit form on 'Enter'*/
        var characterCode;
        if (e && e.which) {
            e = e;
            characterCode = e.which;
        } else {
            e = event;
            characterCode = e.keyCode;
        }
        if (characterCode == 13) {
            document.forms[1].submit();
            return false;
        } else {
            return true;
        }
    }
    function publicInit() { /* Styles */
        $('input#login, input#textPasswordBox, input#searchBox').css("color", "#b3b3b3");
        $('input#password').hide();
        $('input#textPasswordBox').show(); /* Keypresses */
        $('input#login, input#password').keypress(function () {
            PressEnter();
        });
        $('input#tbCompanyName, input#tbUsername, input#tbPassword').keypress(function () {
            checkEnter();
        }); /* Cookies */
        if (readCookie_("login") != "" && readCookie_("login") != "null") {
            $('input#login, input#login2').attr("value", readCookie_("login")).css("color", "#3f3f41");
            passwordFocus();
        } else {
            $('input#login').attr("value", "Customer Login");
        } /* Focuses & blurs */
        $('input#login').focus(function () {
            $(this).css("color", "#3f3f41");
            if ($(this).attr("value") == "Customer Login") {
                $(this).attr("value", "");
            }
        }).blur(function () {
            if (!$(this).attr("value") || $(this).attr("value") == "undefined" || $(this).attr("value") == "") {
                $(this).attr("value", "Customer Login").css("color", "#b3b3b3");
            }
        });
        $('input#password').blur(function () {
            passwordBlur();
        });
        $('input#textPasswordBox').focus(function () {
            passwordFocus();
        });
    } /* public */
    return {
        init: publicInit
    };
} (); /* Rotation of legacy popup and logo images*/
var m3xRotateImages = function () { /* private*/
    var config = {
        shortInterval: 3000,
        longInterval: 6000,
        cashForQuittersRHS: 5000
    };

    function rotateClass(whichClass, interval) {
        var i = 1;
        setInterval(function () {
            $('.' + whichClass).hide();
            $('.' + whichClass + ':eq(' + i + ')').show();
            if (++i >= $('.' + whichClass).length) {
                i = 0;
            }
        }, interval);
    }
    function publicInit() {
        if ($('.rotatingLogos').length > 0 || $('.rotatingImages').length > 0) {
            var interval = config.shortInterval;
            var whichClass = 'rotatingLogos';
            if ($('.rotatingImages').length > 0) {
                interval = config.longInterval;
                whichClass = 'rotatingImages';
                if ($('.imageSet').length > 0) {
                    for (var k = 0; k < $('.imageSet').length; k++) {
                        rotateClass('set' + k + ' .' + whichClass, interval);
                    }
                    return;
                }
            }
            rotateClass(whichClass, interval);
        }
        if ($('#cashForQuittersRHS').length > 0) {
            rotateClass('csrRotate', config.cashForQuittersRHS);
        }
    } /* public */
    return {
        init: publicInit
    };
} ();
var m3xSavingsFlash = function () { /* private*/
    var config = {
        "savings": [
            ["bannatyne.jpg", "/press-release.aspx?id=193"],
            ["barloworld.jpg", "/press-release.aspx?id=76"],
            ["britvic.jpg", "/press-release.aspx?id=124"],
            ["carillion.jpg", "/press-release.aspx?id=65"],
            ["cms.jpg", "/press-release.aspx?id=140"],
            ["currie-european.jpg", "/press-release.aspx?id=209"],
            ["four-seasons.jpg", "/press-release.aspx?id=208"],
            ["heatons.jpg", "/press-release.aspx?id=190"],
            ["igloo.jpg", "/press-release.aspx?id=119"],
            ["jcb.jpg", "/press-release.aspx?id=105"],
            ["mears.jpg", "/press-release.aspx?id=40"],
            ["millers.jpg", "/press-release.aspx?id=14"],
            ["movianto.jpg", "/press-release.aspx?id=38"],
            ["phs-group.jpg", "/press-release.aspx?id=197"],
            ["ringway.jpg", "/press-release.aspx?id=16"],
            ["total-foods.jpg", "/press-release.aspx?id=206"],
            ["unipart.jpg", "/press-release.aspx?id=22"],
            ["united-biscuits.jpg", "/press-release.aspx?id=189"],
            ["wigan-council.jpg", "/press-release.aspx?id=36"]
        ],
        "threexSavings": [
            ["threex/send-jobs.jpg", "/mobile-tracking/"],
            ["threex/paperless.jpg", "/mobile-tracking/"],
            ["threex/more-jobs.jpg", "/mobile-tracking/"],
            ["threex/a-to-b.jpg", "/mobile-tracking/"],
            ["threex/invoice-queries.jpg", "/mobile-tracking/"]
        ],
        "delay": 15000
    };

    function getSlates() {
        var path = "/content/images/visitor/flashAssets/savings/";
        var html = [];
        var savingsToUse = config.savings;
        var url = window.location;
        var re = /threex\.co\.uk/;
        if (re.test(url)) {
            savingsToUse = config.threexSavings;
        }
        savingsToUse.sort(function () {
            return (0.5 - Math.random());
        });
        savingsToUse.splice(0, 0, ["appstogo.jpg", "/vehicle-tracking/apps-to-go.aspx"]);
        savingsToUse.splice(1, 1, ["wow.jpg", "/wow/war-on-waste.aspx"]);
        savingsToUse.splice(2, 2, ["greenerbox-ad.jpg", "/vehicle-tracking/greener-vehicle-tracking.aspx"]);
        savingsToUse.splice(3, 3, ["mcc2.jpg", "/vehicle-tracking/mcc.aspx"]);
        for (var i = 0; i < 3; i++) {
            html[i] = "<a href=\"" + savingsToUse[i][1] + "\" style=\"display:none;\"><img id=\"savingsImage" + i + "\" src=\"" + path + savingsToUse[i][0] + "\" /></a>";
        }
        $("div.customerContent").append(html.join("\n"));
        $("img#savingsImage2").load(function () {
            animate();
        });
    }
    function animate() {
        $(function () {
            $("div.customerContent a:gt(0)").hide();
            setInterval(function () {
                $("div.customerContent a").eq(0).fadeOut().next('a').fadeIn().end().appendTo("div.customerContent");
            }, config.delay);
        });
    }
    function publicInit() {
        getSlates();
    } /* public */
    return {
        init: publicInit
    };
} ();
var m3xFrontNews = function () {
    var flashCount = 0;
    var newsCycleIterator = 1;
    var configNewsCycleDelay = 10000;
    var configFlashCycleDelay = 18000;
    var timeoutID;
    var flashElements = [];

    function cycleNews() {
        var newsCycleDelay = configNewsCycleDelay;
        if ($('div.newsEventItems:eq(' + newsCycleIterator + ')').children("div").length == 1) {
            initialiseFlash($('div.newsEventItems:eq(' + newsCycleIterator + ')'));
            newsCycleDelay = configFlashCycleDelay;
        }
        $('div.newsEventItems').hide();
        $('div.newsEventItems:eq(' + newsCycleIterator + ')').show();
        newsCycleIterator++;
        if (newsCycleIterator >= $('div.newsEventItems').length) {
            newsCycleIterator = 0;
            flashCount = 0;
        }
        if (timeoutID > 0) {
            clearTimeout(timeoutID);
        }
        timeoutID = setTimeout(cycleNews, newsCycleDelay);
    }
    function initialiseFlash(element) {
        var whichDiv = $(element).children("div");
        var thisId = $(whichDiv).attr("id");
        flashElements[flashCount] = new SWFObject($(whichDiv).attr("class"), "movie" + thisId, "252", "210", "9");
        flashElements[flashCount].write(thisId);
        flashCount++;
    }
    function publicInit() {
        var newsCycleDelay = configNewsCycleDelay;
        $("div.newsEventItems").each(function (index) {
            if ($(this).children("div").length == 1) {
                initialiseFlash($(this));
                if (index == 0) {
                    newsCycleDelay = configFlashCycleDelay;
                }
            }
        });
        timeoutID = setTimeout(cycleNews, newsCycleDelay); /* News scroller*/
        $().newsTicker({
            newsList: "#newsTickerList",
            tickerRate: 50,
            startDelay: 10,
            placeHolder1: "_"
        });
    } /* public */
    return {
        init: publicInit
    };
} ();
var m3xFrontTestimonials = function () { /* private*/
    var globalCount = 1;
    var index = 1;
    var extraContent = {
        entry1: {
            "title": "&pound;30,000 saved each year.",
            "body": "We have improved the service we provide and increased the efficiency of our operation.",
            "cite": "Tyrefix",
            "solution": "Mobile Workforce Management",
            "img": "tyrefix.jpg",
            "alt": "Tyrefix's Mobile Workforce Management solution"
        },
        entry2: {
            "title": "",
            "body": "By working in partnership with Masternaut we have developed solutions that are providing real benefits to Ringway, our clients and the communities in which we operate.",
            "cite": "Ringway",
            "solution": "Vehicle Tracking solution",
            "img": "ringway.jpg",
            "alt": "Ringway's vehicle tracking solution"
        },
        entry3: {
            "title": "&pound;200k saved each year.",
            "body": "We have improved efficiency, decreased working capital, and dramatically increased green benefits.",
            "cite": "United Biscuits",
            "solution": "Vehicle Tracking solution",
            "img": "unitedBiscuitsPic.jpg",
            "alt": "United Biscuit's vehicle tracking solution"
        },
        entry4: {
            "title": "A 40% increase in productivity across the fleet.",
            "body": "The mapping is simply superb and we see it as the best on the market.",
            "cite": "Ward Recycling",
            "solution": "Vehicle Tracking solution",
            "img": "wardRecycling.jpg",
            "alt": "Ward Recycling's vehicle tracking solution"
        },
        entry5: {
            "title": "10% reduction in travel time.",
            "body": "Masternaut's system also reduces emissions and has increased our responsiveness and customer satisfaction levels.",
            "cite": "Britvic",
            "solution": "Vehicle Tracking solution",
            "img": "britvicPic.jpg",
            "alt": "Britvic's vehicle tracking solution"
        },
        entry6: {
            "title": "&pound;100k saved each year.",
            "body": "By reducing unnecessary mileage we're set to reduce our annual fuel bill by half.",
            "cite": "Glencroft Construction",
            "solution": "Vehicle Tracking solution",
            "img": "glencroftConstruction.jpg",
            "alt": "Glencroft's vehicle tracking solution"
        },
        entry7: {
            "title": "A 10% reduction in transport costs.",
            "body": "The Masternaut system really does highlight inefficiencies.",
            "cite": "Creta Ceramica",
            "solution": "Vehicle Tracking solution",
            "img": "cretaCeramica.jpg",
            "alt": "Creta Ceramica's vehicle tracking solution"
        }
    };

    function changeTestimonial() {
        $(".testimonialsQuote").css("display", "none");
        $(".testimonialsQuote:eq(" + index + ")").css("display", "block");
        $(".testimonialsLink").css("text-decoration", "none");
        var linkLength = $(".testimonialsQuote").length / 2;
        if (index >= linkLength) {
            $(".testimonialsLink:eq(" + (index - linkLength) + ")").css("text-decoration", "underline");
        } else {
            $(".testimonialsLink:eq(" + index + ")").css("text-decoration", "underline");
        }
        $(".testimonialsImg").css("display", "none");
        $(".testimonialsImg:eq(" + index + ")").css("display", "block");
        globalCount = index = index + 1;
        if (globalCount == $(".testimonialsQuote").length) {
            globalCount = 0;
            index = 0;
        }
    }
    function publicInit() {
        if ($("#testimonialsQuote0").length > 0) {
            var html = [];
            for (var i = 1; i < 8; i++) {
                var thisTitle = extraContent["entry" + i].title != "" ? "<p class=\"quoteTitle\">" + extraContent["entry" + i].title + "</p>" : "";
                html.push("<div class=\"testimonialsQuote\" id=\"testimonialsQuote" + i + "\" style=\"display:none;\">\ <blockquote>\n" + thisTitle + "\n\ <p class=\"quoteBody\">\"" + extraContent["entry" + i].body + "\"</p>\ </blockquote>\ <cite>" + extraContent["entry" + i].cite + "</cite>\ <strong class=\"testimonialSolution\">" + extraContent["entry" + i].solution + "</strong>\ </div>\ <img id=\"testimonalsImage" + i + "\" src=\"/content/images/visitor/front/" + extraContent["entry" + i].img + "\" alt=\"" + extraContent["entry" + i].alt + "\" style=\"border:none;display:none;\" id=\"testimonialsImg" + i + "\" class=\"testimonialsImg\" />");
            }
            $("#testimonialsBox").append(html.join("\n"));
            $("#testimonialsBox span a").mouseover(function () {
                index = $("#testimonialsBox span a").index(this);
                globalCount = 0;
                changeTestimonial();
            });
            $("img#testimonalsImage1").load(function () {
                setInterval(changeTestimonial, 7000);
            });
        }
    }
    return {
        init: publicInit
    };
} (); /* About us page of office locations*/
var m3xMap = function () { /* private*/
    var config = {
        "aberfordMap": [53.821757, -1.344682, 8, ""],
        "skiptonMap": [53.95295, -2.089446, 7, ""],
        "belfastMap": [54.61312, -5.902277, 9, ""],
        "sydneyMap": [-33.705459, 151.209902, 8, ""],
        "portugalMap": [38.743196, -9.148838, 8, ""],
        "italyMap": [45.498948, 9.137226, 8, ""],
        "cybitMap": [52.337494, -0.209175, 9, ""],
        "parisMap": [48.873777, 2.233386, 11, ""],
        "germanyMap": [51.247961, 6.693294, 11, ""],
        "spainMap": [41.583208, 2.323654, 9, ""],
        "belgiumMap": [50.711888, 4.443202, 9, ""],
        "switzerlandMap": [46.550157, 6.512765, 9, ""],
        "franceRD1": [49.229384, 1.172267, 8, ""],
        "franceRD2": [45.913917, 6.149661, 9, ""]
    };

    function getMapLocation() {
        if ($('.locationMapsOZ').length > 0) {
            return 'http://www.masternaut.co.uk/map/OfficeLocator.html?lat=-33.705459&lon=151.209902&height=400&width=230&bgcolor=white&withDirection=1&title=&zoom=8';
        }
        return 'http://www.masternaut.co.uk/map/OfficeLocator.html?lat=53.821757&lon=-1.344682&height=400&width=230&bgcolor=white&withDirection=1&title=&zoom=8';
    }
    function publicInit() {
        $(".map-icon").fancybox({
            'titleShow': false,
            'transitionIn': 'none',
            'transitionOut': 'none',
            'scrolling': 'no',
            onStart: function (selectedArray, selectedIndex, selectedOpts) {
                var whichMap = selectedArray[selectedIndex].id;
                $('#locationMap').html("<iframe id=\"mapFrame\" allowtransparency=\"true\" src=\"http://www.masternaut.co.uk/map/OfficeLocator.html?lat=" + config[whichMap][0] + "&lon=" + config[whichMap][1] + "&height=400&width=600&bgcolor=white&withDirection=1&title=" + config[whichMap][3] + "&zoom=" + config[whichMap][2] + "\" width=\"600\" height=\"405\" scrolling=\"no\" frameborder=\"no\" style=\"border-width:0\"></iframe>");
                $('#mapFrame').attr('src', 'http://www.masternaut.co.uk/map/OfficeLocator.html?lat=' + config[whichMap][0] + '&lon=' + config[whichMap][1] + '&height=400&width=230&bgcolor=white&withDirection=1&title=' + config[whichMap][3] + '&zoom=' + config[whichMap][2]);
            },
            onClosed: function () {
                $('#locationMap').html("");
            },
            'autoScale': false
        });
    } /* public  */
    return {
        getMapLocation: getMapLocation,
        init: publicInit
    };
} ();
var m3xFancybox = function () { /* private*/
    var config = {
        uTubeVids: {
            aboutPage: ["NdSscNIOT0M", "CTiqqcv0va8"],
            newsPage: {
                "234": "aBr4vcpXNlU"
            }
        }
    };

    function requestCallBack() {
        $("#requestCallBack, #requestCallBackLink, #requestCallBackSent, #ourPurposePopup, #whyChoosePopup, #crmFindOutMore, #crmBenefitsPopup, #whyChooseHostedPopup").fancybox({
            'titleShow': false,
            'transitionIn': 'none',
            'transitionOut': 'none',
            'margin': '0',
            'padding': '0',
            'scrolling': 'no',
            'autoScale': false
        });
    }
    function createLightBoxes() {
        $("a.lightbox").fancybox({
            'transitionIn': 'none',
            'transitionOut': 'none',
            'scrolling': 'no',
            'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
                var prevNextButtons = "";
                if (currentArray.length > 1) {
                    if ((currentIndex + 1) == currentArray.length) {
                        prevNextButtons = '<a href="javascript:;" onclick="$.fancybox.prev();">Prev</a>';
                    } else {
                        prevNextButtons = '<a href="javascript:;" onclick="$.fancybox.next();">Next</a>';
                    }
                    return '<span class="fancyBoxFormatTitle">' + (currentIndex + 1) + ' of ' + currentArray.length + " (" + prevNextButtons + ')</span>';
                }
            },
            'autoScale': false
        });
    }
    function fancyboxGallerys() {
        $("a[rel=crm-screens]").fancybox({
            'transitionIn': 'none',
            'transitionOut': 'none',
            'scrolling': 'no',
            'autoScale': false
        });
    }
    function uTubeVideo() {
        $("a[rel=uTubePlayer]").fancybox({
            'transitionIn': 'none',
            'transitionOut': 'none',
            'scrolling': 'no',
            'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
                var prevNextButtons = "";
                if (currentArray.length > 1) {
                    if ((currentIndex + 1) == currentArray.length) {
                        prevNextButtons = '<a href="javascript:;" onclick="$.fancybox.prev();">Prev</a>';
                    } else {
                        prevNextButtons = '<a href="javascript:;" onclick="$.fancybox.next();">Next</a>';
                    }
                    return '<span class="fancyBoxFormatTitle">Part ' + (currentIndex + 1) + ' of ' + currentArray.length + " (" + prevNextButtons + ')</span>';
                }
                return prevNextButtons;
            },
            onStart: function (selectedArray, selectedIndex, selectedOpts) {
                var uTubeHtml = "";
                if (m3xPage.isAboutPage() || m3xPage.isHubPage() || m3xPage.isCsrPage() || m3xPage.isMapPage() || m3xPage.isVehiclePage()) {
                    uTubeHtml = '<script type="text/javascript" language="javascript">var ut = new SWFObject("http://www.youtube.com/v/' + config.uTubeVids.aboutPage[0] + '&enablejsapi=1&playerapiid=ytplayer&autoplay=1&showsearch=0&showinfo=0&hd=1&rel=0&cc_load_policy=0&iv_load_policy=3", "mymovie", "700", "420", "8", "#ffffff");ut.addParam("menu", "false");ut.write("uTubeVid");</script>';
                    if (selectedIndex) {
                        uTubeHtml = '<script type="text/javascript" language="javascript">var ut = new SWFObject("http://www.youtube.com/v/' + config.uTubeVids.aboutPage[1] + '&enablejsapi=1&playerapiid=ytplayer&autoplay=1&showsearch=0&showinfo=0&hd=1&rel=0&cc_load_policy=0&iv_load_policy=3", "mymovie", "700", "420", "8", "#ffffff");ut.addParam("menu", "false");ut.write("uTubeVid2");</script>';
                    }
                    $('#uTubeVid, #uTubeVid2').html(uTubeHtml);
                } else if (m3xPage.isNewsPage()) {
                    var qStrId = window.location.href.split('?')[1].split('&')[0].split('=')[1].split('#')[0];
                    if (config.uTubeVids.newsPage[qStrId]) {
                        $('#uTubeVid').html('<script type="text/javascript" language="javascript">var ut = new SWFObject("http://www.youtube.com/v/' + config.uTubeVids.newsPage[qStrId] + '&enablejsapi=1&playerapiid=ytplayer&autoplay=1&showsearch=0&showinfo=0&hd=1&rel=0&cc_load_policy=0&iv_load_policy=3", "mymovie", "700", "420", "8", "#ffffff");ut.addParam("menu", "false");ut.write("uTubeVid");</script>');
                    }
                }
            },
            onClosed: function () {
                $('#uTubeVid, #uTubeVid2').html("");
            },
            'autoScale': false
        });
    }
    function getVideo(whichVid, isRadio, vidWidth, vidHeight) {
        var pathArr = whichVid.split("/");
        var flashPath = pathArr.slice(0, (pathArr.length - 1)).join("/") + "/";
        whichVid = pathArr[pathArr.length - 1];
        var api = flashembed("vid", {
            src: '/content/flash/FlowPlayerLight.swf',
            width: vidWidth,
            height: vidHeight,
            bgcolor: '#ffffff'
        }, {
            config: {
                videoFile: flashPath + whichVid + '.flv',
                autoPlay: false,
                initialScale: 'scale',
                useNativeFullScreen: false,
                loop: false,
                showFullScreenButton: false,
                showMenu: false
            }
        });
    }
    function genericVideo() {
        $("#vidPlayer, .iglooVid").fancybox({
            'titleShow': false,
            'transitionIn': 'none',
            'transitionOut': 'none',
            'scrolling': 'no',
            onStart: function () {
                var whichVid, isRadio, vidWidth, vidHeight;
                if ($('.corpVid').length > 0) {
                    whichVid = '/content/flash/masternaut3x';
                    isRadio = false;
                    vidWidth = 768;
                    vidHeight = 489;
                } else if ($('.lokateVid').length > 0) {
                    whichVid = '/content/flash/lokate_product_video';
                    isRadio = false;
                    vidWidth = 640;
                    vidHeight = 480;
                } else if ($('.iglooVid').length > 0) {
                    whichVid = '/content/flash/iglooCaseStudy';
                    isRadio = false;
                    vidWidth = 640;
                    vidHeight = 361;
                }
                getVideo(whichVid, isRadio, vidWidth, vidHeight);
            },
            onClosed: function () {
                $('#vid').html("");
            },
            'autoScale': false
        });
        if ($(".pressreleaseVid").length > 0) {
            $(".pressreleaseVid").fancybox({
                'titleShow': false,
                'transitionIn': 'none',
                'transitionOut': 'none',
                'scrolling': 'no',
                'href': '#vid',
                onStart: function (selectedArray, selectedIndex, selectedOpts) {
                    var vidArgs = selectedArray[selectedIndex].href;
                    vidArgs = vidArgs.replace("javascript:getVideo('", "").replace(");", "");
                    var vidArgsArr = vidArgs.split(',');
                    var whichVid = vidArgsArr[0].replace("'", "");
                    var isRadio = vidArgsArr[1].replace("%20", "");
                    var vidWidth = vidArgsArr[3].replace("%20", "");
                    var vidHeight = vidArgsArr[4].replace("%20", "");
                    $('#vid').css({
                        width: vidWidth + "px",
                        height: vidHeight + "px"
                    });
                    getVideo(whichVid, isRadio, vidWidth, vidHeight);
                },
                onClosed: function () {
                    $('#vid').html("");
                },
                'autoScale': false
            });
        }
    }
    function publicInit() {
        requestCallBack();
        fancyboxGallerys();
        genericVideo();
        if (m3xPage.isAboutPage() || m3xPage.isHubPage() || m3xPage.isCsrPage() || m3xPage.isMapPage() || m3xPage.isVehiclePage() || m3xPage.isNewsPage()) {
            uTubeVideo();
        }
        if (m3xPage.hasLightbox()) {
            createLightBoxes();
        }
    } /* public*/
    return {
        init: publicInit
    };
} ();
var m3xPartners = function () { /* private*/


    function publicInit() {
        $(".accreditationPara").css({
            "font-size": "1.2em",
            "line-height": "1.4em",
            "padding": "20px"
        });
        $(".currentPartnersLogo").fancybox({
            'titleShow': false,
            'transitionIn': 'none',
            'transitionOut': 'none',
            'scrolling': 'no',
            'autoScale': false
        });
    } /* public*/
    return {
        init: publicInit
    };
} ();
var m3xSpinningLogos = function () { /* private*/
    var config = {
        path: "/content/images/visitor/spinningLogos/",
        logoTotal: 69,
        logoLimit: 19,
        logoOrder: [],
        delay: 3000
    };

    function getLogos() {
        var html = [];
        for (var i = 0; i <= config.logoTotal; i++) {
            config.logoOrder[i] = i;
        }
        config.logoOrder.sort(function () {
            return (0.5 - Math.random());
        });
        for (var i = 0; i <= config.logoLimit; i++) {
            if ((i == 0 || i % 5 == 0)) {
                html[i] = "<span class=\"logoRow\" style=\"display:none;\">\n";
            } else {
                html[i] = "";
            }
            html[i] += "<span class=\"imgHolder\" style=\"background-image: url(" + config.path + config.logoOrder[i] + ".gif);\"></span>\n";
            if ((i + 1) % 5 == 0 || i == config.logoLimit) {
                html[i] += "</span>\n";
            }
        }
        $("span#spinningLogos").append(html.join(""));
        $("span#spinningLogos span.logoRow:eq(0)").show();
    }
    function animate() {
        $(function () {
            setInterval(function () {
                $("span#spinningLogos span.logoRow").eq(0).fadeOut().next('span.logoRow').fadeIn().end().appendTo("span#spinningLogos");
            }, config.delay);
        });
    }
    function publicInit() {
        getLogos();
        animate();
    } /* public*/
    return {
        init: publicInit
    };
} ();
$(document).ready(function () { /* Initialise event listeners*/
    m3xPage.init(); /* Sort some css issues with IE6 for the accordian down arrows*/
    if (m3xPage.isIE() && m3xPage.browserVersion() < 7) {
        m3xPage.fixDownArrows();
    } /* If we're not on the partner page*/
    if (m3xPage.isntPartnerPage() && !m3xPage.isVehiclePage()) {
        m3xFancybox.init();
    } /* If we're on current Partners page*/
    if (m3xPage.isCurrentPartners()) {
        m3xPartners.init();
    } /* Check query string for stuff*/
    m3xPage.checkQueryParams();
});
window.onload = function () { /* Load extra home page stuff after the page has loaded*/
    if (m3xPage.isHomePage()) {
        m3xSavingsFlash.init();
        m3xSpinningLogos.init();
        m3xFrontTestimonials.init();
        m3xFrontNews.init();
    } /* If we're on about page*/
    else if (m3xPage.isMapPage()) {
        m3xPage.generateMap();
    }
};
