



// Copyright 2006-2007 javascript-array.com

var timeout = 500;
var closetimer  = 0;
var ddmenuitem  = 0;

// open hidden layer
function mopen(id)
{   
    // cancel close timer
    mcancelclosetime();

    // close old layer
    if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

    // get new layer and show it
    ddmenuitem = document.getElementById(id);
    ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
    if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
    closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
    if(closetimer)
    {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}

// close layer when click-out
document.onclick = mclose; 














/* site specific scripts */


function siteInit(){
  // Called with the body onload event.
  // Customise according to site requirements.
  if(current_browser.isIE) {
    fixExplorerCornersBug();
  }

  if(document.body.className.indexOf("HomePage") >= 0) {
    sameHomeTeaserHeights('content_c',['thumbimage','teaser'],3);
  }
  if(document.body.className.indexOf("SectionTop") >= 0) {
    compensateForTeaserViews('main_content_2','teaser');
  }  
}

function compensateForTeaserViews(id,cls) {
  var contentArea = document.getElementById(id);
  var content = null;
  var imgs = null;
  var teasers = null;
  if(typeof(contentArea) == "object" && contentArea != null) {
    teasers = getSubElementsByClass(contentArea,cls);
    for(var i in teasers) {
      content = getSubElementByClass(teasers[i],'content');
      if(content){
        imgs = content.getElementsByTagName("img");
        if(imgs.length <= 0) {
          removeFloatAndWidth(teasers[i].childNodes);
          removeFloatAndWidth(content.childNodes);
        }
      }
    }
  }
}

function removeFloatAndWidth(els) {
  for(var i in els) {
    if(els[i].nodeType == 1) {
      els[i].style.styleFloat = "none";
      els[i].style.cssFloat = "none";
      els[i].style.width = "auto";
    } 
  }
}

function sameHomeTeaserHeights(contentAreaName, elementClasses) {
  var contentArea = document.getElementById(contentAreaName);
  if(contentArea) {
    var elements = getSubElementsByClasses(contentArea, elementClasses);
    var onlyElements = new Array();
    var maxHeight = 0;
    var temp = null;

    var count = 0; // because i does not equal the required value
    for(var i=0; i < elements.length; i++) {
      if(isElement(elements[i])) {
        onlyElements.push(elements[i]);
        if(maxHeight < elements[i].offsetHeight) {
          maxHeight  = elements[i].offsetHeight;
        }
      }
    }

    // Helps prevent IE bug on positioning corners...
    if(maxHeight % 2 != 0) {
      maxHeight -=1;
    }

    for(var i=0; i < onlyElements.length; i++) { 
      if(navigator.userAgent.indexOf("Netscape") >= 0) {
        // disabled for Netscape because it throws a paddy...
        var title = getSubElementByClass(onlyElements[i], "title");
        title.style.position = "static";
      }
      else {
        onlyElements[i].style.height = maxHeight + "px";
        var content = getSubElementByClass(onlyElements[i],"content");
      }
    }
  }
}

function getSubElementByClass(element, classname) {
  var elementByClass = null;
  if(element) {
    var children = element.childNodes;
    if(children){
      for(var i=0; i < children.length; i++) {
        if(children[i].nodeType == 1) {
          if(children[i].className.indexOf(classname) >= 0) {
            elementByClass = children[i];
            break;
          }
        }
      }
    }
  }
  return elementByClass;
}

function isElement(el) {
  return (typeof(el == "object") && el != null);
}

function getSubElementsByClasses(element, classnames) {
  var children = element.childNodes;
  var elementsByClasses = new Array();
  var index = 0;

  for(var i=0; i < children.length; i++) {
    if((children[i].nodeType == 1) && (children[i] != 'undefined') && (children[i] != null)) {
      for(var a=0; a < classnames.length; a++) {
        if(children[i].className.indexOf(classnames[a]) >= 0) {
          elementsByClasses[index] = children[i];
        }
      }
      index++;
    }
  }
  return elementsByClasses;
}

function getSections() {
  sections = new Array();

  sections[0] = document.getElementById('main-banner');
  sections[1] = document.getElementById('main-left');
  sections[2] = document.getElementById('main-right');
  sections[3] = null;
  sections[4] = document.getElementById('main-content');
  sections[5] = document.getElementById('main-footer');

  return sections;
}

function setLayout() {
 ; // Not required.
}

function redrawLayout() {
  if(document.body.className.indexOf("HomePage") >= 0) {
    alignHeights('content_c','thumbimage',3);
  }
}

function printPageComponent() {
  html  = '<button class="button" \n';
  html += '        id="print-page-button" \n';
  html += '        onclick="window.print();" \n';
  html += '        onmouseover="this.className = \'button over\';" \n';
  html += '        onmouseout="this.className = \'button\';" \n';
  html += '        onmouseup="this.blur();" \n';
  html += '        title="Print the current page." \n'; 
  html += '        type="button">'; 
  html += '  <span>Print page</span>\n';
  html += '</button>';
  return html;
}


function hoverHelp(el,action) {
  switch(action) {
    case 0: el.className = "hoverHelp hhClose";
            break;
    case 1: el.className = "hoverHelp hhOpen";
            break;
    default : ;
  }
}

SIZE_DOWN_MSG = "Text size";
SIZE_UP_MSG = "Text size";
function displayFontSwitch() {
  document.write("\n <a href=\"#top\" \n");
  document.write("   id=\"font-switch\" \n");
  document.write("   onclick=\"switchFontSize(this)\" \n");
  document.write("   onmouseup=\"this.blur();\"> \n");
  if(getCookie("baseFontSize") > 0) {
    document.write(SIZE_DOWN_MSG);
  }
  else {
    document.write(SIZE_UP_MSG);
  }
  document.write("</a> \n");
}


function printPageComponent() {
  html  = '<a href="#top"';
  html += '   id="print-page"';
  html += '   onclick="window.print();" \n';
  html += '   onmouseup="this.blur();" \n';
  html += '   title="Print the current page."> \n'; 
  html += '  Print<span class="accessHidden"> this</span> page \n';
  html += '</a> \n';
  return html;
}

function addToClass(el,str) {
  currentClass = el.className;
  if(currentClass.length <= 0) {
    // Class is empty so stick str in
    el.className = str;
  }
  else {
    // Class not empty so make sure to put in preceding space
    el.className = currentClass + " " + str;
  }
}

function removeFromClass(el,str) {
  currentClass = el.className;
  // Do twice to catch any whitespace variants first.
  var withSpace = " " + str;
  el.className = currentClass.replace(withSpace,"");
  el.className = currentClass.replace(str,"");
}


function highlightLink(element, componentClass, location) {
  var currentClass = element.className;
  var activeClass = " " + componentClass + "Active";
  if(element && currentClass) {
    element.className = currentClass + activeClass;
    self.status = location;
  }
}

function unhighlightLink(element, componentClass) {
  var currentClass = element.className;
  var activeClass = " " + componentClass + "Active";
  if(element && currentClass) { 
    element.className = currentClass.replace(activeClass, "");
    self.status = "";
  }
}

function fixExplorerCornersBug() {
  var divs = document.getElementById("page").getElementsByTagName("div");
  var roundedElements = new Array();
  var innerHeight = 0;
  var innerWidth = 0;
  var newHeight = 0;
  var newWidth = 0;

  for(var i in divs) {
    if(typeof divs[i] == "object" && divs[i] != null && divs[i].nodeType == 1) {
      if(divs[i].className.indexOf("roundedElement") >= 0 || divs[i].className.indexOf("nestedRoundedElement") >= 0) {
        roundedElements.push(divs[i]);
      }
    }
  }

  for(var i in roundedElements) {
    adjustCorners(roundedElements[i]);
  }
}

function adjustCorners(el) {
  var elHeight = el.clientHeight;
  var elWidth = el.offsetWidth;
  var children = getSubElementsByClass(el, "bgElement");
  var child = null;
  var childBottom = null;
  var childRight = null;
  var newChildBottom = null;
  var newChildRight = null;

  for(var i in children) {
    child = children[i];

    if(getStyleValue(child, "display") != "none") {

      childBottom = child.offsetTop + child.offsetHeight;
      if(childBottom < elHeight) {
        newChildBottom = getStyleValue(child, "bottom").replace("px","") - (elHeight - childBottom);
      }
      childRight = elWidth - (child.offsetWidth + child.offsetLeft);
      if(childRight > 0) {
        newChildRight = getStyleValue(child, "right").replace("px","") - 1;
      }
      if(child.className.indexOf("bgOne") >= 0) {
      }
      if(child.className.indexOf("bgTwo") >= 0 && newChildRight) {
        child.style.right = newChildRight + "px";
      }
      if(child.className.indexOf("bgThree") >= 0 && newChildBottom) {
        child.style.bottom = newChildBottom + "px";
      }
      if(child.className.indexOf("bgFour") >= 0) {
        if(childRight > 0 && newChildRight) {
          child.style.right = newChildRight + "px";
        }
        if(childBottom < elHeight && newChildBottom) {
          child.style.bottom = newChildBottom + "px";
        }
      } 
    }
  }
}

