/*
WM_changeVisibility()
Changes whether a layer is visible or hidden.

Source: Webmonkey Code Library (http://www.hotwired.com/webmonkey/javascript/code_library/)

Author: Nadav Savio
Author Email: nadav@wired.com

usage: WM_changeVisibility('targetLayer1',[visible|hidden|toggle],'targetLayer2',[visible|hidden|toggle],...,'targetLayerN',[visible|hidden|toggle])

*/
// set hidden/visible vars for Netscape 4 compatibility

function WM_checkIn(WM_id) {

  // First we initialize all the variables.
  var theObj,ss,sr,i,j,WM_layers=new Array();
  // This chunk handles the IE portion of the checkIn code.
  if (document.all) {
    // This checks to see if the inline style declaration has a position property associated with it. If not, it will scan the global stylesheets for the ID.
    if((document.all[WM_id].style.position != 'absolute') && (document.all[WM_id].style.position != 'relative')){
      // This loops through all global stylesheets and all the rules in each stylesheet, 
      // tests for the selected ID, then returns that as the object.
      for (ss=0 ; ss < document.styleSheets.length; ss++) {
        for (sr=0 ; sr < document.styleSheets(ss).rules.length; sr++) { 
          if (document.styleSheets(ss).rules(sr).selectorText == '#' + WM_id) {
            theObj = document.styleSheets(ss).rules(sr).style;
            break;
          }
        }
      }
    } else {
      // This works the same as in the light version, so you can 
      // use inline styles.
      theObj = document.all[WM_id].style;
    }
  } else if(document.layers) {
    // Now we're in Netscapeland. The main problem here is finding the object in a maze of hierarchy.
    WM_layers = new Array();
    with (document) {
      for (i=0; i<layers.length; i++) WM_layers[i]=layers[i]; {
        for (i=0; i<WM_layers.length; i++) {
          if (WM_layers[i].document && WM_layers[i].document.layers) {
            for (j=0; j<WM_layers[i].document.layers.length; j++) {
              WM_layers[WM_layers.length] = WM_layers[i].document.layers[j];
            }
            if(WM_layers[i].name == WM_id){
              // So if the code matches the name of the layer, 
              // return the reference. 
              theObj = WM_layers[i];
            }
          }
        }
      }
    }
  }
  return theObj;
}



if (!document.layers) {
  var hidden = "hidden";
  var visible = "visible";
} else {
  var hidden = "hide";
  var visible = "show";
}


function show_layer() {
	if(! isArray(arguments[0]) ){
		var args = arguments;
	} else { 
		var args = arguments[0];
	}
	var inc, endInc=args.length;
  	if (document.layers || document.all) {
    	
    	// run through the args (objects) and set the visibility of each
		//hide all: daObj.visibility = hidden;
    	for (inc=0; inc<endInc; inc++) {
      		// get a good object reference
	  //		alert(arguments[inc]);
      		var daObj = WM_checkIn(args[inc]);
           	daObj.visibility = visible;
      
    	} // end for
  	} else if( document.getElementById ){
		//alert(arguments[0]);
		for (inc=0; inc<endInc; inc++) {
			//alert("2" + arguments[0]);
			var daObj = args[inc];
			var obj = document.getElementById(daObj);
			obj.style.visibility =  visible;
		}			
	}
	return true;
}

function hide_layer() {
	
	if(! isArray(arguments[0]) ){
		var args = arguments;
	} else { 
		var args = arguments[0];
	}
	var inc, endInc=args.length;
  	if (document.layers || document.all) {	
    	// run through the args (objects) and set the visibility of each
		//hide all: daObj.visibility = hidden;
    	for (inc=0; inc<endInc; inc++) {
      		// get a good object reference
	  		// alert(args[inc]);
	  
      		var daObj = WM_checkIn(args[inc]);
           	daObj.visibility = hidden;
      
    	} // end for
  	} else if( document.getElementById ){
		//alert(arguments[0]);
		for (inc=0; inc<endInc; inc++) {
			//alert("2" + arguments[0]);
			var daObj = args[inc];
			var obj = document.getElementById(daObj);
			obj.style.visibility =  hidden;
		}			
	}
	return true;
}

var  city_layers = ["city_map", "stornoway", "johnogroats", "inverness", "fortwilliam",  "glasgow", 
"edinburgh", "aberdeen", "londonderry", "belfast", "carlisle", "newcastle", "durham", "lancaster",
"blackpool", "york", "leeds", "manchester", "sheffield", "liverpool", "bangor", "derby", "nottingham",
"peterborough", "norwich", "shrewsbury", "birmingham", "aberystwyth", "stratford", "pembroke", "swansea",
"cardiff", "bristol", "stives", "plymouth", "taunton", "bournemouth", "oxford", "cambridge","london",
"southampton", "brighton", "dover"];

var location_layers =  ["cairngorms", "lomond", "northumberland", "lakedistrict", "peakdistrict", "northyorkmoors",
"pennines", "thebroads", "anglesea", "snowdonia", "brecon", "cambrian", "neagh", "dartmoor", "exmoor", "isleofman", 
"hebrides", "newforest", "isleofwight", "orkney", "thewash", "thames", "cotswold"];

var landmark_layers = ["landmarks_map", "staffa", "bennevis", "glencoe", "leith", "abbotsford", "helvellyn", "cockermouth",
"bamburgh", "dunstanburgh", "shields", "richmond", "bowder", "ambleside", "sligo", "snowdon", "arenig", "mawddach",
"tintern", "horse", "stonehenge", "cerneabbas", "penwith", "landsend", "painswick", "creswell", "dungeon", "salisbury", 
"martello", "pegwell", "hadleigh", "mousehold", "yarmouth", "breydon", "flatford"];


function isArray(){
if (typeof arguments[0] == 'object') {
  var criterion =
    arguments[0].constructor.toString().match(/array/i);
   return (criterion != null);
  }
return false;
} 

isOPERA = (navigator.userAgent.indexOf('Opera') >= 0)? true : false;
isIE    = (document.all && !isOPERA)? true : false;
isDOM   = (document.getElementById && !isIE && !isOPERA)? true : false;

function getID(id){
	if (isDOM || isOPERA){
		return document.getElementById(id);		
	} else if (isIE) {
		return document.all[id];
	}  else {
		return false;
	}
}

function hoverreg(  region, action ){
	
    	// run through the args (objects) and set the visibility of each
		//hide all: daObj.visibility = hidden;
      		// get a good object reference
	  //		alert(arguments[inc]);
      var daObj = getID(region);
		if( action == "over" ){ // do the underline
				//alert(region);
			daObj.className = "regionhover";
		} else {
			daObj.className = "region";
		}
	return true;
}
