// the function below is a fix for IE's lack of support for css min-width property
<!--
function P7_limit(a,b){ //v1.1.3 by PVII-www.projectseven.com
 document.p7limit=a;document.p7min=b;
 if(document.getElementById&&navigator.appVersion.indexOf("MSIE")>-1&&!window.opera){
 if(window.attachEvent){window.attachEvent("onresize",P7_setMinWidth);
 window.attachEvent("onload",P7_setMinWidth);}else{onload=P7_setMinWidth;
 onresize=P7_setMinWidth;}}}P7_limit('container',800);
function P7_setMinWidth(){ //v1.1.3 by PVII-www.projectseven.com
 var cw,w,pl,pr,ml,mr,br,bl,ad,theDiv=document.p7limit;
 var g=document.getElementById(theDiv);w=parseInt(document.p7min);
 if(g&&document.body&&document.body.clientWidth){gs=g.currentStyle;
 cw=parseInt(document.body.clientWidth);pl=parseInt(gs.paddingLeft);
 pr=parseInt(gs.paddingRight);ml=parseInt(gs.marginLeft);mr=parseInt(gs.marginRight);
 bl=parseInt(gs.borderLeftWidth);br=parseInt(gs.borderRightWidth);ml=ml?ml:0;
 mr=mr?mr:0;pl=pl?pl:0;pr=pr?pr:0;bl=bl?bl:0;br=br?br:0;ad=pl+pr+ml+mr+bl+br;
 if(cw<=w){w-=ad;g.style.width=w+"px";}else{g.style.width="auto";}}
}
//-->

// this function highlights the current link in the left hand side menu
var url = String(window.location);;

function iamhere() {
	
  	for(var i=0; i < id_list.length; i++)
  	{
    	var id = id_list[i];	
		var search_url = url.match(id);	
	if ((search_url == id))
    		{
				var getNode = document.getElementById(search_url);
					getNode.className = "here";			
			}
	
	}

}

//this function is for the horizonatal menu

function fixLinks()
{
  if (!document.getElementsByTagName) return null;
  var server = document.location.hostname;
  var anchors = document.getElementsByTagName("a");
  for (var i=0; i < anchors.length; i++)
  {
    var a = anchors[i];
    var href = a.href;
    var id = a.id;
    var title = a.title;
    if (href.indexOf("#top_page") != -1) { // back to top, change to your link for back to top
      a.className = "alt";
    } 
	if ((href.indexOf("#") != -1) && (href.indexOf("top_page") == -1)) { // jump ref
      var index = href.indexOf("#section") + 1;
      href = "javascript:show('" + href.substring(index) + "');";
      a.setAttribute("href",href);
    }
	if (a.title == "Next page") {
		a.className = "nextbtn_display";
	}	
  }
}



function hideDivs(exempt)
{
  var divs2hide = new Array("section1", "section2", "section3", "section4", "section5", "section6", "staging_info_menu", "how_thm_works_menu", "howmany_themes_menu", "typical_patterns_menu", "repetition_menu", "synonymy_menu", "taxonomy_menu", "specialised_vocab_menu");
  //array of divs to be hidden
  if (!document.getElementsByTagName) return null;
  if (!exempt) exempt = "";
  var divs = document.getElementsByTagName("div"); 
  for(var x=0; x < divs.length; x++) 
  {
  	var div = divs[x];
  	var id = div.id;

	  for(var i=0; i < divs2hide.length; i++)
	  {
		var hid_id = document.getElementById(divs2hide[i]);
		if (!hid_id) {
		  	hid_id = "";
		}
		else if (hid_id.id != exempt) {
			hid_id.className = "hidden";
		}
	  } 
   }
}

function show(what)
{
  if (!document.getElementById) return null;
  showWhat = document.getElementById(what);
  showWhat.className = "";
  hideDivs(what);
}

// This next bit just highlights the current topic in the horizontal menu

function highlight(id) {

if (document.getElementById)
   {
	   var current = document.getElementById(id)
	   if (!current) {
	   return;
	   }
	   else {
	   current.className = "current";
	   }
   }

   var anchorID = new Array("link_s1", "link_s2", "link_s3", "link_s4", "link_s5", "link_s6");
   if (id == anchorID[0]) {   	
		anchorID.splice(0,1); //this deletes the current link id
		for (var i=0; i < anchorID.length; i++) {
			back2normal(anchorID[i]);
		}
   }
   if (id == anchorID[1]) {   	
		anchorID.splice(1,1);
		for (var i=0; i < anchorID.length; i++) {
			back2normal(anchorID[i]);
		}
   }
   if (id == anchorID[2]) {   	
		anchorID.splice(2,1);
		for (var i=0; i < anchorID.length; i++) {
			back2normal(anchorID[i]);
		}
   }
   if (id == anchorID[3]) {   	
		anchorID.splice(3,1);
		for (var i=0; i < anchorID.length; i++) {
			back2normal(anchorID[i]);
		}
   }
   if (id == anchorID[4]) {   	
		anchorID.splice(4,1);
		for (var i=0; i < anchorID.length; i++) {
			back2normal(anchorID[i]);
		}
   }
   if (id == anchorID[5]) {   	
		anchorID.splice(5,1);
		for (var i=0; i < anchorID.length; i++) {
			back2normal(anchorID[i]);
		}
   }     
							
}

function back2normal(id) {
   var current = document.getElementById(id)
   	   if (!current) {
	   return;
	   }
	   else {
	   current.className = "normal";
	   }  
}

function initializeMenu(menuId, actuatorId) {
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);

    if (menu == null || actuator == null) return;
    actuator.parentNode.style.backgroundImage = "url(http://bugs.bio.usyd.edu.au/clearer_writing/images/design/plus.gif)";
    actuator.onclick = function() {
        var display = menu.style.display;
        this.parentNode.style.backgroundImage =
            (display == "block") ? "url(http://bugs.bio.usyd.edu.au/clearer_writing/images/design/plus.gif)" : "url(http://bugs.bio.usyd.edu.au/clearer_writing/images/design/minus.gif)";
        menu.style.display = (display == "block") ? "none" : "block";

        return false;
    }
	
}

var showmenu_id = null;

function showMenu() {	
	if (showmenu_id == null) {
		return false;
	}
	else {
	var menuDisplay = document.getElementById(showmenu_id);
	menuDisplay.style.display = "block";
	menuDisplay.parentNode.style.backgroundImage = "url(http://bugs.bio.usyd.edu.au/clearer_writing/images/design/minus.gif)";
	}
}

window.onload = function()
{
  fixLinks();
  hideDivs("section1");	//id of the div to appear onload
  highlight("link_s1"); //id of the anchor link of the first section
  iamhere(); 
  initializeMenu("staging_info_menu", "staging_info");
  initializeMenu("how_thm_works_menu", "how_thm_works");  
  initializeMenu("howmany_themes_menu", "how_many_themes");
  initializeMenu("typical_patterns_menu", "typical_patterns"); 
  showMenu();
}
