﻿
    function hammonds()
    {
    }

    // Slideshow Launcher
    // ******************
    hammonds.slideshowLauncher = function (elementID, initialFlashVideoFilePath)
    {
        this.slideshow = null;
        this.elementID = elementID;
        this.initialFlashVideoFilePath = initialFlashVideoFilePath;
        this.slides = [];
    }
    hammonds.slideshowLauncher.prototype.addSlide = function (image, imageDescription, linkURL)
    {
        this.slides.push(new hammonds.slideshowLauncher.slide(image, imageDescription, linkURL));
    };
    hammonds.slideshowLauncher.prototype.initialise = function ()
    {
        var _this = this;
        var parentNode = document.getElementById(_this.elementID);

        if (parentNode)
        {
            while (parentNode.childNodes.length > 0)
                parentNode.removeChild(parentNode.childNodes[0]);

            _this.element = document.createElement("div");
            _this.element.className = "slide-show";
            parentNode.appendChild(_this.element);

            _this.divViewPort = document.createElement("div");
            _this.divViewPort.className = "viewport";
            _this.element.appendChild(_this.divViewPort);

            _this.divControlPanel = document.createElement("div");
            _this.divControlPanel.className = "control-panel";
            _this.divControlPanel.style.opacity = 0;
            _this.divControlPanel.style.filter = "alpha(opacity = 0)";
            _this.element.appendChild(_this.divControlPanel);

            _this.aLeft = document.createElement("a");
            _this.aLeft.className = "arrow-block-left-pink";
            _this.aLeft.href = "#";
            _this.aLeft.style.opacity = 0;
            _this.aLeft.style.filter = "alpha(opacity = 0)";
            _this.divControlPanel.appendChild(_this.aLeft);

            attachEventHandler(_this.aLeft, "click", function (sender, event)
            {
                _this.slideshow.slideLeft();
                if (event.preventDefault)
                    event.preventDefault();
                event.returnValue = false;
                return false;
            });

            _this.aRight = document.createElement("a");
            _this.aRight.className = "arrow-block-right-pink";
            _this.aRight.href = "#";
            _this.aRight.style.opacity = 0;
            _this.aRight.style.filter = "alpha(opacity = 0)";
            _this.divControlPanel.appendChild(_this.aRight);

            attachEventHandler(_this.aRight, "click", function (sender, event)
            {
                _this.slideshow.slideRight();
                if (event.preventDefault)
                    event.preventDefault();
                event.returnValue = false;
                return false;
            });

            if (_this.initialFlashVideoFilePath != "")
            {

                _this.divFlash = document.createElement("div");
                _this.divFlash.className = "slide";
                _this.divViewPort.appendChild(_this.divFlash);

                _this.divFlashInner = document.createElement("div");
                _this.divFlashInner.id = "divFlashInner";
                _this.divFlash.appendChild(_this.divFlashInner);

                var flashvars = {};
                var params = {};
                params.allowScriptAccess = "always";
                params.scale = "noscale";
                params.wmode = "opaque";
                var attributes = {};
                swfobject.embedSWF(_this.initialFlashVideoFilePath, "divFlashInner", "712", "331", "9.0.0", false, flashvars, params, attributes);
                _gaq.push(["_trackEvent", "video", "play", "home page"]);

                function _startSlideShow()
                {
                    var _totalWidth = 0;

                    for (var i = 0; i < _this.slides.length; i++)
                    {
                        _this.divViewPort.appendChild(_this.slides[i].element);
                        _totalWidth += _this.slides[i].element.offsetWidth;
                    }

                    _this.divViewPort.style.width = _totalWidth + "px";

                    _this.slideshow = new hammonds.slideshow(_this.divViewPort, 3000, true, 1000);
                    _this.slideshow._autoCallback = function ()
                    {
                        _this.divFlash.parentNode.removeChild(_this.divFlash);
                        _this.slideshow._autoCallback = null;
                    };

                    _this.slideshow.stepChanged = function (startIndex, endIndex, value)
                    {
                        var percent = value * 100;

                        _this.divControlPanel.style.display = "block";
                        _this.divControlPanel.style.opacity = (percent / 100 * 0.92);
                        _this.divControlPanel.style.filter = "alpha(opacity = " + (percent / 100 * 92) + ")";
                        _this.aLeft.style.opacity = percent / 100;
                        _this.aLeft.style.filter = "alpha(opacity = " + percent + ")";
                        _this.aRight.style.opacity = percent / 100;
                        _this.aRight.style.filter = "alpha(opacity = " + percent + ")";

                        if (percent == 100)
                            _this.slideshow.stepChanged = null;
                    };
                }
                setTimeout(_startSlideShow, 10000);
            }
            else
            {
                var _totalWidth = 0;

                for (var i = 0; i < _this.slides.length; i++)
                {
                    _this.divViewPort.appendChild(_this.slides[i].element);
                    _totalWidth += _this.slides[i].element.offsetWidth;
                }

                _this.divViewPort.style.width = _totalWidth + "px";

                _this.slideshow = new hammonds.slideshow(_this.divViewPort, 3000, true, 1000);
                _this.slideshow._autoCallback = function ()
                {
                    _this.slideshow._autoCallback = null;
                };

                _this.divControlPanel.style.display = "block";
                _this.divControlPanel.style.opacity = 0.92;
                _this.divControlPanel.style.filter = "alpha(opacity = 92)";
                _this.aLeft.style.opacity = 1;
                _this.aLeft.style.filter = "alpha(opacity = 100)";
                _this.aRight.style.opacity = 1;
                _this.aRight.style.filter = "alpha(opacity = 100)";
            }
        }
    };
    hammonds.slideshowLauncher.slide = function (image, imageDescription, linkURL)
    {
        this.element = document.createElement("div");
        this.element.className = "slide";

        this.a = document.createElement("a");
        this.a.href = linkURL;
        this.element.appendChild(this.a);

        this.img = document.createElement("img");
        this.img.alt = imageDescription;
        this.img.src = image;
        this.a.appendChild(this.img);
    }

    hammonds.easing = {};
    hammonds.easing._reverse = function (eq, t, b, c, d)
    {
        return -eq(d - t, b, c, d) + c + 2 * b;
    };
    hammonds.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));
    };
    hammonds.easing._outToInOut = function (easeOut, t)
    {
        t = 2 * t;
        return 0.5 * (t < 1 ? 1 - easeOut(1 - t) : 1 + easeOut(t - 1));
    };
    hammonds.easing._inOutPairToInOut = function (easeIn, easeOut, t)
    {
        t = 2 * t;
        return 0.5 * (t < 1 ? easeIn(t) : 1 + easeOut(t - 1));
    };
    hammonds.easing.quinticIn = function (t, b, c, d)
    {
        return c * (t /= d) * t * t * t * t + b;
    };
    hammonds.easing.quinticOut = function (t, b, c, d)
    {
        return this._reverse(this.quinticIn, t, b, c, d);
    };
    hammonds.easing.quinticInOut = function (t, b, c, d)
    {
        return this._inToInOut(this.quinticIn, t, b, c, d);
    };

    // Slideshow Control
    // *****************
    hammonds.slideshow = function (divSlider, interval, autoStart, animationLength)
    {
        var _this = this;
        _this.divSlider = divSlider;

        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--;
            }
        }
        
        _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;
        _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;
        _this._autoCallback = null;

        function _slideToNextRight()
        {
            var 
                _panelsToMove = Math.round(_this.divSlider.parentNode.offsetWidth / _this.panelWidth),
                _next = _this.startIndex + _panelsToMove;

            if (_next > _this.panelCount - 1)
                _next = _next - _this.panelCount;

            function callback()
            {
                if (_this._autoCallback)
                    _this._autoCallback();

                _this.autoTimeoutID = setTimeout(_slideToNextRight, interval);
            }
            _this._slideToIndex(_next, _this.directionEnum.right, callback);
        }

        if (_this.autoStart)
            _this.autoTimeoutID = setTimeout(_slideToNextRight, interval);
    }
    hammonds.slideshow.prototype.directionEnum = { left: 0, right: 1, leftRight: 2 };
    hammonds.slideshow.prototype.slideLeft = function (completedCallback)
    {
        var _index = this.startIndex - 1;
        if (_index < 0)
            _index = this.panelCount - 1;
        this.slideToIndex(_index, this.directionEnum.left, completedCallback);
    };
    hammonds.slideshow.prototype.slideRight = function (completedCallback)
    {
        var _index = this.startIndex + 1;
        if (_index > this.panelCount - 1)
            _index = 0;
        this.slideToIndex(_index, this.directionEnum.right, completedCallback);
    };
    hammonds.slideshow.prototype.visibleSlides = function ()
    {
        return this.divSlider.parentNode.offsetWidth / this.panelWidth;
    };
    hammonds.slideshow.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);
    };
    hammonds.slideshow.prototype.stopAutoSlideShow = function ()
    {
        if (this.autoTimeoutID > 0)
            clearTimeout(this.autoTimeoutID);
    };
    hammonds.slideshow.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);
    }
    hammonds.slideshow.prototype._slideToIndex = function (index, direction, completedCallback, f)
    {
        var 
                    _this = this,
                    _steps = _this.animationLength / 20,
                    _newPos = 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(hammonds.easing.quinticInOut(_this._step, _this._startPosition, _this._desiredPosition - _this._startPosition, _steps));
            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._queueIndex > 0)
                    setTimeout(function () { _this._slideToIndex(_this._queueIndex, direction, completedCallback, f); _this._queueIndex = 0; }, 1);
            }

            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);

    }

    // Store Locator
    // *************
    hammonds.storeLocator = function ()
    {
        this.googleMap = null;

        this.labSearchText = null;
        this.labSearchText_OriginalInnerHTML = "";
        this.tboSearchText = null;

        this.ddlRange = null;
        this.aSearchButton = null;
        this.aRangeButton = null;
        this.geoCoder = null;
        this.initialise();
    }
    hammonds.storeLocator.prototype.initialise = function ()
    {
        var _this = this;
        _this.labSearchText = document.getElementById("labSearchText");
        _this.labSearchText_OriginalInnerHTML = _this.labSearchText.innerHTML;
        _this.tboSearchText = document.getElementById("tboSearchText");

        _this.ddlRange = document.getElementById("ddlRange");
        _this.aSearchButton = document.getElementById("aSearchButton");
        _this.aRangeButton = document.getElementById("aRangeButton");
        _this.geoCoder = new google.maps.Geocoder();

        attachEventHandler(_this.tboSearchText, "keydown", function (sender, event)
        {
            if (event.keyCode == 13)
            {
                _this.searchClick(sender, event);
                if (event.preventDefault)
                    event.preventDefault();
                event.returnValue = false;
                event.cancel = true;
                return false;
            }
        });

        attachEventHandler(_this.aSearchButton, "click", function (sender, event)
        {
            hammonds.googleTracking.storeLocatorSearch();
            return _this.searchClick(sender, event);
        });

        attachEventHandler(_this.aRangeButton, "click", function (sender, event)
        {
            hammonds.googleTracking.storeLocatorSearch();
            return _this.searchClick(sender, event);
        });

        _this.googleMap = googlemapmanager.maps.getByName("gmcStoreLocator");
        _this.googleMap.createInfoBox = function (googleMarker) { return _this.createInfoBox(googleMarker); };
        _this.googleMap.initialise(function ()
        {
            if (_this.tboSearchText.value != "")
                _this.searchClick(null, null);
        });
    };
    hammonds.storeLocator.prototype.searchClick = function (sender, event)
    {
        var 
            _this = this,
            isPostcode = /^[a-zA-Z]{1,2}[0-9][0-9A-Za-z]{0,1}[ ]{0,1}[0-9][A-Za-z]{2}$/.test(_this.tboSearchText.value.trim());

        this.labSearchText.className = "label";
        this.labSearchText.innerHTML = this.labSearchText_OriginalInnerHTML;

        if (isPostcode)
        {
            _this.tboSearchText.value = _this.tboSearchText.value.toUpperCase().trim();
            if (_this.tboSearchText.value.indexOf(" ") == -1)
            {
                if (_this.tboSearchText.value.length > 4)
                    _this.tboSearchText.value = _this.tboSearchText.value.substr(0, _this.tboSearchText.value.length - 3) + " " + _this.tboSearchText.value.substr(_this.tboSearchText.value.length - 3)
            }
        }
        else
        {
            var 
                parts = _this.tboSearchText.value.trim().split(" ");

            for (var i = 0; i < parts.length; i++)
                parts[i] = parts[i].substr(0, 1).toUpperCase() + parts[i].substr(1).toLowerCase();

            _this.tboSearchText.value = parts.join(" ");
        }

        // Geocode
        // *******
        if (_this.tboSearchText.value.trim() != "")
            _this.geoCoder.geocode({ address: _this.tboSearchText.value, region: "UK" }, function (results, status) { _this.geoCodeCallback(results, status); });
        else
            _this.geoCodeCallback(null, "NO_POSTCODE");

        if (event)
        {
            if (event.preventDefault)
                event.preventDefault();
            event.returnValue = false;
            event.cancel = true;
        }
        return false;
    };
    hammonds.storeLocator.prototype.geoCodeCallback = function (results, status)
    {
        var _this = this;
        if (status == "OK")
        {
            _this.updateResults(results, status);
        }
        else if (status == "NO_POSTCODE")
        {
            _this.labSearchText.className = "label label-error";
            _this.labSearchText.innerHTML = "Please enter your postcode*";
        }
        else
        {
            _this.labSearchText.className = "label label-error";
            _this.labSearchText.innerHTML = "No results, please try again*";
        }
    };
    hammonds.storeLocator.prototype.updateResults = function (results, status)
    {
        this.labSearchText.className = "label";
        this.labSearchText.innerHTML = this.labSearchText_OriginalInnerHTML;

        // Find the number of results
        var searchResultsMarkers = [];
        for (var i = 0; i < this.googleMap.markers.count; i++)
        {
            if (this.ddlRange.value != "")
            {
                var 
                    productOptions = this.googleMap.markers.items[i].dataRow.getValue("StoreProductOptions").split(","),
                    hasProductOption = false;

                for (var j = 0; j < productOptions.length; j++)
                {
                    if (productOptions[j].length >= this.ddlRange.value.length && productOptions[j].substr(0, this.ddlRange.value.length) == this.ddlRange.value)
                    {
                        hasProductOption = true;
                        break;
                    }
                }

                if (hasProductOption)
                    searchResultsMarkers.push(this.googleMap.markers.items[i]);
            }
            else
                searchResultsMarkers.push(this.googleMap.markers.items[i]);
        }

        var hasResults = false;
        for (var i = 0; i < searchResultsMarkers.length; i++)
        {
            if (this.calculateDistance(results[0].geometry.location.lat(), results[0].geometry.location.lng(), searchResultsMarkers[i].location.latitude, searchResultsMarkers[i].location.longitude) < 48.28032)
            {
                hasResults = true;
                break;
            }
        }

        if (!hasResults)
        {
            this.labSearchText.className = "label label-error";
            this.labSearchText.innerHTML = "No results, please try again*";
        }
        else
        {
            for (var i = 0; i < this.googleMap.markers.count; i++)
            {
                if (this.googleMap.markers.items[i].infoBox)
                    this.googleMap.markers.items[i].infoBox.setMap(null);

                if (this.ddlRange.value != "")
                {
                    var 
                    productOptions = this.googleMap.markers.items[i].dataRow.getValue("StoreProductOptions").split(","),
                    hasProductOption = false;

                    for (var j = 0; j < productOptions.length; j++)
                    {
                        if (productOptions[j].length >= this.ddlRange.value.length && productOptions[j].substr(0, this.ddlRange.value.length) == this.ddlRange.value)
                        {
                            hasProductOption = true;
                            break;
                        }
                    }

                    this.googleMap.markers.items[i].display = hasProductOption;
                }
                else
                    this.googleMap.markers.items[i].display = true;
            }

            for (var i = 0; i < this.googleMap.markerGroups.count; i++)
            {
                var hasDisplay = false;
                for (var j = 0; j < this.googleMap.markers.count; j++)
                {
                    if (this.googleMap.markers.items[j].groupName == this.googleMap.markerGroups.items[i].groupName)
                    {
                        if (this.googleMap.markers.items[j].display)
                        {
                            hasDisplay = true;
                            break;
                        }
                    }
                }
                this.googleMap.markerGroups.items[i].display = hasDisplay;
            }

            this.googleMap.updateMarkers();

            var sortedLatLng = [];
            for (var i = 0; i < this.googleMap.markers.count; i++)
            {
                if (this.googleMap.markers.items[i].display)
                    sortedLatLng.push(
                {
                    lat: this.googleMap.markers.items[i].location.latitude,
                    lng: this.googleMap.markers.items[i].location.longitude,
                    distance: this.calculateDistance
                    (
                        results[0].geometry.location.lat(),
                        results[0].geometry.location.lng(),
                        this.googleMap.markers.items[i].location.latitude,
                        this.googleMap.markers.items[i].location.longitude
                    ),
                    marker: this.googleMap.markers.items[i]
                });
            }

            var changed = true;
            while (changed)
            {
                changed = false;
                for (var i = 0; i < sortedLatLng.length - 1; i++)
                {
                    if (sortedLatLng[i].distance > sortedLatLng[i + 1].distance)
                    {
                        var temp = sortedLatLng[i];
                        sortedLatLng[i] = sortedLatLng[i + 1];
                        sortedLatLng[i + 1] = temp;
                        changed = true;
                    }
                }
            }

            var bounds = new google.maps.LatLngBounds();
            bounds.extend(new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng()));
            for (var i = 0; i < sortedLatLng.length; i++)
            {
                if (i == 10 || sortedLatLng[i].distance > 48.28032)
                    break;
                bounds.extend(new google.maps.LatLng(sortedLatLng[i].lat, sortedLatLng[i].lng));
                $(".store-locator-details-stores").append($(sortedLatLng[i].marker.dataRow.getValue("StoreSummaryPanelHTML")));
            }

            this.googleMap.map.fitBounds(bounds);

            function getSortedLatLngByMarkerID(markerID)
            {
                for (var i = 0; i < sortedLatLng.length; i++)
                {
                    if (sortedLatLng[i].marker.dataRow.getValue("ID") == markerID)
                        return sortedLatLng[i];
                }

                return null;
            }

            // Animate panels
            $(".store-locator-details-container").fadeTo(500, 0, function ()
            {
                var originalHeight = $(".store-locator-details-container").height();
                $(".store-locator-details-container").css("height", originalHeight + "px");

                $(".store-locator-details-container").css("visibility", "hidden");
                $(".store-locator-details-stores").empty();

                for (var i = 0; i < sortedLatLng.length; i++)
                {
                    if (i == 10 || sortedLatLng[i].distance > 48.28032)
                        break;
                    $(".store-locator-details-stores").append($(sortedLatLng[i].marker.dataRow.getValue("StoreSummaryPanelHTML")));
                }

                $(".store-locator-details-container").css("height", "auto");
                var containerHeight = $(".store-locator-details-container").height();
                $(".store-locator-details-container").css("height", originalHeight + "px");
                $(".store-locator-details-container").animate({ height: containerHeight }, 500, null, function ()
                {
                    $(".store-locator-details-container").fadeTo(0, 0);
                    $(".store-locator-details-container").css("visibility", "visible");

                    $(".store-locator-details-store").each(function (index, element)
                    {
                        var 
                            sortedLatLng = getSortedLatLngByMarkerID(element.id.substr(9));

                        if (sortedLatLng)
                        {
                            var 
                                header = $(".store-locator-details-text-header h3", element);

                            header.html(header.html() + " - " + (Math.round(sortedLatLng.distance * 0.621371192 * 100) / 100) + " Miles");
                        }
                    });

                    $(".store-locator-details-text-column a").each(function (index, element)
                    {
                        element.href = element.href + "/" + results[0].geometry.location.lat() + "/" + results[0].geometry.location.lng();
                    });

                    $(".store-locator-details-container").fadeTo(500, 1, function ()
                    {
                        $(".store-locator-details-store").each(function (index, element)
                        {
                            var 
                                sortedLatLng = getSortedLatLngByMarkerID(element.id.substr(9));

                            if (sortedLatLng)
                            {
                                var 
                                    marker = sortedLatLng.marker,
                                    mapContainer = $(".store-locator-details-map", element),
                                    myOptions =
                                    {
                                        zoom: 10,
                                        center: new google.maps.LatLng(marker.location.latitude, marker.location.longitude),
                                        mapTypeId: google.maps.MapTypeId.ROADMAP,
                                        disableDefaultUI: true,
                                        disableDoubleClickZoom: true,
                                        draggable: false,
                                        keyboardShortcuts: false,
                                        mapTypeControl: false,
                                        overviewMapControl: false,
                                        panControl: false,
                                        rotateControl: false,
                                        scaleControl: false,
                                        scrollwheel: false,
                                        streetViewControl: false,
                                        zoomControl: false
                                    },
                                    googleMap = new google.maps.Map(mapContainer[0], myOptions),
                                    image = (!isIE6 ? marker.image : marker.image.substr(0, marker.image.length - 3) + "gif"),
                                    googleMarker = new google.maps.Marker({
                                        position: new google.maps.LatLng(marker.location.latitude, marker.location.longitude),
                                        map: googleMap,
                                        icon: image,
                                        shadow: (!isIE6 ? new google.maps.MarkerImage(marker.shadow, new google.maps.Size(30, 18), new google.maps.Point(0, 0), new google.maps.Point(0, 18)) : null),
                                        clickable: false
                                    });
                            }
                        });
                    });
                });
            });
        }
    };
    hammonds.storeLocator.prototype.calculateDistance = function(lat1, lng1, lat2, lng2)
    {
        var R = 6371; // Radius of the earth in km
        var dLat = this.degreesToRadians(lat2 - lat1);  // Javascript functions in radians
        var dLon = this.degreesToRadians(lng2 - lng1);
        var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
        Math.cos(this.degreesToRadians(lat1)) * Math.cos(this.degreesToRadians(lat2)) *
        Math.sin(dLon / 2) * Math.sin(dLon / 2);
        var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
        return R * c; // Distance in km
    };
    hammonds.storeLocator.prototype.degreesToRadians = function (degrees)
    {
        return degrees * Math.PI / 180;
    };
    hammonds.storeLocator.prototype.createInfoBox = function (googleMarker)
    {
        return new hammonds.googleInfoBox(googleMarker);
    };

    // Store Locator Details Page
    // **************************
    hammonds.storeLocatorDetailPage = function ()
    {
        var _this = this;
        $(function () { _this.initialise(); });
    }
    hammonds.storeLocatorDetailPage.prototype.initialise = function ()
    {
        $(".store-locator-back-button").click(function (evt)
        {
            evt.preventDefault();

            if (document.referrer.indexOf(window.location.hostname) != -1)
            {
                parent.history.back();
                return false;
            }
        });
    };

    // Google Info Box
    // ***************
    hammonds.googleInfoBox = function (googleMarker)
    {
        var 
            _this = this;

        google.maps.OverlayView.call(_this);

        _this._googleMarker = googleMarker;
        _this._latlng = googleMarker.marker.getPosition();
        _this._map = googleMarker.marker.map;

        _this.initialise();

    }
    if (typeof google != "undefined")
        hammonds.googleInfoBox.prototype = new google.maps.OverlayView();
    hammonds.googleInfoBox.prototype.remove = function ()
    {
        if (this.element)
            this.element.parentNode.removeChild(this.element);
    };
    hammonds.googleInfoBox.prototype.draw = function ()
    {
        if (this.element)
        {
            var 
                pixPosition = this.getProjection().fromLatLngToDivPixel(this._latlng),
                panes = this.getPanes();

            if (pixPosition && panes)
            {
                for (var i = 0; i < this._googleMarker.googleMap.markers.count; i++)
                {
                    if (this._googleMarker.googleMap.markers.items[i].infoBox && this._googleMarker.googleMap.markers.items[i].infoBox != this)
                        this._googleMarker.googleMap.markers.items[i].infoBox.setMap(null);
                }

                while (panes.floatPane.childNodes.length > 0)
                    panes.floatPane.removeChild(panes.floatPane.childNodes[0]);

                if (this.element.parentNode != panes.floatPane)
                    panes.floatPane.appendChild(this.element);

                var 
                    maxHeight = 0;

                this.divTabPanel1.style.display = "block";
                this.divTabPanel2.style.display = "block";

                maxHeight = this.divTabPanel1.offsetHeight > this.divTabPanel2.offsetHeight ? this.divTabPanel1.offsetHeight : this.divTabPanel2.offsetHeight;

                this.divTabPanel1.style.height = maxHeight + "px";
                this.divTabPanel2.style.height = maxHeight + "px";

                this.divTabPanel1.style.display = "";
                this.divTabPanel2.style.display = "";

                this.element.style.left = (pixPosition.x - this.element.offsetWidth) + "px";
                this.element.style.top = (pixPosition.y - this.element.offsetHeight) + "px";

                this.panMap();
            }

        }
    };
    hammonds.googleInfoBox.prototype.initialise = function ()
    {
        var 
            _this = this,
            divClear = document.createElement("div");

        divClear.className = "clear";

        _this.element = document.createElement("div");
        _this.element.className = "map-info-box";

        _this.divInner = document.createElement("div");
        _this.divInner.className = "map-info-box-inner";
        _this.element.appendChild(_this.divInner);

        _this.divShadow = document.createElement("div");
        _this.divShadow.className = "shadow";
        _this.divInner.appendChild(_this.divShadow);

        _this.divPointer = document.createElement("div");
        _this.divPointer.className = "pointer";
        _this.divInner.appendChild(_this.divPointer);

        _this.divTabControl = document.createElement("div");
        _this.divTabControl.className = "tab-control";
        _this.divInner.appendChild(_this.divTabControl);

        _this.divTabStrip = document.createElement("div");
        _this.divTabStrip.className = "tab-strip";
        _this.divTabControl.appendChild(_this.divTabStrip);

        _this.divTab1 = document.createElement("div");
        _this.divTab1.className = "tab tab-on";
        _this.divTabStrip.appendChild(_this.divTab1);

        _this.pTab1 = document.createElement("p");
        _this.divTab1.appendChild(_this.pTab1);

        _this.aTab1 = document.createElement("a");
        _this.aTab1.href = "#";
        _this.aTab1.appendChild(document.createTextNode("Location info"));
        _this.pTab1.appendChild(_this.aTab1);

        _this.divTab2 = document.createElement("div");
        _this.divTab2.className = "tab tab-last";
        _this.divTabStrip.appendChild(_this.divTab2);

        _this.pTab2 = document.createElement("p");
        _this.divTab2.appendChild(_this.pTab2);

        _this.aTab2 = document.createElement("a");
        _this.aTab2.href = "#";
        _this.aTab2.appendChild(document.createTextNode("Ranges on display"));
        _this.pTab2.appendChild(_this.aTab2);

        _this.divTabStrip.appendChild(divClear.cloneNode(true));

        _this.divTabPanels = document.createElement("div");
        _this.divTabPanels.className = "tab-panels";
        _this.divTabControl.appendChild(_this.divTabPanels);

        _this.divTabPanel1 = document.createElement("div");
        _this.divTabPanel1.className = "tab-panel tab-panel-active";
        _this.divTabPanels.appendChild(_this.divTabPanel1);

        if (_this._googleMarker && _this._googleMarker.dataRow)
            _this.divTabPanel1.innerHTML = _this._googleMarker.dataRow.getValue("Tab1HTML");

        _this.divTabPanel2 = document.createElement("div");
        _this.divTabPanel2.className = "tab-panel";
        _this.divTabPanels.appendChild(_this.divTabPanel2);

        if (_this._googleMarker && _this._googleMarker.dataRow)
            _this.divTabPanel2.innerHTML = _this._googleMarker.dataRow.getValue("Tab2HTML");

        _this.pZoom = document.createElement("p");
        _this.pZoom.className = "zoom";
        _this.divTabPanels.appendChild(_this.pZoom);

        _this.aZoom = document.createElement("a");
        _this.aZoom.href = "#";
        _this.aZoom.appendChild(document.createTextNode("Zoom to here"));
        _this.pZoom.appendChild(_this.aZoom);

        _this.pZoom.appendChild(document.createElement("br"));

        _this.aViewStoreDetails = document.createElement("a");
        _this.aViewStoreDetails.href = _this._googleMarker.dataRow.getValue("StoreLinkURL");
        _this.aViewStoreDetails.appendChild(document.createTextNode("View store details"));
        _this.pZoom.appendChild(_this.aViewStoreDetails);

        _this.aClose = document.createElement("a");
        _this.aClose.href = "#";
        _this.aClose.className = "close";
        _this.divTabPanels.appendChild(_this.aClose);

        attachEventHandler(_this.aTab1, "click", function (sender, event)
        {
            DOMHelper.removeClass(_this.divTab2, "tab-on");
            DOMHelper.removeClass(_this.divTabPanel2, "tab-panel-active");

            DOMHelper.addClass(_this.divTab1, "tab-on");
            DOMHelper.addClass(_this.divTabPanel1, "tab-panel-active");

            if (event.preventDefault)
                event.preventDefault();
            return false;
        });

        attachEventHandler(_this.aTab2, "click", function (sender, event)
        {
            DOMHelper.removeClass(_this.divTab1, "tab-on");
            DOMHelper.removeClass(_this.divTabPanel1, "tab-panel-active");

            DOMHelper.addClass(_this.divTab2, "tab-on");
            DOMHelper.addClass(_this.divTabPanel2, "tab-panel-active");

            if (event.preventDefault)
                event.preventDefault();
            return false;
        });

        attachEventHandler(_this.aZoom, "click", function (sender, event)
        {
            _this._map.setZoom(15);
            _this._map.setCenter(_this._latlng);
            _this.panMap();

            if (event.preventDefault)
                event.preventDefault();
            return false;
        });

        attachEventHandler(_this.aClose, "click", function (sender, event)
        {
            _this.setMap(null);

            if (event.preventDefault)
                event.preventDefault();
            return false;
        });
    }
    hammonds.googleInfoBox.prototype.onRemove = function ()
    {
        if (this.element.parentNode)
            this.element.parentNode.removeChild(this.element);
    };
    hammonds.googleInfoBox.prototype.panMap = function ()
    {
        var 
            bounds = this._map.getBounds();

        if (bounds)
        {
            var 
                padX = 50,
                padY = 50,
                mapDiv = this._map.getDiv(),
                boundsSpan = bounds.toSpan(),
                longSpan = boundsSpan.lng(),
                latSpan = boundsSpan.lat(),
                degPixelX = longSpan / mapDiv.offsetWidth,
                degPixelY = latSpan / mapDiv.offsetHeight;

            var 
                mapWestLng = bounds.getSouthWest().lng(),
                mapEastLng = bounds.getNorthEast().lng(),
                mapNorthLat = bounds.getNorthEast().lat(),
                mapSouthLat = bounds.getSouthWest().lat();

            var 
                iwWestLng = this._latlng.lng() - (this.element.offsetWidth + padX) * degPixelX,
                iwEastLng = this._latlng.lng(), /*+ (this.element.offsetWidth + padX) * degPixelX,*/
                iwNorthLat = this._latlng.lat() + (this.element.offsetHeight + padY) * degPixelY,
                iwSouthLat = this._latlng.lat(); /* -(this.element.offsetHeight - padY) * degPixelY;*/

            var 
                shiftLng = (iwWestLng < mapWestLng ? mapWestLng - iwWestLng : 0) + (iwEastLng > mapEastLng ? mapEastLng - iwEastLng : 0),
                shiftLat = (iwNorthLat > mapNorthLat ? mapNorthLat - iwNorthLat : 0) + (iwSouthLat < mapSouthLat ? mapSouthLat - iwSouthLat : 0);

            var 
                center = this._map.getCenter();

            this._map.panTo(new google.maps.LatLng(center.lat() - shiftLat, center.lng() - shiftLng));

        }
    };


    // Store Details Map
    // *****************
    hammonds.storeDetailsMap = function (latitude, longitude, markerImage, markerShadowImage)
    {
        var _this = this;
        _this.latitude = latitude;
        _this.longitude = longitude;
        _this.markerImage = markerImage;
        _this.markerShadowImage = markerShadowImage;
        _this.expanded = false;
        _this.animating = false;
        $(function () { _this.initialise(); });
    };
    hammonds.storeDetailsMap.prototype.initialise = function ()
    {
        var _this = this;
        _this.storeDetailsContainer = $(".store-details-container");
        _this.storeDetailsMapContainer = $(".store-details-map-container");
        _this.storeDetailsMap = $(".store-details-map");
        _this.expandMapButton = $(".expand-map-button");

        var 
            myOptions =
            {
                zoom: 10,
                center: new google.maps.LatLng(_this.latitude, _this.longitude),
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                disableDefaultUI: true,
                disableDoubleClickZoom: true,
                draggable: false,
                keyboardShortcuts: false,
                mapTypeControl: false,
                overviewMapControl: false,
                panControl: false,
                rotateControl: false,
                scaleControl: false,
                scrollwheel: false,
                streetViewControl: false,
                zoomControl: false
            },
            googleMap = new google.maps.Map(_this.storeDetailsMap[0], myOptions),
            image = (!isIE6 ? _this.markerImage : _this.markerImage.substr(0, _this.markerImage.length - 3) + "gif"),
            googleMarker = new google.maps.Marker({
                position: new google.maps.LatLng(_this.latitude, _this.longitude),
                map: googleMap,
                icon: image,
                shadow: (!isIE6 ? new google.maps.MarkerImage(_this.markerShadowImage, new google.maps.Size(30, 18), new google.maps.Point(0, 0), new google.maps.Point(0, 18)) : null),
                clickable: false
            });

        if (isIE6)
            _this.expandMapButton.hide();

        _this.expandMapButton.click(function (evt)
        {
            evt.preventDefault();

            if (_this.animating)
                return;

            _this.animating = true;

            if (_this.expanded)
            {
                _this.expandMapButton.css("backgroundPosition", "0 0");
                _this.storeDetailsMapContainer.animate({ left: 0, width: 220 }, 500);
                _this.storeDetailsMap.animate({ left: -360 }, 500, null, function ()
                {
                    _this.storeDetailsContainer.animate({ marginTop: 0 }, 500, null, function ()
                    {
                        _this.expanded = false;
                        _this.animating = false;
                    });
                });
            }
            else
            {
                _this.expandMapButton.css("backgroundPosition", "0 -38px");
                _this.storeDetailsContainer.animate({ marginTop: 352 }, 500, null, function ()
                {
                    _this.storeDetailsMapContainer.animate({ left: -721, width: 940 }, 500);
                    _this.storeDetailsMap.animate({ left: 0 }, 500, null, function ()
                    {
                        _this.expanded = true;
                        _this.animating = false;
                    });
                });
            }
        });
    };

    // Product Landing Page
    // ********************
    hammonds.productLandingPage = function (isAdmin)
    {
        var _this = this;
        _this.webService = null;
        _this.isAdmin = isAdmin;
        _this.dropDown = null;
        _this.pods = null;
        _this.panels = null;
        _this.mainText = null;
        _this.mainImage = null;
        _this.originalMainTextHeight = 0;
        _this.originalMainImageHeight = 0;

        $(function () { _this.initialise(); });
    }
    hammonds.productLandingPage.prototype.initialise = function ()
    {
        var _this = this;
        _this.webService = new webService(WEBSITE_CONTENT_URL + "productdataservice.asmx");

        $(".collection-drop-down-panel input").hide();

        _this.dropDown = $(".collection-drop-down-panel select");
        _this.dropDown.change(function (evt)
        {
            if (!_this.isAdmin)
            {
                hammonds.googleTracking.landingPageFiltered($("option:selected", _this.dropDown).text());

                $(".landing-page-item-pods .search-icon").css("display", "none");
                _this.hideAllSectionPods(
                    function ()
                    {
                        _this.removeSectionPods(
                            function ()
                            {
                                _this.showSectionPods(function ()
                                {
                                    $(".landing-page-item-pods .search-icon").css("display", "block");
                                });
                            });
                    });
            }
        });

        _this.pods = $(".landing-page-pods");
        _this.panels = $(".landing-page-panels");

        _this.mainText = $(".text-inner");
        _this.mainImage = $("#divImagePanel");

        if (_this.mainText.css("display") == "none")
            _this.mainText.animate({ opacity: 0 }, 500);

        if (_this.mainImage.css("display") == "none")
            _this.mainImage.animate({ opacity: 0 }, 500);

        _this.panels.css("display", "block");

        $(".landing-page-item-pods .search-icon").css("display", "block");
        $(".landing-page-item-pods .search-icon").click(function (evt)
        {
            evt.preventDefault();
            if (this.href.indexOf("?id=") > -1)
            {
                var id = this.href.substr(this.href.indexOf("?id=") + 4);
                if (!isNaN(parseInt(id)))
                {
                    hammonds.productPopup.instance.show(id);
                }
            }
        });
    };
    hammonds.productLandingPage.prototype.hideAllSectionPods = function (callBack)
    {
        this.mainText.animate({ opacity: 0 }, 500);
        this.mainImage.animate({ opacity: 0 }, 500);

        this.panels.animate({ opacity: 0 }, 500);
        this.pods.animate({ opacity: 0 }, 500, null, function () { if (callBack) callBack(); });

        var tempHeight = (this.mainText.css("height") == "0px" ? 0 : this.mainText.height());
        if (!isIE6)
            this.mainText.css("display", "block");
        this.mainText.css("height", "auto");
        this.originalMainTextHeight = this.mainText.height();
        this.mainText.css("height", tempHeight + "px");

        tempHeight = (this.mainImage.css("height") == "0px" ? 0 : this.mainImage.height());
        if (!isIE6)
            this.mainImage.css("display", "block");
        this.mainImage.css("height", "auto");
        this.originalMainImageHeight = this.mainImage.height();
        this.mainImage.css("height", tempHeight + "px");

        // Move wishlist
        if (this.dropDown.val() == 0)
        {
            var i = 0, positioned = false;
            this.pods.children().each(function (index, element)
            {
                if (!positioned)
                {
                    if (element.id.substr(0, 17) == "SectionHeaderPod_")
                    {
                        if (i == 4)
                        {
                            $("#WishListPod").insertBefore(element);
                            positioned = true;
                        }
                        i++;
                    }
                }
            });
        }
        else
            $("#WishListPod").insertBefore($("div.clear", this.pods));

    };
    hammonds.productLandingPage.prototype.removeSectionPods = function (callBack)
    {
        var 
            _this = this,
            originalPodsHeight = _this.pods.height(),
            newPodsHeight = 0,
            originalPanelsHeight = _this.panels.height(),
            newPanelsHeight = 0,
            sectionID = _this.dropDown.val(),
            currentSectionID = 0;

        if (sectionID == 0)
        {
            _this.mainText.css("display", "block");
            _this.mainText.animate({ height: _this.originalMainTextHeight }, 500);

            _this.mainImage.css("display", "block");
            _this.mainImage.animate({ height: (sectionID == 0 ? _this.originalMainImageHeight : 0) }, 500);

            $(".collection-drop-down-panel").animate({ marginTop: 23 }, 500);
        }
        else
        {
            _this.mainText.animate({ height: 0 }, 500, null, function () { $(this).css("display", "none"); });
            _this.mainImage.animate({ height: 0 }, 500, null, function () { $(this).css("display", "none"); });
            $(".collection-drop-down-panel").animate({ marginTop: 0 }, 500);
        }

        this.panels.children().each(function (index, element)
        {
            if (element.id.substr(0, 13) == "SectionPanel_")
            {
                currentSectionID = element.id.substr(13);

                if (currentSectionID != sectionID)
                    $(element).css("display", "none");
                else
                    $(element).css("display", "block");
            }
        });

        this.pods.children().each(function (index, element)
        {
            if (element.id.substr(0, 17) == "SectionHeaderPod_" || element.id.substr(0, 15) == "SectionItemPod_")
            {
                if (element.id.substr(0, 17) == "SectionHeaderPod_")
                    currentSectionID = element.id.substr(17);

                if (sectionID != 0 && currentSectionID != sectionID)
                    $(element).css("display", "none");
                else
                    $(element).css("display", "block");
            }
            else if (element.id == "WishListPod")
            {
                $(element).css("display", "block");
            }
            else if (element.id == "DesignServicePod")
            {
                if (sectionID != 0)
                    $(element).css("display", "none");
                else
                    $(element).css("display", "block");
            }
        });

        newPanelsHeight = _this.panels.height();
        _this.panels.css("height", originalPanelsHeight + "px");

        _this.panels.animate({ height: newPanelsHeight }, 500, null, function () { _this.panels.css("height", "auto"); });

        newPodsHeight = _this.pods.height();
        _this.pods.css("height", originalPodsHeight + "px");

        _this.pods.animate({ height: newPodsHeight }, 500, null, function () { _this.pods.css("height", "auto"); if (callBack) callBack(); });
    };
    hammonds.productLandingPage.prototype.showSectionPods = function (callBack)
    {
        var 
            sectionID = this.dropDown.val(),
            currentSectionID = 0,
            iCurrentPod = 0;

        if (sectionID == 0)
        {
            this.mainText.animate({ opacity: 1 }, 500);
            this.mainImage.animate({ opacity: 1 }, 500);
        }

        this.pods.children().each(function (index, element)
        {
            if ($(element).css("display") == "block")
            {
                if ((iCurrentPod + 1) % 4 == 0)
                    $(element).addClass("last-pod");
                else
                    $(element).removeClass("last-pod");
                iCurrentPod++;
            }
        });

        this.panels.animate({ opacity: 1 }, 500);
        this.pods.animate({ opacity: 1 }, 500, null, function () { if (callBack) callBack(); });
    };

    // Wish List Page
    // **************
    hammonds.wishListPage = function ()
    {
        var _this = this;
        $(function () { _this.initialise(); });
    }
    hammonds.wishListPage.prototype.initialise = function ()
    {
        var _this = this;
        $(".landing-page-item-pods .search-icon").css("display", "block");
        $(".landing-page-item-pods .search-icon").click(function (evt)
        {
            evt.preventDefault();
            if (this.href.indexOf("?id=") > -1)
            {
                var id = this.href.substr(this.href.indexOf("?id=") + 4);
                if (!isNaN(parseInt(id)))
                {
                    hammonds.productPopup.instance.show(id);
                }
            }
        });
    };

    // Product Popup
    // *************
    hammonds.productPopup = function ()
    {
        var _this = this;
        _this.productID = 0;
        _this.inWishList = false;
        _this.webService = null;
        _this.popupContainer = null;
        _this.productDetailPopupLoader = null;
        _this.popupElementInner = null;
        _this.slideshowArrowLeft = null;
        _this.slideshowArrowRight = null;
        _this.slideshowClose = null;
        _this.popupToolTip = null;
        _this.popupToolTipTimeout = 0;
        _this.productDetailPopupImages = null;
        _this.productDetailPopupThumbnails = null;
        _this.productDetailPopupAvailableFinishesContainer = null;
        _this.productDetailPopupAvailableColoursContainer = null;
        _this.slides = 0;
        _this.currentSlide = 0;
        _this.imagePanelWidth = 700;
        _this.animating = false;
        $(function () { _this.initialise(); });
    }
    hammonds.productPopup.prototype.initialise = function ()
    {
        var _this = this;
        _this.webService = new webService(WEBSITE_CONTENT_URL + "productdataservice.asmx");
        _this.popupContainer = $(".product-detail-popup-container");
        _this.popupContainer.click(function (evt)
        {
            evt.stopPropagation();
            _this.popupElementInner.stop().animate({ opacity: 0 }, 500, null, function () { _this.popupElementInner.css("display", "none"); _this.popupContainer.css("display", "none"); });
        });

        _this.productDetailPopupLoader = $(".product-detail-popup-loader", _this.popupContainer);

        _this.popupElementInner = $(".product-detail-popup-inner", _this.popupContainer);
        _this.popupElementInner.animate({ opacity: 0 }, 0);
        _this.popupElementInner.click(function (evt)
        {
            evt.stopPropagation();
        });

        _this.popupElementInner.mouseover(function (evt)
        {
            if (_this.popupToolTip.css("display") == "block")
                _this.popupToolTipTimeout = setTimeout(function () { _this.popupToolTipTimeout = 0; _this.popupToolTip.stop().animate({ opacity: 0 }, 250, null, function (evt) { _this.popupToolTip.css("display", "none"); }); }, 250);
        });

        _this.slideshowArrowLeft = $(".slideshow-arrow-left", _this.popupContainer);
        _this.slideshowArrowLeft.click(function (evt)
        {
            evt.preventDefault();

            if (_this.animating)
                return;
            _this.animating = true;

            _this.currentSlide--;

            if (_this.currentSlide < 0)
                _this.currentSlide = _this.slides - 1;

            _this.productDetailPopupImages.children().last().prependTo(_this.productDetailPopupImages);
            _this.productDetailPopupImages.css("left", (_this.productDetailPopupImages.position().left - _this.imagePanelWidth) + "px");
            _this.productDetailPopupImages.animate({ left: _this.productDetailPopupImages.position().left + _this.imagePanelWidth }, 500, null, function () { _this.animating = false; });
        });

        _this.slideshowArrowRight = $(".slideshow-arrow-right", _this.popupContainer);
        _this.slideshowArrowRight.click(function (evt)
        {
            evt.preventDefault();

            if (_this.animating)
                return;
            _this.animating = true;

            _this.currentSlide++;

            if (_this.currentSlide >= _this.slides)
                _this.currentSlide = 0;

            _this.productDetailPopupImages.animate({ left: _this.productDetailPopupImages.position().left - _this.imagePanelWidth }, 500, null, function ()
            {
                _this.productDetailPopupImages.children().first().appendTo(_this.productDetailPopupImages);
                _this.productDetailPopupImages.css("left", (_this.productDetailPopupImages.position().left + _this.imagePanelWidth) + "px"); _this.animating = false;
            });
        });

        _this.slideshowClose = $(".slideshow-close", _this.popupContainer);
        _this.slideshowClose.click(function (evt)
        {
            evt.preventDefault();
            _this.popupElementInner.stop().animate({ opacity: 0 }, 500, null, function () { _this.popupElementInner.css("display", "none"); _this.popupContainer.css("display", "none"); });
        });

        _this.popupToolTip = $(".tool-tip-container", _this.popupContainer);
        _this.popupToolTip.stop().animate({ opacity: 0 }, 0);

        _this.productDetailPopupImages = $(".product-detail-popup-images", _this.popupContainer);
        _this.productDetailPopupThumbnails = $(".product-detail-popup-thumbnails", _this.popupContainer);
        _this.productDetailPopupAvailableFinishesContainer = $(".product-detail-popup-available-finishes-container", _this.popupContainer);
        _this.productDetailPopupAvailableColoursContainer = $(".product-detail-popup-available-colours-container", _this.popupContainer);

        $(".add-to-wish-list", _this.popupContainer).click(function (evt)
        {
            evt.preventDefault();

            if (_this.productID > 0)
            {
                if (!_this.inWishList)
                {
                    hammonds.googleTracking.wishListAdd();
                    _this.webService.getScalar
                    (
                        "Products_AddToWishList",
                        "ProductID=" + _this.productID,
                        false,
                        function (result)
                        {
                            if (result.toString() == "true")
                            {
                                $(".add-to-wish-list", _this.popupContainer).html("<span class=\"pink-star\"></span>Remove from wish list");
                                _this.inWishList = true;
                            }
                            else
                                alert("An error occurred trying to add the product to your wish list");
                        },
                        function ()
                        {
                            alert("An error occurred trying to add the product to your wish list");
                        }
                    );
                }
                else
                {
                    hammonds.googleTracking.wishListRemove();
                    _this.webService.getScalar
                    (
                        "Products_RemoveFromWishList",
                        "ProductID=" + _this.productID,
                        false,
                        function (result)
                        {
                            if (result.toString() == "true")
                            {
                                $(".add-to-wish-list", _this.popupContainer).html("<span class=\"pink-star\"></span>Add to wish list");
                                _this.inWishList = false;
                            }
                            else
                                alert("An error occurred trying to remove the product from your wish list");
                        },
                        function ()
                        {
                            alert("An error occurred trying to remove the product from your wish list");
                        }
                    );
                }
            }
        });
    };
    hammonds.productPopup.prototype.show = function (pageID)
    {
        var _this = this;
        _this.productID = 0;
        _this.productDetailPopupImages.empty();
        _this.productDetailPopupThumbnails.empty();
        _this.productDetailPopupAvailableFinishesContainer.empty();
        _this.productDetailPopupAvailableColoursContainer.empty();
        _this.popupContainer.css("display", "block");
        _this.productDetailPopupLoader.css("display", "block");
        _this.slides = 0;
        _this.currentSlide = 0;
        _this.animating = false;
        _this.loadFromWebService
            (
                pageID,
                function ()
                {
                    _this.productDetailPopupLoader.css("display", "none");
                    _this.popupElementInner.css("display", "block");
                    _this.popupElementInner.stop().animate({ opacity: 1 }, 500);
                },
                function ()
                {
                    _this.productDetailPopupLoader.css("display", "none");
                    _this.popupElementInner.css("display", "none");
                    _this.popupContainer.css("display", "none");
                }
            );

    };
    hammonds.productPopup.prototype.loadFromWebService = function (pageID, successCallBack, errorCallBack)
    {
        var _this = this;
        _this.webService.getDataSet
        (
            "Products_GetForPopup",
            "PageID=" + pageID,
            true,
            function (dataSet)
            {
                var 
                    dtaProducts = dataSet.getTable("Products"),
                    dtaGalleryImages = dataSet.getTable("GalleryImages"),
                    dtaProductOptions = dataSet.getTable("ProductOptions");

                // Image Pre-Loading
                var 
                    imagesToLoad = 0,
                    imagesLoaded = 0;

                if (dtaGalleryImages)
                    imagesToLoad += (dtaGalleryImages.rows.length > 6 ? 6 : dtaGalleryImages.rows.length);

                if (dtaProductOptions)
                    imagesToLoad += dtaProductOptions.rows.length;

                function imageLoaded()
                {
                    imagesLoaded++;
                }

                if (dtaGalleryImages)
                {
                    for (var i = 0; i < dtaGalleryImages.rows.length; i++)
                    {
                        if (i == 6)
                            break;

                        var dataRow = dtaGalleryImages.rows[i]

                        $("<img />").error(imageLoaded).load(imageLoaded).attr("src", WEBSITE_MEDIALIBRARY_URL + dataRow.getValue("ImageFilePath"));
                    }
                }

                if (dtaProductOptions)
                {
                    for (var i = 0; i < dtaProductOptions.rows.length; i++)
                    {
                        var dataRow = dtaProductOptions.rows[i];

                        $("<img />").error(imageLoaded).load(imageLoaded).attr("src", WEBSITE_CONTENT_URL + "thumbnailgenerator.aspx?height=14&fileid=" + dataRow.getValue("ThumbnailImage1FileID"));
                    }
                }

                if (dtaProducts && dtaProducts.rows.length == 1)
                {
                    var dr = dtaProducts.rows[0];
                    _this.productID = dr.getValue("pro_ID");
                    $(".view-full-range-button", _this.popupContainer)[0].href = WEBSITE_CONTENT_URL + dr.getValue("PageURL");

                    if (dr.getValue("InWishList") == true || dr.getValue("InWishList") == "true")
                    {
                        $(".add-to-wish-list", _this.popupContainer).html("<span class=\"pink-star\"></span>Remove from wish list");
                        _this.inWishList = true;
                    }
                    else
                    {
                        $(".add-to-wish-list", _this.popupContainer).html("<span class=\"pink-star\"></span>Add to wish list");
                        _this.inWishList = false;
                    }

                    $(".product-detail-popup-price-guide .text", _this.popupContainer).html(dr.getValue("PriceGuideText"));
                    $(".product-detail-popup-price-guide .price", _this.popupContainer).html(dr.getValue("PriceText"));
                }

                if (dtaGalleryImages)
                {
                    for (var i = 0; i < dtaGalleryImages.rows.length; i++)
                    {
                        if (i == 6)
                            break;

                        var dataRow = dtaGalleryImages.rows[i];

                        $(
                            "<div class=\"product-detail-popup-image\">" +
                            "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"border-collapse: collapse;\">" +
                            "<tbody>" +
                            "<tr>" +
                            "<td valign=\"middle\">" +
                            "<img alt=\"test\" src=\"" + WEBSITE_MEDIALIBRARY_URL + dataRow.getValue("ImageFilePath") + "\">" +
                            "</td>" +
                            "</tr>" +
                            "</tbody>" +
                            "</table>" +
                            "</div>").appendTo(_this.productDetailPopupImages);

                        $("<img class=\"white-border\" src=\"" + WEBSITE_CONTENT_URL + "thumbnailgenerator.aspx?height=43&fileid=" + dataRow.getValue("ImageFileID") + "\" alt=\"" + dataRow.getValue("gim_Title").replace(/"/gi, "\"") + "\" style=\"border-width: 0px;\">").appendTo(_this.productDetailPopupThumbnails);

                        _this.slides++;
                    }
                }

                if (_this.slides > 1)
                {
                    _this.slideshowArrowLeft.show();
                    _this.slideshowArrowRight.show();

                    $("img", _this.productDetailPopupThumbnails).click(function (evt)
                    {
                        evt.preventDefault();

                        if (_this.animating)
                            return;

                        _this.animating = true;

                        var 
                            index = $(this).index(),
                            rightDistance = (_this.currentSlide < index ? index - _this.currentSlide : -1),
                            leftDistance = (_this.currentSlide > index ? _this.currentSlide - index : -1);

                        if (index == _this.currentSlide)
                            _this.animating = false;
                        else
                        {
                            _this.currentSlide = index;

                            if (rightDistance != -1)
                            {
                                for (var i = 0; i < rightDistance; i++)
                                {
                                    $(_this.productDetailPopupImages.children()[i]).clone().appendTo(_this.productDetailPopupImages);
                                }

                                _this.productDetailPopupImages.animate({ left: _this.productDetailPopupImages.position().left - (_this.imagePanelWidth * rightDistance) }, 500, null, function ()
                                {
                                    for (var j = 0; j < rightDistance; j++)
                                        _this.productDetailPopupImages.children().first().remove();

                                    _this.productDetailPopupImages.css("left", (_this.productDetailPopupImages.position().left + (_this.imagePanelWidth * rightDistance)) + "px");

                                    _this.animating = false;
                                });
                            }
                            else
                            {
                                for (var i = 0; i < leftDistance; i++)
                                {
                                    $(_this.productDetailPopupImages.children()[_this.slides - 1]).clone().prependTo(_this.productDetailPopupImages);
                                }

                                _this.productDetailPopupImages.css("left", (_this.productDetailPopupImages.position().left - (_this.imagePanelWidth * leftDistance)) + "px");

                                _this.productDetailPopupImages.animate({ left: _this.productDetailPopupImages.position().left + (_this.imagePanelWidth * leftDistance) }, 500, null, function ()
                                {
                                    for (var j = 0; j < leftDistance; j++)
                                        _this.productDetailPopupImages.children().last().remove();
                                    _this.animating = false;
                                });
                            }
                        }
                    });

                }
                else
                {
                    _this.slideshowArrowLeft.hide();
                    _this.slideshowArrowRight.hide();
                }

                // Product Options
                if (dtaProductOptions)
                {
                    var 
                        finishesCount = 0,
                        coloursCount = 0;

                    for (var i = 0; i < dtaProductOptions.rows.length; i++)
                    {
                        var dataRow = dtaProductOptions.rows[i];
                        switch (dataRow.getValue("TypeDescription"))
                        {
                            case "Finish":
                                $("<img alt=\"" + dataRow.getValue("opt_Name") + "\" src=\"" + WEBSITE_CONTENT_URL + "thumbnailgenerator.aspx?height=14&fileid=" + dataRow.getValue("ThumbnailImage1FileID") + "\" class=\"black-border\">").appendTo(_this.productDetailPopupAvailableFinishesContainer);
                                finishesCount++;
                                break;
                            case "Colour":
                                $("<img alt=\"" + dataRow.getValue("opt_Name") + "\" src=\"" + WEBSITE_CONTENT_URL + "thumbnailgenerator.aspx?height=14&fileid=" + dataRow.getValue("ThumbnailImage1FileID") + "\" class=\"black-border\">").appendTo(_this.productDetailPopupAvailableColoursContainer);
                                coloursCount++;
                                break;
                        }
                    }

                    if (finishesCount == 0)
                        $(".product-detail-popup-available-finishes", _this.popupContainer).hide();
                    else
                        $(".product-detail-popup-available-finishes", _this.popupContainer).show();

                    if (coloursCount == 0)
                        $(".product-detail-popup-available-colours", _this.popupContainer).hide();
                    else
                        $(".product-detail-popup-available-colours", _this.popupContainer).show();

                    if (!isIE6)
                    {
                        $(".product-detail-popup-available-finishes img, .product-detail-popup-available-colours img").mouseover(function (evt)
                        {
                            clearTimeout(_this.popupToolTipTimeout);
                            _this.popupToolTipTimeout = 0;

                            $(".tool-tip-middle-content", _this.popupToolTip).html("<p>" + this.alt + "</p>");

                            evt.stopPropagation();

                            var 
                                currentTarget = $(evt.currentTarget),
                                position = currentTarget.position();

                            _this.popupToolTip.css("left", position.left - 23 + (currentTarget.width() / 2) + "px");
                            _this.popupToolTip.css("top", position.top + currentTarget.height() + 5 + "px");

                            _this.popupToolTip.css("display", "block");
                            _this.popupToolTip.stop().animate({ opacity: 1 }, 250);
                        });
                    }
                }

                function hasImagesLoaded()
                {
                    if (imagesLoaded == imagesToLoad)
                    {
                        if (successCallBack)
                            successCallBack();
                    }
                    else
                        setTimeout(hasImagesLoaded, 1000);
                }
                setTimeout(hasImagesLoaded, 1000);
            },
            function ()
            {
                alert("An error occurred trying to get the product information");
                if (errorCallBack)
                    errorCallBack();
            }
        );
    };
    hammonds.productPopup.instance = new hammonds.productPopup();

    // Main Navigation
    // ***************
    hammonds.mainNavigation = function ()
    {
        var _this = this;
        _this.mainNavigation = null;
        _this.mainNavigationUL = null;
        _this.dropDownPanels = [];
        _this.hideAllMenusTimeout = 0;
        $(function () { _this.initialise(); });
    }
    hammonds.mainNavigation.prototype.initialise = function ()
    {
        var _this = this;
        _this.mainNavigation = $(".main-navigation20110809");
        _this.mainNavigationUL = $(".main-navigation-ul", _this.mainNavigation);
        _this.mainNavigationLI = $("li", _this.mainNavigationUL);
        for (var i = 0; i < _this.mainNavigationLI.length; i++)
        {
            var o = {};
            o.visible = false;
            o.li = $(_this.mainNavigationLI[i]);
            o.a = $("a", o.li);
            o.dropDown = $("#drop-down-" + (i + 1));
            o.dropDown.animate({ opacity: 0 }, 0);
            o.dropDown.mouseover(function (evt)
            {
                evt.stopPropagation();
                clearHideAllMenusTimeout();
            });
            o.dropDown.appendTo(".container");
            o.dropDown.css("top", _this.mainNavigation.position().top + _this.mainNavigation.height());
            _this.dropDownPanels.push(o);
        }

        function hideMenu(dropDownPanel)
        {
            if (dropDownPanel.dropDown.length > 0)
            {
                dropDownPanel.dropDown
                    .stop()
                    .animate({ opacity: 0 }, 200, null, function () { $(this).css("display", "none"); dropDownPanel.a.removeClass("selected"); })
            }
        }

        function hideAllMenus()
        {
            for (var i = 0; i < _this.dropDownPanels.length; i++)
                hideMenu(_this.dropDownPanels[i]);
        }

        function showMenu(dropDownPanel)
        {
            if (dropDownPanel.dropDown.length > 0)
            {
                dropDownPanel.a.addClass("selected");
                dropDownPanel.dropDown
                    .stop()
                    .css("display", "block")
                    .animate({ opacity: 1 }, 200);
            }
        }

        function clearHideAllMenusTimeout()
        {
            clearTimeout(_this.hideAllMenusTimeout);
            _this.hideAllMenusTimeout = 0;
        }

        $("body").mouseover(function (evt)
        {
            if (_this.hideAllMenusTimeout == 0)
                _this.hideAllMenusTimeout = setTimeout(hideAllMenus, 500);
        });

        _this.mainNavigationLI.mouseover(function (evt)
        {
            evt.stopPropagation();
            clearHideAllMenusTimeout();

            var 
                element = this;

            for (var i = 0; i < _this.dropDownPanels.length; i++)
            {
                if (_this.dropDownPanels[i].li[0] == element)
                    showMenu(_this.dropDownPanels[i]);
                else
                    hideMenu(_this.dropDownPanels[i]);
            }
        });
    };

    // Accordian Panel
    // ***************
    hammonds.accordianPanel = function ()
    {
        var _this = this;
        _this.container = null;
        _this.headers = null;
        _this.panels = [];
        _this.links = null;
        $(function () { _this.initialise(); });
    }
    hammonds.accordianPanel.prototype.initialise = function ()
    {
        var _this = this;
        _this.container = $(".choices-accordian-container");
        _this.headers = $("p.accordian-header", _this.container);
        _this.links = $("a", _this.container);

        _this.headers.each(function (index, element)
        {
            var o = {};
            o.p = element;
            o.aTags = $("a", o.p);
            o.div = element.nextSibling;
            _this.panels.push(o);
            if (index > 0)
                $(o.div).css("height", "0px");
        });

        _this.links.click(function (evt)
        {
            evt.preventDefault();

            for (var i = 0; i < _this.panels.length; i++)
            {
                for (var j = 0; j < _this.panels[i].aTags.length; j++)
                {
                    if (_this.panels[i].aTags[j] == this)
                    {
                        var 
                            div = $(_this.panels[i].div),
                            actualHeight = 0;

                        div.stop();
                        if (div.height() == 0)
                        {
                            div.css("height", "auto");
                            actualHeight = div.height();
                            div.css("height", "0px");
                            div.animate({ height: actualHeight }, 250);
                        }
                        else
                        {
                            div.animate({ height: 0 }, 250);
                        }
                        break;
                    }
                }
            }
        });
    };

    // Product Detail Page
    // *******************
    function productDetailPage(imageDetailArray, showImageTitle)
    {
        var _this = this;
        _this.imageDetailArray = (imageDetailArray ? imageDetailArray : []);
        _this.showImageTitle = (typeof showImageTitle != undefined ? showImageTitle : true);
        _this.productDetailPopupViewport = null;
        _this.productDetailPopupImages = null;
        _this.slideshowArrowLeft = null;
        _this.slideshowArrowRight = null;
        _this.productDetailPopupThumbnails = null;
        _this.productDetailPopupThumbnailsInner = null;
        _this.slideshowArrowLeftSmall = null;
        _this.slideshowArrowRightSmall = null;
        _this.imagePanelWidth = 700;
        _this.thumbnailWidth = 117;
        _this.animating = false;
        _this.currentSlide = 0;
        _this.thumbnailOffset = 0;
        _this.pinkOverlayCollapseTimeout = 0;
        $(window).load(function (evt) { _this.initialise(); });
    }
    productDetailPage.prototype.initialise = function ()
    {
        var _this = this;
        _this.productDetailPopupViewportContainer = $(".product-detail-popup-viewport-container");
        _this.productDetailPopupViewport = $(".product-detail-popup-viewport");
        _this.productDetailPopupImages = $(".product-detail-popup-images", _this.productDetailPopupViewport);
        _this.slideshowArrowLeft = $(".slideshow-arrow-left", _this.productDetailPopupViewport);
        _this.slideshowArrowRight = $(".slideshow-arrow-right", _this.productDetailPopupViewport);
        _this.productDetailPopupThumbnails = $(".product-detail-popup-thumbnails");
        _this.productDetailPopupThumbnailsInner = $(".product-detail-popup-thumbnails-inner", _this.productDetailPopupThumbnails);
        _this.slideshowArrowLeftSmall = $(".slideshow-arrow-left-small", _this.productDetailPopupThumbnails);
        _this.slideshowArrowRightSmall = $(".slideshow-arrow-right-small", _this.productDetailPopupThumbnails);
        _this.productDetailTitleBG = $(".product-detail-title-bg", _this.productDetailPopupViewport);
        _this.productDetailTitleBGBlack = $(".black", _this.productDetailTitleBG);
        _this.productDetailTitleBGWhite = $(".white", _this.productDetailTitleBG);

        if (_this.showImageTitle)
            _this.productDetailTitleBG.css("display", "block");

        if (_this.imageDetailArray.length > 1)
        {
            _this.slideshowArrowLeft.css("display", "block");
            _this.slideshowArrowRight.css("display", "block");
        }

        _this.slideshowArrowLeftSmall.css("display", "none");
        _this.slideshowArrowLeftSmall.animate({ opacity: 0 }, 0);
        _this.slideshowArrowRightSmall.css("display", "none");
        _this.slideshowArrowRightSmall.animate({ opacity: 0 }, 0);

        _this.slides = _this.productDetailPopupImages.children().length;

        _this.productDetailPopupThumbnailsInner.children().each(function (index, element)
        {
            $(element).css("cursor", "pointer");
            if (index != _this.currentSlide)
                $("img", element).animate({ opacity: 0.4 }, 0);
        });

        _this.productDetailPopupThumbnailsInner.children().mouseenter(function (evt)
        {
            if (_this.thumbnailOffset > 0)
            {
                _this.slideshowArrowLeftSmall.css("display", "block");
                _this.slideshowArrowLeftSmall.stop().animate({ opacity: 1 }, 200);
            }
            if (_this.thumbnailOffset < _this.slides - 6)
            {
                _this.slideshowArrowRightSmall.css("display", "block");
                _this.slideshowArrowRightSmall.stop().animate({ opacity: 1 }, 200);
            }

            $("img", this).stop().animate({ opacity: 1 }, 200);
        });

        _this.slideshowArrowLeftSmall.mouseenter(function (evt)
        {
            _this.slideshowArrowLeftSmall.css("display", "block");
            _this.slideshowArrowLeftSmall.stop().animate({ opacity: 1 }, 200);
        });

        _this.slideshowArrowLeftSmall.mouseleave(function (evt)
        {
            _this.slideshowArrowLeftSmall.stop().animate({ opacity: 0 }, 200, null, function () { _this.slideshowArrowLeftSmall.css("display", "none"); });
        });

        _this.slideshowArrowRightSmall.mouseenter(function (evt)
        {
            _this.slideshowArrowRightSmall.css("display", "block");
            _this.slideshowArrowRightSmall.stop().animate({ opacity: 1 }, 200);
        });

        _this.slideshowArrowRightSmall.mouseleave(function (evt)
        {
            _this.slideshowArrowRightSmall.stop().animate({ opacity: 0 }, 200, null, function () { _this.slideshowArrowRightSmall.css("display", "none"); });
        });

        _this.productDetailPopupThumbnailsInner.children().mouseleave(function (evt)
        {
            _this.slideshowArrowLeftSmall.stop().animate({ opacity: 0 }, 200, null, function () { _this.slideshowArrowLeftSmall.css("display", "none"); });
            _this.slideshowArrowRightSmall.stop().animate({ opacity: 0 }, 200, null, function () { _this.slideshowArrowRightSmall.css("display", "none"); });

            if ($(this).index() != _this.currentSlide)
                $("img", this).stop().animate({ opacity: 0.4 }, 200);
        });

        _this.slideshowArrowLeft.click(function (evt)
        {
            evt.preventDefault();

            if (_this.animating)
                return;
            _this.animating = true;

            var _lastSlide = _this.currentSlide;

            _this.currentSlide--;

            if (_this.currentSlide < 0)
                _this.currentSlide = _this.slides - 1;

            _this.productDetailPopupImages.children().last().prependTo(_this.productDetailPopupImages);
            _this.productDetailPopupImages.css("left", (_this.productDetailPopupImages.position().left - _this.imagePanelWidth) + "px");

            $("img", _this.productDetailPopupThumbnailsInner.children()[_lastSlide]).animate({ opacity: 0.4 }, 250);
            $("img", _this.productDetailPopupThumbnailsInner.children()[_this.currentSlide]).animate({ opacity: 1 }, 250);

            hidePinkOverlay(function ()
            {
                _this.productDetailPopupImages.animate({ left: _this.productDetailPopupImages.position().left + _this.imagePanelWidth }, 250, null, function () { _this.animating = false; showPinkOverlay(); });
            });
        });

        _this.slideshowArrowRight.click(function (evt)
        {
            evt.preventDefault();

            if (_this.animating)
                return;
            _this.animating = true;

            var _lastSlide = _this.currentSlide;

            _this.currentSlide++;

            if (_this.currentSlide >= _this.slides)
                _this.currentSlide = 0;

            $("img", _this.productDetailPopupThumbnailsInner.children()[_lastSlide]).animate({ opacity: 0.4 }, 250);
            $("img", _this.productDetailPopupThumbnailsInner.children()[_this.currentSlide]).animate({ opacity: 1 }, 250);

            hidePinkOverlay(function ()
            {
                _this.productDetailPopupImages.animate({ left: _this.productDetailPopupImages.position().left - _this.imagePanelWidth }, 250, null, function ()
                {
                    _this.productDetailPopupImages.children().first().appendTo(_this.productDetailPopupImages);
                    _this.productDetailPopupImages.css("left", (_this.productDetailPopupImages.position().left + _this.imagePanelWidth) + "px");
                    _this.animating = false;
                    showPinkOverlay();
                });
            });
        });

        _this.slideshowArrowLeftSmall.click(function (evt)
        {
            evt.preventDefault();

            if (_this.animating)
                return;
            _this.animating = true;

            var oldThumbnailOffset = _this.thumbnailOffset;

            _this.thumbnailOffset = _this.thumbnailOffset - 6;
            if (_this.thumbnailOffset < 0)
                _this.thumbnailOffset = 0;

            _this.productDetailPopupThumbnailsInner.animate({ left: -(_this.thumbnailOffset * _this.thumbnailWidth) }, 250 * Math.abs(oldThumbnailOffset - _this.thumbnailOffset), null, function () { _this.animating = false; });
        });

        _this.slideshowArrowRightSmall.click(function (evt)
        {
            evt.preventDefault();

            if (_this.animating)
                return;
            _this.animating = true;

            var oldThumbnailOffset = _this.thumbnailOffset;

            _this.thumbnailOffset = _this.thumbnailOffset + 6;
            if (_this.thumbnailOffset > _this.slides - 6)
                _this.thumbnailOffset = _this.slides - 6;

            _this.productDetailPopupThumbnailsInner.animate({ left: -(_this.thumbnailOffset * _this.thumbnailWidth) }, 250 * Math.abs(oldThumbnailOffset - _this.thumbnailOffset), null, function () { _this.animating = false; });
        });

        _this.productDetailPopupThumbnailsInner.children().click(function (evt)
        {
            evt.preventDefault();

            if (_this.animating)
                return;

            _this.animating = true;

            var 
                index = $(this).index(),
                rightDistance = (_this.currentSlide < index ? index - _this.currentSlide : -1),
                leftDistance = (_this.currentSlide > index ? _this.currentSlide - index : -1);

            if (index == _this.currentSlide)
                _this.animating = false;
            else
            {
                var _lastSlide = _this.currentSlide;
                _this.currentSlide = index;

                $("img", _this.productDetailPopupThumbnailsInner.children()[_lastSlide]).animate({ opacity: 0.4 }, 250 * Math.abs(_lastSlide - _this.currentSlide));
                $("img", _this.productDetailPopupThumbnailsInner.children()[_this.currentSlide]).animate({ opacity: 1 }, 250 * Math.abs(_lastSlide - _this.currentSlide));

                if (rightDistance != -1)
                {
                    for (var i = 0; i < rightDistance; i++)
                    {
                        $(_this.productDetailPopupImages.children()[i]).clone().appendTo(_this.productDetailPopupImages);
                    }

                    hidePinkOverlay(function ()
                    {
                        _this.productDetailPopupImages.animate({ left: _this.productDetailPopupImages.position().left - (_this.imagePanelWidth * rightDistance) }, 250 * Math.abs(_lastSlide - _this.currentSlide), null, function ()
                        {
                            for (var j = 0; j < rightDistance; j++)
                                _this.productDetailPopupImages.children().first().remove();

                            _this.productDetailPopupImages.css("left", (_this.productDetailPopupImages.position().left + (_this.imagePanelWidth * rightDistance)) + "px");
                            showPinkOverlay();
                            _this.animating = false;
                        });
                    });
                }
                else
                {
                    for (var i = 0; i < leftDistance; i++)
                    {
                        $(_this.productDetailPopupImages.children()[_this.slides - 1]).clone().prependTo(_this.productDetailPopupImages);
                    }

                    _this.productDetailPopupImages.css("left", (_this.productDetailPopupImages.position().left - (_this.imagePanelWidth * leftDistance)) + "px");

                    hidePinkOverlay(function ()
                    {
                        _this.productDetailPopupImages.animate({ left: _this.productDetailPopupImages.position().left + (_this.imagePanelWidth * leftDistance) }, 250 * Math.abs(_lastSlide - _this.currentSlide), null, function ()
                        {
                            for (var j = 0; j < leftDistance; j++)
                                _this.productDetailPopupImages.children().last().remove();
                            showPinkOverlay();
                            _this.animating = false;
                        });
                    });
                }
            }
        });

        $(".product-wish-list-panel a.add-to-wish-list").click(function (evt)
        {
            var 
                href = $(this).attr("href");

            if (href != undefined)
            {
                if (href.indexOf("action=add") > -1)
                    hammonds.googleTracking.wishListAdd();
                else
                    hammonds.googleTracking.wishListRemove();
            }
        });

        $(".product-wish-list-panel a.view-wish-list").click(function (evt)
        {
            hammonds.googleTracking.wishListView();
        });

        function showPinkOverlay()
        {
            if (_this.showImageTitle)
            {
                if (_this.imageDetailArray.length > _this.currentSlide)
                {
                    _this.productDetailTitleBGBlack.html(_this.imageDetailArray[_this.currentSlide].productName + ",");
                    _this.productDetailTitleBGWhite.html(_this.imageDetailArray[_this.currentSlide].imageTitle + ".");
                    _this.productDetailTitleBG.stop().animate({ height: 60 }, 250);
                }
            }
        }
        showPinkOverlay();

        function hidePinkOverlay(callBack)
        {
            if (_this.showImageTitle)
            {
                _this.productDetailTitleBG.stop().animate({ height: 1 }, 250, null, function ()
                {
                    if (callBack)
                        callBack();
                });
            }
            else
                if (callBack)
                    callBack();
        }

        $(".product-detail-popup-viewport-container").mouseenter(function (evt)
        {
            if (_this.pinkOverlayCollapseTimeout != 0)
            {
                clearTimeout(_this.pinkOverlayCollapseTimeout);
                _this.pinkOverlayCollapseTimeout = 0;
            }
            showPinkOverlay();
            evt.stopPropagation();
        });

        $(".product-detail-popup-viewport-container").mouseleave(function (evt)
        {
            if (_this.pinkOverlayCollapseTimeout == 0)
                _this.pinkOverlayCollapseTimeout = setTimeout(function () { hidePinkOverlay() }, 5000);
        });
    };

    // Google Tracking
    // ***************
    hammonds._googleTracking = function ()
    {
        this.atlasTrackingFired = false;
    };
    hammonds._googleTracking.prototype.trackEvent = function (category, action)
    {
        if (_gaq)
            _gaq.push(["_trackEvent", category, action]);
    };
    hammonds._googleTracking.prototype.wishListAdd = function ()
    {
        this.trackEvent("Wish List", "Add");
    };
    hammonds._googleTracking.prototype.wishListRemove = function ()
    {
        this.trackEvent("Wish List", "Remove");
    };
    hammonds._googleTracking.prototype.wishListView = function ()
    {
        this.trackEvent("Wish List", "View");
    };
    hammonds._googleTracking.prototype.landingPageFiltered = function (filterName)
    {
        this.trackEvent("Filter", filterName);
    };
    hammonds._googleTracking.prototype.tabViewed = function (tabName)
    {
        this.trackEvent("Tab View", tabName);
    };
    hammonds._googleTracking.prototype.storeLocatorSearch = function ()
    {
        if (_gaq)
            _gaq.push(["_trackPageview", "storelocator/submit-postcode"]);
        this.trackEvent("Store Locator", "Search");

        if (!this.atlasTrackingFired)
        {
            var atlasJS = document.createElement("script");
            atlasJS.type = "text/javascript";
            atlasJS.src = "http://view.atdmt.com/jaction/p7ah11_Hammonds2011StoreResults_1";
            $("body").append(atlasJS);
            this.atlasTrackingFired = true;
        }
    };
    hammonds.googleTracking = new hammonds._googleTracking();

    hammonds.designVisitForm = function ()
    {
        var _this = this;
        _this.callBackLinkExpanded = false;
        _this.callBackOuter = null;
        $(function () { _this.initialise(); });
    };
    hammonds.designVisitForm.prototype.initialise = function ()
    {
        var _this = this;
        _this.callBackOuter = $(".call-back-outer");
        $(".call-back-link").click(function (evt)
        {
            evt.preventDefault();

            if (!_this.callBackLinkExpanded)
            {
                _this.callBackOuter.css("height", "auto");
                var height = _this.callBackOuter.height();
                _this.callBackOuter.css("height", "0px");
                _this.callBackOuter.stop().animate({ height: height }, 500);
            }
            else
                _this.callBackOuter.stop().animate({ height: 0 }, 500);

            _this.callBackLinkExpanded = !_this.callBackLinkExpanded;
        });

        $(".close-call-back").click(function (evt)
        {
            evt.preventDefault();
            _this.callBackOuter.stop().animate({ height: 0 }, 500);
        });
    };
