﻿    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);
    };

    function setImageBGPositionXY(e, x, y)
    {
        e.style.backgroundPosition = x + "px " + y + "px";
    }

    function setImageBGPositionY(e, i)
    {
        var sBGPosition = e.style.backgroundPosition;
        var iSpace = sBGPosition.indexOf(" ");
        sBGPosition = sBGPosition.substring(0, iSpace) + " " + i + "px";
        e.style.backgroundPosition = sBGPosition;
    }
    
    function tabbedContent(baseID, noTabs)
    {
        var tabbedContent = this;
        tabbedContent.baseID = baseID;
        tabbedContent.noTabs = noTabs;
        tabbedContent.tabCount = 0;
        tabbedContent.tabs = new Object();
        tabbedContent.panelCount = 0;
        tabbedContent.panels = new Object();
        tabbedContent.panelClass = new Object();
        tabbedContent.selectedTab = 0;
        tabbedContent.initialise();
        tabbedContent.onBeforeTabChanged = null;
        tabbedContent.onTabChanged = null;
    }

    tabbedContent.prototype =
    {
        initialise: function()
        {
            var tabbedContent = this, div, a, qs = new queryStringManager(), inpSelected = document.getElementById(tabbedContent.baseID + "_SelectedTab");
            var tab = 1;

            if (inpSelected && inpSelected.value != "")
            {
                tab = inpSelected.value;
                if (tab < 1) tab = 1;
                if (tab > tabbedContent.noTabs) tab = 1;
                inpSelected.value = tab;
            }

            tabbedContent.selectedTab = tab - 1;

            for (var i = 0; i < tabbedContent.noTabs; i++)
            {
                div = document.getElementById(tabbedContent.baseID + "_Tab" + (i + 1));
                if (div)
                {
                    tabbedContent.tabs[tabbedContent.tabCount] = div;
                    tabbedContent.tabCount++;

                    if (i == (tab - 1)) div.parentNode.className = "TabIn";
                    else div.parentNode.className = "Tab";

                    if (div.childNodes.length > 0)
                    {
                        a = div.childNodes[0];
                        a.href = "javascript:tabbedcontentmanager.showTab(\"" + tabbedContent.baseID + "\", " + i + ");";
                    }
                }
                div = document.getElementById(tabbedContent.baseID + "_Content" + (i + 1));
                if (div)
                {
                    tabbedContent.panels[tabbedContent.panelCount] = div;
                    tabbedContent.panelClass[tabbedContent.panelCount] = div.parentNode.className;
                    tabbedContent.panelCount++;
                    if (i != (tab - 1))
                        div.parentNode.className = tabbedContent.panelClass[tabbedContent.panelCount] + " TabPanelOff";
                }
            }

            if (tabbedContent.onTabChanged != null)
                tabbedContent.onTabChanged(tabbedContent.selectedTab);
        },

        showTab: function(tabNo)
        {
            var tabbedContent = this, inpSelected = document.getElementById(tabbedContent.baseID + "_SelectedTab");

            if (!tabbedContent.onBeforeTabChanged || (tabbedContent.onBeforeTabChanged && tabbedContent.onBeforeTabChanged(tabNo)))
            {

                for (var i = 0; i < tabbedContent.tabCount; i++)
                {
                    if (i == tabNo)
                        tabbedContent.tabs[i].parentNode.className = "TabIn";
                    else
                        tabbedContent.tabs[i].parentNode.className = "Tab";
                }
                for (var i = 0; i < tabbedContent.panelCount; i++)
                {
                    if (i == tabNo)
                    {
                        tabbedContent.panels[i].parentNode.className = tabbedContent.panelClass[i];
                        tabbedContent.panels[i].parentNode.style.display = "";
                    }
                    else
                        tabbedContent.panels[i].parentNode.className = tabbedContent.panelClass[i] + " TabPanelOff";
                }

                if (inpSelected) inpSelected.value = tabNo + 1;
                tabbedContent.selectedTab = tabNo;

                if (tabbedContent.onTabChanged != null)
                    tabbedContent.onTabChanged(tabbedContent.selectedTab);

            }
        }
    };
    
    function tabbedContentManager()
    {
        var tabbedContentManager = this;
        tabbedContentManager.tabbedContentCount = 0;
        tabbedContentManager.tabbedContent = new Object();
    }

    tabbedContentManager.prototype =
    {
        create: function(baseID, noTabs)
        {
            var tabbedContentManager = this, tc = new tabbedContent(baseID, noTabs);
            tabbedContentManager.tabbedContent[tabbedContentManager.tabbedContentCount] = tc;
            tabbedContentManager.tabbedContentCount++;
            return tc;
        },

        getByBaseID: function(baseID)
        {
            var tabbedContentManager = this;
            for (var i = 0; i < tabbedContentManager.tabbedContentCount; i++)
            {
                if (tabbedContentManager.tabbedContent[i].baseID == baseID)
                    return tabbedContentManager.tabbedContent[i];
            }
        },

        showTab: function(baseID, tabNo)
        {
            try
            {
                var tabbedContentManager = this, tc = tabbedContentManager.getByBaseID(baseID);
                if (tc) tc.showTab(tabNo);
            }
            catch (e) { };
        }
    };
    
    var tabbedcontentmanager = new tabbedContentManager();
    
    function helpPopUpManager()
    {
        this.divPopupBlocker = null;
        this.divPopup = null;
    }
    
    helpPopUpManager.prototype =
    {
        initialise: function()
        {
            for (var i = 0; i < document.links.length; i++)
            {
                if (document.links[i].className.indexOf("HelpPopUp") > -1)
                {
                    document.links[i].id = "helppopup" + i;
                    document.links[i].href = "javascript:helppopupmanager.launchPopup('" + document.links[i].href + "', 'helppopup" + i + "');";
                    document.links[i].target = "";
                }
            }
            this.divPopupBlocker = document.createElement("div");
            this.divPopupBlocker.className = "PopUpBlocker";
            this.divPopupBlocker.style.textAlign = "left";
            this.divPopup = document.createElement("div");
            this.divPopupBlocker.appendChild(this.divPopup);
        },
        
        getXMLHTTP: function()
        {
            var obj = null;

            try
            {
                obj = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) { }

            if (obj == null)
            {
                try
                {
                    obj = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e) { }
            }

            if ((obj == null) && (typeof XMLHttpRequest != "undefined"))
                obj = new XMLHttpRequest();

            return(obj);
        },
        
        launchPopup: function(url, elID)
        {
            var xmlHTTP = this.getXMLHTTP();
            if (xmlHTTP)
            {
                xmlHTTP.open("GET", url, false);
                xmlHTTP.send("");
                var failed = false;
                
                if (xmlHTTP.status != 200)
                    failed = true
                else
                {
                    var html = xmlHTTP.responseText;
                    var bodyStart = html.indexOf("<body");
                    if (bodyStart > -1) bodyStart = html.indexOf(">", bodyStart);
                    if (bodyStart > -1)
                    {
                        var bodyEnd = html.indexOf("</body");
                        if (bodyEnd > -1)
                        {
                            this.divPopup.innerHTML = html.substring(bodyStart + 1, bodyEnd);
                            document.body.appendChild(this.divPopupBlocker);
                            this.center(elID);
                        }
                        else
                            failed = true;
                    }
                    else
                        failed = true;
                }
                
                if (failed) window.open(url);
            }
        },
        
        center: function(elID)
        {
            var el = document.getElementById(elID);
            if (el)
            {
                var x = findPosX(el), y = findPosY(el);
                this.divPopup.style.position = "absolute";
                this.divPopup.style.left = "50%";
                this.divPopup.style.marginLeft = -(this.divPopup.offsetWidth / 2) + "px";
                this.divPopup.style.top = y + el.offsetHeight + "px";
            }
        },
        
        closePopUp: function()
        {
            try
            {
                document.body.removeChild(this.divPopupBlocker);
            }
            catch (e) {}
        }
        
    };
    
    var helppopupmanager = new helpPopUpManager();
    
    function initialiseHelpPopUps()
    {
        var qs = new queryStringManager();
        var designmode = qs.get("designmode", "");
        if (designmode != "on")
            helppopupmanager.initialise();
    }
    
    function getFirstParentNode(n, nodeName)
    {
        var node = n;
        var nodeNames = nodeName.split("|");
        while (node)
        {
            for (var i = 0; i < nodeNames.length; i++)
            {
                if (nodeNames[i] != "" && nodeNames[i].toUpperCase() == node.nodeName.toUpperCase()) return node;
            }
            node = node.parentNode;
        }
        return null;
    }
    
    // Default Button
    function clickButton(btn, event)
    {
        if ((event.keyCode && event.keyCode == 13) || (event.which && event.which == 13))
        {
            var oBtn = document.getElementById(btn);
            if (oBtn)
            {
                event.returnValue = false;
                event.cancel = true;
                if (event.preventDefault) event.preventDefault();
                oBtn.click();
            }
        }
    }
    
    function findPosX(obj)
    {
        if (!obj) return 0;
        var curleft = 0;
        if(obj.offsetParent)
            while(1) 
            {
                curleft += obj.offsetLeft;
                if(!obj.offsetParent)
                    break;
                obj = obj.offsetParent;
            }
        else if(obj.x)
            curleft += obj.x;
        return curleft;
    }

    function findPosY(obj)
    {
        if (!obj) return 0;    
        var curtop = 0;
        if(obj.offsetParent)
            while(1)
            {
                curtop += obj.offsetTop;
                if(!obj.offsetParent)
                    break;
                obj = obj.offsetParent;
            }
        else if(obj.y)
            curtop += obj.y;
        return curtop;
    }
    
    if (window.addEventListener)
        window.addEventListener("load", initialiseHelpPopUps, false);
    else if (window.attachEvent)
        window.attachEvent("onload", initialiseHelpPopUps);
        
    function exitSurvey()
    {
        this.close = function()
        {
            var
                divButton = document.getElementById("exitsurvey_popup"),
                divPanel = document.getElementById("exitsurvey"),
                divThankyou = document.getElementById("exitsurvey_thankyou");
            
            divButton.style.display = "none";
            divPanel.style.display = "none";
            divThankyou.style.display = "none";
            
            var expiryDate = new Date();
            expiryDate.setDate(expiryDate.getDate() + 90);
            document.cookie = "exitSurvey=off; expires=" + expiryDate.toGMTString() + "; path=/";
        };
        
        this.showPanel = function()
        {
            var
                divButton = document.getElementById("exitsurvey_popup"),
                divPanel = document.getElementById("exitsurvey"),
                divThankyou = document.getElementById("exitsurvey_thankyou");
            
            divButton.style.display = "none";
            divPanel.style.display = "";
            divThankyou.style.display = "none";
        };
    }
    
    var exitsurvey = new exitSurvey();

    var oGLocalSearch = new GlocalSearch();
    
    function geocodeSubmit(path, elID, event, qs)
    {
        var el = document.getElementById(elID), isPostcode = false;
        
        if (/^[a-zA-Z]{1,2}[0-9][0-9A-Za-z]{0,1}[ ]{0,1}[0-9][A-Za-z]{2}$/.test(el.value))
            isPostcode = true;
        
        if (isPostcode)
        {
            el.value = el.value.toUpperCase();
            if (el.value.indexOf(" ") == -1)
            {
                if (el.value.length > 4)
                    el.value = el.value.substr(0, el.value.length - 3) + " " + el.value.substr(el.value.length - 3)
            }
            oGLocalSearch.setSearchCompleteCallback
            (
                null,
                function()
                {
                    if (oGLocalSearch.results[0])
                        window.location = path + "?loc=" + el.value + "&lat=" + oGLocalSearch.results[0].lat + "&lng=" + oGLocalSearch.results[0].lng + (qs ? "&" + qs : "");
                    else
                        alert("Postcode not found!");
                }
            );
            oGLocalSearch.execute(el.value + ", UK");
        }
        else
            window.location = path + "?loc=" + el.value + (qs ? "&" + qs : "");
        
        if (event)
        {
            if (event.preventDefault) event.preventDefault();
            event.returnValue = false;
            event.cancel = true;
        }
        return false;
    }

    /* Local Area - Home page
     ******************************************************************************************/
    var _localArea = null;
    function initialiseLocalArea()
    {
        _localArea = new localArea();
    }

    function localArea ()
    {
        var _this = this;

        _this.button = null;
        _this.filters = null;
        _this.filtersInner = null;
        _this.expanded = false;
        _this.animationDuration = 500;
        _this.expandedHeight = 0;

        _this.initialise();
    }
    localArea.prototype.initialise = function ()
    {
        var _this = this;
        _this.button = document.getElementById("SearchByTopic");
        _this.filters = document.getElementById("LocalAreaFilters");
        _this.filtersInner = document.getElementById("LocalAreaFiltersInner");

        _this.button.style.display = "";
        _this.button.onclick = function ()
        {
            if (_this.expanded)
                _this.collapse();
            else
            {
                _this.expand();
                dcsMultiTrack('DCS.dcsuri', '/Home/local-search/expand', 'WT.ti', 'Home local search expanded');
            }

            return false;
        };

        _this.expandedHeight = _this.filtersInner.offsetHeight;
        _this.filters.style.height = 0;
        _this.filters.style.overflow = "hidden";

        _this.filtersInner.style.position = "absolute";
        _this.filtersInner.style.left = 0;
        _this.filtersInner.style.bottom = 0;
    }
    localArea.prototype.expand = function ()
    {
        var _this = this;
        _this.expanded = true;
        _this.button.className = "SearchByTopic SearchByTopic-Expanded";

        var frames = 1, x = 0;
        if (_this.animationDuration)
            frames = _this.animationDuration / 30;

        setTimeout('_localArea.animate(' + _this.expandedHeight + ', ' + _this.filters.offsetHeight + ', ' + 1 + ', ' + frames + ')', 30);
    }
    localArea.prototype.collapse = function ()
    {
        var _this = this;
        _this.expanded = false;
        _this.button.className = "SearchByTopic";

        var frames = 1, x = 0;
        frames = _this.animationDuration / 30;

        setTimeout('_localArea.animate(0, ' + _this.filters.offsetHeight + ', 1, ' + frames + ')', 30);
    }
    localArea.prototype.animate = function (targetHeight, startHeight, frame, totalFrames)
    {
        var _this = this;

        var vector = targetHeight - startHeight;    // The total distance we need to cover with the direction (+ve or -ve).

        var rad = (Math.PI / 2) / totalFrames;      // The number of radians of change per frame.

        var ratio;                                  // The total ratio of the distance that will be covered at the current frame.
        if (vector > 0)
            ratio = Math.sin(rad * frame);
        else
            ratio = Math.sin((Math.PI / 2) - (rad * frame));

        var distance = Math.abs(vector);            // The total distance we need to cover without direction.

        var height = Math.ceil(distance * ratio);   // The height for this frame.

        // Check if the target height has been reached or if the frame is the last one.
        if ((targetHeight - startHeight) < 0 && (height > targetHeight) || (targetHeight - startHeight) > 0 && (height < targetHeight) && frame < totalFrames)
            _this.filters.style.height = height + 'px';
        else
        {
            _this.filters.style.height = targetHeight + 'px';
            return;
        }

        // Iterative cycle.
        setTimeout('_localArea.animate(' + targetHeight + ', ' + startHeight + ', ' + (frame + 1) + ', ' + totalFrames + ')', 30);
    }

    /* Local Area - Strategic Slideshow
     ******************************************************************************************/
    var _slideShow = null;
    function initialiseSlideshow(id)
    {
        if (document.getElementById(id + '_Controls'))
        {
            var 
            _divSlideShow = document.getElementById(id + "_Slideshow"),
            _divSlideShowSlides = document.getElementById(id + "_Slides"),
            _divControls = document.getElementById(id + '_Controls').childNodes;

            _divSlideShow.style.display = "";
            _slideShow = new yorkshirewater.slideShow(_divSlideShowSlides, 2000, true, window.attachEvent ? 800 : 1000);
            _slideShow.beforeIndexChanged = function (index)
            {
                for (var i = 0; i < _divControls.length; i++)
                {
                    if (i == index)
                    {
                        if (_divControls[i].className.indexOf("-Selected") == -1)
                            _divControls[i].className = _divControls[i].className + " " + _divControls[i].className + "-Selected";
                    }
                    else
                    {
                        if (_divControls[i].className.indexOf("-Selected") != -1)
                            _divControls[i].className = _divControls[i].className.substring(0, _divControls[i].className.indexOf(" "));
                    }
                }

                for (var i = 0; i < _youTubeVideos.length; i++)
                {
                    try
                    {
                        _youTubeVideos[i].pauseVideo();
                    }
                    catch (e)
                    {
                    }
                }
            };
        }
    }

    var _youTubeVideos = [];
    function embedYouTubeVideo(elID, width, height, youTubeID)
    {
        function _embedYouTubeVideo()
        {
            var 
                parameters =
                {
                    allowScriptAccess: "always",
                    allowFullScreen: "true",
                    wmode: "opaque"
                },
                attributes =
                {
                    id: elID + "Object"
                };

            var pv = swfobject.getFlashPlayerVersion();
            if (navigator.appVersion.indexOf("MSIE 6") != -1 && pv.major == 10 && pv.minor == 0 && pv.release == 45)
            {
                if (document.getElementById(elID))
                    document.getElementById(elID).innerHTML = '<div class="ie6-flash-error"><p>To view this content please <a href="http://get.adobe.com/flashplayer/">upgrade your Adobe Flash Player</a>.</p><p>Or visit the <a href="http://www.youtube.com/yorkshirewatertube">Yorkshire Water YouTube Channel</a>.</div>';
            }
            else
                swfobject.embedSWF("http://www.youtube.com/v/" + youTubeID + "?enablejsapi=1&rel=0&playerapiid=" + elID + "Object", elID, width, height, "8", null, null, parameters, attributes);
        }

        if (window.attachEvent)
            window.attachEvent("onload", _embedYouTubeVideo);
        else if (window.addEventListener)
            window.addEventListener("load", _embedYouTubeVideo, false);
    }

    /* Utility functions
     ******************************************************************************************/
    function getChildElementsByClass(node, cssClass)
    {
        var children = node.childNodes,
            matches = new Array();
        if (children.length > 0)
        {
            for (var x = 0; x < children.length; x++)
            {
                var classes = children[x].className.split(' ');
                for (var y = 0; y < classes.length; y++)
                {
                    if (classes[y] == cssClass)
                    {
                        matches.push(children[x]);
                        break;
                    }
                }
            }

            return matches;
        }
        else
            return null;
    }

    var easing = {};
    easing._reverse = function (eq, t, b, c, d)
    {
        return -eq(d - t, b, c, d) + c + 2 * b;
    };
    easing._inToInOut = function (easeIn, t, b, c, d)
    {
        t = t * 2;
        return (t < d ? easeIn(t, b, c / 2, d) : this._reverse(easeIn, t - d, b + c / 2, c / 2, d));
    };
    easing._outToInOut = function (easeOut, t)
    {
        t = 2 * t;
        return 0.5 * (t < 1 ? 1 - easeOut(1 - t) : 1 + easeOut(t - 1));
    };
    easing._inOutPairToInOut = function (easeIn, easeOut, t)
    {
        t = 2 * t;
        return 0.5 * (t < 1 ? easeIn(t) : 1 + easeOut(t - 1));
    };
    easing.quinticIn = function (t, b, c, d)
    {
        return c * (t /= d) * t * t * t * t + b;
    };
    easing.quinticOut = function (t, b, c, d)
    {
        return this._reverse(this.quinticIn, t, b, c, d);
    };
    easing.quinticInOut = function (t, b, c, d)
    {
        return this._inToInOut(this.quinticIn, t, b, c, d);
    };

    // DOM Helper
    // Used for common DOM tasks
    function _domHelper()
    {
    }
    _domHelper.prototype.addClass = function (el, className)
    {
        this.removeClass(el, className);
        el.className += " " + className;
    };
    _domHelper.prototype.removeClass = function (el, className)
    {
        var 
                    _classes = el.className.split(" "),
                    _newClassString = "";

        for (var i = 0; i < _classes.length; i++)
        {
            if (_classes[i] != className)
                _newClassString += _classes[i] + " ";
        }

        el.className = _newClassString.trim();
    };
    _domHelper.prototype.attachEvent = function (event, el, fn)
    {

        if (window.attachEvent)
            el.attachEvent("on" + event, fn);
        else if (window.addEventListener)
            el.addEventListener(event, fn, false);
    };
    _domHelper.prototype.setFloat = function (el, styleFloat)
    {
        el.style.styleFloat = styleFloat;
    };

    var domHelper = new _domHelper();
    this.domHelper = domHelper;


    /* Flickr!!!
    ******************************************************************************************/   
    function flickrSlideshow(divSlider, interval, autoStart, animationLength)
    {
        var _this = this;
        _this.element = divSlider;
        _this.viewport = getChildElementsByClass(_this.element, "Viewport")[0];
        _this.divSlider = getChildElementsByClass(_this.element, "Viewport")[0].childNodes[0];
        var _height = 0;

        for (var i = 0; i < _this.divSlider.childNodes.length; i++)
        {
            if (_this.divSlider.childNodes[i].nodeType != 1)
            {
                _this.divSlider.removeChild(_this.divSlider.childNodes[i]);
                i--;
            }
            else
            {
                if (_this.divSlider.childNodes[i].offsetHeight > _height)
                {
                    _height = _this.divSlider.childNodes[i].offsetHeight;
                }
            }
        }

        if (_height > 0)
        {
            _this.viewport.style.height = _height + "px";
            _this.divSlider.style.height = _height + "px";
            for (var i = 0; i < _this.divSlider.childNodes.length; i++)
            {
                _this.divSlider.childNodes[i].style.height = _height + "px";
            }
        }

        _this.aLeftArrow = getChildElementsByClass(_this.element, "Previous")[0];
        _this.aRightArrow = getChildElementsByClass(_this.element, "Next")[0];

        if ((_this.divSlider.childNodes && _this.element.className.indexOf("FlickrFeed-3Wide") != -1 && _this.divSlider.childNodes.length > 3) ||
            (_this.divSlider.childNodes && _this.element.className.indexOf("FlickrFeed-5Wide") != -1 && _this.divSlider.childNodes.length > 5))
        {
            _this.aLeftArrow.style.display = "block";
            _this.aRightArrow.style.display = "block";
        }

        domHelper.attachEvent(
                    "click",
                    _this.aLeftArrow,
                    function (e)
                    {
                        var evt = typeof event != "undefined" ? event : e;
                        var _index = _this.startIndex - 3;
                        if (_index < 0)
                            _index = _index + _this.panelCount;
                        _this.slideToIndex(_index, _this.directionEnum.left)
                        if (e.preventDefault)
                            e.preventDefault();
                        return false;
                    }
                );

        domHelper.attachEvent(
                    "click",
                    _this.aRightArrow,
                    function (e)
                    {
                        var evt = typeof event != "undefined" ? event : e;
                        var _index = _this.startIndex + 3;
                        if (_index > _this.panelCount - 1)
                            _index = _index - _this.panelCount;
                        _this.slideToIndex(_index, _this.directionEnum.right)
                        if (e.preventDefault)
                            e.preventDefault();
                        return false;
                    }
                );

        _this.interval = interval;
        _this.autoStart = autoStart;
        _this.animationLength = (typeof animationLength != "undefined" ? animationLength : 1000);

        _this.beforeIndexChanged = null;
        _this.afterIndexChanged = null;
        _this.slidingStart = null;
        _this.stepChanged = null;

        _this.panelCount = _this.divSlider.childNodes.length;
        if (_this.divSlider.childNodes[0])
            _this.panelWidth = (_this.divSlider.childNodes ? _this.divSlider.childNodes[0].offsetWidth : 0);
        _this.originalStartIndex = 0;
        _this.startIndex = 0;
        _this.autoTimeoutID = 0;
        _this.timeoutID = 0;
        _this._step = 0;
        _this._startPosition = 0;
        _this._desiredPosition = 0;
        _this._queueIndex = 0;

        function _slideToNextRight()
        {
            var 
                    _panelsToMove = Math.round(_this.divSlider.parentNode.offsetWidth / _this.panelWidth, 0),
                    _next = _this.startIndex + _panelsToMove;

            if (_next > _this.panelCount - 1)
                _next = _next - _this.panelCount;

            function callback()
            {
                _this.autoTimeoutID = setTimeout(_slideToNextRight, interval);
            }
            _this._slideToIndex(_next, _this.directionEnum.right, callback);
        }

        if (_this.autoStart)
            _this.autoTimeoutID = setTimeout(_slideToNextRight, interval);
    }
    flickrSlideshow.prototype.directionEnum = { left: 0, right: 1, leftRight: 2 };
    flickrSlideshow.prototype.slideLeft = function (completedCallback)
    {
        var _index = this.startIndex - 1;
        if (_index < 0)
            _index = this.panelCount - 1;
        this.slideToIndex(_index, this.directionEnum.left, completedCallback);
    };
    flickrSlideshow.prototype.slideRight = function (completedCallback)
    {
        var _index = this.startIndex + 1;
        if (_index > this.panelCount - 1)
            _index = 0;
        this.slideToIndex(_index, this.directionEnum.right, completedCallback);
    };
    flickrSlideshow.prototype.jumpToIndex = function (index)
    {
        if (this.beforeIndexChanged)
            this.beforeIndexChanged(index);

        clearTimeout(this.autoTimeoutID);
        if (index >= 0 && index < this.panelCount)
        {
            while (this.startIndex != index)
            {
                this.divSlider.appendChild(this.divSlider.childNodes[0]);
                this.startIndex++;
                if (this.startIndex > this.panelCount - 1)
                    this.startIndex = 0;
            }
        }

        if (this.afterIndexChanged)
            this.afterIndexChanged(index);
    };
    flickrSlideshow.prototype.stopAutoSlideShow = function ()
    {
        if (this.autoTimeoutID > 0)
            clearTimeout(this.autoTimeoutID);
    };
    flickrSlideshow.prototype.slideToIndex = function (index, direction, completedCallback)
    {
        if (this.timeoutID > 0)
        {
            this._queueIndex = index;
            return;
        }
        if (this.autoTimeoutID > 0)
            clearTimeout(this.autoTimeoutID);
        this._slideToIndex(index, direction, completedCallback);
    }
    flickrSlideshow.prototype._slideToIndex = function (index, direction, completedCallback, f)
    {
        var 
            _this = this,
            _steps = _this.animationLength / 20,
            _newPos = 0;

        if (_this.divSlider && _this.divSlider.childNodes.length > 0)
        {
            if (_this.beforeIndexChanged)
                _this.beforeIndexChanged(index);

            _this.originalStartIndex = _this.startIndex;

            _this._startPosition = isNaN(parseInt(_this.divSlider.style.left)) ? 0 : -parseInt(_this.divSlider.style.left);

            if (direction == _this.directionEnum.right && index < _this.startIndex)
                _this._desiredPosition = (_this.panelCount - _this.startIndex + index) * _this.panelWidth;
            else if (direction == _this.directionEnum.left && index > _this.startIndex)
                _this._desiredPosition = (-_this.panelCount - _this.startIndex + index) * _this.panelWidth;
            else
                _this._desiredPosition = (index - _this.startIndex) * _this.panelWidth;

            function _nextStep()
            {
                _newPos = Math.round(easing.quinticInOut(_this._step, _this._startPosition, _this._desiredPosition - _this._startPosition, _steps), 0);
                if (_newPos >= _this.panelWidth)
                {
                    _this.divSlider.appendChild(_this.divSlider.childNodes[0]);

                    _newPos -= _this.panelWidth;
                    _this._desiredPosition -= _this.panelWidth;
                    _this._startPosition -= _this.panelWidth;

                    _this.startIndex++;
                    if (_this.startIndex > _this.panelCount - 1)
                        _this.startIndex = 0;
                }
                else if (_newPos < 0)
                {
                    _this.divSlider.insertBefore(_this.divSlider.childNodes[_this.divSlider.childNodes.length - 1], _this.divSlider.childNodes[0]);

                    _newPos += _this.panelWidth;
                    _this._desiredPosition += _this.panelWidth;
                    _this._startPosition += _this.panelWidth;

                    _this.startIndex--;
                    if (_this.startIndex < 0)
                        _this.startIndex = _this.panelCount - 1;
                }

                _this.divSlider.style.left = (-_newPos) + "px";

                if (_this._step < _steps)
                {
                    _this._step++;
                    _this.timeoutID = setTimeout(_nextStep, 20);
                }
                else
                {
                    _newPos = _this._desiredPosition
                    _this.timeoutID = 0;
                    _this._step = 0;

                    if (completedCallback)
                        completedCallback();

                    if (_this.afterIndexChanged)
                        _this.afterIndexChanged(index);
                }

                if (_this.stepChanged)
                    _this.stepChanged(_this.originalStartIndex, index, (_newPos - _this._startPosition) / (_this._desiredPosition - _this._startPosition));
            }
            _this.timeoutID = setTimeout(_nextStep, 20);

            if (_this.slidingStart)
                _this.slidingStart(_this.startIndex, index);
        }
    }

    /* Switching tabs new contact us
    ******************************************************************************************/

    function switchTab(div)
    {
        if (div == 'Tab1')
        {
            document.getElementById('Tab1').style.display = "block";
            document.getElementById('Tab2').style.display = "none";
        }
        else
        {
            document.getElementById('Tab1').style.display = "none";
            document.getElementById('Tab2').style.display = "block";
        }
    }

    /* Pop Up Splash Pages
    **********************/
    var popUpSplashPages = [];
    function popUpSplashPage(url, id)
    {
        var _this = this;
        _this.divPopupBlocker = null;
        _this.divPopup = null;
        _this.url = url;
        _this.id = id;

        popUpSplashPages.push(_this);

        if (window.addEventListener)
            window.addEventListener("load", function () { _this.initialise(); }, false);
        else if (window.attachEvent)
            window.attachEvent("onload", function () { _this.initialise(); });
    }
    popUpSplashPage.closePopUp = function (id)
    {
        for (var i = 0; i < popUpSplashPages.length; i++)
        {
            if (popUpSplashPages[i].id == id)
            {
                popUpSplashPages[i].closePopUp();
                break;
            }
        }
    };

    popUpSplashPage.prototype =
    {
        initialise: function ()
        {
            var _this = this;
            this.divPopupBlocker = document.createElement("div");
            this.divPopupBlocker.className = "PopUpBlocker";
            this.divPopupBlocker.style.textAlign = "left";
            this.divPopup = document.createElement("div");
            this.divPopupBlocker.appendChild(this.divPopup);

            setTimeout(function () { _this.launchPopup(); }, 1000);
        },

        getXMLHTTP: function ()
        {
            var obj = null;

            try
            {
                obj = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) { }

            if (obj == null)
            {
                try
                {
                    obj = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e) { }
            }

            if ((obj == null) && (typeof XMLHttpRequest != "undefined"))
                obj = new XMLHttpRequest();

            return (obj);
        },

        launchPopup: function ()
        {
            var xmlHTTP = this.getXMLHTTP();
            if (xmlHTTP)
            {
                xmlHTTP.open("GET", this.url + "?id=" + this.id, false);
                xmlHTTP.send("");
                var failed = false;

                if (xmlHTTP.status != 200)
                    failed = true
                else
                {
                    var html = xmlHTTP.responseText;
                    var bodyStart = html.indexOf("<body");
                    if (bodyStart > -1) bodyStart = html.indexOf(">", bodyStart);
                    if (bodyStart > -1)
                    {
                        var bodyEnd = html.indexOf("</body");
                        if (bodyEnd > -1)
                        {
                            this.divPopup.innerHTML = html.substring(bodyStart + 1, bodyEnd);
                            document.body.appendChild(this.divPopupBlocker);
                            this.center();
                        }
                        else
                            failed = true;
                    }
                    else
                        failed = true;
                }

                if (failed) window.open(this.url);
            }
        },

        center: function ()
        {
            var _this = this;
            _this.divPopup.style.position = "absolute";
            _this.divPopup.style.left = "50%";
            _this.divPopup.style.marginLeft = -(_this.divPopup.offsetWidth / 2) + "px";
            _this.divPopup.style.top = ($(window).scrollTop() + 100) + "px";

            window.onscroll = function ()
            {
                _this.divPopup.style.top = ($(window).scrollTop() + 100) + "px";
            };
        },

        closePopUp: function ()
        {
            try
            {
                var expiryDate = new Date();
                expiryDate.setDate(expiryDate.getDate() + 90);
                document.cookie = "pop-up-splash-page-" + this.id.replace(" ", "-") + "=off; expires=" + expiryDate.toGMTString() + "; path=/";
                document.body.removeChild(this.divPopupBlocker);
            }
            catch (e) { }
        }
    };
