var arrow_on = "http://a1977.g.akamai.net/f/1977/1448/1d/webmd.download.akamai.com/1448/GSK/Plain_Talk/images/subnav_arrow_on.gif";
var arrow_off = "http://a1977.g.akamai.net/f/1977/1448/1d/webmd.download.akamai.com/1448/GSK/Plain_Talk/images/subnav_arrow_off.gif";

function loadMenu() {
  /* preload the arrow images */
 /* preloadImages(); */

  /* turn off all the menus...
     explicitly set their display property to 'none' so the
     toggle function will work as expected the first time
	 */
	 var i;
	 for (i = 1; i < 7; i++) {
	 var theMenu = "subhead"+ i +"_on";
	 var e = document.getElementById(theMenu);
	 e.style.display = 'none';
	 }
  
  //setDisplay('subhead1_on','none');
  /******************************************
  ATTENTION:  Add server side code to pass in the appropriate id in each HTML file
  for the menu that should remain open based on what page the user is on
  ******************************************/
 if (parent_nav_css_id != "subhead1_on") {
  setInitialDisplay(parent_nav_css_id, sub_nav_css_id);
 }
}


/* this adds a function to the window onLoad event.  Note that this this function will preserve any existing onload event.
   reference: http://simon.incutio.com/archive/2004/05/26/addLoadEvent */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  }
  else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
addLoadEvent(loadMenu);


var wmd_left_nav = {
  'a.wmd_left_nav' : function(element){
    element.onclick = function(){
      return doMenu(this);
    }
  }
};
Behaviour.register(wmd_left_nav);


function doMenu(a_elem) {
  /* a_elem is the A tag where the event was triggered */

  /* get its parent div - the off state */
  var off_div = a_elem.parentNode.id;

  /* strip off "_off" and add "_on" */
  var div_to_open = off_div.substring(0,off_div.lastIndexOf('_')) + '_on';

  /* now turn it on */
  toggleDisplay(div_to_open);

  /* to remove the weird selector lines...
     may not be a good idea...
  */
  a_elem.blur();

  return false;
}

function toggleDisplay(objectID) {
  var object = document.getElementById(objectID);
  state = object.style.display;

  var imgName = objectID.substring(0,objectID.lastIndexOf('_')) + '_arrow';
  var a_tag = getAnchorFromOff(objectID);

  if (state == 'none') {
    document[imgName].src = arrow_on; /*eval(imgName + "on.src");*/
    //a_tag.title = (g_alwaysOpen == objectID) ? "" : "Click to collapse menu";
    object.style.display = 'block';
  }
  else if (state != 'none') {
    document[imgName].src = arrow_off; /*eval(imgName + "off.src"); */
    //a_tag.title = (g_alwaysOpen == objectID) ? "" : "Click to expand menu";
    object.style.display = 'none';
  }

}

var g_alwaysOpen = null;

/* function called once to set the menu that will always stay open */
function setInitialDisplay(objectID, objectID_subnav) {
  g_alwaysOpen = objectID;
  //alert(g_alwaysOpen);
  /* open nav */
  toggleDisplay(objectID);

  /* disable the arrow link */
  var a_tag = getAnchorFromOff(objectID);
  a_tag.style.cursor = "normal";
  a_tag.onclick = function(){ this.blur(); return false; };

  /* hilite subnav */
  var li = document.getElementById(objectID_subnav);  
  if (li != null) {
	  li.className = "navItemHighlight";
  }
}

function doNothing(){
  return false;
}

/* does just what it says.  only called onload */
function setDisplay(objectID,state) {
  var object = document.getElementById(objectID);
  object.style.display = state;
}

function getAnchorFromOff(objectID){
  var off_div = document.getElementById(objectID.substring(0,objectID.lastIndexOf('_')) + '_off');
  var a_tags = off_div.getElementsByTagName('a');
  return a_tags[1];
}


function preloadImages(){
  if (document.images) {
    subhead1_arrowon = new Image();
    subhead1_arrowon.src = "images/subnav_arrow3_on.gif";
    subhead1_arrowoff = new Image();
    subhead1_arrowoff.src = "images/subnav_arrow3_off.gif";
  }
}

function textSize(toggle) {
  var fontWrapper = document.getElementById('WMDcenterContent');
  var size = null;   

  size = fontWrapper.style.fontSize;
  if (isNothing(size)){
    size = '100%';
  } 

  size = (toggle) ? String( (parseInt(size) + 10) + "%") : String( (parseInt(size) - 10) + "%");
  
  if (size == '60%' && toggle == 0) {
  	return false;
  }
  else {
  	fontWrapper.style.fontSize = size;
  }
  
  return false;
}


function isNothing(x) {
  if ( typeof(x) == "undefined" || x == null || x == "" || x == "undefined" ) {
    return true;
  }
  else {
    return false;
  }
}
