﻿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];}}
}

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_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 DoHoverBanner(ShowBanner, Style, Text)
{
    var bc = document.getElementById('breadcrumb');
    var hb = document.getElementById('hoverbanner');
    if(bc != null)
        bc.style.display = (!ShowBanner)?'block':'none';
    hb.style.display = (ShowBanner)?'block':'none';
    hb.className = Style;
    hb.innerHTML = '<span>' + Text + '</span>';
}

function URLencode(sStr) {
    return escape(sStr).replace(/\+/g, '%2C').replace(/\"/g,'%22').replace(/\'/g, '%27').replace(/\//g, '%2f');
}

function MapInitialize(div, longitude, latitude) {
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById(div));
        map.setCenter(new GLatLng(longitude + (0.005697/2), latitude + (0.011673/2)), 12);
        
        map.setUIToDefault();
    }
}

function MapInitialize_Address(address, div) {
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById(div));
        geocoder = new GClientGeocoder();     
        if (geocoder) {
            geocoder.getLatLng(
                address,
                function(point) {
                    if (!point) {
                        alert(address + " not found");
                    } else {
                        map.setCenter(point, 16);
                        map.addControl(new GSmallMapControl());
                        var Icon = new GIcon();
                        Icon.iconSize = new GSize(12, 10);
                        Icon.shadowSize = new GSize(100, 100);
                        markerOptions = { icon:Icon };
                        //var marker = new GMarker(point, markerOptions);
                        var marker = new GMarker(point);
                        map.addOverlay(marker);
                        /*marker.openInfoWindowHtml(address);*/
                    }
                }
            );
        }
    }
}

function MapInitialize2() {
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById('map1'));
        map.setCenter(new GLatLng(51.506552 + (0.005697/2),-0.093727 + (0.011673/2)), 12);
        
        map.setUIToDefault();
    }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function addUnLoadEvent(func) {
  var oldonunload = window.unonload;
  if (typeof window.unonload != 'function') {
    window.unonload = func;
  } else {
    window.unonload = function() {
      if (oldunonload) {
        oldunonload();
      }
      func();
    }
  }
}

/* ExpandCollapse_Content
/**********************/
function ExpandCollapse_Content(theParent, theContentClass, theCurrentObject) {
    //Get an element using classname contained by a parent
    var expCnt = getElemByClassFromParent(theParent, theContentClass, 'div');
    //Get background image url
    var expHd = theCurrentObject.parentNode;
    //Set visibility through style when clicked
    if (expCnt.style.display != 'none') {
        expHd.className = "exp_header exp_invisible";
        expCnt.style.display = 'none';
    }
    else {
        expHd.className = "exp_header";
        expCnt.style.display = 'block';
    }
}

/* getElemByClassFromParent
/**********************/
function getElemByClassFromParent(theParent, theChildClass, tag) {
    //Create Array of All HTML Tags
    var allHTMLTags = theParent.getElementsByTagName(tag);
    //Loop through all tags using a for loop
    for (i = 0; i < allHTMLTags.length; i++) {
        //Get all tags with the specified class name.
        if (allHTMLTags[i].className == theChildClass) {
            //Place any code you want to apply to all
            //pages with the class specified.
            //In this example is to “display:none;” them
            //Making them all dissapear on the page.
            return allHTMLTags[i];
        }
    }
}

/* collapseAll
/**********************/
function collapseAll(firstBoxInd, theChildClass, tag) {
    //Create Array of All HTML Tags
    var allHTMLTags = document.getElementsByTagName(tag);
    //Loop through all tags using a for loop
    var boxInd = 0;
    for (i = 0; i < allHTMLTags.length; i++) {
        //Get all tags with the specified class name.
        if (allHTMLTags[i].className == theChildClass && firstBoxInd <= boxInd++) {
            //Place any code you want to apply to all
            //pages with the class specified.
            //In this example is to “display:none;” them
            //Making them all dissapear on the page.
            allHTMLTags[i].style.display = 'none';
            //var expHd = allHTMLTags[i].previousSibling;
            var expHd = getPrevSibling(allHTMLTags[i]);
            expHd.className = "exp_header exp_invisible";
        }
    }
}


/* getElemByClassFromParent
/**********************/
function onloadCollapseContainers() {
    collapseAll(1, 'exp_content', 'div');
}

addLoadEvent(onloadCollapseContainers);


/* getNextSibling
/**********************/
function getNextSibling(startBrother) {
    endBrother = startBrother.nextSibling;
    while (endBrother.nodeType != 1) {
        endBrother = endBrother.nextSibling;
    }
    return endBrother;
}

/* getPrevSibling
/**********************/
function getPrevSibling(startBrother) {
    endBrother = startBrother.previousSibling;
    while (endBrother.nodeType != 1) {
        endBrother = endBrother.previousSibling;
    }
    return endBrother;
}

/* preloadImages
/*********************/
function preloadImages() {
    MM_preloadImages('/_images/Top_Navigation/Nav-Core-active.png', '/_images/Top_Navigation/Nav-Inspiration-active.png', '/_images/Top_Navigation/Nav-Evolve-active.png');
}

addLoadEvent(preloadImages);