var DG = {
    scroller: new Fx.Scroll(window),
    configure: function () {

        // Code for smooth scrolling links
        new SmoothScroll();

        if ($("shop-online")) {
            $("shop-online").style.display = "block";
            $("shop-links").style.display = "none";
            $("shop-online").addEvent("mouseover", function (e) {
                $("shop-online").style.display = "none";
                $("shop-links").style.display = "block";
            });
            $("shop-links").addEvent("mouseout", function (e) {
                $("shop-links").style.display = "none";
                $("shop-online").style.display = "block";
            });
        }


        $$(".volatile").each(function (el) {
            $(el).addEvent("focus", function () {
                if (this.getValue() == this.getProperty("title")) {
                    this.value = "";
                }
            });
        });

        $$(".pressbasketadd").each(function (el) {
            $(el).addEvent("click", function (e) {

                new Event(e).stop();
                DG.basketMessage.show("Adding to your basket...");
                var form = this;
                //alert(el.href);
                pageTracker._trackPageview("/ajax/addBasket/");
                DG.ajaxAddPress(el.href + '&requestType=ajax');
                return false;
            });
        });

        $$(".pressbasketremove").each(function (el) {
            $(el).addEvent("click", function (e) {
                new Event(e).stop();
                DG.basketMessage.show("Removing from your basket...");
                DG.ajaxAddPress(el.href + '&requestType=ajax');
                return false;
            });
        });

        $$("a[rel*='external']").each(function (a) {
            $(a).setProperty("target", "_blank");
        });

        $$(".globaldesigners, .calls2action, .collectiondesigns .rightcol ul, ul.swatches, ul.productthumbs, ul.ukcalls2action").each(function (el) {
            new ListItemSelector($(el), { "fxMin": 1, "fxMax": 0.5, "staySelected": false });
        });

        $$("#masthead .kids div").each(function (el) {
            var nav = new ListItemSelector($(el), { "fxMin": 1, "fxMax": 0.01 });
            nav.selectClass("selected");
        });

        new Accordion($$("#faqlist li h2"), $$("#faqlist li div"), { "alwaysHide": true, "show": -1 });

        new Accordion($$(".sizecharts li h2"), $$(".sizecharts li div"));

        new Accordion($$(".formopen"), $$(".addressforms li"), { "alwaysHide": true, "show": -1 });

        new Tips($$(".tooltip"), {
            "initialize": function () {
                this.fx = new Fx.Style(this.toolTip, "opacity", { "wait": false });
            },
            "onHide": function () {
                this.fx.start(0);
            },
            "onShow": function () {
                this.fx.start(1);
            },
            "offsets": {
                "x": -20,
                "y": -130
            }
        });

        if ($("globalhomeflash")) {
            var flash = new FlashObject("/_images/flash/home/homepage.swf", "globalhomeflash", "910", "380", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("globalhomeflash");
        }

        /*	
        if($("aboutusflash")){
        var flash = new FlashObject("/_images/flash/global/about-us.swf", "aboutusflash", "600", "275", "7", "#ffffff");
        flash.addParam("menu","false");
        flash.addParam("quality","high");
        flash.write("aboutusflash");
        }
        */

        if ($("contactusflash")) {
            var flash = new FlashObject("/_images/flash/global/contact-us.swf", "contactusflash", "600", "275", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("contactusflash");
        }

        if ($("dgprofessionalflash")) {
            var flash = new FlashObject("/_images/flash/global/dg-professional.swf", "dgprofessionalflash", "600", "275", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("dgprofessionalflash");
        }

        if ($("stockistsflash")) {
            var flash = new FlashObject("/_images/flash/global/map.swf", "aboutusflash", "520", "354", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("stockistsflash");
        }

        if ($("ukhomeflash")) {
            var flash = new FlashObject("/_images/flash/uk-shop/uk-home.swf", "ukhomeflash", "602", "313", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("ukhomeflash");
        }

        if ($("bedandbathflash")) {
            var flash = new FlashObject("/_images/flash/cat-banners/banner-bed-and-bath.swf", "bedandbathflash", "602", "240", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("bedandbathflash");
        }
        if ($("furnitureflash")) {
            var flash = new FlashObject("/_images/flash/cat-banners/banner-furniture.swf", "furnitureflash", "602", "240", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("furnitureflash");
        }
        if ($("paintflash")) {
            var flash = new FlashObject("/_images/flash/cat-banners/banner-paint.swf", "paintflash", "602", "240", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("paintflash");
        }
        if ($("rugsflash")) {
            var flash = new FlashObject("/_images/flash/cat-banners/banner-rugs.swf", "rugsflash", "602", "240", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("rugsflash");
        }
        if ($("homefragranceflash")) {
            var flash = new FlashObject("/_images/flash/cat-banners/banner-home-fragrance.swf", "homefragranceflash", "602", "240", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("homefragranceflash");
        }
        if ($("booksflash")) {
            var flash = new FlashObject("/_images/flash/cat-banners/banner-books.swf", "booksflash", "602", "240", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("booksflash");
        }
        if ($("leatherandstationaryflash")) {
            var flash = new FlashObject("/_images/flash/cat-banners/banner-leather-and-stationary.swf", "leatherandstationaryflash", "602", "240", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("leatherandstationaryflash");
        }
        if ($("kidsflash")) {
            var flash = new FlashObject("/_images/flash/cat-banners/banner-kids.swf", "kidsflash", "602", "240", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("kidsflash");
        }
        if ($("whitecollectionflash")) {
            var flash = new FlashObject("/_images/flash/cat-banners/banner-white-collection.swf", "whitecollectionflash", "602", "240", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("whitecollectionflash");
        }
        if ($("bedlinenflash")) {
            var flash = new FlashObject("/_images/flash/cat-banners/banner-bedlinen.swf", "bedlinenflash", "602", "240", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("bedlinenflash");
        }
        if ($("towelsflash")) {
            var flash = new FlashObject("/_images/flash/cat-banners/banner-towels.swf", "towelsflash", "602", "240", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("towelsflash");
        }
        if ($("cushionsflash")) {
            var flash = new FlashObject("/_images/flash/cat-banners/banner-cushions.swf", "cushionsflash", "602", "240", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("cushionsflash");
        }
        if ($("blanketsflash")) {
            var flash = new FlashObject("/_images/flash/cat-banners/banner-blankets.swf", "blanketsflash", "602", "240", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("blanketsflash");
        }
        if ($("quiltsflash")) {
            var flash = new FlashObject("/_images/flash/cat-banners/banner-quilts.swf", "quiltsflash", "602", "240", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("quiltsflash");
        }
        if ($("tablelinenflash")) {
            var flash = new FlashObject("/_images/flash/cat-banners/banner-tablelinen.swf", "tablelinenflash", "602", "240", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("tablelinenflash");
        }
        if ($("giftsflash")) {
            var flash = new FlashObject("/_images/flash/cat-banners/banner-gifts.swf", "giftsflash", "602", "240", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("giftsflash");
        }
        if ($("ukhomepageflash")) {
            var flash = new FlashObject("/_images/flash/cat-banners/banner-shophomepage.swf", "ukhomepageflash", "602", "240", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("ukhomepageflash");
        }

        if ($("fabricwallpaperflash")) {
            var flash = new FlashObject("/_images/flash/fabric-and-wallpaper/fw-banner.swf", "fabricwallpaperflash", "602", "313", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("fabricwallpaperflash");
        }

        if ($("jasperconranflash")) {
            var flash = new FlashObject("/_images/flash/global/jasper-conran.swf", "jasperconranflash", "600", "275", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("jasperconranflash");
        }

        if ($("williamyeowardflash")) {
            var flash = new FlashObject("/_images/flash/global/william-yeoward.swf", "williamyeowardflash", "600", "275", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("williamyeowardflash");
        }

        if ($("structureflash")) {
            var flash = new FlashObject("/_images/flash/global/structure.swf", "structureflash", "600", "273", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("structureflash");
        }

        if ($("london-showroom")) {
            var flash = new FlashObject("/_images/flash/stockists/showroom.swf", "london-showroom", "600", "273", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("london-showroom");
        }

        if ($("london-homestore")) {
            var flash = new FlashObject("/_images/flash/stockists/homestore.swf", "london-homestore", "600", "273", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("london-homestore");
        }

        if ($("london-selfridges")) {
            var flash = new FlashObject("/_images/flash/stockists/selfridges.swf", "london-selfridges", "600", "273", "7", "#ffffff");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("london-selfridges");
        }

        if ($("royalcollectionflash")) {
            var flash = new FlashObject("/_images/flash/royal-collection/royal-collection.swf", "london-selfridges", "605", "620", "7", "#000000");
            flash.addParam("menu", "false");
            flash.addParam("quality", "high");
            flash.write("royalcollectionflash");
        }

        $$(".stockistssearchform select").each(function (sel) {
            sel.addEvent("change", function () {
                this.form.submit();
            });
        });

        DG.sbArray = [null, null];
        DG.ddArray = [null, null];

        if ($("sitesearch")) {
            var shopId = 1;
            if ($("search_shop_id"))
                shopId = $("search_shop_id").getValue();

            new MysticMeg("sitesearch", {
                ajaxUrl: "/_colony/meta-directory/ajax-search.asp?ShopID=" + shopId,
                topOffset: 25,
                listClass: "predictive",
                highlight: false,
                multipleSelect: false,
                onSelect: function (v, f, o) {
                    f.value = v.value;
                    o.flush();
                    o.hideResults();
                    if (v.url != "") {
                        window.location.href = v.url;
                    }
                },
                onSuccess: function (r, f, o) {
                    if (r.length == 10) {
                        var showAll = new Element("li", { "class": "more" });
                        new Element("a", {
                            "href": "#",
                            "events": {
                                "click": function (e) {
                                    new Event(e).stop();
                                    o.flush();
                                    o.hideResults();
                                    if ($E(".sitesearchform"))
                                        $E(".sitesearchform").submit();

                                    if ($E(".uksearchform"))
                                        $E(".uksearchform").submit();
                                }
                            }
                        }).setText("more results >").injectInside(showAll);
                        showAll.injectInside(o.listContainer.getFirst());
                    }
                }
            });
        }

        if ($("dropContainer")) {
            var drop = $('dropContainer');

            $ES(".colourBlob", $("paintSwatches")).each(function (item) {

                item.addEvent('mousedown', function (e) {
                    e = new Event(e).stop();

                    var coords = this.getCoordinates();

                    if ($("paintSwatches"))
                        coords.left -= $("paintSwatches").getSize().scroll.x;

                    var clone = this.clone()
						.setStyles(coords)
						.setStyle("position", "absolute")
						.addEvent('emptydrop', function () {
						    this.remove();
						    drop.removeEvents();
						}).inject(document.body);

                    drop.addEvents({
                        'drop': function () {
                            drop.removeEvents();
                            clone.remove();
                            item.clone().injectBefore(drop.getLast());
                            paintBlobs = DG.makeSortable("dropContainer");
                        }
                    });

                    var drag = clone.makeDraggable({
                        droppables: [drop]
                    });

                    drag.start(e);
                });
            });

            paintBlobs = DG.makeSortable("dropContainer");

        }

        if ($("savePalette")) {
            $("savePalette").addEvent("click", function (e) {
                new Event(e).stop();
                DG.setPalette(this.getAttribute("href"));
            });

            $("clearPalette").addEvent("click", function (e) {
                new Event(e).stop();
                $$("#dropContainer .colourBlob").removeElements();
            });
        }

        if ($("slideshow")) {
            new MooSlideshow("slideshow", "#slideshow img", { "wait": 5000, "fxDuration": 1000 });
        }

        if ($("collectiondetailsflash")) {
            $("collectionNumber").setStyle("opacity", 0.7);

            var collectionNumbers = $("collectionNumber").getChildren();

            var slides_selector = "#collectiondetailsflash .slide";

            var getTheLook = new MooSlideshow("collectiondetailsflash", slides_selector, {
                "wait": 3000,
                "fxDuration": 1000,
                "onChange": function (index, element, obj) {
                    try {
                        if (!$(collectionNumbers[index])) return;
                        collectionNumbers.each(function (el) { el.removeClass("selected"); });
                        collectionNumbers[index].addClass("selected");
                    } catch (ex) { }
                }
            });

            collectionNumbers.each(function (el, index) {
                el.addEvent("click", function (e) {
                    getTheLook.jumpTo(index);
                });
            });
        }

        this.basketMessage = new MessageWindow({
            "timeout": 2000,
            "onShow": function () { DG.basketMessage.modalShow() },
            "onHide": function () { DG.basketMessage.modalHide() }
        });

        this.loadingMessage = new MessageWindow({
            "onShow": function () { DG.loadingMessage.modalShow() },
            "onHide": function () { DG.loadingMessage.modalHide() }
        });

        $$("#purchaseform").addEvent("submit", function (e) {
            new Event(e).stop();
            DG.basketMessage.show("Adding to your basket...");
            var form = this;
            DG.ajaxAdd(form.getProperty("action") + "&ajax=true", form);
            return false;
        });

        if ($("searchTabs")) {

            this.message = new MessageWindow();

            var tabs = new SimpleTabs($("searchTabs"), {
                "entrySelector": "h4",
                "show": Cookie.get("tabSelected") ? Cookie.get("tabSelected") : 0,
                "onShow": function (toggle, container, index) {
                    toggle.addClass('tab-selected');
                    container.setStyle('display', '');
                    Cookie.set("tabSelected", index);
                },
                "onHide": function (toggle, container, index) {
                    toggle.removeClass('tab-selected');
                    container.setStyle('display', 'none');
                    DG.sbArray[index].reset();
                    if ($("formContents").getFirst().getTag() != "img") {
                        if (index == 0) {
                            $("formContents").setStyle("display", "none");
                        } else {
                            $("formContents2").setStyle("display", "none");
                        }
                    }
                }
            });

            DG.sbArray[0] = new MooSelect("searchType", {
                "onSelect": function (v) {
                    DG.clearSearchCache();
                    DG.getSearchForm("searchForm", "formContents");
                    DG.historyManager.addState("search_designs");
                    Cookie.set("searchType", v);
                }
            });

            DG.sbArray[1] = new MooSelect("searchType2", {
                "onSelect": function (v) {
                    DG.clearSearchCache();
                    DG.getSearchForm("searchForm2", "formContents2");
                    DG.historyManager.addState("search_collections");
                    Cookie.set("searchType2", v);
                }
            });

            if (Cookie.get("tabSelected")) {
                tabs.select(Cookie.get("tabSelected"));
            }

        }

        var curLocation = this.historyManager.getCurrentLocation();

        if (curLocation == "search_designs") {
            $("content").empty();
            $("searchType").value = Cookie.get("searchType");
            DG.getSearchForm("searchForm", "formContents", true);
            DG.getSearchResults("/_colony/collections/colourways/");
        }

        if (curLocation == "search_collections") {
            $("content").empty();
            $("searchType2").value = Cookie.get("searchType2");
            DG.getSearchForm("searchForm2", "formContents2", true);
            DG.getSearchResults("/_colony/collections/");
        }

        //Gift Wrap Service JS
        if ($('giftwrap-ajax-wrapper')) {
            DG.GiftWrapService.initialize();
        }

        if ($('GiftVoucherMessages')) {

            attachGiftVoucherMessagesCharLimit();

        }
    },

    clearSearchCache: function () {
        if ($("brand")) { $("brand").setProperty("value", "") };
        if ($("property")) { $("property").setProperty("value", "") };
    },

    ajaxAdd: function (url, data) {
        new Ajax(url, {
            "encoding": "ISO-8859-1",
            "data": data,
            "onTimeout": function () {
                DG.basketMessage.show("The request to add a product has timed out, please try again.");
            },
            "onFailure": function () {
                DG.basketMessage.show("An error occured, please try again.");
            },
            "onComplete": function (response) {
                var jsonObj = Json.evaluate(response);
                if ($("basketlink")) {
                    /* STS - 11/3/2010 - Basket > 0 then Display in Bold/Lowercase */
                    jsonObj.html = "<strong>" + jsonObj.html.toLowerCase() + "</strong>"
                    $("basketlink").getFirst().replaceWith(new Element("div").setHTML(jsonObj.html).getFirst());
                };
                if (jsonObj.status == 1) {
                    DG.basketMessage.show(jsonObj.message);
                    DG.clearGiftVoucherForm();

                    if ($("addtobasket_checkout")) { $("addtobasket_checkout").setStyle("display", "block"); }
                } else if (jsonObj.status == 3) {
                    DG.basketMessage.setOptions(
						{
						    "timeout": 2000,
						    "onHide": function () {
						        DG.basketMessage.modalHide();
						        $$('div[id^=RecipientNameError_]').each(function (el) { el.setStyle("display", "none") });
						        $('RecipientNameError_' + jsonObj.errorfield).setStyle("display", "block");
						        $('RecipientName_' + jsonObj.errorfield).focus();
						    }
						}
					);
                    DG.basketMessage.show(jsonObj.message);
                } else {
                    DG.basketMessage.show(jsonObj.message);
                }
            }
        }).request();
    },

    clearGiftVoucherForm: function () {
        if ($("GiftVoucherMessages")) {
            $("GiftVoucherMessages").getElements("input[type=text]").each(function (el) {
                el.value = ''
            });
            $("GiftVoucherMessages").getElements("textarea").each(function (el) {
                el.value = ''
            });
            $("GiftVoucherMessages").getElements("select").each(function (el) {
                el.value = ''
            });

            attachGiftVoucherMessagesCharLimit();
        }
    },

    ajaxAddPress: function (url, data) {
        new Ajax(url, {
            "data": 'xxxx',
            "onTimeout": function () {
                DG.basketMessage.show("The request has timed out, please try again.");
            },
            "onFailure": function () {
                DG.basketMessage.show("An error occured, please try again.");
            },
            "onComplete": function (response) {
                var jsonObj = Json.evaluate(response);
                if (jsonObj.status == 1) {
                    DG.basketMessage.show(jsonObj.message);
                    // $$("pressbasket").getFirst().replaceWith(new Element("div").setHTML(jsonObj.html).getFirst());
                    $("pressbasket").innerHTML = jsonObj.html;
                } else {
                    DG.basketMessage.show(jsonObj.message);
                }
            }
        }).request();
    },

    setPalette: function (url) {

        if (window.ie) {
            $ES("div, span", $("dropContainer")).each(function (el) {
                el.removeAttribute("$included");
            });
        }

        DG.basketMessage.show("Saving your palette...");
        new Ajax(url, {
            "method": "post",
            "data": "palette=" + escape($("dropContainer").innerHTML),
            "onTimeout": function () {
                DG.basketMessage.show("The request to save your palette has timed out, please try again.");
            },
            "onFailure": function () {
                DG.basketMessage.show("An error occured, please try again.");
            },
            "onComplete": function (response) {
                var jsonObj = Json.evaluate(response);
                if (jsonObj.status == 1) {
                    DG.basketMessage.show(jsonObj.message);
                } else {
                    DG.basketMessage.show(jsonObj.message);
                }
            }
        }).request();

    },

    ajax: function (url, data, update, func) {
        if (!DG.message) DG.message = new MessageWindow();
        DG.message.show("<img src='/_images/general/ajax-loader.gif' />");
        return new Ajax(url, {
            "method": "get",
            "data": $(data),
            "update": $(update),
            "timeout": 20000,
            "evalScripts": true,
            "onComplete": function () {
                DG.message.hide();
                if (func) func();
            },
            "onFailure": function () {
                DG.message.show("There was a problem retrieving your search results, please try again.");
            },
            "onTimeout": function () {
                DG.message.show("Your search has timed out, please try again.");
            }
        }).request();
    },

    getSearchForm: function (searchForm, formContents, disableUpdate) {
        $(formContents).effect("opacity").set(0);
        $(formContents).setStyle("display", "block");

        var path = "/_colony/collections/colourways/";
        var ddIndex = 0;

        if (searchForm != "searchForm") {
            path = "/_colony/collections/";
            ddIndex = 1;
        }

        var qs = "";

        if (disableUpdate) qs = "&update=disabled";

        DG.ajax(path + "searchform.asp?cache=" + Date.parse(new Date()) + qs, searchForm, formContents, function () {
            DG.fadeElement(formContents, true);

            inputName = "";

            DG.ddArray[ddIndex] = new Accordion($ES(".criteriaHeading", $(formContents)), $ES(".criteriaContent", $(formContents)), { "alwaysHide": true, "show": -1, "fixedWidth": 208 });
            $ES(".criteriaHeading", $(formContents)).each(function (el) {
                el.addEvent("click", function (e) {
                    new Event(e).stop();
                    inputName = this.getProperty("title");
                });
            });

            $$(".swatch a").each(function (a) {
                a.removeEvents();
                a.addEvent("click", function (e) {
                    new Event(e).stop();
                    $("search_page").value = "1";
                    $("brand").value = "";
                    $(inputName).value = this.getProperty("rel");
                    DG.getSearchResults(path);
                });
            });

            $$("#collectionList, #designList").each(DG.makeScroller);

        });
    },

    makeScroller: function (container) {
        if (container) {
            containerHeight = $E(".scrollContainer", container).getCoordinates().height;

            containerScroller = new Slider($E(".scrollBar", container), $E(".scrollHandle", container), {
                steps: 100,
                mode: "vertical",
                onChange: function (step) {
                    var y = $E(".scrollContainer", container).getFirst().getCoordinates().height;
                    y -= containerHeight;
                    y = (y / 100) * step;
                    if (y >= 0) {
                        $E(".scrollContainer", container).scrollTo(0, Math.floor(y));
                    }
                }
            }).set(0);

            container.addEvent("mousewheel", function (event) {
                event = new Event(event).preventDefault();
                var step = containerScroller.step;
                if (event.wheel > 0) {
                    step -= 10;
                    if (step < 0) {
                        step = 0;
                    }
                } else if (event.wheel < 0) {
                    step += 10;
                    if (step > 100) {
                        step = 100;
                    }
                }
                containerScroller.set(step);
            });
        }
    },

    getSearchResults: function (path) {
        this.ajax(path + "search.asp?cache=" + Date.parse(new Date()), "searchCriteria", "content", function () {

            //scroll to top of retreived results
            DG.scroller.toElement($("content"));

            $$(".removeCriteria").each(function (a) {
                a.addEvent("click", function (e) {
                    new Event(e).stop();
                    if (this.getProperty("id").contains("remove_brand")) {
                        $("remove_brand").value = "true";
                    } else {
                        $("remove_brand").value = "";
                    }
                    var removeID = this.getProperty("id").replace("remove_metaproperty_", "");
                    $("search_page").value = "1";
                    $("brand").value = "";
                    $("property").value = "";
                    $("remove_property").value = removeID;
                    DG.getSearchResults(path);
                });
            });

            $$(".search_paging").each(function (paging) {
                paging.addEvent("click", function (e) {
                    new Event(e).stop();
                    var path = (paging.hasClass("swatches_search")) ? "/_colony/collections/colourways/" : "/_colony/collections/";
                    $("search_page").value = this.getProperty("rel");
                    DG.getSearchResults(path);
                });
            });
        });
    },

    replaceSelect: function (el, func) {
        new MooSelect(el, { "onSelect": func });
    },

    fadeElement: function (el, bDirection) {
        if (bDirection) {
            $(el).effect("opacity").start(0, 1);
        } else {
            $(el).effect("opacity").start(1, 0);
        }
    },

    makeSortable: function (el) {
        $ES(".removeBlob", $("dropContainer")).removeEvents().addEvent("click", function (e) {
            new Event(e).stop();
            this.getParent().getParent().remove();
        });

        return new MooSortables($(el), {
            "ghost": true,
            "onComplete": function (sortEl) {
                if ($defined(sortEl.getPrevious())) {
                    if (sortEl.getPrevious().hasClass("clear")) {
                        sortEl.injectBefore(sortEl.getPrevious());
                    }
                }
            }
        });
    },

    GiftWrapService: {

        initialize: function () {

            //Refresh wrapping page incase the back button has been used
            DG.GiftWrapService.refresh($('GiftWrapService'), "&Process=false", null, '');
            DG.GiftWrapService.attachEvents();
        },

        attachEvents: function () {

            $$("#GiftWrapService .nojs").each(function (el) {
                el.setStyle("display", "none");
            });

            $$("#GiftWrapService select").each(function (el) {
                el.addEvent("change", function () {
                    DG.GiftWrapService.refresh($('GiftWrapService'), "", null, '');
                });
            });

            /*
            $('ResetGiftBags').addEvent("click", function(e) {
            DG.GiftWrapService.refresh($('GiftWrapService'), "&ImageButtonClicked=reset");
            new Event(e).stop();
            });
            */

            if ($('UpdateGiftBags')) {
                $('UpdateGiftBags').setStyle("display", "none");
            }

            $$(".recipientName").each(function (el) {
                el.addEvent("blur", function () {
                    DG.GiftWrapService.refresh($('GiftWrapService'), "", function () {
                        /*
                        var giftBagID = el.id.split("_")[1]
                        if (window.ie) {
                        setTimeout (function(){
                        $('GiftBagMessage_' + giftBagID).focus();
                        }, 500);
                        }
                        else
                        {
                        $('GiftBagMessage_' + giftBagID).focus();
                        }
                        */

                    }, 'step3-ajax')
                });
            });

            Lightbox.init();

            DG.GiftWrapService.addGiftMessageCharacterCount();

        },

        addGiftMessageCharacterCount: function () {

            $$("#GiftWrapService .messageBox").each(function (el) {

                //GiftBagID
                var giftBagID = el.id.split("_")[1]

                //char limit label element
                var charCountElement = $('GiftBagMessageCharCount_' + giftBagID);

                attachCharacterLimit(el, charCountElement, 250)

            });

        },

        // Function which posts the set search via AJAX and updates the results
        refresh: function (dataSource, additionalQuerystring, onCompleteFunction, section) {

            DG.loadingMessage.show("Loading...");

            var giftWrapServiceURI = currentPageURI();
            new Ajax(giftWrapServiceURI + "?ajax=true" + additionalQuerystring + '&sectionUpdate=' + section, {
                "encoding": "ISO-8859-1",
                data: dataSource,
                onComplete: function (response) {

                    if (section.length > 0) {
                        $(section).setHTML(response);
                    } else {
                        $("giftwrap-ajax-wrapper").setHTML(response);
                    }

                    DG.GiftWrapService.attachEvents();

                    DG.loadingMessage.hide();

                    if (onCompleteFunction) {
                        onCompleteFunction();
                    }
                },
                method: "post"
            }).request();

            return false;

        }


    }

};

function attachGiftVoucherMessagesCharLimit() {
    $$("#GiftVoucherMessages textarea").each(function (el) {

        //GiftVoucherID
        var giftVoucherID = el.id.split("_")[1]

        //char limit label element
        var charCountElement = $('GiftVoucherMessageCharCount_' + giftVoucherID);

        attachCharacterLimit(el, charCountElement, 250)

    });
}

function attachCharacterLimit(textAreaElement, counterElementID, charLimit) {

    refreshCharLimit(textAreaElement, counterElementID, charLimit)

    textAreaElement.addEvent("keyup", function (e) {

        refreshCharLimit(this, counterElementID, charLimit)

    });
}

function refreshCharLimit(textAreaElement, counterElementID, charLimit) {

    if (textAreaElement.getProperty("value").length > charLimit) {
        textAreaElement.value = textAreaElement.getProperty("value").substr(0, charLimit);
    }

    //chars remaining
    var lngRemaining = charLimit - textAreaElement.value.length;

    counterElementID.innerHTML = '(' + lngRemaining + ' Chars)';

}

function currentPageURI() {
    if ($('CurrentPageURI')) {
        return $('CurrentPageURI').value
    }
}

Ajax = Ajax.extend({
    request: function () {
        if (this.options.timeout) {
            this.timeoutTimer = this.callTimeout.delay(this.options.timeout, this);
            this.addEvent('onComplete', this.removeTimer);
            this.addEvent('onFailure', this.removeTimer);
        }
        this.parent();
    },

    callTimeout: function () {
        this.transport.abort();
        this.onFailure();
        if (this.options.onTimeout) {
            this.options.onTimeout();
        }
    },

    removeTimer: function () {
        $clear(this.timeoutTimer);
    }
});

var DGBanners = {
    configure: function () {

        $$(".dynabanner").each(function (banner) {

            var bannerID = banner.id;
            var locationID = bannerID.substring(bannerID.indexOf("_") + 1);

            var pageURI = window.location.pathname;
            /*
            if (window.location.search.length > 0){
            pageURI = pageURI + "?" + window.location.search;
            }
            */

            new Ajax("/_colony/banners/placements/ajax.asp", {
                "data": {
                    "BannerLocationID": locationID,
                    "PageURI": pageURI
                },
                "onComplete": function (response) {

                    if (response.length > 0) {
                        banner.setHTML(response);
                        banner.setStyle("display", "block");
                    }

                }
            }).request();

        });

        $$(".topbanner, .dynabanner").each(function (el) {
            el.setStyle("opacity", "1");
            el.fx = new Fx.Style(el, "opacity", { duration: 300, wait: false });
            el.addEvent("mouseover", function (e) {
                el.fx.start(0.5);
            });
            el.addEvent("mouseout", function (e) {
                el.fx.start(1);
            });
        });

    }
}

window.addEvent("domready", function () {

    DG.historyManager = new HistoryManager();

    DG.configure();
    DGBanners.configure();

});

function intOnly(i) {
    if (i.value.length > 0) {
        i.value = i.value.replace(/[^\d]+/g, '');
    } 
}

function ShowPassword() {
    var showPassword = document.getElementById("Login_ShowPassword_0");
    if (showPassword.checked) { document.getElementById("fieldwrapper_Login_Password").style.display = 'block'; }
    else { document.getElementById("fieldwrapper_Login_Password").style.display = 'none'; }
    document.getElementById("fieldwrapper_Login_ShowPassword").style.display = 'block';
}

function HideDeliverToShop() {
    var deliverToAddress = document.getElementById("Delivery_Type_1");
    if (deliverToAddress.checked) 
    {
        document.getElementById("divAddress").style.display = 'block';
        document.getElementById("divShop").style.display = 'none';
    }
    else    
    {
        document.getElementById("divAddress").style.display = 'none';
        document.getElementById("divShop").style.display = 'block';
        
        }
    
}

function updateQuantity(id) {
    var quantity = document.getElementById("quantity_" + id).value;
    if (isNumber(quantity)) window.location.href = '?action=updateQuantity&BasketID=' + id + '&Quantity=' + quantity;
}

function isNumber(n) {
    return !isNaN(parseFloat(n)) && isFinite(n);
}



/*
* jqModal - Minimalist Modaling with jQuery
*   (http://dev.iceburg.net/jquery/jqModal/)
*
* Copyright (c) 2007,2008 Brice Burgess <bhb@iceburg.net>
* Dual licensed under the MIT and GPL licenses:
*   http://www.opensource.org/licenses/mit-license.php
*   http://www.gnu.org/licenses/gpl.html
* 
* $Version: 03/01/2009 +r14
*/
(function ($) {
    $.fn.jqm = function (o) {
        var p = {
            overlay: 50,
            overlayClass: 'jqmOverlay',
            closeClass: 'jqmClose',
            trigger: '.jqModal',
            ajax: F,
            ajaxText: '',
            target: F,
            modal: F,
            toTop: F,
            onShow: F,
            onHide: F,
            onLoad: F
        };
        return this.each(function () {
            if (this._jqm) return H[this._jqm].c = $.extend({}, H[this._jqm].c, o); s++; this._jqm = s;
            H[s] = { c: $.extend(p, $.jqm.params, o), a: F, w: $(this).addClass('jqmID' + s), s: s };
            if (p.trigger) $(this).jqmAddTrigger(p.trigger);
        });
    };

    $.fn.jqmAddClose = function (e) { return hs(this, e, 'jqmHide'); };
    $.fn.jqmAddTrigger = function (e) { return hs(this, e, 'jqmShow'); };
    $.fn.jqmShow = function (t) { return this.each(function () { t = t || window.event; $.jqm.open(this._jqm, t); }); };
    $.fn.jqmHide = function (t) { return this.each(function () { t = t || window.event; $.jqm.close(this._jqm, t) }); };

    $.jqm = {
        hash: {},
        open: function (s, t) {
            var h = H[s], c = h.c, cc = '.' + c.closeClass, z = (parseInt(h.w.css('z-index'))), z = (z > 0) ? z : 3000, o = $('<div></div>').css({ height: '100%', width: '100%', position: 'fixed', left: 0, top: 0, 'z-index': z - 1, opacity: c.overlay / 100 }); if (h.a) return F; h.t = t; h.a = true; h.w.css('z-index', z);
            if (c.modal) { if (!A[0]) L('bind'); A.push(s); }
            else if (c.overlay > 0) h.w.jqmAddClose(o);
            else o = F;

            h.o = (o) ? o.addClass(c.overlayClass).prependTo('body') : F;
            if (ie6) { $('html,body').css({ height: '100%', width: '100%' }); if (o) { o = o.css({ position: 'absolute' })[0]; for (var y in { Top: 1, Left: 1 }) o.style.setExpression(y.toLowerCase(), "(_=(document.documentElement.scroll" + y + " || document.body.scroll" + y + "))+'px'"); } }

            if (c.ajax) {
                var r = c.target || h.w, u = c.ajax, r = (typeof r == 'string') ? $(r, h.w) : $(r), u = (u.substr(0, 1) == '@') ? $(t).attr(u.substring(1)) : u;
                r.html(c.ajaxText).load(u, function () { if (c.onLoad) c.onLoad.call(this, h); if (cc) h.w.jqmAddClose($(cc, h.w)); e(h); });
            }
            else if (cc) h.w.jqmAddClose($(cc, h.w));

            if (c.toTop && h.o) h.w.before('<span id="jqmP' + h.w[0]._jqm + '"></span>').insertAfter(h.o);
            (c.onShow) ? c.onShow(h) : h.w.show(); e(h); return F;
        },
        close: function (s) {
            var h = H[s]; if (!h.a) return F; h.a = F;
            if (A[0]) { A.pop(); if (!A[0]) L('unbind'); }
            if (h.c.toTop && h.o) $('#jqmP' + h.w[0]._jqm).after(h.w).remove();
            if (h.c.onHide) h.c.onHide(h); else { h.w.hide(); if (h.o) h.o.remove(); } return F;
        },
        params: {}
    };
    var s = 0, H = $.jqm.hash, A = [], ie6 = $.browser.msie && ($.browser.version == "6.0"), F = false,
i = $('<iframe src="javascript:false;document.write(\'\');" class="jqm"></iframe>').css({ opacity: 0 }),
e = function (h) { if (ie6) if (h.o) h.o.html('<p style="width:100%;height:100%"/>').prepend(i); else if (!$('iframe.jqm', h.w)[0]) h.w.prepend(i); f(h); },
f = function (h) { try { $(':input:visible', h.w)[0].focus(); } catch (_) { } },
L = function (t) { $()[t]("keypress", m)[t]("keydown", m)[t]("mousedown", m); },
m = function (e) { var h = H[A[A.length - 1]], r = (!$(e.target).parents('.jqmID' + h.s)[0]); if (r) f(h); return !r; },
hs = function (w, t, c) {
    return w.each(function () {
        var s = this._jqm; $(t).each(function () {
            if (!this[c]) { this[c] = []; $(this).click(function () { for (var i in { jqmShow: 1, jqmHide: 1 }) for (var s in this[i]) if (H[this[i][s]]) H[this[i][s]].w[i](this); return F; }); } this[c].push(s);
        });
    });
};
})(jQuery);


function divClick(obj) {
    var divs = document.getElementsByTagName('DIV');
    for (var i = 0; i < divs.length; i++) {
        if (divs[i].className === 'clickDiv') {
            if (divs[i] != obj)
                if (divs[i].style.zIndex > 1)
                    divs[i].style.zIndex -= 1;
        }
    }
    obj.style.zIndex = 10;
}

function ShowShopInfo() {
    var showShopInfo = document.getElementById("shopSelector");
    
    document.getElementById("divKingsRoad").style.display = 'none';
    document.getElementById("divMarelybone").style.display = 'none';

    if (showShopInfo.options[showShopInfo.selectedIndex].value == "KingsRoad") {
        document.getElementById("divKingsRoad").style.display = 'block';
        
        }
    if (showShopInfo.options[showShopInfo.selectedIndex].value == "MarelyboneHighStreet") { document.getElementById("divMarelybone").style.display = 'block'; }
}

function ShowPassword() {
    var showPassword = document.getElementById("Login_ShowPassword_0");
    if (showPassword.checked) { document.getElementById("Login_Password").style.display = 'block'; }
    else { document.getElementById("Login_Password").style.display = 'none'; }
}

function ShowDelivery() {
    var showDelivery01 = document.getElementById("delivery01");
    var showDelivery02 = document.getElementById("delivery02");

    if (showDelivery02.checked) {
        document.getElementById("deliverToShop").style.display = 'block';
        document.getElementById("deliverToAddress").style.display = 'none';
    } else if (showDelivery01.checked) {
        document.getElementById("deliverToShop").style.display = 'none';
        document.getElementById("deliverToAddress").style.display = 'block';
    }
    else {
        document.getElementById("deliverToShop").style.display = 'none';
        document.getElementById("deliverToAddress").style.display = 'none';
    }

  
}

function ShowAddressType() {
    var addressType01 = document.getElementById("addressType01");
    var addressType02 = document.getElementById("addressType02");

    if (addressType01.checked) {
        document.getElementById("divAddressTypeLookUp").style.display = 'block';
        document.getElementById("divAddressTypeManual").style.display = 'none';
    } else if (addressType02.checked) {
        document.getElementById("divAddressTypeLookUp").style.display = 'none';
        document.getElementById("divAddressTypeManual").style.display = 'block';
    }
    else {
        document.getElementById("divAddressTypeLookUp").style.display = 'none';
        document.getElementById("divAddressTypeManual").style.display = 'none';
    }
    
}


function ShowTotal() {
    var showTotal01 = document.getElementById("showTotal01");
    var showTotal02 = document.getElementById("showTotal02");
    var showTotal03 = document.getElementById("showTotal03");
    var showTotal04 = document.getElementById("showTotal04");

    document.getElementById("divTotal01").style.display = 'none';
    document.getElementById("divTotal02").style.display = 'none';
    document.getElementById("divTotal03").style.display = 'none';
    document.getElementById("divTotal04").style.display = 'none';

    document.getElementById("price01").style.display = 'none';
    document.getElementById("price02").style.display = 'none';
    document.getElementById("price03a").style.display = 'none';
    document.getElementById("price03b").style.display = 'none';
    document.getElementById("price04a").style.display = 'none';
    document.getElementById("price04b").style.display = 'none';

    if (showTotal03.checked) {
        document.getElementById("price03a").style.display = 'block';
        document.getElementById("price03b").style.display = 'block';

        document.getElementById("divTotal01").style.display = 'block';
        document.getElementById("divTotal02").style.display = 'none';
        document.getElementById("divTotal03").style.display = 'none';
        document.getElementById("divTotal04").style.display = 'none';
    }

    if (showTotal04.checked) {
        document.getElementById("price04a").style.display = 'block';
        document.getElementById("price04b").style.display = 'block';

        document.getElementById("divTotal02").style.display = 'block';
        document.getElementById("divTotal01").style.display = 'none';
        document.getElementById("divTotal03").style.display = 'none';
        document.getElementById("divTotal04").style.display = 'none';
    }

    if ((showTotal01.checked) && (showTotal03.checked)) {
        document.getElementById("price01").style.display = 'block';
        document.getElementById("price03a").style.display = 'block';
        document.getElementById("price03b").style.display = 'block';

        document.getElementById("divTotal01").style.display = 'block';
        document.getElementById("divTotal02").style.display = 'none';
        document.getElementById("divTotal03").style.display = 'none';
        document.getElementById("divTotal04").style.display = 'none';

    }
    if ((showTotal01.checked) && (showTotal04.checked)) {
        document.getElementById("price01").style.display = 'block';
        document.getElementById("price04a").style.display = 'block';
        document.getElementById("price04b").style.display = 'block';

        document.getElementById("divTotal02").style.display = 'block';
        document.getElementById("divTotal01").style.display = 'none';
        document.getElementById("divTotal03").style.display = 'none';
        document.getElementById("divTotal04").style.display = 'none';

    }
    if ((showTotal02.checked) && (showTotal03.checked)) {
        document.getElementById("price02").style.display = 'block';
        document.getElementById("price03a").style.display = 'block';
        document.getElementById("price03b").style.display = 'block';

        document.getElementById("divTotal03").style.display = 'block';
        document.getElementById("divTotal01").style.display = 'none';
        document.getElementById("divTotal02").style.display = 'none';
        document.getElementById("divTotal04").style.display = 'none';

    }
    if ((showTotal02.checked) && (showTotal04.checked)) {
        document.getElementById("price02").style.display = 'block';
        document.getElementById("price04a").style.display = 'block';
        document.getElementById("price04b").style.display = 'block';

        document.getElementById("divTotal04").style.display = 'block';
        document.getElementById("divTotal01").style.display = 'none';
        document.getElementById("divTotal02").style.display = 'none';
        document.getElementById("divTotal03").style.display = 'none';
    }

    document.getElementById("loadingPanel2").style.display = 'none';

}

function ShowTotalUS() {
    var showTotal01 = document.getElementById("showTotal01");
    var showTotal02 = document.getElementById("showTotal02");
 
    document.getElementById("divTotal01").style.display = 'none';
    document.getElementById("divTotal02").style.display = 'none';
 
    if (showTotal01.checked){
        document.getElementById("divTotal01").style.display = 'block';
        document.getElementById("divTotal02").style.display = 'none';
    }
    if (showTotal02.checked) {
       
        document.getElementById("divTotal02").style.display = 'block';
        document.getElementById("divTotal01").style.display = 'none';       
    }
}

function ShowDeliverToThisAddress() {
    var oButton = document.getElementById("deliverToThisAddress");
    var oSelect = document.getElementById("selectedAddress");

    if (oSelect.value == "") {
        oButton.style.display = 'none';
    } else oButton.style.display = 'block';
}

function ShowBillingAddress() {
    var oCheckBox = document.getElementById("useDeliveryAddress");
    document.getElementById("divBillingAddress").style.display = 'block';

    if(!!oCheckBox){
    if (oCheckBox.checked)
    {
        document.getElementById("divBillingAddress").style.display = 'none';
        }
}
    
}

function ShowLoading() {
    document.getElementById("loadingPanel").style.display = 'block';
}

function HideLoading() {
    document.getElementById("loadingPanel").style.display = 'none';
}

function confirmClearBasket()
{
    if (confirm('Are you sure to clear your basket?'))
    {
        window.location.href = loc;
    }
return false; // cancel the click event always
}

function confirmDeleteAddress() {
    if (confirm('Are you sure to delete this address?')) {
        window.location.href = loc;
    }
    return false; // cancel the click event always
}

function ShowStates() {
    
    var showCountry = document.getElementById("txbCountry");
    var IndexValue = showCountry.selectedIndex;

    document.getElementById("USA_County").style.display = 'none';
    document.getElementById("Canada_County").style.display = 'none';
    document.getElementById("spanState").style.display = 'none';
    document.getElementById("spanProvince").style.display = 'none';
    document.getElementById("spanZipcode").style.display = 'none';
    document.getElementById("spanPostalcode").style.display = 'none';
    document.getElementById("spanZipcode2").style.display = 'none';
    document.getElementById("spanPostalcode2").style.display = 'none';
    document.getElementById("spanCounty").style.display = 'none';
    document.getElementById("NewYork_Town").style.display = 'none';

    if (showCountry.options[IndexValue].value == '1697') {
        document.getElementById("USA_County").style.display = 'block';
        document.getElementById("spanState").style.display = 'block';
        document.getElementById("spanZipcode").style.display = 'block';
        document.getElementById("spanZipcode2").style.display = 'block';

        var showUSAState = document.getElementById("USA_County");
        var IndexValue2 = showUSAState.selectedIndex;

        if (showUSAState.options[IndexValue2].value == 'New York') {
            document.getElementById("spanCounty").style.display = 'block';
            document.getElementById("NewYork_Town").style.display = 'block';
        }

    }

    if (showCountry.options[IndexValue].value == '1509') {
        document.getElementById("Canada_County").style.display = 'block';
        document.getElementById("spanProvince").style.display = 'block';
        document.getElementById("spanPostalcode").style.display = 'block';
        document.getElementById("spanPostalcode2").style.display = 'block';
    }
}

function ShowStates2() {

    var showCountry = document.getElementById("txbCountry");
    var IndexValue = showCountry.selectedIndex;

    document.getElementById("USA_County").style.display = 'none';
    document.getElementById("Canada_County").style.display = 'none';
    document.getElementById("spanState").style.display = 'none';
    document.getElementById("spanProvince").style.display = 'none';
    //document.getElementById("spanZipcode").style.display = 'none';
    //document.getElementById("spanPostalcode").style.display = 'none';
    //document.getElementById("spanZipcode2").style.display = 'none';
    //document.getElementById("spanPostalcode2").style.display = 'none';
    document.getElementById("spanCounty").style.display = 'none';
    document.getElementById("NewYork_Town").style.display = 'none';

    if (showCountry.options[IndexValue].value == '1697') {
        document.getElementById("USA_County").style.display = 'block';
        document.getElementById("spanState").style.display = 'block';
        //document.getElementById("spanZipcode").style.display = 'block';
        //document.getElementById("spanZipcode2").style.display = 'block';

        var showUSAState = document.getElementById("USA_County");
        var IndexValue2 = showUSAState.selectedIndex;

        if (showUSAState.options[IndexValue2].value == 'New York') {
            document.getElementById("spanCounty").style.display = 'block';
            document.getElementById("NewYork_Town").style.display = 'block';
        }

    }

    if (showCountry.options[IndexValue].value == '1509') {
        document.getElementById("Canada_County").style.display = 'block';
        document.getElementById("spanProvince").style.display = 'block';
        //document.getElementById("spanPostalcode").style.display = 'block';
        //document.getElementById("spanPostalcode2").style.display = 'block';
    }
}

function RefreshImage(valImageId) {
    var objImage = document.images[valImageId];
    if (objImage == undefined) {
        return;
    }
    var now = new Date();
    objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}
function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
    }
}


// OrderForm Gallery

function HasClass(element, $class) {
    var pattern = new RegExp("(^| )" + $class + "( |$)");
    //ternary to choose
    return pattern.test(element.className) ? true : false;
}

function ShowGallery(partNumber) {
    var divGallery = document.getElementById('div_' + partNumber);
    var divOrderForm = document.getElementById('divOrderForm');
    var alsoLookAt = document.getElementById('alsoLookAt');

    if (HasClass(divGallery, 'hide')) {

        divGallery.className = 'productGallery';
        divOrderForm.className = 'hide';
        alsoLookAt.className = 'hide';
        jQuery.history.load("gallery");
    }
    else {
        divGallery.className = 'hide';
        divOrderForm.className = 'mc_purchasable_product_main';
        alsoLookAt.className = 'mc_also_look_at';
        //jQuery.history.load("new-hash-value2");
    } 
}







