
var LIVESEARCH =
{
    init: function() {
        var sURL = "/live-search?zoom_per_page=250&zoom_query=" + $(".search").val();
        $('.search').liveSearch({ url: sURL });
    }
};

var FONTREPLACE =
{
    init: function() {
        Cufon.replace('#head .hd-banner p.strand', { fontFamily: 'NewBaskerville' });
        Cufon.replace('.dmsearchfilter label', { fontFamily: 'NewBaskerville' });
        Cufon.replace('#body h1', { fontFamily: 'NewBaskerville' });
        Cufon.replace('#body .intro-copy h2', { fontFamily: 'NewBaskerville' });
        Cufon.replace('#body .events h2', { fontFamily: 'NewBaskerville' });
        Cufon.replace('#body .intro-copy h3', { fontFamily: 'NewBaskerville' });
        Cufon.replace('#body .spotlight h3', { fontFamily: 'NewBaskerville' });
        Cufon.replace('#body h4.summary', { fontFamily: 'NewBaskerville' });
        Cufon.replace('#membersarea .landing4 h2', { fontFamily: 'NewBaskerville' });
        Cufon.replace('#contour h4', { fontFamily: 'NewBaskerville' });
        Cufon.replace('#contour legend', { fontFamily: 'NewBaskerville' });
        Cufon.replace('.event-list-item h3', { fontFamily: 'NewBaskerville' });
        Cufon.replace('#designermakerpieces h2', { fontFamily: 'NewBaskerville' });
        Cufon.replace('.spotlight h2', { fontFamily: 'NewBaskerville' });
        Cufon.replace('.spotlight h3', { fontFamily: 'NewBaskerville' });
        Cufon.replace('.spotlight h4', { fontFamily: 'NewBaskerville' });
        Cufon.replace('#contour .contourField label.fieldLabel', { fontFamily: 'NewBaskerville' });
        Cufon.replace('#contour span.checkboxlist label', { fontFamily: 'NewBaskerville' });
        Cufon.replace('#contour span.radiobuttonlist label', { fontFamily: 'NewBaskerville' });
        Cufon.replace('#contour .contourField span.checkbox label', { fontFamily: 'NewBaskerville' });
        Cufon.replace('.news-list h2', { fontFamily: 'NewBaskerville' });
        Cufon.replace('.secondary-nav h2', { fontFamily: 'NewBaskerville' });
        Cufon.replace('.xmasprice', { fontFamily: 'NewBaskerville' });
    }
};

var PROMO =
{
    config:
	{
	    $wrapper: $("div.overlay", "#body")
	},

    init: function() {
        var $wrapper = PROMO.config.$wrapper,
			imgMarkup = "<img src='" + $wrapper.find("img").attr("src") +
			            "'    alt='" + $wrapper.find("img").attr("alt") +
			                "' />",
			btnMarkup = "<p><a href='#' class='enlarge'>Enlarge image</a></p>",
			thisPage = $("body").attr("id");

        if (thisPage = 'collections') {
            var imgMarkup1 = "<img src='" + $("#body .col1 div.overlay img").eq(0).attr("src") + "' alt='" + $("#body .col1 div.overlay img").eq(0).attr("alt") + "' />",
				imgMarkup2 = "<img src='" + $("#body .col2 div.overlay img").eq(0).attr("src") + "' alt='" + $("#body .col2 div.overlay img").eq(0).attr("alt") + "' />";

            $("#body .col1 .overlay").prepend(imgMarkup1 + btnMarkup);
            $("#body .col2 .overlay").prepend(imgMarkup2 + btnMarkup);

            $("#body .col1 div.promo-overlay").attr("id", "promo-overlay1");
            $("#body .col2 div.promo-overlay").attr("id", "promo-overlay2");

            $("#body .col1 a.enlarge").attr("rel", "#promo-overlay1").overlay();
            $("#body .col2 a.enlarge").attr("rel", "#promo-overlay2").overlay();
        } else {
            $("#body .col1 .overlay").prepend(imgMarkup + btnMarkup);
            $("div.promo-overlay", $wrapper).attr("id", "promo-overlay");
            $("a.enlarge", $wrapper)
		        .attr("rel", "#promo-overlay")
		        .overlay();
        }
    }
};

var VGLINKS =
{
    config:
	{
	    $wrapper: $("div.button-list div.bd", "#body")
	},

    init: function() {
        var $wrapper = VGLINKS.config.$wrapper;
            //$("a.button", $wrapper).overlay();
                $(".inline").fancybox({//configure the overlay
                titlePosition: 'inside',
                showNavArrows: false,
                transitionIn: 'fade',
                transitionOut: 'fade',
                speedIn: 300,
                speedOut: 200,
                overlayShow: false,
                hideOnContentClick: false,
                autoDimensions: false,
                width: 500,
                height: 350
            });
            $("div[id^='vg-'] > p > a", $wrapper).addClass("slant").prepend("<b></b>");
    }
};

var TOOLTIPS =
{
    init: function() {
        if ($("#contour").length) {
            if ($(".thegoldtrailform").length) {
                $("#contour .contourField .tt-trigger").each(function() {
                    $(this).tooltip({
                        position: "center right",
                        offset: [-2, 15],
                        effect: "fade",
                        opacity: 1,
                        layout: "<div><b></b></div>",
                        onBeforeShow: function() {
                            var tip = this.getTip();
                            var trigger = this.getTrigger();
                            var h = tip.height();
                            if (h === 18) {
                                tip.addClass("small");
                            };
                            if (trigger.hasClass("confirm-sub")) {
                                tip.addClass("confirm-sub");
                            }
                            if (trigger.hasClass("artefacts")) {
                                tip.addClass("artefacts");
                            }
                            if (trigger.hasClass("type-filter")) {
                                tip.addClass("type-filter");
                            }
                            
                        }
                    });
                });
            } else {
                $("#contour .contourField small").each(function() {
                    t = $(this).text();
                    $(this).prev().children(":input").attr("title", t).tooltip({
                        position: "center right",
                        offset: [-2, 15],
                        effect: "fade",
                        opacity: 1,
                        layout: "<div><b></b></div>",
                        onBeforeShow: function() {
                            var tip = this.getTip();
                            var h = tip.height();
                            if (h === 18) {
                                tip.addClass("small");
                            };
                        }
                    });
                });
            }
        }
    }
};

var GLOSSARY =
{
    opts: {
        gturl: "/technology-training/technical-portal/technical-glossary/"
    },

    init: function() {
        console.log("triggered glossary");
        // if glossary term anchor link exists
        if ($("a[href='/glossary']")) {

            // loop thru all glossry links on page
            $.each($("a[href='/glossary']"), function() {

                var el = $(this);
                var popupId = "tt_gt" + el.text().toLowerCase().split(" ").join("");
                var gtUrl = GLOSSARY.opts.gturl + el.text().toLowerCase().replace(" ", "-");

                el.attr("rel", "#" + popupId).attr("href", gtUrl).css("background-color", "#efefef").addClass("glossary-term");
                
                el.tooltip({
                    tip: "#" + popupId,
                    position: "top center",
                    relative: true,
                    offset: [10, 0],
                    //offset: [-150, -240],
                    effect: "slide",
                });
                $("a.glossary-term").live("click", function(event) {
                    event.preventDefault();
                });
            });
        }
    }
};

var GLOSSARYLIST =
{
    init: function() {
        var m = 0;
        $(".glossary-column").each(function() {
            var c = $(this).height();
            if (m < c) m = c;
        });
        $(".glossary-column").height(m);
    }
};

var FLOWTABS =
{
    init: function() {
        // select #flowplanes and make it scrollable. use circular and navigator plugins
        $("#flowpanes").scrollable().navigator(
			{
			    navi: ".flowtabs",
			    naviItem: 'a.tablink',
			    activeClass: 'current'
			}
		);
        $("#flowtabs a:eq(0)").addClass("current");
        $("#flowtabs a.tablink").live("click", function() {
            return false;
        });
        var h = 0, m = 0;
        $("#flowpanes .pane").each(function() {
            h = $(this).height();
            if (m < h) m = h;
        });
        $("#flowpanes").hide().css("height", m).slideDown(1400);
        $("#tab2 .supplier-carousel div.scrollable").scrollable({
            prev: ".prev1",
            next: ".next1"
        }).navigator();
        FLOWTABS.navcalc("#tab2");
        $("#tab3 .whoswho-carousel div.scrollable").scrollable({
            prev: ".prev2",
            next: ".next2"
        }).navigator();
        FLOWTABS.navcalc("#tab3");
        $("#tab4 .relatedtopics-carousel div.scrollable").scrollable({
            prev: ".prev3",
            next: ".next3"
        }).navigator();
        FLOWTABS.navcalc("#tab4");
    },

    navcalc: function(el) {
        var w = 0;
        $(el+ " .navi > a").each(function() {
            w += $(this).width() + 6;
        });
        $(el + " .navi").width(w);
    }
};

var SLIDER =
{
    init: function() {

        var markup = $("#accordion");

        // hide the accordion during config
        markup.hide();

        // Create pane headings
        $(".tab-header").each(function() {
            var t = $(this).text();
            $(this).next().find(".bd").prepend("<h3>" + t + "</h3>");
        });

        // initialise vars        
        var numTabs = $("div.tab-header").length,
            tabWidth = 720 - (numTabs * 20);

        // calculate the tab width
        $(".tab-pane").width(tabWidth).hide();

        // reveal configured accordion
        markup.show();

        // show the first tab by default
        $("div.tab-header:eq(0)", markup).addClass("current").next().show();

        // add click handler
        $("#accordion div.tab-header").live("click", function() {
            if ($(this).attr("class") !== "current") {
                $("div.current", markup).removeClass("current").next().animate({ width: "toggle" }, 600);
                $(this).addClass("current").next().animate({ width: "toggle" }, 600);
            }
        });
    }
};

var GALLERY =
{
	init: function()
	{
        $(".scrollable").scrollable();
		$(".items img").click(function()
		{
			if ($(this).hasClass("active"))
			{
				return;
			}
			var url = $(this).attr("src").replace("_t",""),
			    cap = $(this).attr("alt"),
				wrap = $("#image-wrapper").fadeTo("medium", 0.5),
				img = new Image();
	
			img.onload = function()
			{
			    wrap.find("p").remove();
				wrap.fadeTo("fast", 1);
				wrap.find("img").attr("src", url).attr("alt",cap).after("<p><em>" + cap + "</em></p>");
			};
			img.src = url;
			$(".items img").removeClass("active");
			$(this).addClass("active");
		}).filter(":first").click();
	}
};

var HACCORDION =
{
	init: function()
	{
		$('.horizontal .exhibitions').kwicks({  
			max: 100,
			spacing:2,
			sticky: true,  
			event: 'click'
		});
	}
};

var SITEMAP =
{
    init: function() {
        if ($("#body .sitemap").length) {
            // add hyphen to front of sitemap list items
            $("#body .sitemap .sitemap-section li a").prepend("- ");
            // set all columns to the same height
            var h1 = 0, h2 = 0;
            $("#body .sitemap .sitemap-column").each(function() {
                h1 = $(this).height();
                if (h1 > h2) {h2 = h1;}
            });
            $("#body .sitemap .sitemap-column").height(h2);
        }
    }
};

var SPOTCLASS =
{
    init: function() {
        // remove the non-breaking space from within the <b> tags
        $("a.slant b").html("");
        $("a.button b").html("");

        // if IE6, add extra class to hero spotlights
        if ($.browser.msie && ($.browser.version === "6.0")) {
            $("div.spotlight").each(function() {
                if ($(this).hasClass("type-page") && $(this).hasClass("hero") && $(this).hasClass("mid"))
                    $(this).addClass("page-hero-mid");

                if ($(this).hasClass("type-page") && $(this).hasClass("hero") && $(this).hasClass("rt"))
                    $(this).addClass("page-hero-rt");

                if ($(this).hasClass("type-content") && $(this).hasClass("hero") && $(this).hasClass("mid"))
                    $(this).addClass("content-hero-mid");

                if ($(this).hasClass("type-content") && $(this).hasClass("hero") && $(this).hasClass("rt"))
                    $(this).addClass("content-hero-rt");
            });
        }
    }
};

var CAPTIONS =
{
    init: function() {
        if ($(".intro-copy img.left").length) {
            $(".intro-copy img.left").each(function() {
                var captionText = $(this).attr("alt");
                $(this).wrap("<div class='image-wrapper left'></div>");
                $(this).after("<p class='caption'>" + captionText + "</p>");
            });
        }
        else if ($(".intro-copy img.none").length) {
            $(".intro-copy img.none").each(function() {
                var captionText = $(this).attr("alt");
                $(this).wrap("");
                $(this).after("");
            });
        }
        else if ($(".intro-copy .gallery img").length) {
            $(".intro-copy img").each(function() {
                var captionText = $(this).attr("alt");
                $(this).wrap("");
                $(this).after("");
            });
        }
        else if ($(".intro-copy img.fullwidth").length) {
            $(".intro-copy img.fullwidth").each(function() {
                var captionText = $(this).attr("alt");
                $(this).wrap("<div class='image-wrapper'></div>");
                $(this).after("<p class='caption fullwidth'>" + captionText + "</p>");
            });
        }
        else if ($(".intro-copy img").length) {
            $(".intro-copy img").each(function() {
                var captionText = $(this).attr("alt");
                $(this).wrap("<div class='image-wrapper'></div>");
                $(this).after("<p class='caption'>" + captionText + "</p>");
            });
        }
        if ($(".landing4 .col1 img").length) {
            $(".landing4 .col1 img").each(function() {
                var captionText = $(this).attr("alt");
                $(this).wrap("<div class='image-wrapper'></div>");
                $(this).after("<p class='caption'>" + captionText + "</p>");
            });
        }
        if ($(".intro-copy .glossary-definition.spotlight img").length) {
            $(".intro-copy .glossary-definition.spotlight img").each(function() {
                $(this).addClass("left");
                $(this).parent().addClass("left");
            });
        }
    }
};

var INTROPARA =
{
   init: function() {
        if ($("#body .intro-copy")) {
          //  $("#body .intro-copy h1 + p").addClass("first");
          //  $("#body.landing2 .intro-copy > p:eq(0)").addClass("first");
          //  $("#body.landing3 .intro-copy > p:eq(0)").addClass("first");
        }
    }
};

var FAQ =
{
    init: function() {
        $("#body .faq li div.answer").hide();
        $("#body .faq li div.question a").click(function() {
            $(this).parent().next("div.answer").slideToggle(200);
            return false;
        });
    }
};

var DMNAV =
{
    init: function() {
        var el = $(".dm-page-nav", "#body");
        var navWidth = $(".bd", el).width();
        if ($("body").attr("id") === "exhibitions") {
            var navMargin = parseInt((720 - navWidth) / 2);
        } else {
            var navMargin = parseInt((500 - navWidth) / 2);
        }
        el.css("margin-left", navMargin).css("margin-right", navMargin)
    }

};

var DMSEARCH =
{
    init: function() {

        $(".dm-search-categories h2", "#dm-search").each(function() {
            $(this).after("<p><a class='slant selectall' href='#'><b></b>Check all</a></p>");
        });

        $(".dm-search-categories a.selectall", "#dm-search").live("click", function() {
            var cat = $(this).text();

            if ($(this).parent().next().hasClass("checked")) {
                
                // uncheck all
                $(this).text("Check all").prepend("<b></b>");
                $(this).parent().next().removeClass("checked").addClass("unchecked");
                $(this).parent().next().find("li input:checkbox").attr("checked", "");

            } else {
            
                // check all
                $(this).text("Uncheck all").prepend("<b></b>");
                $(this).parent().next().removeClass("unchecked").addClass("checked");
                $(this).parent().next().find("li input:checkbox").attr("checked", "checked");

            }
            return false;
        })

    }
};

var DESIGNERMAKERPIECES =
{
	init: function() {
		$('#divSilver').jcarousel().closest(".jcarousel-skin-goldsmiths").hide();
		$("#divWorksOfArt").jcarousel().closest(".jcarousel-skin-goldsmiths").hide();
		$("#divJewellery").jcarousel().closest(".jcarousel-skin-goldsmiths").hide();
		
		//find first carousel and show
		$(".jcarousel-skin-goldsmiths:eq(0)").show();

		$("#SilverTitle").live("click", function() {
		    if($("#divSilver").not(":visible")) {
			    $("#divSilver").closest(".jcarousel-skin-goldsmiths").fadeIn(400);
			    $("#divWorksOfArt").closest(".jcarousel-skin-goldsmiths").hide();
			    $("#divJewellery").closest(".jcarousel-skin-goldsmiths").hide();
			}
			return false;
		});

		$("#WorksOfArt").live("click", function() {
		     if($("#divWorksOfArt").not(":visible")) {
			    $("#divSilver").closest(".jcarousel-skin-goldsmiths").hide();
			    $("#divWorksOfArt").closest(".jcarousel-skin-goldsmiths").fadeIn(400);
			    $("#divJewellery").closest(".jcarousel-skin-goldsmiths").hide();
			 }
			 return false;
		});

		$("#JewelleryTitle").live("click", function() {
		     if($("#divJewellery").not(":visible")) {
		        $("#divSilver").closest(".jcarousel-skin-goldsmiths").hide();
		        $("#divWorksOfArt").closest(".jcarousel-skin-goldsmiths").hide();
		        $("#divJewellery").closest(".jcarousel-skin-goldsmiths").fadeIn(400);
		     }
		     return false;
		});

		$("a.fancypopup").fancybox({//configure the overlay
			titlePosition : 'right',
			showNavArrows :false,
			transitionIn : 'fade',
			transitionOut : 'fade',
			speedIn : 300,
			speedOut : 200,
			overlayShow : false,
			hideOnContentClick: true,
			autoDimensions : false,
			width: 500,
			height: 270
		});
	}
};

var CALENDARPICKER =
{
    init: function() {
        /* serialise querystring parameters in urlParams object */
        var urlParams = {};
            (function () {
                var e,
                    d = function (s) { return decodeURIComponent(s.replace(/\+/g, " ")); },
                    q = window.location.search.substring(1),
                    r = /([^&=]+)=?([^&]*)/g;

                while (e = r.exec(q))
                   urlParams[d(e[1])] = d(e[2]);
            })();

        $(":date").dateinput({
            trigger: true,
            speed: 'fast',
            min: -1,
            format: 'dd/mm/yyyy'
        });

        $(":date").bind("onShow onHide", function() {
            $(this).parent().toggleClass("active");
        });

        $(":date:first").data("dateinput").change(function() {
            $(":date:last").data("dateinput").setMin(this.getValue(), true);
        });

        $('#eventSearchSubmit').click(function() {
            var sURL = unescape(window.location.pathname),
                eventsFrom = $(":date:first").val(),
                eventsTo = $(":date:last").val();
            window.location.href = sURL + "?eFrom=" + eventsFrom + "&eTo=" + eventsTo;
        });
    }
};

var CHARS = {
    //
    // limit characters ouput in Spotlights
    // without image - max 4 lines of text
    // with image - max 2 lines of text
    //
    init: function() {
        if ($(".spotlight").length) {
            CHARS.chrCnt();
        }
    },

    chrCnt: function() {
        // set different letter count depending on
        // whether or not box has image
        var count1 = 75, 	// content spotlights with image
			count2 = 140, 	// section spotlight with image or content without image
            count3 = 220;   // news or event spotlight


        $(".spotlight").each(function() {
            var para = $("div.bd > div > p", $(this)).text();
            var len = para.length;
            var cArray = [len];

            if ($(this).hasClass("type-content") && $(this).hasClass("img")) {
                var lc = count1;
            } else if ($(this).hasClass("type-content") || $(this).hasClass("type-section")) {
                var lc = count2;
            } else if ($(this).hasClass("type-news")) {
                para = $("div.news-summary > p", $(this));
                var lc = count3;
            }

            for (i = 0; i < len; i++) {
                cArray[i] = para.substr(i, 1);
            }

            if (((lc = count1) || (lc = count2)) && (len > lc)) {
                $("div.bd > div > p", $(this)).text("");
                for (j = 0; j < lc; j++) {
                    $("div.bd > div > p", $(this)).append(cArray[j]);
                }
                while (cArray[j] !== " ") {
                    $("div.bd > div > p", $(this)).append(cArray[j]);
                    j++;
                }
                $("div.bd > div > p", $(this)).append("...");
            } else {
            $("div.news-summary > p", $(this)).text("");
                for (j = 0; j < lc; j++) {
                    $("div.news-summary > p", $(this)).append(cArray[j]);
                }
                while (cArray[j] !== " ") {
                    $("div.news-summary > p", $(this)).append(cArray[j]);
                    j++;
                }
                $("div.news-summary > p", $(this)).append("...");
            }
        });
    }
};

var COMPLETIONCOUNTDOWN = {
    init: function() {
        var date = new Date("October 7, 2011"),
            now = new Date(),
            diff = date.getTime() - now.getTime(),
            days = Math.floor(diff / (1000 * 60 * 60 * 24));
        $('.countdown p').html(days + ' days <span>remaining</span>');
    }
};


var gsNews = {

    init: function() {
        $("div[rel='newsDate']").hide();

        $(".list-header-newshome").live("click", function() {

            $("#" +
            $(this).attr("rel")
         ).toggle();
        });
    }
};

var textAreaCount = {
    init: function() {
        var options = {
			"maxCharacterSize": 200,
			"originalStyle": "original",
			"warningStyle": "warning",  
			"warningNumber": 25,
			"displayFormat": "#input/#max | #words Words"
		};
		
		$(".textarea", "#contour").textareaCount(options);
    }
};

$(function() {

    FONTREPLACE.init();
    SITEMAP.init();
    SPOTCLASS.init();
    CAPTIONS.init();
    INTROPARA.init();
    TOOLTIPS.init();
    VGLINKS.init();
    LIVESEARCH.init();
    gsNews.init();
    //if ($("body").hasClass("thegoldtrailform")) {
        textAreaCount.init();
    //}
    /*
    if ($(":date").length)
    {
    $(":date").dateinput();
    }
    */

    //if ($("#body.landing3 div.overlay").length || $("#body.landing2 div.overlay").length || $("#body.landing0 div.overlay").length)
    //PROMO.init();

    //CHARS.init();

    if ($("body").attr("id") === "collections") {
        $('#collections .hd-primary-nav li:last-child').addClass('last-child');
        $('#collections .hd-primary-nav li:first-child').addClass('first-child');
    }

    if ($("#thecentre #body.landing1").length) {
        GALLERY.init();
        COMPLETIONCOUNTDOWN.init();
    }

    if ($(".accordion").length)
        HACCORDION.init();

    if ($("a[href='/glossary']", "#body").length && (location.pathname.search("technical-glossary") === -1 )) {
        console.log(location.pathname.search("technical-glossary"));
        GLOSSARY.init();
    }

    if ($(".glossary-column", "#body").length)
        GLOSSARYLIST.init();

    if ($(".hz-accordion").length)
        SLIDER.init();

    if ($("#flowtabs").length) {
        FLOWTABS.init();
    }

    if ($("#body .faq").length) {
        FAQ.init();
    }

    if ($("#body .dm-page-nav").length) {
        DMNAV.init();
    }

    if ($("#dm-search").length) {
        DMSEARCH.init();
    }


    if ($(":date").length) {
        CALENDARPICKER.init();
    }

    if ($("#designermakerpieces").length) {
        DESIGNERMAKERPIECES.init();
    }

    if ($(".gallery", "#body")) {
        GALLERY.init();
    }

    if (($("body").attr("id") === "collections") && ($("h1", "#body").text() === "Publications")) {
        $(".intro-copy p", "#body").addClass("cr");
    }


    // Apply Drop Cap to first para - SWITCHED OFF UNTIL FIXED!
    /*
    switch ($("#body").attr("class")) {
    case "landing0":
    $("#body .col2 .intro-copy h1 + p").dropCap();
    break;
    case "landing2":
    $("#body .intro-copy h1 + p").dropCap();
    $("#body .intro-copy p:eq(0)").dropCap();
    break;
    case "landing3":
    $("#body .intro-copy h1 + p").dropCap();
    $("#body .intro-copy p:eq(0)").dropCap();
    break;
    case "landing5":
    $("#body .intro-copy h1 + p").dropCap();
    break;
    case "secondary3":
    $("#body .intro-copy h1 + p").dropCap();
    break;
    case "tertiary2":
    var p = $.trim($("#body .intro-copy h1 + p").text());
    if (p === "") {
    $("#body .intro-copy h1 + p").remove();
    } else {
    $("#body .intro-copy h1 + p").dropCap();
    }
    break;
    case "tertiary3":
    $("#body .intro-copy h1 + p").dropCap();
    break;
    }
    */
    //$("#body").upNext();

    $(document).bind("contextmenu", function(e) {
        return false;
    });

    $('.footerSocialLinks a').each(function() {
        var url = this.href;
        this.href = url + window.location.href;
    });

    $("body div.grid").siteUtils();
    // $("#utils-print").bookmark();

    var myFile = document.location.toString()
    if (myFile.match('goldsmiths-centre')) {
        $('#head .hd-group-nav a[href ^= "/"]').each(function() {
            var downloadlink = gsSiteURL + $(this).attr("href");
            $(this).attr("href", downloadlink);
        });
        $('#head .hd-banner-spotlight a[href ^= "/"]').each(function() {
            var downloadlink = gsSiteURL + $(this).attr("href");
            $(this).attr("href", downloadlink);
        });
        $('#foot a[href ^= "/"]').each(function() {
            var downloadlink = gsSiteURL + $(this).attr("href");
            $(this).attr("href", downloadlink);
        });

        $('#body a[href ^= "/"]').each(function() {

            if ($(this).attr("title").indexOf('|') > 0) {
                $(this).attr("title", $(this).attr("title").replace("|", ""));
            }
            else if
                ($('.secondary-nav li a')) {
            }
            else {
                var downloadlink = gsSiteURL + $(this).attr("href");
                $(this).attr("href", downloadlink);
            }
        });
    }
    if (myFile.match('technical-journal/')) {
        $('.secondary-nav ul li a:contains("Technical Journal")').parent().addClass("in");
    }
    if (myFile.match('technical-research/')) {
        $('.secondary-nav ul li a:contains("Technical Research")').parent().addClass("in");
    }
    
    if (myFile.match('members/')) {
        $('.spotlight-header a[href ^= "/"]').each(function() {
            var newslink = "/members" + $(this).attr("href");
            $(this).attr("href", newslink);
        });
    }

    $("a.newsletterpopup").fancybox({//configure the overlay
        titlePosition: 'inside',
        showNavArrows: false,
        transitionIn: 'fade',
        transitionOut: 'fade',
        speedIn: 300,
        speedOut: 200,
        overlayShow: false,
        hideOnContentClick: false,
        autoDimensions: false,
        width: 500,
        height: 350
    });

    $("a[href*=.pdf]").click(function() {
        window.open(this.href);
        return false;
    });

    $("a[href*=.doc]").click(function() {
        window.open(this.href);
        return false;
    });

    $("a[href*=.docx]").click(function() {
        window.open(this.href);
        return false;
    });

    $("#body a[href*=http://]").click(function() {
        window.open(this.href);
        return false;
    });

    $("#body a[href*=https://]").click(function() {
        window.open(this.href);
        return false;
    });

    $('#body a[href ^= "http://thegoldsmiths.serverbeta.co.uk"]').each(function() {
        var downloadlink = $(this).attr("href");
        var newdownloadlink = downloadlink.replace("http://thegoldsmiths.serverbeta.co.uk", "http://www.thegoldsmiths.co.uk");
        $(this).attr("href", newdownloadlink);
    });

    $(".infoline").each(function() {
        if ($(this).children().length == 0) {
            $(this).text($(this).text().replace('http://thegoldsmiths.serverbeta.co.uk', 'http://www.thegoldsmiths.co.uk'));
        }
    });

}); 
