// Common functions.

// Function
// domStyle ()
// Find out which of the 3 possible DOM versions the current browser supports.
// Takes 2 arguments:
// elementID = this is the id of the element you are looking at.
// returnWhat = this must be "style" or "object" and will return the appropriate method for accessing the element.
function getDom (elementID, returnWhat) {	
	
	if (document.layers) {
		
		// Browser supports rubbish buggy Netscape 4 document object model.
		currentDomSupport = "netscape4DOM";
		
		// Check that element exists!
		if (document.layers[elementID]) {
			
			currentDomObject = document.layers[elementID];
			currentDomStyle = document.layers[elementID];
			
		} else {
			
			return false;
			
		}		
	
	}

	if (document.all) {
		
		// Browser supports Internet Explorer 4 document object model.
		currentDomSupport = "internetexplorer4DOM";
		
		// Check that element exists!
		if (document.all[elementID]) {
			
			currentDomObject = document.all[elementID];
			currentDomStyle = document.all[elementID].style;
			
		} else {
			
			return false;
			
		}
		
	}

	if (document.getElementById) {
		
		// Browser supports proper WC3 complient document object model.
		currentDomSupport = "wc3DOM";
		
		// Check that element exists!
		if (document.getElementById(elementID)) {
			
			currentDomObject = document.getElementById(elementID);
			currentDomStyle = document.getElementById(elementID).style;
			
		} else {
			
			return false;
			
		}
	
	}

	if (returnWhat == "object") {
	
		return currentDomObject;
	
	}

	if (returnWhat == "style") {
	
		return currentDomStyle;
		
	}

}

// Function
// domStyle ()
// Find the inner dimensions of the current window or frame.
// Takes 1 arguments:
// returnWhat = this must be "width" or "height" and will return the appropriate value.
function getWindowDimensions(returnWhat) {

	// All except Explorer.
	if (window.innerHeight) {

		windowWidth = window.innerWidth;
		windowHeight = window.innerHeight;
		
	// Explorer 6 Strict Mode.
	} else if (document.documentElement && document.documentElement.clientHeight) {

		windowWidth = document.documentElement.clientWidth;
		windowHeight= document.documentElement.clientHeight;
	
	// other Explorers
	} else if (document.body) {

		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
		
	}
	
	if (returnWhat == "width") {
	
		return windowWidth;
	
	}

	if (returnWhat == "height") {
	
		return windowHeight;
		
	}
	
}

// Function
// writeDIV ()
// Find out which of the 3 possible dynamic div content writing methods the current browser supports.
// Write the content of a DIV in the appropriate way.
// NOTE - For Netscape 4 (and only for Netscape 4) you have to give the div element an absolute position when defining on the page.
// Takes 2 arguments:
// elementID = this is the id of the DIV element you are writing to.
// content = this is the content that you wish to write to the DIV.
function writeDIV (divElementID, content) {

	// Browser supports WC3 complient method.
	if (document.getElementById) {

		x = document.getElementById(divElementID);
		x.innerHTML = '';
		x.innerHTML = content;
	
	// Browser supports Internet Explorer 4 method.
	} else if (document.all) {
		
		x = document.all[divElementID];
		x.innerHTML = content;
	
	// Browser supports bloody Netscape 4 method.
	} else if (document.layers) {

		x = document.layers[divElementID];
		x.document.open();
		x.document.write(content);
		x.document.close();

	}

}

function get_mouse(e) {
  var posx = 0;
  var posy = 0;
  if (!e) var e = window.event;
  if (e.pageX || e.pageY) {
    posx = e.pageX;
    posy = e.pageY;
  }
  else if (e.clientX || e.clientY) {
    posx = e.clientX + document.body.scrollLeft;
    posy = e.clientY + document.body.scrollTop;
    posy = posy-2;
  }
  showx = posx-5;
  showy = posy-25;
  nameclubstyle.left = showx+"px";
  nameclubstyle.top = showy+"px";
}

function showclubname(text) {
  imagename = text.toLowerCase();
  for (i=0;i<imagename.length;i++) {
    if (imagename.substring(i,i+1) == " ") {
      imagename = imagename.substring(0,i)+"_"+imagename.substring(i+1,imagename.length);
    }
  }
  document.images[imagename].src = "images/dot-hover.gif";
  content = "<table class=\"clubname\"><tr><td>"+text+"</td></tr></table>";
  writeDIV("clubname",content);
  playsound("popup");
  nameclubstyle.visibility = "visible";
}

function hideclubname(text,type) {
  imagename = text.toLowerCase();
  for (i=0;i<imagename.length;i++) {
    if (imagename.substring(i,i+1) == " ") {
      imagename = imagename.substring(0,i)+"_"+imagename.substring(i+1,imagename.length);
    }
  }
  document.images[imagename].src = "images/dot-"+type+".gif";
  nameclubstyle.visibility = "hidden";
}

function mapcontrolall() {
  if (document.controlmap.elements["all"].checked) {
    playsound("select-all");
    state = true;
  } else {
    playsound("deselect-all");
    state = false;
  }
  for (i=1;i<document.controlmap.elements.length-1;i++) {
    document.controlmap.elements[i].checked = state;
  }
  checkmapcontrol("no");
}

function checkmapcontrol(soundyn) {
  if (viewmode == "map") {
    state = true;
    selected = true;
    for (i=1;i<document.controlmap.elements.length-1;i++) {
      if (document.controlmap.elements[i].checked) {
        for (c=0;c<clubtype.length;c++) {
          if (document.controlmap.elements[i].value == clubtype[c]) {
            look = getDom(clubid[c],"style");
            look.visibility = "visible";
          }
        }
      } else {
        for (c=0;c<clubtype.length;c++) {
          if (document.controlmap.elements[i].value == clubtype[c]) {
            look = getDom(clubid[c],"style");
            look.visibility = "hidden";
          }
        }
        state = false;
        selected = false;
      }
    }
    if (soundyn == "yes" && !selected) {
      playsound("deselect");
    }
    if (soundyn == "yes" && selected) {
      playsound("select");
    }
    document.controlmap.elements["all"].checked = state;
  }
}

function playsound(which) {
  if (!mute) {
    writeDIV("sounds","<embed type=\"application/x-shockwave-flash\" width=\"0\" height=\"0\" src=\"audio/"+which+".swf\"></embed>");
  }
}

function mapmute() {
  if (viewmode == "map") {
    mute = document.controlmap.elements["mute"].checked;
  }
}

startup = function() {
  document.onmousemove = get_mouse;
  nameclubstyle = getDom("clubname","style");
  nameclubobject = getDom("clubname","object");
  soundsobject = getDom("sounds","object");
  mute = false;
  checkmapcontrol("no");
  mapmute();
}

var minheight_large = 584;
var minheight_small = 452;
window.onload = startup;
