﻿function queryStringManager(qs)
{ // optionally pass a querystring to parse
    this.params = {};

    if (qs == null) qs = location.search.substring(1, location.search.length);
    if (qs.length == 0) return;

    qs = qs.replace(/\+/g, ' ');
    var args = qs.split('&');

    for (var i = 0; i < args.length; i++)
    {
        var pair = args[i].split('=');
        var name = decodeURIComponent(pair[0]);

        var value = (pair.length == 2)
		        ? decodeURIComponent(pair[1])
		        : name;

        this.params[name] = value;
    }
}
queryStringManager.prototype.get = function (key, default_)
{
    var value = this.params[key];
    return (value != null) ? value : default_;
};
queryStringManager.prototype.contains = function (key)
{
    var value = this.params[key];
    return (value != null);
};

var IsDesignMode = false;
var animating = false;
var popupmanager = null;
var newsCategory = null;
var newsSort = null;

if (!Array.prototype.indexOf)
{
    Array.prototype.indexOf = function (o)
    {
        var _this = this;
        try
        {
            for (var _i = 0; _i < _this.length; _i++)
            {
                if (_this[_i] == o)
                    return _i;
            }
            return -1;
        }
        finally
        {
            _this = null;
        }
    };
}

function escapeString(s)
{
    var sTemp = s.replace(new RegExp("&amp;", "g"), "&");
    sTemp = escape(sTemp);
    return sTemp.replace(new RegExp("[\+]", "g"), "%2B");
}

function unescapeString(s)
{
    return unescape(s.replace(new RegExp("%2B", "g"), "+"));
}

$(document).ready(function ()
{
    /* Filter Links
    ******************************************************************************/
    $("#pSearchCaseStudies").show();
    $("#pSearchClients").show();
    $("#pSearchAwards").show();

    //$(".NoJS").remove();
    $(".Grid .Item a").show();

    /* Carousel
    ******************************************************************************/
    //$(".Carousel").indigoCarousel();

    /* Header
    ******************************************************************************/
    $(".ExpandableContent").brassHeader();

    // Speech bubble
    $(".ContactUs .PhoneNumber a").hoverIntent(function ()
    {
        var 
            isInternetExplorer = new RegExp("MSIE", "g").test(window.navigator.userAgent),
            version = 0;

        if (isInternetExplorer)
        {
            var 
                iMSIE = window.navigator.userAgent.indexOf("MSIE ") + 5,
                iSemiColon = window.navigator.userAgent.indexOf(";", iMSIE) - 1;

            if (iMSIE > -1 && iSemiColon > -1)
            {
                try
                {
                    version = Math.floor(parseFloat(window.navigator.userAgent.substring(iMSIE, iSemiColon)));
                }
                catch (e) { }
            }
        }

        $(".ContactUs .Speech").css({
            "top": $(".ContactUs .PhoneNumber a").position().top,   // - $(".ContactUs .Speech").outerHeight(),
            "right": 50
        });

        if (!(isInternetExplorer && version == 8))
        {
            $(".ContactUs .Speech").fadeIn(250);
        }
        else
        {
            $(".ContactUs .Speech").css({
                "display": "block"
            });
        }
    },
    function ()
    {
        var 
            isInternetExplorer = new RegExp("MSIE", "g").test(window.navigator.userAgent),
            version = 0;

        if (isInternetExplorer)
        {
            var 
                iMSIE = window.navigator.userAgent.indexOf("MSIE ") + 5,
                iSemiColon = window.navigator.userAgent.indexOf(";", iMSIE) - 1;

            if (iMSIE > -1 && iSemiColon > -1)
            {
                try
                {
                    version = Math.floor(parseFloat(window.navigator.userAgent.substring(iMSIE, iSemiColon)));
                }
                catch (e) { }
            }
        }

        if (!(isInternetExplorer && version == 8))
        {
            $(".ContactUs .Speech").fadeOut(250);
        }
        else
        {
            $(".ContactUs .Speech").css({
                "display": "none"
            });
        }
    });

    /* Home
    ******************************************************************************/
    $(".Home .CaseStudy .Overlay")
        .removeClass("Overlay")
        .addClass("Text")
        .append('<div class="Corner"></div>')
        .children("span").css({ "position": "relative",
            "display": "block",
            "opacity": "0",
            "z-index": "75"
        });

    // Case study hover behaviour
    $(".Home .CaseStudy .Text").hoverIntent(function ()
    {
        $(this).addClass("Item-Hover");
        $(".Corner", this).animate({ borderWidth: 185 }, 250).siblings("span").delay(250).animate({ opacity: 1 }, 150);
    },
    function ()
    {
        $(this).removeClass("Item-Hover");
        $(this).children("span").animate({ opacity: 0 }, 100).siblings(".Corner").delay(100).animate({ borderWidth: 20 }, 250);
    });

    /* Radio Buttons
    ******************************************************************************/
    BeautifyRadioButtons();

    /* Pop ups
    ******************************************************************************/
    popupmanager = new popUpManager();
    var qs = new queryStringManager();
    var designmode = qs.get("designmode", "");
    IsDesignMode = designmode;
    if (designmode != "on")
        popupmanager.initialise();

    /* Case Study
    ******************************************************************************/
//    if (IsDesignMode != null && !IsDesignMode)
//    {
//        $(".CaseStudy .Print").show();

//        $(".CaseStudy .HiddenContent").each(function ()
//        {
//            $(this).attr("id", $(this).outerHeight());
//        });
//        $(".CaseStudy .HiddenContent").css({ "height": 0 });
//        $(".CaseStudy .Expand").fadeIn(100);

//        $(".CaseStudy .Expand a").toggle(function ()
//        {
//            if (!animating)
//            {
//                animating = true;
//                var _this = this;

//                _gaq.push(['_trackEvent', 'campaign_summary', 'expand', PAGE_NAME]);

//                var hidden = $(this).parent().parent().siblings(".HiddenContent");
//                $(hidden).stop().animate({ height: $(hidden).attr("id") }, 500, function ()
//                {
//                    $(_this).text("Hide").siblings("span").text("-");
//                    animating = false;
//                });
//            }
//        },
//        function ()
//        {
//            if (!animating)
//            {
//                animating = true;
//                var _this = this;

//                _gaq.push(['_trackEvent', 'campaign_summary', 'collapse', PAGE_NAME]);

//                $(this).parent().parent().siblings(".HiddenContent").stop().animate({ height: 0 }, 500, function ()
//                {
//                    $(_this).text("Expand to find out more").siblings("span").text("+");
//                    animating = false;
//                });
//            }
//        });
//    }
//    else
//        $(".HiddenContent").css({ "display": "block" });

    /* News
    /******************************************************************************/
    $(".News select").hide();
    if ($.browser.msie && ($.browser.version == 6 || $.browser.version == 7))
        $(".News .BrassDropDownList").css({ "display": "inline", "zoom": "1" });
    else
        $(".News .BrassDropDownList").css({ "display": "inline-block" });

    // Category dropdown
    $(".News .ViewCateogry").brassDropDownList({
        selectedValue: newsCategory,
        onchange: function (text)
        {
            // Track category filtering
            switch (text)
            {
                case "All categories":
                    _gaq.push(["_trackEvent", "news", "filter_category", "all"]);
                    break;
                case "Business":
                    _gaq.push(["_trackEvent", "news", "filter_category", "business"]);
                    break;
                case "News":
                    _gaq.push(["_trackEvent", "news", "filter_category", "news"]);
                    break;
            }
        }
    });

    // Order by dropdown
    $(".News .OrderBy").brassDropDownList({
        followLinks: false,
        selectedValue: newsSort,
        click: function (item)
        {
            // Make webservice call
            var service = new indigo.communication.webService(WEBSITE_ROOT_URL + "NewsService.asmx");
            service.getScalar("NewsItems_SetOrdering", "Ordering=" + $(item).attr("href").replace("../", "").replace("../", "").replace("#", ""), true, function (ds)
            {
                window.location.reload();
            });
        },
        onchange: function (text)
        {
            // Track order filtering
            switch (text)
            {
                case "Date - Latest first":
                    _gaq.push(["_trackEvent", "news", "filter_date", "date_oldest"]);
                    break;
                case "Date - Oldest first":
                    _gaq.push(["_trackEvent", "news", "filter_date", "date_newest"]);
                    break;
                case "Alphabetically - A to Z":
                    _gaq.push(["_trackEvent", "news", "filter_date", "a-z"]);
                    break;
                case "Alphabetically - Z to A":
                    _gaq.push(["_trackEvent", "news", "filter_date", "z-a"]);
                    break;
            }
        }
    });

    /* Our Approach
    /******************************************************************************/
    if (IsDesignMode != null && !IsDesignMode && $(".OurApproach").length > 0)
    {
        // Init tabs
        $(".Tabs .Tab-Holder").removeClass().addClass("Tab-ViewPort");
        $(".Tabs .Content-Item").children("div").width(570);
        $(".Tabs .Links").removeClass().addClass("TabStrip");

        if ($.browser.msie && $.browser.version == 6)
        {
            $(".TabStrip .Background").each(function ()
            {
                $(this).css({
                    "width": $(this).parent().outerWidth()
                });
            });
        }

        $(".TabStrip a").click(function (evt)
        {
            evt.preventDefault();
            switch ($(".TabStrip a").index($(this)))
            {
                case 0:
                    _gaq.push(["_trackPageview", "/our-approach/Intro"]);
                    break;
                case 1:
                    _gaq.push(["_trackPageview", "/our-approach/Explore"]);
                    break;
                case 2:
                    _gaq.push(["_trackPageview", "/our-approach/Create"]);
                    break;
                case 3:
                    _gaq.push(["_trackPageview", "/our-approach/Connect"]);
                    break;
                case 4:
                    _gaq.push(["_trackPageview", "/our-approach/Invent"]);
                    break;
            }

            if (!$(this).parent().hasClass("Selected"))
            {
                var _this = this;
                $(".TabStrip a").parent().removeClass("Selected");
                $(".TabStrip .Background").stop().animate({ height: 0 }, 150);
                $(".Tab-Content").stop().animate({
                    left: -$(".Tab-Content").children("[name=" + $(this).attr("href").replace("#", "") + "]").position().left
                }, 750, function ()
                {
                    $(".Background", $(_this).parent()).stop().animate({
                        height: $(_this).outerHeight() + 10
                    }, 250, function ()
                    {
                        $(_this).parent().addClass("Selected");

                        if ($(".TabStrip .Tab").first().hasClass("Selected"))
                            $(".Tabs .Previous").fadeOut(250);
                        else
                            $(".Tabs .Previous").fadeIn(250);

                        if ($(".TabStrip .Tab").last().hasClass("Selected"))
                            $(".Tabs .Next").fadeOut(250);
                        else
                            $(".Tabs .Next").fadeIn(250);
                    });
                });
            }
        });
        $(".TabStrip a").first().click();

        // Next & previous
        $(".Tabs .Previous, .Tabs .Next").hover(function ()
        {
            $("div", this).fadeIn(250);
        },
        function ()
        {
            $("div", this).fadeOut(250);
        });

        $(".Tabs .Previous div").click(function ()
        {
            if ($(".TabStrip .Selected").prev().length > 0)
                $("a", $(".TabStrip .Selected").prev()).click();
        });

        $(".Tabs .Next div").click(function ()
        {
            if ($(".TabStrip .Selected").next().length > 0)
                $("a", $(".TabStrip .Selected").next()).click();
        });
    }
    else
    {
        $(".Tabs").addClass("Tabs-CMS");
        $(".Tabs .Links").removeClass().addClass("TabStrip");
    }

    /* Awards
    /******************************************************************************/
    $(".Awards").indigoSlidingGrid({
        filterFunctionName: "AwardPages_Filter",
        itemOnExpand: function (item)
        {
            _gaq.push(['_trackEvent', 'our_awards', 'view_summary', "'" + $(".Title", item.item).html() + "'"]);
        },
        itemOnHover: function (item)
        {
            _gaq.push(['_trackEvent', 'our_awards', 'mouse_over', "'" + $(".Title", item.item).html() + "'"]);
        },
        itemButtonOnClick: function (item)
        {
            _gaq.push(['_trackEvent', 'our_awards', 'view_our_casestudies', "'" + $(".Title", item.item).html() + "'"]);
        },
        filterOpen: function () { _gaq.push(['_trackEvent', 'our_awards', 'filter_open']); },
        filterSubmit: function () { _gaq.push(['_trackEvent', 'our_awards', 'filter_submit']); },
        filterClear: function () { _gaq.push(['_trackEvent', 'our_awards', 'filter_clear']); }
    });

    /* Our Clients
    /******************************************************************************/
    $(".OurClients").indigoSlidingGrid({
        filterFunctionName: "ClientPages_Filter",
        itemOnExpand: function (item)
        {
            _gaq.push(['_trackEvent', 'our_clients', 'view_summary', "'" + $(".Title", item.item).html() + "'"]);
        },
        itemOnHover: function (item)
        {
            _gaq.push(['_trackEvent', 'our_clients', 'mouse_over', "'" + $(".Title", item.item).html() + "'"]);
        },
        itemButtonOnClick: function (item)
        {
            _gaq.push(['_trackEvent', 'our_clients', 'view_our_other_work', "'" + $(".Title", item.item).html() + "'"]);
        },
        filterOpen: function () { _gaq.push(['_trackEvent', 'our_clients', 'filter_open']); },
        filterSubmit: function () { _gaq.push(['_trackEvent', 'our_clients', 'filter_submit']); },
        filterClear: function () { _gaq.push(['_trackEvent', 'our_clients', 'filter_clear']); }
    });

    $(".GetInTouch", ".OurClients").click(function ()
    {
        _gaq.push(['_trackEvent', 'our_clients', 'get_in_touch']);
    });

    /* Our Work
    /******************************************************************************/
    $(".OurWork").indigoSlidingGrid({
        name: "our-work",
        cornerSize: 21,
        cornerAnimateSize: 41,
        itemHeight: 175,
        itemsCanExpand: false,
        filterFunctionName: "CaseStudyPages_Filter",
        itemOnClick: function (item)
        {
            _gaq.push(['_trackEvent', 'our_work', 'click_to_casestudy', "'" + $(".Title", item.item).html() + "'"]);
        },
        itemOnHover: function (item)
        {
            _gaq.push(['_trackEvent', 'our_work', 'mouse_over', "'" + $(".Title", item.item).html() + "'"]);
        },
        filterOpen: function () { _gaq.push(['_trackEvent', 'our_work', 'filter_open']); },
        filterSubmit: function () { _gaq.push(['_trackEvent', 'our_work', 'filter_submit']); },
        filterClear: function () { _gaq.push(['_trackEvent', 'our_work', 'filter_clear']); }
    });

    /* Vacancies
    ******************************************************************************/
//    if (IsDesignMode != null && !IsDesignMode)
//    {
//        $(".Vacancies .Vacancy .HiddenContent").each(function ()
//        {
//            $(this).attr("id", $(this).outerHeight());
//        });
//        $(".Vacancies .Vacancy .HiddenContent").css({ "height": 0 });
//        $(".Vacancies .Vacancy .Expand").fadeIn(100);

//        $(".Vacancies .Vacancy .Expand a").toggle(function ()
//        {
//            if (!animating)
//            {
//                animating = true;
//                var _this = this;
//                var hidden = $(this).parent().parent().siblings(".HiddenContent");
//                $(hidden).stop().animate({ height: $(hidden).attr("id") }, 500, function ()
//                {
//                    $(_this).text("Hide").siblings("span").text("-");
//                    animating = false;
//                });
//            }
//        },
//        function ()
//        {
//            if (!animating)
//            {
//                animating = true;
//                var _this = this;
//                $(this).parent().parent().siblings(".HiddenContent").stop().animate({ height: 0 }, 500, function ()
//                {
//                    $(_this).text("Tell me more").siblings("span").text("+");
//                    animating = false;
//                });
//            }
//        });
//    }
//    else
//        $(".HiddenContent").css({ "display": "block" });

    /* Search
    ******************************************************************************/
    $(".Header .Search .TextBox").focus(function ()
    {
        $(this).parent().addClass("Search-Highlight");
    });

    $(".Header .Search .TextBox").blur(function ()
    {
        $(this).parent().removeClass("Search-Highlight");
    });

    $(".Search select").hide();
    if ($.browser.msie && ($.browser.version == 6 || $.browser.version == 7))
        $(".Search .BrassDropDownList").css({ "display": "inline", "zoom": "1" });
    else
        $(".Search .BrassDropDownList").css({ "display": "inline-block" });

    $(".Search .OrderBy").brassDropDownList({
        followLinks: false,
        selectedValue: "#LatestFirst",
        click: function (item)
        {
            // Make webservice call
            var service = new indigo.communication.webService(WEBSITE_ROOT_URL + "NewsService.asmx");
            service.getDataSet("SearchItems_SetOrdering", "Ordering=" + $(item).attr("href").replace("../", "").replace("../", "").replace("#", ""), true, function (ds)
            {
                window.location.reload();
            });
        }
    });

    /* Services
    ******************************************************************************/
//    if (IsDesignMode != null && !IsDesignMode)
//    {
//        $(".ServiceOverview .HiddenContent").each(function ()
//        {
//            $(this).attr("id", $(this).outerHeight());
//        });
//        $(".ServiceOverview .HiddenContent").css({ "height": 0 });
//        $(".ServiceOverview .Expand").fadeIn(100);

//        $(".ServiceOverview .Expand a").toggle(function ()
//        {
//            if (!animating)
//            {
//                animating = true;
//                var _this = this;
//                var hidden = $(this).parent().parent().siblings(".HiddenContent");
//                $(hidden).stop().animate({ height: $(hidden).attr("id") }, 500, function ()
//                {
//                    if ($(this).siblings(".Expand").hasClass("Left"))
//                        $(this).siblings(".Expand").animate({ width: 720 }, 500);

//                    $(_this).text("Hide").siblings("span").text("-");
//                    animating = false;
//                });
//            }
//        },
//        function ()
//        {
//            if (!animating)
//            {
//                animating = true;
//                var _this = this;
//                var duration = 0;
//                if ($(this).parent().parent().hasClass("Left"))
//                    duration = 250;

//                $(this).parent().parent().animate({ width: 160 }, duration, function ()
//                {
//                    $(this).siblings(".HiddenContent").stop().animate({ height: 0 }, 500, function ()
//                    {
//                        $(_this).text("Tell me more").siblings("span").text("+");
//                        animating = false;
//                    });
//                });
//            }
//        });
//    }
//    else
//        $(".HiddenContent").css({ "display": "block" });

    $(".ServiceOverview .CaseStudy .Overlay")
        .removeClass("Overlay")
        .addClass("Text")
        .append('<div class="Corner"></div>')
        .children("span").css({ "position": "relative",
            "display": "block",
            "opacity": "0",
            "z-index": "75"
        });

    // Case study hover behaviour
    $(".ServiceOverview .CaseStudy .Text").hoverIntent(function ()
    {
        $(this).addClass("Item-Hover");
        $(".Corner", this).animate({ borderWidth: 185 }, 250).siblings("span").delay(250).animate({ opacity: 1 }, 150);
    },
    function ()
    {
        $(this).removeClass("Item-Hover");
        $(this).children("span").animate({ opacity: 0 }, 100).siblings(".Corner").delay(100).animate({ borderWidth: 20 }, 250);
    });

    /* Footer
    ******************************************************************************/
    //    var _footerHeight = $(".ExploreBrass").height();
    //    $(".Footer .Explore").toggle(function (evt)
    //    {
    //        $(this).html("<span>-</span> Hide");

    //        var 
    //            _exploreBrass = $(".ExploreBrass"),
    //            _htmlBody = $("html,body");

    //        try
    //        {
    //            _htmlBody.stop().animate({ scrollTop: _htmlBody.scrollTop() + _footerHeight }, { duration: 1000 });
    //            _exploreBrass.stop().animate({ height: "toggle" }, { duration: 1000 });
    //        }
    //        finally
    //        {
    //            _exploreBrass = null;
    //            _htmlBody = null;
    //        }

    //    }, function (evt)
    //    {
    //        $(this).html("<span>+</span> Explore Brass");
    //        $(".ExploreBrass").stop().animate({ height: "toggle" }, 1000);
    //    });

    /*****************************************************************************************************************************/
    /* Forms
    /*****************************************************************************************************************************/
    // Highlight - focus
    $(".Form .TextBox, .CVUpload .TextBox").live("focus", function ()
    {
        if ($(this).hasClass("TextBox-Small"))
            $(this).parent().append('<div id="TextBox-Highlight-' + $(this).attr("id") + '" class="TextBox-Small-Highlight"></div>');
        else
            $(this).parent().append('<div id="TextBox-Highlight-' + $(this).attr("id") + '" class="TextBox-Highlight"></div>');

        $("#TextBox-Highlight-" + $(this).attr("id")).css({
            "top": $(this).position().top - 7,
            "left": $(this).position().left - 7
        }).fadeIn(250);
    });

    // Highlight - blur
    $(".Form .TextBox, .CVUpload .TextBox").live("blur", function ()
    {
        $("#TextBox-Highlight-" + $(this).attr("id")).fadeOut(250, function ()
        {
            $(this).remove();
        });
    });

    // Javascript & non-js buttons
    $(".Form input.Submit").css({
        "display": "none"
    });

    if ($.browser.msie && ($.browser.version == 6 || $.browser.version == 7))
        $(".Form a.Submit").css({ "display": "inline", "zoom": "1" });
    else
        $(".Form a.Submit").css({ "display": "inline-block" });

    /* C.V. Upload
    /******************************************************************************/
    var __cvUploader = null;
    if (typeof __cvUploaderClientID != "undefined")
        __cvUploader = new cvUploader(__cvUploaderClientID);

    $(".CVUpload .Close").click(function (evt)
    {
        evt.preventDefault();
        popupmanager.close();
    });

    if (IsDesignMode)
        $(".CVUpload .ThankYou").css({ "display": "block", "height": $(".CVUpload .Form").height() });

    $(".CVUpload .Submit").click(function (evt)
    {
        evt.preventDefault();
        var _parent = $(this).parent().parent().parent();
        var validator = new validation();
        var isValid = true;

        if ($(".RoleType", _parent).length > 0)
        {
            // Role type
            if ($(".RadioButton-Freelance input", _parent).attr("checked") == false
                && $(".RadioButton-WorkPlacement input", _parent).attr("checked") == false
                && $(".RadioButton-Speculative input", _parent).attr("checked") == false)
            {
                isValid = false;
                $(".RoleType p").addClass("Label-Error").html('What kind of work are you looking for? <span="Highlight">*</span> Please indicate what kind of work you\'re looking for.');
            }
            else
                $(".RoleType p").removeClass("Label-Error").html('What kind of work are you looking for? <span="Highlight">*</span>');
        }

        // First name - required field
        if (!validator.required($(".TextBox-FirstName", _parent).val()))
        {
            $(".TextBox-FirstName", _parent).prev("label")
                .addClass("Label-Error")
                .html('First Name <span class="Highlight">*</span> Please enter your first name.');
            isValid = false;
        }
        else
            $(".TextBox-FirstName", _parent).prev("label")
                .removeClass("Label-Error")
                .html('First Name <span class="Highlight">*</span>');

        // Surname - required field
        if (!validator.required($(".TextBox-Surname", _parent).val()))
        {
            $(".TextBox-Surname", _parent).prev("label")
                .addClass("Label-Error")
                .html('Surname <span class="Highlight">*</span> Please enter your surname.');
            isValid = false;
        }
        else
            $(".TextBox-Surname", _parent).prev("label")
                .removeClass("Label-Error")
                .html('Surname <span class="Highlight">*</span>');

        // Email - required field & must be valid email
        if (!validator.required($(".TextBox-Email", _parent).val()))
        {
            $(".TextBox-Email", _parent).prev("label")
                .addClass("Label-Error")
                .html('Email <span class="Highlight">*</span> Please enter your email.');
            isValid = false;
        }
        else if (!validator.email($(".TextBox-Email", _parent).val()))
        {
            $(".TextBox-Email", _parent).prev("label")
                .addClass("Label-Error")
                .html('Email <span class="Highlight">*</span> Whoops! Please enter a valid email.');
            isValid = false;
        }
        else
            $(".TextBox-Email", _parent).prev("label")
                .removeClass("Label-Error")
                .html('Email <span class="Highlight">*</span>');

        // Confirm email - required field
        if (!validator.match($(".TextBox-Email", _parent).val(), $(".TextBox-ConfirmEmail", _parent).val()))
        {
            $(".TextBox-ConfirmEmail").prev("label")
                .addClass("Label-Error")
                .html('Confirm email <span class="Highlight">*</span> Please confirm you email address.');
            isValid = false;
        }
        else
            $(".TextBox-ConfirmEmail").prev("label")
                .removeClass("Label-Error")
                .html('Confirm email <span class="Highlight">*</span>');

        // Telephone - required field
        if (!validator.required($(".TextBox-Telephone", _parent).val()))
        {
            $(".TextBox-Telephone", _parent).prev("label")
                .addClass("Label-Error")
                .html('Telephone <span class="Highlight">*</span> Please enter your telephone.');
            isValid = false;
        }
        else
            $(".TextBox-Telephone", _parent).prev("label")
                .removeClass("Label-Error")
                .html('Telephone <span class="Highlight">*</span>');

        if (!__cvUploader || !__cvUploader.hasFile)
        {
            $(".Upload", _parent).addClass("Upload-Error");
            isValid = false;
        }
        else
        {
            $(".Upload", _parent).removeClass("Upload-Error");
        }

        // CV Upload - required field

        if (isValid)
        {
            $(".Sending", _parent).css({ "height": $(".Form", _parent).height() });
            $(".Sending h3", _parent).css({ "line-height": ($(".Form", _parent).height() - 70) + "px" });

            $(".Form", _parent).fadeOut(150, function ()
            {
                $(".Sending", _parent).fadeIn(150, function ()
                {
                    // Make webservice call
                    var service = new indigo.communication.webService(WEBSITE_ROOT_URL + "plugins/contact/dataservice.asmx");
                    service.getDataSet("FormSubmissions_AddUpdate", "ID=0&TypeLKP=" + $(_parent).children("input[type=hidden]").val(), true, function (ds)
                    {
                        var id = ds.tables.items[0].rows.items[0].getValue("fsu_ID");
                        service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=FirstName&Value=" + escapeString($(".TextBox-FirstName", _parent).val()), true);
                        service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=Surname&Value=" + escapeString($(".TextBox-Surname", _parent).val()), true);
                        service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=Email&Value=" + escapeString($(".TextBox-Email", _parent).val()), true);
                        service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=Telephone&Value=" + escapeString($(".TextBox-Telephone", _parent).val()), true);

                        var 
                            roleType = "",
                            role = "";

                        if ($(".RoleType", _parent).length > 0)
                        {
                            if ($(".RadioButton-Freelance input", _parent).attr("checked"))
                            {
                                service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=Freelance&Value=true", true);
                                roleType = "Freelance";
                            }
                            if ($(".RadioButton-WorkPlacement input", _parent).attr("checked"))
                            {
                                service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=WorkPlacement&Value=true", true);
                                roleType = "WorkPlacement";
                            }
                            if ($(".RadioButton-Speculative input", _parent).attr("checked"))
                            {
                                service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=Speculative&Value=true", true);
                                roleType = "Speculative";
                            }
                        }
                        else
                        {
                            service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=Vacancy&Value=" + $(".Form", _parent).children("p").children(".Highlight").text(), true);
                            role = $(".Form", _parent).children("p").children(".Highlight").text();
                        }

                        $(".Sending", _parent).fadeOut(150, function ()
                        {
                            $(".ThankYou", _parent).fadeIn(250);
                        });

                        service.getDataSet("CVUpload_SendEmails", "UploadKeyHiddenField=" + escapeString($(_parent).children("input[type=hidden]")[1].value) +
                                                                    "&RoleType=" + escapeString(roleType) +
                                                                    "&Role=" + escapeString(role) +
                                                                    "&FirstName=" + escapeString($(".TextBox-FirstName", _parent).val()) +
                                                                    "&Surname=" + escapeString($(".TextBox-Surname", _parent).val()) +
                                                                    "&Telephone=" + escapeString($(".TextBox-Telephone", _parent).val()) +
                                                                    "&Email=" + escapeString($(".TextBox-Email", _parent).val()));
                    },
                    function ()
                    {
                        // Oh no!
                    });
                });
            });
        }
    });

    /* Gallery Sign Up
    /******************************************************************************/
    $(".GallerySignUp .Close").click(function (evt)
    {
        evt.preventDefault();
        popupmanager.close();
    });

    if (IsDesignMode)
        $(".GallerySignUp .ThankYou").css({ "display": "block", "height": $(".CVUpload .Form").height() });

    $(".GallerySignUp .Submit").click(function (evt)
    {
        evt.preventDefault();
        var _parent = $(this).parent().parent().parent();
        var validator = new validation();
        var isValid = true;

        // First name - required field
        if (!validator.required($(".TextBox-FirstName", _parent).val()))
        {
            $(".TextBox-FirstName").prev("label")
                .addClass("Label-Error")
                .html('First name <span class="Highlight">*</span> Please enter your first name.');
            isValid = false;
        }
        else
            $(".TextBox-FirstName").prev("label")
                .removeClass("Label-Error")
                .html('First name <span class="Highlight">*</span>');

        // Surname - required field
        if (!validator.required($(".TextBox-Surname", _parent).val()))
        {
            $(".TextBox-Surname").prev("label")
                .addClass("Label-Error")
                .html('Surname <span class="Highlight">*</span> Please enter your surname.');
            isValid = false;
        }
        else
            $(".TextBox-Surname").prev("label")
                .removeClass("Label-Error")
                .html('Surname <span class="Highlight">*</span>');

        // Email - required field & must be valid email
        if (!validator.required($(".TextBox-Email", _parent).val()))
        {
            $(".TextBox-Email").prev("label")
                .addClass("Label-Error")
                .html('Email <span class="Highlight">*</span> Please enter your email.');
            isValid = false;
        }
        else if (!validator.email($(".TextBox-Email", _parent).val()))
        {
            $(".TextBox-Email").prev("label")
                .addClass("Label-Error")
                .html('Email <span class="Highlight">*</span> Whoops! Please enter a valid email.');
            isValid = false;
        }
        else
            $(".TextBox-Email").prev("label")
                .removeClass("Label-Error")
                .html('Email <span class="Highlight">*</span>');

        // Confirm email - required field
        if (!validator.match($(".TextBox-Email", _parent).val(), $(".TextBox-ConfirmEmail", _parent).val()))
        {
            $(".TextBox-ConfirmEmail").prev("label")
                .addClass("Label-Error")
                .html('Confirm email <span class="Highlight">*</span> Please confirm you email address.');
            isValid = false;
        }
        else
            $(".TextBox-ConfirmEmail").prev("label")
                .removeClass("Label-Error")
                .html('Confirm email <span class="Highlight">*</span>');

        // Address - required field
        if (!validator.required($(".TextBox-AddressOne", _parent).val()))
        {
            $(".TextBox-AddressOne").prev("label")
                .addClass("Label-Error")
                .html('Address <span class="Highlight">*</span> Please enter your address.');
            isValid = false;
        }
        else
            $(".TextBox-AddressOne").prev("label")
                .removeClass("Label-Error")
                .html('Address <span class="Highlight">*</span>');

        // City/Town - required field
        if (!validator.required($(".TextBox-CityOrTown", _parent).val()))
        {
            $(".TextBox-CityOrTown").prev("label")
                .addClass("Label-Error")
                .html('City/Town <span class="Highlight">*</span> Please enter your city or town.');
            isValid = false;
        }
        else
            $(".TextBox-CityOrTown").prev("label")
                .removeClass("Label-Error")
                .html('City/Town <span class="Highlight">*</span>');

        // Post code - required field
        if (!validator.required($(".TextBox-Postcode", _parent).val()))
        {
            $(".TextBox-Postcode").prev("label")
                .addClass("Label-Error").removeClass("Label-Small")
                .html('Post code <span class="Highlight">*</span> Please enter your post code.');
            isValid = false;
        }
        else
            $(".TextBox-Postcode").prev("label")
                .removeClass("Label-Error").addClass("Label-Small")
                .html('Post code <span class="Highlight">*</span>');

        if (isValid)
        {
            $(".Sending", _parent).css({ "height": $(".Form", _parent).height() });
            $(".Sending h3", _parent).css({ "line-height": ($(".Form", _parent).height() - 70) + "px" });

            $(".Form", _parent).fadeOut(150, function ()
            {
                $(".Sending", _parent).fadeIn(150, function ()
                {
                    // Make webservice call
                    var service = new indigo.communication.webService(WEBSITE_ROOT_URL + "plugins/contact/dataservice.asmx");
                    service.getDataSet("FormSubmissions_AddUpdate", "ID=0&TypeLKP=" + $(_parent).children("input[type=hidden]").val(), true, function (ds)
                    {
                        var id = ds.tables.items[0].rows.items[0].getValue("fsu_ID");
                        service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=FirstName&Value=" + $(".TextBox-FirstName", _parent).val(), true);
                        service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=Surname&Value=" + $(".TextBox-Surname", _parent).val(), true);
                        service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=Company&Value=" + $(".TextBox-Company", _parent).val(), true);
                        service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=Email&Value=" + $(".TextBox-Email", _parent).val(), true);
                        service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=Address1&Value=" + $(".TextBox-AddressOne", _parent).val(), true);
                        service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=Address2&Value=" + $(".TextBox-AddressTwo", _parent).val(), true);
                        service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=CityOrTown&Value=" + $(".TextBox-CityOrTown", _parent).val(), true);
                        service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=PostCode&Value=" + $(".TextBox-Postcode", _parent).val(), true);
                        service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=Newsletter&Value=" + $(".CheckBox-NewsLetter input", _parent).is(":checked"), true);
                        $(".Sending", _parent).fadeOut(150, function ()
                        {
                            $(".ThankYou", _parent).fadeIn(250);
                        });

                        service.getDataSet("GallerySignUp_SendEmails", "FirstName=" + $(".TextBox-FirstName", _parent).val() +
                                                                       "&Surname=" + $(".TextBox-Surname", _parent).val() +
                                                                       "&Company=" + $(".TextBox-Company", _parent).val() +
                                                                       "&AddressOne=" + $(".TextBox-AddressOne", _parent).val() +
                                                                       "&AddressTwo=" + $(".TextBox-AddressTwo", _parent).val() +
                                                                       "&CityOrTown=" + $(".TextBox-CityOrTown", _parent).val() +
                                                                       "&Postcode=" + $(".TextBox-Postcode", _parent).val() +
                                                                       "&Email=" + $(".TextBox-Email", _parent).val() +
                                                                       "&MarketingOptIn=" + $(".CheckBox-NewsLetter input", _parent).is(":checked"));
                    },
                    function ()
                    {
                        // Oh no!
                    });
                });
            });
        }
    });

    /* Mailing List
    /******************************************************************************/
    $(".MailingList .Close").click(function (evt)
    {
        evt.preventDefault();
        popupmanager.close();
    });

    $(".PopUp-MailingList .Close").live("click", function (evt)
    {
        evt.preventDefault();
        _gaq.push(['_trackPageview', 'vpv/header/join-mailinglist/close form/' + PAGE_PATH]);
    });

    if (IsDesignMode)
        $(".MailingList .ThankYou").css({ "display": "block", "height": $(".CVUpload .Form").height() });

    $(".MailingList .Submit").click(function (evt)
    {
        evt.preventDefault();
        var _parent = $(this).parent().parent().parent();
        var validator = new validation();
        var isValid = true;

        // Name - required field
        if (!validator.required($(".TextBox-FirstName", _parent).val()))
        {
            $(".TextBox-FirstName").prev("label")
                .addClass("Label-Error")
                .html('First name <span class="Highlight">*</span> Please enter your first name.');
            isValid = false;
        }
        else
            $(".TextBox-FirstName").prev("label")
                .removeClass("Label-Error")
                .html('First name <span class="Highlight">*</span>')

        // Surname - required field
        if (!validator.required($(".TextBox-Surname", _parent).val()))
        {
            $(".TextBox-Surname").prev("label")
                .addClass("Label-Error")
                .html('Surname <span class="Highlight">*</span> Please enter your surname.');
            isValid = false;
        }
        else
            $(".TextBox-Surname").prev("label")
                .removeClass("Label-Error")
                .html('Surname <span class="Highlight">*</span>')

        // Email - required field & must be valid email
        if (!validator.required($(".TextBox-Email", _parent).val()))
        {
            $(".TextBox-Email").prev("label")
                .addClass("Label-Error")
                .html('Email <span class="Highlight">*</span> Please enter your email.');
            isValid = false;
        }
        else if (!validator.email($(".TextBox-Email", _parent).val()))
        {
            $(".TextBox-Email").prev("label")
                .addClass("Label-Error")
                .html('Email <span class="Highlight">*</span> Whoops! Please enter a valid email.');
            isValid = false;
        }
        else
            $(".TextBox-Email").prev("label")
                .removeClass("Label-Error")
                .html('Email <span class="Highlight">*</span>');

        // Confirm email - required field
        if (!validator.match($(".TextBox-Email", _parent).val(), $(".TextBox-ConfirmEmail", _parent).val()))
        {
            $(".TextBox-ConfirmEmail").prev("label")
                .addClass("Label-Error")
                .html('Confirm email <span class="Highlight">*</span> Please confirm your email address.');
            isValid = false;
        }
        else
            $(".TextBox-ConfirmEmail").prev("label")
                .removeClass("Label-Error")
                .html('Confirm email <span class="Highlight">*</span>');

        if (isValid)
        {
            $(".Sending", _parent).css({ "height": $(".Form", _parent).height() });
            $(".Sending h3", _parent).css({ "line-height": ($(".Form", _parent).height() - 70) + "px" });

            $(".Form", _parent).fadeOut(150, function ()
            {
                $(".Sending", _parent).fadeIn(150, function ()
                {
                    // Make webservice call
                    var service = new indigo.communication.webService(WEBSITE_ROOT_URL + "plugins/contact/dataservice.asmx");
                    service.getDataSet("FormSubmissions_AddUpdate", "ID=0&TypeLKP=" + $(_parent).children("input[type=hidden]").val(), true, function (ds)
                    {
                        var id = ds.tables.items[0].rows.items[0].getValue("fsu_ID");
                        service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=FirstName&Value=" + $(".TextBox-FirstName", _parent).val(), true);
                        service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=Surname&Value=" + $(".TextBox-Surname", _parent).val(), true);
                        service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=Company&Value=" + $(".TextBox-Company", _parent).val(), true);
                        service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=Email&Value=" + $(".TextBox-Email", _parent).val(), true);

                        $(".Sending", _parent).fadeOut(150, function ()
                        {
                            $(".ThankYou", _parent).css("display", "block");
                            var height = $(".Content").outerHeight();
                            $(".ThankYou", _parent).css("display", "none");

                            window.parent.popupmanager.resize(height, function ()
                            {
                                $(".ThankYou", _parent).fadeIn(250);
                            });
                        });

                        service.getDataSet("MailingList_SendEmails", "FirstName=" + $(".TextBox-FirstName", _parent).val() +
                                                                       "&Surname=" + $(".TextBox-Surname", _parent).val() +
                                                                       "&Company=" + $(".TextBox-Company", _parent).val() +
                                                                       "&Email=" + $(".TextBox-Email", _parent).val());
                    },
                    function ()
                    {
                        // Oh no!
                    });
                });
            });
        }
    });

    /* Unsubscribe
    /******************************************************************************/
    if (IsDesignMode)
        $(".Unsubscribe .ThankYou").css({ "display": "block", "height": $(".CVUpload .Form").height() });

    $(".Unsubscribe .Submit").click(function (evt)
    {
        evt.preventDefault();
        var _parent = $(this).parent().parent();
        var validator = new validation();
        var isValid = true;

        // Email - required field & must be valid email
        if (!validator.required($(".TextBox-Email", _parent).val()))
        {
            $(".TextBox-Email", _parent).prev().prev("label")
                .addClass("Label-Error")
                .html('Please enter your email address: Please enter your email.');
            isValid = false;
        }
        else if (!validator.email($(".TextBox-Email", _parent).val()))
        {
            $(".TextBox-Email", _parent).prev().prev("label")
                .addClass("Label-Error")
                .html('Please enter your email address: Whoops! Please enter a valid email.');
            isValid = false;
        }
        else
            $(".TextBox-Email", _parent).prev().prev("label")
                .removeClass("Label-Error")
                .html('Please enter your email address: ');

        // Confirm email - required field
        if (!validator.match($(".TextBox-Email", _parent).val(), $(".TextBox-ConfirmEmail", _parent).val()))
        {
            $(".TextBox-ConfirmEmail", _parent).prev().prev("label")
                .addClass("Label-Error")
                .html('Confirm your email: Please confirm your email address.');
            isValid = false;
        }
        else
            $(".TextBox-ConfirmEmail", _parent).prev().prev("label")
                .removeClass("Label-Error")
                .html('Confirm your email:');

        // Unsubscribe items
        if ($(".CheckBox-GalleryNewsLetter input", _parent).attr("checked") == false && $(".CheckBox-NewsLetter input", _parent).attr("checked") == false)
        {
            isValid = false;
            if ($(".Label-CheckBoxError", _parent).length == 0)
                $('<label class="Label Label-CheckBoxError Label-Error">Please select at least one item to unsubscribe from.</label>').insertAfter(".TextBox-ConfirmEmail", _parent);
        }
        else
            $(".Label-CheckBoxError", _parent).remove();

        if (isValid)
        {
            $(".Sending", _parent).css({ "height": $(".Form", _parent).height() });
            $(".Sending h3", _parent).css({ "line-height": ($(".Form", _parent).height() - 70) + "px" });

            $(".Form", _parent).fadeOut(150, function ()
            {
                $(".Sending", _parent).fadeIn(150, function ()
                {
                    // Make webservice call
                    var service = new indigo.communication.webService(WEBSITE_ROOT_URL + "plugins/contact/dataservice.asmx");
                    service.getDataSet("FormSubmissions_AddUpdate", "ID=0&TypeLKP=" + $(_parent).children("input[type=hidden]").val(), true, function (ds)
                    {
                        var id = ds.tables.items[0].rows.items[0].getValue("fsu_ID");
                        service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=Email&Value=" + $(".TextBox-Email", _parent).val(), true);

                        if ($(".CheckBox-GalleryNewsLetter input", _parent).attr("checked") == true)
                            service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=GalleryNewsLetter&Value=true", true);

                        if ($(".CheckBox-NewsLetter input", _parent).attr("checked") == true)
                            service.getScalar("FormSubmissionData_AddUpdate", "ID=0&FormSubmissionID=" + id + "&Name=NewsLetter&Value=true", true);

                        $(".Sending", _parent).fadeOut(150, function ()
                        {
                            $(".ThankYou", _parent).fadeIn(250);
                        });

                        service.getDataSet("Unsubscribe_SendEmails", "Email=" + $(".TextBox-Email", _parent).val());
                    },
                    function ()
                    {
                        // Oh no!
                    });
                });
            });
        }
    });
});


function validation()
{

}
validation.prototype.required = function (input)
{
    return !(input == "");
}
validation.prototype.email = function (address)
{
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    return reg.test(address);
}
validation.prototype.match = function (inputOne, inputTwo)
{
    return (inputOne == inputTwo);
}


function BeautifyRadioButtons()
{
    $(".RadioButton").each(function ()
    {
        if (!$(this).hasClass("RadioButton-Loaded"))
        {
            $(this).children("input").hide();
            var button = $('<div class="Icon"><div class="Overlay"></div></div>').prependTo(this);
            $(button).hover(function ()
            {
                $(".Overlay", this).fadeIn(250);
            }, function ()
            {
                $(".Overlay", this).fadeOut(100);
            });

            $(button).add($(button).siblings("label")).click(function ()
            {
                $(this).siblings("input").attr("checked", true);
                if ($.browser.msie)
                {
                    this.blur();
                    this.focus();
                }
                $("input[name='" + $(this).siblings("input").attr("name") + "']").each(function ()
                {
                    if ($(this).is(':checked'))
                        $(this).siblings(".Icon").addClass("RadioButton-Selected");
                    else
                        $(this).siblings(".Icon").removeClass("RadioButton-Selected");
                });
            });

            $(button).mousedown(function ()
            {
                $(".Overlay", this).addClass("Overlay-Pressed");
            });

            $(button).mouseup(function ()
            {
                $(".Overlay", this).removeClass("Overlay-Pressed");
            });

            $(this).addClass("RadioButton-Loaded");
        }
    });
}

/* Twitter Influence
/******************************************************************************/
function _twitterInfluence(hashTag)
{
    var _this = this;
    _this.hashTag = hashTag;
    _this._slideShowIntervalID = 0;
    _this._updateDataIntervalID = 0;
    _this._displayedPanel = 0;
    _this._webService = new indigo.communication.webService(WEBSITE_ROOT_URL + "plugins/twitterinfluencetool/dataservice.asmx");

    $(".Twitter-Influence .Buttons .TopFiveTweets, .Twitter-Influence .Slider-Controls .First").click(function (evt)
    {
        _this.stopAutoSlideShow();
        if (_this._displayedPanel != 0)
            _this.showTweets(evt);
        else
        {
            if (evt)
                evt.preventDefault();
        }
    });

    $(".Twitter-Influence .Buttons .TopFiveInfluences, .Twitter-Influence .Slider-Controls .Last").click(function (evt)
    {
        _this.stopAutoSlideShow();
        if (_this._displayedPanel != 1)
            _this.showInfluences(evt);
        else
        {
            if (evt)
                evt.preventDefault();
        }
    });

    $(".Twitter-Influence .Top-Tweets .Scroll-Up").click(function (evt)
    {
        _this.stopAutoSlideShow();
        $(".Twitter-Influence .Top-Tweets-List-Container").animate({ top: 0 }, 1000);
        $(".Twitter-Influence .Top-Tweets .Scroll-Up").animate({ opacity: 0 }, 1000);
        $(".Twitter-Influence .Top-Tweets .Scroll-Down").animate({ opacity: 1 }, 1000);
        if (evt) evt.preventDefault();
    });

    $(".Twitter-Influence .Top-Tweets .Scroll-Down").click(function (evt)
    {
        _this.stopAutoSlideShow(); 
        $(".Twitter-Influence .Top-Tweets-List-Container").animate({ top: -($(".Twitter-Influence .Top-Tweets-List-Container").height() - $(".Tweet-ViewPort .Top-Tweets").height()) }, 1000);
        $(".Twitter-Influence .Top-Tweets .Scroll-Up").animate({ opacity: 1 }, 1000);
        $(".Twitter-Influence .Top-Tweets .Scroll-Down").animate({ opacity: 0 }, 1000);
        if (evt) evt.preventDefault();
    });

    $(".Twitter-Influence .Top-Influencers .Scroll-Up").click(function (evt)
    {
        _this.stopAutoSlideShow();
        $(".Twitter-Influence .Top-Influencers-List-Container").animate({ top: 0 }, 1000);
        $(".Twitter-Influence .Top-Influencers .Scroll-Up").animate({ opacity: 0 }, 1000);
        $(".Twitter-Influence .Top-Influencers .Scroll-Down").animate({ opacity: 1 }, 1000);
        if (evt) evt.preventDefault();
    });

    $(".Twitter-Influence .Top-Influencers .Scroll-Down").click(function (evt)
    {
        _this.stopAutoSlideShow();
        $(".Twitter-Influence .Top-Influencers-List-Container").animate({ top: -($(".Twitter-Influence .Top-Influencers-List-Container").height() - $(".Tweet-ViewPort .Top-Influencers").height()) }, 1000);
        $(".Twitter-Influence .Top-Influencers .Scroll-Up").animate({ opacity: 1 }, 1000);
        $(".Twitter-Influence .Top-Influencers .Scroll-Down").animate({ opacity: 0 }, 1000);
        if (evt) evt.preventDefault();
    });

    _this._slideShowIntervalID = setInterval(function () { _this.togglePanels(); }, 30000);

    $(document).ready(function ()
    {
        $(".Tweet-ViewPort").height($(".Right-Column").outerHeight());
        $(".Tweet-ViewPort .Top-Tweets").height($(".Right-Column").outerHeight() - 60);
        $(".Tweet-ViewPort .Top-Influencers").height($(".Right-Column").outerHeight() - 60);
        $(".Twitter-Influence .Top-Tweets .Scroll-Up").animate({ opacity: 0 }, 1);
        $(".Twitter-Influence .Top-Influencers .Scroll-Up").animate({ opacity: 0 }, 1);
    });
}
_twitterInfluence.prototype.stopAutoSlideShow = function ()
{
    var _this = this;
    if (_this._slideShowIntervalID > 0)
    {
        clearInterval(_this._slideShowIntervalID);
        _this._slideShowIntervalID = 0;
        _this._updateDataIntervalID = setInterval(function () { _this.updateData(); }, 30000);
    }
};
_twitterInfluence.prototype.updateData = function ()
{
    var _this = this;

    function _tweetsSuccess(_dataSet)
    {
        if (_dataSet.tables.count > 0)
        {
            var 
                    _lis = $(".Tweet-Container .Top-Tweets li"),
                    _data = [];

            for (var i = 0; i < _dataSet.tables.items[0].rows.count; i++)
            {
                _data.push({
                    id: _dataSet.tables.items[0].rows.items[i].getValue("twe_ID"),
                    text: _dataSet.tables.items[0].rows.items[i].getValue("twe_Text"),
                    screenName: _dataSet.tables.items[0].rows.items[i].getValue("use_ScreenName"),
                    url: _dataSet.tables.items[0].rows.items[i].getValue("use_URL")
                });

                if (_dataSet.tables.items[0].rows.items[i].getValue("twe_ID") != _getInnerText($(_lis[i]).children("span")[0]))
                {
                    function _updateTweet()
                    {
                        var 
                                _index = _this.getChildIndex(this),
                                _spans = $(this).children("span");

                        _spans[0].innerHTML = _data[_index].id;
                        _spans[2].innerHTML = _data[_index].text;
                        $(_spans[3]).children("a")[0].href = "http://www.twitter.com/" + _data[_index].screenName;
                        $(_spans[3]).children("a")[0].innerHTML = _data[_index].screenName;

                        $(this).removeClass("Hide");
                        $(this).animate({ opacity: 1 }, 1000)
                    }

                    $(_lis[i]).animate({ opacity: 0 }, 1000, _updateTweet)
                }

                if (i >= 9)
                    break;
            }
        }
    }

    function _usersSuccess(_dataSet)
    {
        if (_dataSet.tables.count > 0)
        {
            var 
                    _lis = $(".Tweet-Container .Top-Influencers li"),
                    _data = [];

            for (var i = 0; i < _dataSet.tables.items[0].rows.count; i++)
            {
                _data.push({
                    id: _dataSet.tables.items[0].rows.items[i].getValue("use_ID"),
                    screenName: _dataSet.tables.items[0].rows.items[i].getValue("use_ScreenName"),
                    url: _dataSet.tables.items[0].rows.items[i].getValue("use_URL"),
                    profileImageURL: _dataSet.tables.items[0].rows.items[i].getValue("use_ProfileImageURL")
                });

                if (_dataSet.tables.items[0].rows.items[i].getValue("use_ID") != _getInnerText($(_lis[i]).children("span")[0]))
                {
                    function _updateUser()
                    {
                        var 
                            _index = _this.getChildIndex(this);

                        $(this).children("span")[0].innerHTML = _data[_index].id;

                        $($($(this).children("span")[2]).children("span")[1]).children("a")[0].href = "http://www.twitter.com/" + _data[_index].screenName;
                        $($($(this).children("span")[2]).children("span")[1]).children("a")[0].innerHTML = _data[_index].screenName;

                        $($(this).children("span")[1]).children("a")[0].href = "http://www.twitter.com/" + _data[_index].screenName;
                        $($($(this).children("span")[1]).children("a")[0]).children("img")[0].src = WEBSITE_ROOT_URL + "templates/images/transparentpx.gif";

                        function _updateImageURL()
                        {
                            $($($(this).children("span")[1]).children("a")[0]).children("img")[0].src = _data[_index].profileImageURL
                        }

                        $(this).removeClass("Hide");
                        $(this).animate({ opacity: 1 }, 1000, _updateImageURL)
                    }

                    $(_lis[i]).animate({ opacity: 0 }, 1000, _updateUser)
                }

                if (i >= 9)
                    break;
            }
        }
    }

    if (_this._displayedPanel == 0 || _this._slideShowIntervalID == 0)
        _this._webService.getDataSet("Report_TopTweets", "HashTag=" + escapeString(_this.hashTag), true, _tweetsSuccess);

    if (_this._displayedPanel == 1 || _this._slideShowIntervalID == 0)
        _this._webService.getDataSet("Report_TopUsers", "HashTag=" + escapeString(_this.hashTag), true, _usersSuccess);
};
_twitterInfluence.prototype.getChildIndex = function (el)
{
    if (el.parentNode)
    {
        for (var i = 0; i < el.parentNode.childNodes.length; i++)
        {
            if (el.parentNode.childNodes[i] == el)
                return i;
        }
    }
    return -1;
};
_twitterInfluence.prototype.togglePanels = function ()
{
    var _this = this;
    if (_this._displayedPanel == 0)
        _this.showInfluences();
    else
        _this.showTweets();
};
_twitterInfluence.prototype.showTweets = function (evt)
{
    var _this = this;
    if (evt)
        evt.preventDefault();

    $(".Tweet-Container").animate({
        left: 0
    }, 1000, undefined, function () { if (_this._slideShowIntervalID > 0) _this.updateData(); });

    $(".Twitter-Influence h1").animate({
        opacity: 0
    }, 500, undefined, function ()
    {
        $(".Twitter-Influence h1")[0].innerHTML = "Top 10 <span class=\"Highlight\">Social Media Week</span> tweets on #SMWLDN";
        $(".Twitter-Influence h1").animate({
            opacity: 1
        }, 500);
    });

    $(".Twitter-Influence .Slider-Controls a").removeClass("Selected");
    $(".Twitter-Influence .Buttons .TopFiveTweets").addClass("Button-Pressed");
    $(".Twitter-Influence .Buttons .TopFiveInfluences").removeClass("Button-Pressed");
    $(".Twitter-Influence .Slider-Controls a").first().addClass("Selected");

    _this._displayedPanel = 0;
};
_twitterInfluence.prototype.showInfluences = function (evt)
{
    var _this = this;
    if (evt)
        evt.preventDefault();

    $(".Tweet-Container").animate({
        left: -580
    }, 1000, undefined, function () { if (_this._slideShowIntervalID > 0) _this.updateData(); });

    $(".Twitter-Influence h1").animate({
        opacity: 0
    }, 500, undefined, function ()
    {
        $(".Twitter-Influence h1")[0].innerHTML = "Top 10 <span class=\"Highlight\">Social Media Week</span> influencers on #SMWLDN";
        $(".Twitter-Influence h1").animate({
            opacity: 1
        }, 500);
    });

    $(".Twitter-Influence .Slider-Controls a").removeClass("Selected");
    $(".Twitter-Influence .Buttons .TopFiveTweets").removeClass("Button-Pressed");
    $(".Twitter-Influence .Buttons .TopFiveInfluences").addClass("Button-Pressed");
    $(".Twitter-Influence .Slider-Controls a").last().addClass("Selected");

    _this._displayedPanel = 1;
};

function _getInnerText(el)
{
    if (document.all)
        return el.innerText;
    else
        return el.textContent;
}

/* Twitter Influence v2
/******************************************************************************/
function _twitterInfluenceV2(hashTag, name)
{
    var _this = this;
    _this.hashTag = hashTag;
    _this.name = name;
    _this._slideShowIntervalID = 0;
    _this._updateDataIntervalID = 0;
    _this._displayedPanel = 0;
    _this._webService = new indigo.communication.webService(WEBSITE_ROOT_URL + "plugins/twitterinfluencetool/dataservice.asmx");

    $(".Twitter-Influence .Buttons .TopFiveTweets, .Twitter-Influence .Slider-Controls .First").click(function (evt)
    {
        _this.stopAutoSlideShow();
        if (_this._displayedPanel != 0)
            _this.showTweets(evt);
        else
        {
            if (evt)
                evt.preventDefault();
        }
    });

    $(".Twitter-Influence .Buttons .TopFiveInfluences, .Twitter-Influence .Slider-Controls .Last").click(function (evt)
    {
        _this.stopAutoSlideShow();
        if (_this._displayedPanel != 1)
            _this.showInfluences(evt);
        else
        {
            if (evt)
                evt.preventDefault();
        }
    });

    $(".Twitter-Influence .Top-Tweets .Scroll-Up").click(function (evt)
    {
        _this.stopAutoSlideShow();
        $(".Twitter-Influence .Top-Tweets-List-Container").animate({ top: 0 }, 1000);
        $(".Twitter-Influence .Top-Tweets .Scroll-Up").animate({ opacity: 0 }, 1000);
        $(".Twitter-Influence .Top-Tweets .Scroll-Down").animate({ opacity: 1 }, 1000);
        if (evt) evt.preventDefault();
    });

    $(".Twitter-Influence .Top-Tweets .Scroll-Down").click(function (evt)
    {
        _this.stopAutoSlideShow();
        $(".Twitter-Influence .Top-Tweets-List-Container").animate({ top: -($(".Twitter-Influence .Top-Tweets-List-Container").height() - $(".Tweet-ViewPort .Top-Tweets").height()) }, 1000);
        $(".Twitter-Influence .Top-Tweets .Scroll-Up").animate({ opacity: 1 }, 1000);
        $(".Twitter-Influence .Top-Tweets .Scroll-Down").animate({ opacity: 0 }, 1000);
        if (evt) evt.preventDefault();
    });

    $(".Twitter-Influence .Top-Influencers .Scroll-Up").click(function (evt)
    {
        _this.stopAutoSlideShow();
        $(".Twitter-Influence .Top-Influencers-List-Container").animate({ top: 0 }, 1000);
        $(".Twitter-Influence .Top-Influencers .Scroll-Up").animate({ opacity: 0 }, 1000);
        $(".Twitter-Influence .Top-Influencers .Scroll-Down").animate({ opacity: 1 }, 1000);
        if (evt) evt.preventDefault();
    });

    $(".Twitter-Influence .Top-Influencers .Scroll-Down").click(function (evt)
    {
        _this.stopAutoSlideShow();
        $(".Twitter-Influence .Top-Influencers-List-Container").animate({ top: -($(".Twitter-Influence .Top-Influencers-List-Container").height() - $(".Tweet-ViewPort .Top-Influencers").height()) }, 1000);
        $(".Twitter-Influence .Top-Influencers .Scroll-Up").animate({ opacity: 1 }, 1000);
        $(".Twitter-Influence .Top-Influencers .Scroll-Down").animate({ opacity: 0 }, 1000);
        if (evt) evt.preventDefault();
    });

    _this._slideShowIntervalID = setInterval(function () { _this.togglePanels(); }, 30000);

    $(document).ready(function ()
    {
        $(".Tweet-ViewPort").height($(".Right-Column").outerHeight());
        $(".Tweet-ViewPort .Top-Tweets").height($(".Right-Column").outerHeight() - 60);
        $(".Tweet-ViewPort .Top-Influencers").height($(".Right-Column").outerHeight() - 60);
        $(".Twitter-Influence .Top-Tweets .Scroll-Up").animate({ opacity: 0 }, 1);
        $(".Twitter-Influence .Top-Influencers .Scroll-Up").animate({ opacity: 0 }, 1);
    });
}
_twitterInfluenceV2.prototype.stopAutoSlideShow = function ()
{
    var _this = this;
    if (_this._slideShowIntervalID > 0)
    {
        clearInterval(_this._slideShowIntervalID);
        _this._slideShowIntervalID = 0;
        _this._updateDataIntervalID = setInterval(function () { _this.updateData(); }, 30000);
    }
};
_twitterInfluenceV2.prototype.updateData = function ()
{
    var _this = this;

    function _tweetsSuccess(_dataSet)
    {
        if (_dataSet.tables.count > 0)
        {
            var 
                    _lis = $(".Tweet-Container .Top-Tweets li"),
                    _data = [];

            for (var i = 0; i < _dataSet.tables.items[0].rows.count; i++)
            {
                _data.push({
                    id: _dataSet.tables.items[0].rows.items[i].getValue("twe_ID"),
                    text: _dataSet.tables.items[0].rows.items[i].getValue("twe_Text"),
                    screenName: _dataSet.tables.items[0].rows.items[i].getValue("use_ScreenName"),
                    url: _dataSet.tables.items[0].rows.items[i].getValue("use_URL")
                });

                if (_dataSet.tables.items[0].rows.items[i].getValue("twe_ID") != _getInnerText($(_lis[i]).children("span")[0]))
                {
                    function _updateTweet()
                    {
                        var 
                                _index = _this.getChildIndex(this),
                                _spans = $(this).children("span");

                        _spans[0].innerHTML = _data[_index].id;
                        _spans[2].innerHTML = _data[_index].text;
                        $(_spans[3]).children("a")[0].href = "http://www.twitter.com/" + _data[_index].screenName;
                        $(_spans[3]).children("a")[0].innerHTML = _data[_index].screenName;

                        $(this).removeClass("Hide");
                        $(this).animate({ opacity: 1 }, 1000)
                    }

                    $(_lis[i]).animate({ opacity: 0 }, 1000, _updateTweet)
                }

                if (i >= 9)
                    break;
            }
        }
    }

    function _usersSuccess(_dataSet)
    {
        if (_dataSet.tables.count > 0)
        {
            var 
                    _lis = $(".Tweet-Container .Top-Influencers li"),
                    _data = [];

            for (var i = 0; i < _dataSet.tables.items[0].rows.count; i++)
            {
                _data.push({
                    id: _dataSet.tables.items[0].rows.items[i].getValue("use_ID"),
                    screenName: _dataSet.tables.items[0].rows.items[i].getValue("use_ScreenName"),
                    url: _dataSet.tables.items[0].rows.items[i].getValue("use_URL"),
                    profileImageURL: _dataSet.tables.items[0].rows.items[i].getValue("use_ProfileImageURL")
                });

                if (_dataSet.tables.items[0].rows.items[i].getValue("use_ID") != _getInnerText($(_lis[i]).children("span")[0]))
                {
                    function _updateUser()
                    {
                        var 
                            _index = _this.getChildIndex(this);

                        $(this).children("span")[0].innerHTML = _data[_index].id;

                        $($($(this).children("span")[2]).children("span")[1]).children("a")[0].href = "http://www.twitter.com/" + _data[_index].screenName;
                        $($($(this).children("span")[2]).children("span")[1]).children("a")[0].innerHTML = _data[_index].screenName;

                        $($(this).children("span")[1]).children("a")[0].href = "http://www.twitter.com/" + _data[_index].screenName;
                        $($($(this).children("span")[1]).children("a")[0]).children("img")[0].src = WEBSITE_ROOT_URL + "templates/images/transparentpx.gif";

                        function _updateImageURL()
                        {
                            $($($(this).children("span")[1]).children("a")[0]).children("img")[0].src = _data[_index].profileImageURL
                        }

                        $(this).removeClass("Hide");
                        $(this).animate({ opacity: 1 }, 1000, _updateImageURL)
                    }

                    $(_lis[i]).animate({ opacity: 0 }, 1000, _updateUser)
                }

                if (i >= 9)
                    break;
            }
        }
    }

    if (_this._displayedPanel == 0 || _this._slideShowIntervalID == 0)
        _this._webService.getDataSet("General_Report_TopTweets", "SearchFor=" + escapeString(_this.hashTag), true, _tweetsSuccess);

    if (_this._displayedPanel == 1 || _this._slideShowIntervalID == 0)
        _this._webService.getDataSet("General_Report_TopUsers", "SearchFor=" + escapeString(_this.hashTag), true, _usersSuccess);
};
_twitterInfluenceV2.prototype.getChildIndex = function (el)
{
    if (el.parentNode)
    {
        for (var i = 0; i < el.parentNode.childNodes.length; i++)
        {
            if (el.parentNode.childNodes[i] == el)
                return i;
        }
    }
    return -1;
};
_twitterInfluenceV2.prototype.togglePanels = function ()
{
    var _this = this;
    if (_this._displayedPanel == 0)
        _this.showInfluences();
    else
        _this.showTweets();
};
_twitterInfluenceV2.prototype.showTweets = function (evt)
{
    var _this = this;
    if (evt)
        evt.preventDefault();

    $(".Tweet-Container").animate({
        left: 0
    }, 1000, undefined, function () { if (_this._slideShowIntervalID > 0) _this.updateData(); });

    $(".Twitter-Influence h1").animate({
        opacity: 0
    }, 500, undefined, function ()
    {
        $(".Twitter-Influence h1")[0].innerHTML = "Top 10 <span class=\"Highlight\">" + _this.name + "</span> tweets on " + _this.hashTag;
        $(".Twitter-Influence h1").animate({
            opacity: 1
        }, 500);
    });

    $(".Twitter-Influence .Slider-Controls a").removeClass("Selected");
    $(".Twitter-Influence .Buttons .TopFiveTweets").addClass("Button-Pressed");
    $(".Twitter-Influence .Buttons .TopFiveInfluences").removeClass("Button-Pressed");
    $(".Twitter-Influence .Slider-Controls a").first().addClass("Selected");

    _this._displayedPanel = 0;
};
_twitterInfluenceV2.prototype.showInfluences = function (evt)
{
    var _this = this;
    if (evt)
        evt.preventDefault();

    $(".Tweet-Container").animate({
        left: -580
    }, 1000, undefined, function () { if (_this._slideShowIntervalID > 0) _this.updateData(); });

    $(".Twitter-Influence h1").animate({
        opacity: 0
    }, 500, undefined, function ()
    {
        $(".Twitter-Influence h1")[0].innerHTML = "Top 10 <span class=\"Highlight\">" + _this.name + "</span> influencers on " + _this.hashTag;
        $(".Twitter-Influence h1").animate({
            opacity: 1
        }, 500);
    });

    $(".Twitter-Influence .Slider-Controls a").removeClass("Selected");
    $(".Twitter-Influence .Buttons .TopFiveTweets").removeClass("Button-Pressed");
    $(".Twitter-Influence .Buttons .TopFiveInfluences").addClass("Button-Pressed");
    $(".Twitter-Influence .Slider-Controls a").last().addClass("Selected");

    _this._displayedPanel = 1;
};

/* Twitter Influence v3
/******************************************************************************/
function _twitterInfluenceV3(monitoredItems, name)
{
    var _this = this;
    _this.monitoredItems = monitoredItems;
    _this.selectedMonitoredItem = (_this.monitoredItems.length > 0 ? _this.monitoredItems[0] : "");
    _this.name = name;
    _this._slideShowIntervalID = 0;
    _this._updateDataIntervalID = 0;
    _this._displayedPanel = 0;
    _this._webService = new indigo.communication.webService(WEBSITE_ROOT_URL + "plugins/twitterinfluencetool/dataservice.asmx");

    var _links = $(".twitter-influence-v3-left-navigation a");

    if (_links.length > 0)
    {
        for (var i = 0; i < _links.length; i++)
            $(_links[i]).click(function (evt)
            {
                _this.stopAutoSlideShow();
                for (var j = 0; j < _links.length; j++)
                {
                    $(_links[j]).removeClass("selected-lihash");
                    $(_links[j]).removeClass("selected-lispeech");
                }
                if (this.className.indexOf("lihash") > -1)
                    $(this).addClass("selected-lihash");
                else
                    $(this).addClass("selected-lispeech");

                _this._monitoredItem_Click(evt);
            });
    }

    $(".li-tweets").click(function (evt)
    {
        _this.stopAutoSlideShow();
        if (_this._displayedPanel != 0)
            _this.showTweets();

        evt.preventDefault();
    });

    $(".li-influencers").click(function (evt)
    {
        _this.stopAutoSlideShow();
        if (_this._displayedPanel != 1)
            _this.showInfluencers();

        evt.preventDefault();
    });

    $(".li-hashtag").click(function (evt)
    {
        _this.stopAutoSlideShow();
        if (_this._displayedPanel != 2)
            _this.showHashTags();

        evt.preventDefault();
    });

    $(".tweets-panel .scroll-up").click(function (evt)
    {
        _this.stopAutoSlideShow();
        _this.tweetPanelScrollUp();
        evt.preventDefault();
    });

    $(".tweets-panel .scroll-down").click(function (evt)
    {
        _this.stopAutoSlideShow();
        _this.tweetPanelScrollDown();
        evt.preventDefault();
    });

    $(".influencers-panel .scroll-up").click(function (evt)
    {
        _this.stopAutoSlideShow();
        _this.influencerPanelScrollUp();
        evt.preventDefault();
    });

    $(".influencers-panel .scroll-down").click(function (evt)
    {
        _this.stopAutoSlideShow();
        _this.influencerPanelScrollDown();
        evt.preventDefault();
    });

    $(".hashtags-panel .scroll-up").click(function (evt)
    {
        _this.stopAutoSlideShow();
        _this.hashTagPanelScrollUp();
        evt.preventDefault();
    });

    $(".hashtags-panel .scroll-down").click(function (evt)
    {
        _this.stopAutoSlideShow();
        _this.hashTagPanelScrollDown();
        evt.preventDefault();
    });

    _this._slideShowIntervalID = setInterval(function () { _this.togglePanels(); }, 30000);
}
_twitterInfluenceV3.prototype.tweetPanelScrollUp = function ()
{
    $(".twitter-influence-v3-tweet-holder").animate({ top: 0 }, 1000);
    $(".tweets-panel .scroll-up").animate({ opacity: 0 }, 1000);
    $(".tweets-panel .scroll-down").animate({ opacity: 1 }, 1000);
};
_twitterInfluenceV3.prototype.tweetPanelScrollDown = function ()
{
    if ($(".twitter-influence-v3-tweet-holder").height() > $(".twitter-influence-v3-right-column-content").height())
    {
        $(".twitter-influence-v3-tweet-holder").animate({ top: -($(".twitter-influence-v3-tweet-holder").height() - $(".twitter-influence-v3-right-column-content").height() + 20) }, 1000);
        $(".tweets-panel .scroll-up").animate({ opacity: 1 }, 1000);
        $(".tweets-panel .scroll-down").animate({ opacity: 0 }, 1000);
    }
};
_twitterInfluenceV3.prototype.influencerPanelScrollUp = function ()
{
    $(".twitter-influence-v3-influencers-holder").animate({ top: 0 }, 1000);
    $(".influencers-panel .scroll-up").animate({ opacity: 0 }, 1000);
    $(".influencers-panel .scroll-down").animate({ opacity: 1 }, 1000);
};
_twitterInfluenceV3.prototype.influencerPanelScrollDown = function ()
{
    if ($(".twitter-influence-v3-influencers-holder").height() > $(".twitter-influence-v3-right-column-content").height())
    {
        $(".twitter-influence-v3-influencers-holder").animate({ top: -($(".twitter-influence-v3-influencers-holder").height() - $(".twitter-influence-v3-right-column-content").height() + 20) }, 1000);
        $(".influencers-panel .scroll-up").animate({ opacity: 1 }, 1000);
        $(".influencers-panel .scroll-down").animate({ opacity: 0 }, 1000);
    }
};
_twitterInfluenceV3.prototype.hashTagPanelScrollUp = function ()
{
    $(".twitter-influence-v3-hashtag-holder").animate({ top: 0 }, 1000);
    $(".hashtags-panel .scroll-up").animate({ opacity: 0 }, 1000);
    $(".hashtags-panel .scroll-down").animate({ opacity: 1 }, 1000);
};
_twitterInfluenceV3.prototype.hashTagPanelScrollDown = function ()
{
    if ($(".twitter-influence-v3-hashtag-holder").height() > $(".twitter-influence-v3-right-column-content").height())
    {
        $(".twitter-influence-v3-hashtag-holder").animate({ top: -($(".twitter-influence-v3-hashtag-holder").height() - $(".twitter-influence-v3-right-column-content").height() + 20) }, 1000);
        $(".hashtags-panel .scroll-up").animate({ opacity: 1 }, 1000);
        $(".hashtags-panel .scroll-down").animate({ opacity: 0 }, 1000);
    }
};
_twitterInfluenceV3.prototype.stopAutoSlideShow = function ()
{
    var _this = this;
    if (_this._slideShowIntervalID > 0)
    {
        clearInterval(_this._slideShowIntervalID);
        _this._slideShowIntervalID = 0;
        _this._updateDataIntervalID = setInterval(function () { _this.updateData(); }, 30000);
    }
};
_twitterInfluenceV3.prototype._monitoredItem_Click = function (evt)
{
    if (this.selectedMonitoredItem != evt.target.innerHTML)
    {
        this.selectedMonitoredItem = evt.target.innerHTML;
        this.updateData(true);
    }
    evt.preventDefault();
};
_twitterInfluenceV3.prototype.updateData = function (manualUpdate)
{
    var _this = this;

    function _tweetsSuccess(_dataSet)
    {
        var 
            _lis = $(".twitter-influence-v3-tweet-holder").children("div"),
            _data = [];

        for (var i = 0; i < 10; i++)
        {
            var 
                _dataRow = null;

            if (_dataSet.tables.count > 0 && _dataSet.tables.items[0].rows.count > i)
                _dataRow = _dataSet.tables.items[0].rows.items[i];

            if (_dataRow != null)
            {
                _data.push({
                    id: _dataRow.getValue("twe_ID"),
                    text: _dataRow.getValue("twe_Text"),
                    screenName: _dataRow.getValue("use_ScreenName"),
                    url: _dataRow.getValue("use_URL")
                });

                if (_dataRow.getValue("twe_ID") != _getInnerText($(_lis[i]).children("span")[0]))
                {
                    function _updateTweet()
                    {
                        var 
                            _index = _this.getChildIndex(this),
                            _spans = $(this).children("span");

                        _spans[0].innerHTML = _data[_index].id;
                        _spans[2].innerHTML = _data[_index].text;
                        $(this).children("a")[0].href = "http://www.twitter.com/" + _data[_index].screenName;
                        $(this).children("a")[0].innerHTML = _data[_index].screenName;

                        $(this).removeClass("hidden");
                        $(this).css({ opacity: 0 });
                        $(this).animate({ opacity: 1 }, 1000)
                    }

                    $(_lis[i]).animate({ opacity: 0 }, 1000, _updateTweet)
                }
            }
            else
            {
                function _clearTweet()
                {
                    var 
                        _index = _this.getChildIndex(this),
                        _spans = $(this).children("span");

                    _spans[0].innerHTML = "0";
                    _spans[2].innerHTML = "";
                    $(this).children("a")[0].href = "";
                    $(this).children("a")[0].innerHTML = "";

                    $(this).addClass("hidden");
                    $(this).css({ opacity: 0 });
                }

                $(_lis[i]).animate({ opacity: 0 }, 1000, _clearTweet)
            }
        }
    }

    if (_this._displayedPanel == 0 || _this._slideShowIntervalID == 0)
        _this._webService.getDataSet("General_Report_TopTweets", "SearchFor=" + escapeString(_this.selectedMonitoredItem), false, _tweetsSuccess, function (s) { alert(s); });

    function _usersSuccess(_dataSet)
    {
        var 
            _lis = $(".twitter-influence-v3-influencers-holder").children("div"),
            _data = [];

        for (var i = 0; i < 10; i++)
        {
            var 
                _dataRow = null;

            if (_dataSet.tables.count > 0 && _dataSet.tables.items[0].rows.count > i)
                _dataRow = _dataSet.tables.items[0].rows.items[i];

            if (_dataRow != null)
            {
                _data.push({
                    id: _dataRow.getValue("use_ID"),
                    screenName: _dataRow.getValue("use_ScreenName"),
                    url: _dataRow.getValue("use_URL"),
                    profileImageURL: _dataRow.getValue("use_ProfileImageURL")
                });

                if (_dataRow.getValue("use_ID") != _getInnerText($(_lis[i]).children("span")[0]))
                {
                    function _updateUser()
                    {
                        var 
                            _index = _this.getChildIndex(this),
                            _spans = $(this).children("span");

                        _spans[0].innerHTML = _data[_index].id;
                        _spans[2].innerHTML = _data[_index].screenName;
                        $(this).children("a")[0].href = "http://www.twitter.com/" + _data[_index].screenName;
                        $(this).children("a").first().children("img")[0].src = _data[_index].profileImageURL;

                        $(this).removeClass("hidden");
                        $(this).css({ opacity: 0 });
                        $(this).animate({ opacity: 1 }, 1000)
                    }

                    $(_lis[i]).animate({ opacity: 0 }, 1000, _updateUser)
                }
            }
            else
            {
                function _clearUser()
                {
                    var 
                        _index = _this.getChildIndex(this),
                        _spans = $(this).children("span");

                    _spans[0].innerHTML = "0";
                    _spans[2].innerHTML = "";
                    $(this).children("a")[0].href = "";
                    $(this).children("a").first().children("img")[0].src = "";

                    $(this).addClass("hidden");
                    $(this).css({ opacity: 0 });
                }

                $(_lis[i]).animate({ opacity: 0 }, 1000, _clearUser)
            }
        }
    }

    if (_this._displayedPanel == 1 || _this._slideShowIntervalID == 0)
        _this._webService.getDataSet("General_Report_TopUsers", "SearchFor=" + escapeString(_this.selectedMonitoredItem), false, _usersSuccess);

    function _hashTagsSuccess(_dataSet)
    {
        var 
            _lis = $(".twitter-influence-v3-hashtag-holder").children("div"),
            _data = [];

        for (var i = 0; i < 10; i++)
        {
            var 
                _dataRow = null;

            if (_dataSet.tables.count > 0 && _dataSet.tables.items[0].rows.count > i)
                _dataRow = _dataSet.tables.items[0].rows.items[i];

            if (_dataRow != null)
            {
                _data.push({
                    id: _dataRow.getValue("hta_ID"),
                    text: "#" + _dataRow.getValue("hta_Text")
                });

                if (_dataRow.getValue("hta_ID") != _getInnerText($(_lis[i]).children("span")[0]))
                {
                    function _updateHashTag()
                    {
                        var 
                            _index = _this.getChildIndex(this),
                            _spans = $(this).children("span");

                        _spans[0].innerHTML = _data[_index].id;
                        _spans[2].innerHTML = _data[_index].text;

                        $(this).removeClass("hidden");
                        $(this).css({ opacity: 0 });
                        $(this).animate({ opacity: 1 }, 1000)
                    }

                    $(_lis[i]).animate({ opacity: 0 }, 1000, _updateHashTag)
                }
            }
            else
            {
                function _clearHashTag()
                {
                    var 
                        _index = _this.getChildIndex(this),
                        _spans = $(this).children("span");

                    _spans[0].innerHTML = "0";
                    _spans[2].innerHTML = "";

                    $(this).addClass("hidden");
                    $(this).css({ opacity: 0 });
                }

                $(_lis[i]).animate({ opacity: 0 }, 1000, _clearHashTag)
            }
        }
    }

    if (_this._displayedPanel == 2 || _this._slideShowIntervalID == 0)
        _this._webService.getDataSet("General_Report_TopHashTags", "SearchFor=" + escapeString(_this.selectedMonitoredItem), false, _hashTagsSuccess);

    if (manualUpdate)
    {
        _this.tweetPanelScrollUp();
        _this.influencerPanelScrollUp();
        _this.hashTagPanelScrollUp();
    }
};
_twitterInfluenceV3.prototype.showTweets = function ()
{
    var _this = this;

    $(".li-tweets input").removeClass("selected");
    $(".li-influencers input").removeClass("selected");
    $(".li-hashtag input").removeClass("selected");

    $(".li-tweets input").addClass("selected");

    $(".twitter-influence-v3-panel-container").animate({
        left: 0
    }, 1000, undefined, function ()
    {
        if (_this._slideShowIntervalID > 0)
            _this.updateData(); 
    });

    _this._displayedPanel = 0;
};
_twitterInfluenceV3.prototype.showInfluencers = function ()
{
    var _this = this;

    $(".li-tweets input").removeClass("selected");
    $(".li-influencers input").removeClass("selected");
    $(".li-hashtag input").removeClass("selected");

    $(".li-influencers input").addClass("selected");

    $(".twitter-influence-v3-panel-container").animate({
        left: -556
    }, 1000, undefined, function ()
    {
        if (_this._slideShowIntervalID > 0)
            _this.updateData(); 
    });

    _this._displayedPanel = 1;
};
_twitterInfluenceV3.prototype.showHashTags = function ()
{
    var _this = this;

    $(".li-tweets input").removeClass("selected");
    $(".li-influencers input").removeClass("selected");
    $(".li-hashtag input").removeClass("selected");

    $(".li-hashtag input").addClass("selected");

    $(".twitter-influence-v3-panel-container").animate({
        left: -1112
    }, 1000, undefined, function ()
    {
        if (_this._slideShowIntervalID > 0)
            _this.updateData(); 
    });

    _this._displayedPanel = 2;
};
_twitterInfluenceV3.prototype.togglePanels = function ()
{
    switch (this._displayedPanel)
    {
        case 0:
            this.showInfluencers();
            break;
        case 1:
            this.showHashTags();
            break;
        default:
            this.showTweets();
            break;
    }
};
_twitterInfluenceV3.prototype.getChildIndex = function (el)
{
    if (el.parentNode)
    {
        for (var i = 0; i < el.parentNode.childNodes.length; i++)
        {
            if (el.parentNode.childNodes[i] == el)
                return i;
        }
    }
    return -1;
};
