addDOMLoadEvent(createMap);addDOMLoadEvent(styleSwitcher);addDOMLoadEvent(flashCheck);addDOMLoadEvent(ie6HeightSet);addDOMLoadEvent(tooltips);addDOMLoadEvent(sliders);function sliders() {    var x = $$('.slidermodule');    for (var i=0; i<x.length;i++)    {        var y = $(x[i]);        y.insert({top: '<span id="ignore1"></span>'});        recalculate(y);        function createBorrowFunc (y)        {            return function(value)            {                updateBorrowing(y, value);            }        }        function createRepayFunc (y)        {            return function(value)            {                updateRepay(y, value);            }        }        borrowSlider = new Control.Slider($(x[i]).down('.borrowslider .handle'), $(x[i]).down('.borrowslider'));        borrowSlider.options.onSlide = createBorrowFunc(y);        repaySlider = new Control.Slider($(x[i]).down('.repayslider .handle'), $(x[i]).down('.repayslider'));        repaySlider.options.onSlide = createRepayFunc(y);    }}function updateBorrowing(y, value){    borrowMin = parseFloat(y.down('.borrow').next('table').down('.minvalue').getValue());    borrowMax = parseFloat(y.down('.borrow').next('table').down('.maxvalue').getValue());    newValue = ((borrowMax - borrowMin)*value)+borrowMin;    if(newValue%5>0) {        newValue = newValue - newValue%5;    }    y.down('.borrowvalue').update(Math.round(newValue));    y.down('.borrowrepeatvalue').update(newValue.toFixed(2));    recalculate(y);}function updateRepay(y, value){    repayMin = parseFloat(y.down('.repay').next('table').down('.minvalue').getValue());    repayMax = parseFloat(y.down('.repay').next('table').down('.maxvalue').getValue());    newValue = ((repayMax - repayMin)*value)+repayMin;    y.down('.repayvalue').update(Math.round(newValue));    recalculate(y);}function recalculate(y){    apr1 = parseFloat(y.down('.cu-apr').innerHTML);    apr2 = parseFloat(y.down('.doorstep-apr').innerHTML);    borrow = parseFloat(y.down('.borrowvalue').innerHTML);    repay = parseFloat(y.down('.repayvalue').innerHTML);    weeklypaymentgood = borrow * ( (apr1/100)/52/(1- Math.pow(1+((apr1/100)/52), 0 - repay)) );    weeklypaymentbad = borrow * ( (apr2/100)/52/(1- Math.pow(1+((apr2/100)/52), 0 - repay)) );    interest = (weeklypaymentgood * repay) - borrow;    paid = weeklypaymentgood * repay;    y.down('.interestvalue').update(interest.toFixed(2));    y.down('.interestrepeatvalue').update(paid.toFixed(2));    y.down('.totalvalue').update(weeklypaymentgood.toFixed(2));    badpaid = weeklypaymentbad * repay;    y.down('.badvalue').update(badpaid.toFixed(2));    /*dayrate = Math.pow(1 + (apr1 / 100), (1/(365/7)));    baddayrate = Math.pow(1+ (apr2 / 100), (1/(365/7)));    daypayment = (borrow * (dayrate - 1)) / (1 - Math.pow(dayrate, 0 - (repay)));    baddaypayment = (borrow * (baddayrate - 1)) / (1 - Math.pow(dayrate, 0 - (repay)));    paid = repay * daypayment;    badpaid = repay * baddaypayment;    interest = paid - borrow;    badinterest = badpaid - borrow;    y.down('.interestvalue').update(interest.toFixed(2));    y.down('.interestrepeatvalue').update(paid.toFixed(2));    totalvalueweek = paid / repay;    y.down('.totalvalue').update(totalvalueweek.toFixed(2));    y.down('.badvalue').update(badpaid.toFixed(2));*/}function tooltips(){    $$("img.tooltipicon").each( function(input) {		new Tooltip(input, {backgroundColor: "#333", opacity:1,borderColor: "#333",		textColor: "#FFF", textShadowColor: "#000"});    });}function ie6HeightSet(){    if (getIEVersionNumber()<7&&getIEVersionNumber()>0) {        if($('sidecol').getHeight() >= $('maincol').getHeight()) {                $('bd').setStyle({height: $('sidecol').getHeight() + 'px'})        }        var x = $$('.content table');        for (var i=0; i<x.length;i++)        {            if($(x[i]).getStyle('width')=="100%") {                $(x[i]).setStyle({width:'95%'});            }        }    }}function flashCheck(){    var x = $$('object embed');    for (var i=0; i<x.length;i++)    {            //debug            //if(FlashDetect.installed) alert("Flash version: " + FlashDetect.major);            //else alert ("No Flash");            if(!FlashDetect.installed){                $(x[i]).up("object").insert({before: '<div class="error"><p>Sorry but you require Adobe Flash Player to view this video - <a href="http://get.adobe.com/flashplayer/">Download Adobe Flash Player</a></p></div>'})                $(x[i]).up("object").remove();            } else if(FlashDetect.installed&&FlashDetect.major<7){                $(x[i]).up("object").insert({before: '<div class="error"><p>Sorry but you need to update your Flash Player to view this video - <a href="http://get.adobe.com/flashplayer/">Upgrade Adobe Flash Player</a></p></div>'})                $(x[i]).up("object").remove();            }    }}function setupCorners(){    ieVersion = getIEVersionNumber();    var cookie = readCookie("style");    if (ieVersion>0&&cookie!="high-contrast") {        var x = $$('div.collectionPointBanner');        if (x.length>0) {            for (var i=0; i<x.length;i++)            {                $(x[i]).addClassName("bannerCorners");            }            Nifty("div.collectionPointBanner", "big transparent");        }        x = $$('div.searchProviderFlexy');        if (x.length>0) {            for (i=0; i<x.length;i++)            {                $(x[i]).addClassName("bannerCorners");            }            Nifty("div.searchProviderFlexy", "big");        }        x = $$('div.sliderregion');        if (x.length>0) {            for (i=0; i<x.length;i++)            {                $(x[i]).addClassName("bannerCorners");            }            Nifty("div.sliderregion", "big transparent");        }    }}function styleSwitcher(){    if ($('stylesheet-switcher'))    {        var cookie = readCookie("style");        if (cookie=="high-contrast") {            loadHighContrastColours();        } else {            loadStandardColours();        }    }}function loadStandardColours(){    Event.stopObserving($('stylesheet-switcher'));    if ($('stylesheet-switcher').down("a")) $('stylesheet-switcher').down("a").remove();    $('stylesheet-switcher').insert({top: '<a class="highcontrast" href="#">High Contrast Colours</a>'});    stopActiveStyleSheet("High Contrast");    createCookie("style", "", 365);    Event.observe($('stylesheet-switcher'), 'click', function(e) {        loadHighContrastColours();        Event.stop(e);    });}function loadHighContrastColours(){    Event.stopObserving($('stylesheet-switcher'));    if ($('stylesheet-switcher').down("a")) $('stylesheet-switcher').down("a").remove();    $('stylesheet-switcher').insert({top: '<a class="highcontrast" href="#">Standard Colours</a>'});    setActiveStyleSheet("High Contrast");    createCookie("style", "high-contrast", 365);    Event.observe($('stylesheet-switcher'), 'click', function(e) {        loadStandardColours();        Event.stop(e);    });}function setActiveStyleSheet(title) {   //$('highcontrast-stylesheet').disabled = false;   var i, a, main;   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {     if(a.getAttribute("rel").indexOf("style") != -1        && a.getAttribute("title")) {       if(a.getAttribute("title") == title) {           a.disabled = false;       }     }   }}function stopActiveStyleSheet(title) {   //$('highcontrast-stylesheet').disabled = true;   var i, a, main;   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {     if(a.getAttribute("rel").indexOf("style") != -1        && a.getAttribute("title")) {       if(a.getAttribute("title") == title) {           a.disabled = true;       }     }   }}function createMap(){    if ($('map')&&$('siteName')) {        $('map').addClassName("mapactive");        var geocoder = new GClientGeocoder();        var map = new GMap2($('map'));        map.setCenter(new GLatLng(54.5730, -1.2379), 6);        map.setUIToDefault();        buildMarkersFromXML(map, $('siteName').getValue());        $('map').insert({before: '<p><label for="postcodeZoom">Enter your address or postcode:</label> <input type="text" id="postcodeZoom"> <input type="submit" id="postcodeZoomButton" class="button" value="Find"></p>'});        Event.observe($('postcodeZoomButton'), 'click', function(e) {            geocoder.getLatLng($('postcodeZoom').getValue()+',UK',function(point) {              if (!point) {                alert("Sorry " + address + " not found");              } else {                map.setCenter(point, 12);                var marker = new GMarker(point);                map.addOverlay(marker);              }            }          );        }, false);    }}function buildMarkersFromXML(map, fileName){    var nmIcon = new GIcon();    nmIcon.image = 'http://www.northernmoney.co.uk/images/icon.png';    nmIcon.iconSize = new GSize(32,32);    nmIcon.iconAnchor = new GPoint(16,16);    nmIcon.infoWindowAnchor = new GPoint(16,16);    var bounds = new GLatLngBounds();    var points = new Array();    GDownloadUrl(fileName, function(data) {        var xml = GXml.parse(data);        var markers = xml.documentElement.getElementsByTagName("marker");        if (markers.length>0)        {            for (var i = 0; i < markers.length; i++) {                var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng")));                points[i] = point;                var infowindow = GXml.value(markers[i].getElementsByTagName("infowindow")[0]);                var marker = new GMarker(point, {icon: nmIcon});                map.addOverlay(marker);                marker.bindInfoWindow(infowindow);                bounds.extend(point);            }            map.setCenter(bounds.getCenter());            minZoom = Math.min(map.getBoundsZoomLevel(bounds), 15);            map.setZoom(minZoom);        }    });}/*function createMap(){    if ($('map')) {        $('map').addClassName("mapactive");        var osMap = new OpenSpace.Map('map');        var gridProjection = new OpenSpace.GridProjection();        var myLonLat = new OpenLayers.LonLat(-1.6379, 54.6730);        var postcodeService = new OpenSpace.Postcode();        osMap.setCenter(gridProjection.getMapPointFromLonLat(myLonLat), 3);        loadMarkers(osMap, false);        $('map').insert({before: '<p><label for="postcodeZoom">Enter your postcode:</label> <input type="text" id="postcodeZoom"> <input type="submit" id="postcodeZoomButton" class="button" value="Find"></p>'});        Event.observe($('postcodeZoomButton'), 'click', function(e) {            postcodeService.getLonLat($('postcodeZoom').getValue(), function(mapPoint) {                findPostcode(mapPoint, osMap);            });        }, false);    }}function findPostcode(mapPoint, osMap) {    if (mapPoint!=null)        osMap.setCenter(mapPoint, 7);}function loadMarkers(osMap) {    osMap.destroyFeatures();    url = $('siteName').getValue();    buildMarkersFromXML(osMap, url);}function buildMarkersFromXML(osMap, fileName, refresh){    var bounds = new OpenSpace.MapBounds();    var gridProjection = new OpenSpace.GridProjection();    var iconSize = new OpenLayers.Size(32,32);    var iconOffset = new OpenLayers.Pixel(-16,-16);    var infoWindowAnchor = new OpenLayers.Pixel(16,16);    var audiobooIcon = new OpenSpace.Icon('http://www.northernmoney.co.uk/images/icon.png', iconSize, iconOffset, null, infoWindowAnchor);    GDownloadUrl(fileName, function(data) {        var xml = GXml.parse(data);        var markers = xml.documentElement.getElementsByTagName("marker");        if (markers.length>0)        {            for (var i = 0; i < markers.length; i++) {                myLonLat = new OpenLayers.LonLat(markers[i].getAttribute("lng"), markers[i].getAttribute("lat"));                myMapPoint = gridProjection.getMapPointFromLonLat(myLonLat);                bounds.extend(myMapPoint);                infowindow = GXml.value(markers[i].getElementsByTagName("infowindow")[0]);                infoWindowSize = new OpenLayers.Size(400,250);                marker = osMap.createMarker(myMapPoint, audiobooIcon.clone(), infowindow, infoWindowSize);            }            osMap.setCenter(bounds.getCenterLonLat(), 5);            bounds.toBBOX();            osMap.zoomToExtent(bounds);        }    });}*/
