/**********************************************************************
	BioWare Javascript File
	
	File: layer_functions.js
	
	Description: Layer Functions - references browser detection variables from HMBio_Loader.js
	
	Created: Robin Mayne, April 11, 2002 Copyright 2002 BioWare Corp.
	Based on "Layer functions" code by Mike Hall http://www.dynamicdrive.com 
***********************************************************************	
	Version: 0.0.2
	
	Version History:
		0.0.1 / 11.04.02 / Created / RM
						PC browsers tested:
						IE 6.0, IE 5.5, IE 4.72, Opera 5.11, Opera 6.0, NS 4.08, NS 4.78, NS 6.21, Mozilla 0.98
						MAC browsers tested:
						IE 5.0, IE 4.5, Opera 5.0, NS 4.78, NS 6.1
		0.0.2 / 16.04.02 / Updated / RM
						Added setWidth() function for IE and NS6

***********************************************************************/


/**********************************************************************
	BioWare Javascript Code
	
	From File: HMBio_Loader.js
	
	Description: Loader file for menu display
	
	Created: Robin Mayne, April 11, 2002 Copyright 2002 BioWare Corp.
	Based on code from HM_Loader.js by Peter Belesis. v4.1 010821
***********************************************************************	
	Version: 0.0.1
	
	Version History:
		0.0.1 / 11.04.02 / Created / RM
		0.0.2 / 11.04.02 / Made changes to reflect HM v4.2.3 020402 / RM

***********************************************************************/

HM_DOM = (document.getElementById) ? true : false;
HM_NS4 = (document.layers) ? true : false;
HM_IE = (document.all) ? true : false;
HM_IE4 = HM_IE && !HM_DOM;
HM_Mac = (navigator.appVersion.indexOf("Mac") != -1);
HM_IE4M = HM_IE4 && HM_Mac;

//4.1

HM_Opera = (navigator.userAgent.indexOf("Opera")!=-1);
HM_Konqueror = (navigator.userAgent.indexOf("Konqueror")!=-1);

// Added following custom browser detect
// Duleepa Wijayawardhana, Dec 17 2001

var HMBio_Agent = navigator.userAgent.toLowerCase();
HMBio_NS6 = (!document.all && document.getElementById) ? true : false;
HMBio_IE5M = (HMBio_Agent.indexOf("msie 5.")!=-1) && HM_Mac;
HMBio_IE4D = (HMBio_Agent.indexOf("msie 4.")!=-1) && !HM_Mac && !HM_Opera;

// End Custom browser detect





//-----------------------------------------------------------------------------
// Layer utilities.
//-----------------------------------------------------------------------------

function getLayer(name) {
	  if (HM_NS4) 
	    return findLayer(name, document);
	  if (HMBio_NS6) 
		return document.getElementById(name); 
	  if (HM_IE)
	  	return eval('document.all.' + name); 
  return null;
}

function findLayer(name, doc) {

  var i, layer;

  for (i = 0; i < doc.layers.length; i++) {
    layer = doc.layers[i];
    if (layer.name == name)
      return layer;
    if (layer.document.layers.length > 0) {
      layer = findLayer(name, layer.document);
      if (layer != null)
        return layer;
    }
  }

  return null;
}

//-----------------------------------------------------------------------------
// Layer visibility.
//-----------------------------------------------------------------------------

function hideLayer(layer) {
	  if (HM_NS4) 
	    layer.visibility = "hide";
	  if (HM_IE || HMBio_NS6) 
	    layer.style.visibility = "hidden";
}

function showLayer(layer) {
	  if (HM_NS4) 
	    layer.visibility = "show";
	  if (HM_IE || HMBio_NS6) 
	  	layer.style.visibility = "visible";
}

//-----------------------------------------------------------------------------
// Layer positioning.
//-----------------------------------------------------------------------------

function moveLayerTo(layer, x, y) {
		if (HM_NS4) 
		    layer.moveTo(x, y);
		if (HM_IE || HMBio_NS6) { 
		    layer.style.left = x;
		    layer.style.top = y;
	   }
}

function moveToShow(name, x, y) { // NOTE - function uses getLayer() to retreive layer object
	moveLayerTo(getLayer(name), x, y);
	showLayer(getLayer(name));
	eval(name + "vis = 1"); // sets a visibility flag to 1
}

function moveToHide(name, x, y) { // NOTE - function uses getLayer() to retreive layer object
	moveLayerTo(getLayer(name), x, y);
	hideLayer(getLayer(name));
	eval(name + "vis = 0"); // sets a visibility flag to 0
}


function moveLayerBy(layer, dx, dy) {

  if (HM_NS4)
    layer.moveBy(dx, dy);
  if (HMBio_NS6) {
  	var xlocation = parseInt(layer.style.left);
	var ylocation = parseInt(layer.style.top);
	xlocation += dx;
	ylocation += dy;
  	layer.style.left = xlocation;
	layer.style.top = ylocation;
  }    
  if (HM_IE) {
    layer.style.pixelLeft += dx;
    layer.style.pixelTop  += dy;
  }
}

function getLeft(layer) {

  if (HM_NS4)
    return(layer.left);
  if (HMBio_NS6)
  	return(parseInt(layer.style.left));
  if (HM_IE)
    return(layer.style.pixelLeft);
  return(-1);
}

function getTop(layer) {

  if (HM_NS4)
    return(layer.top);
  if (HMBio_NS6)
  	return(parseInt(layer.style.top));
  if (HM_IE)
    return(layer.style.pixelTop);
  return(-1);
}

function setWidth(layer, w) {
	if (!HM_Opera && (HM_IE || HMBio_NS6)) {
		layer.style.width = w;
	}
}

/******************************************************************************
* End Layer functions                                                         *
******************************************************************************/

//////////////////////////
// Element Positioning and Offsets
/////////////////////////

// Obtain X coordinate of imageName
function findX(imageName) {
	var objImg
	objImg = document.images[imageName]
	if (HM_NS4){		
		if (document.images[imageName]) { // Test for image in document object
			return eval(objImg).x
		} else { // Fix for Netscape 4 div bug - find image in document.layers object instead (will NOT work for nested divs)			
			for (a = 0; a < document.layers.length; a++) {
				if (document.layers[a].document.images[imageName]) {
					xtotal = document.layers[a].left + document.layers[a].document.images[imageName].x;
					return xtotal;
				}
			}
		}
	} else {
		return getXPosition(objImg);
	}
}

// Called by findX()
function getXPosition(imgElem) {
	xPos = eval(imgElem).offsetLeft;
	tempEl = eval(imgElem).offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}		

// Obtain Y coordinate of imageName
function findY(imageName) {
	var objImg
	objImg = document.images[imageName]
	if (HM_NS4){		
		if (document.images[imageName]) { // Test for image in document object
			return eval(objImg).y
		} else { // Fix for Netscape 4 div bug - find image in document.layers object instead (will NOT work for nested divs)			
			for (a = 0; a < document.layers.length; a++) {
				if (document.layers[a].document.images[imageName]) {
					ytotal = document.layers[a].top + document.layers[a].document.images[imageName].y;
					return ytotal;
				}
			}			
		}
		
	} else {
		return getYPosition(objImg);
	}
}

// Called by findY()
function getYPosition(imgElem) {
	yPos = eval(imgElem).offsetTop;
	tempEl = eval(imgElem).offsetParent;
  	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return yPos;
}

//////////////////////////
// End Element Positioning and Offsets
/////////////////////////

// Functions needed to be updated to new detection and browser support:
function getWindowWidth() {

  if (HM_NS4 || HMBio_NS6 || HM_Opera)
	return(window.innerWidth);
  if (HM_IE)
	return(document.body.clientWidth);
  return(-1);
}

function getWindowHeight() {

  if (HM_NS4 || HMBio_NS6 || HM_Opera)
	return(window.innerHeight);
  if (HM_IE)
	return(document.body.clientHeight);
  return(-1);
}

///////////////////////////
// Custom useful functions
///////////////////////////

	function showWindowSize () {
			////////////////////////////////////////////// Find window positioning
			windowwidth  = getWindowWidth();	
			windowheight = getWindowHeight();	
			//windowmiddle = windowwidth/2;
			
			info = 'Window size: ' + windowwidth + ' x ' + windowheight + '    res. ';
		
			////////////////////////////////////////////// Larghezza
			if (windowwidth > 1580) {
				info += "1900 x ";
			}
			else if (windowwidth > 1260) {
				info += "1600 x ";
			}
			else if (windowwidth > 1004) {
				info += "1280 x ";
			}
			else if (windowwidth > 780){
				info += "1024 x ";
			}
			else if (windowwidth > 620){
				info += "800 x ";
			}
			else {
				info += "640 x ";
			}	

			////////////////////////////////////////////// Altezza
			if (windowheight > 1066) { 
				info += "1400";
			}
			else if (windowheight > 890) { 
				info += "1200";
			}
			else if (windowheight > 634) { 
				info += "1024";
			}
			else if (windowheight > 466) {
				info += "768";
			}
			else if (windowheight > 346) {
				info += "600";
			}
			else {
				info += "480";
			}
			window.status = info;	
	}