// SCRIPT BY Mike Gleason Jr Couturier (mcouturier@bmgmultimedia.com)
// FOR BMG Multimedia
// http://www.bmgmultimedia.com/

// ---- Show a layer               ----
// Parameter(s):
//   - theLayer   (string)
function showLayer(theLayer){
  if (document.layers) document.layers[theLayer].visibility = 'show';
  else if (document.all) document.all[theLayer].style.visibility = 'visible';
  else if (document.getElementById) document.getElementById(theLayer).style.visibility = 'visible';
}

// ---- Hide a layer               ----
// Parameter(s):
//   - theLayer   (string)
function hideLayer(theLayer){
  if (document.layers) document.layers[theLayer].visibility = 'hide';
  else if (document.all) document.all[theLayer].style.visibility = 'hidden';
  else if (document.getElementById) document.getElementById(theLayer).style.visibility = 'hidden';
}

// ---- Move a layer horizontally  ----
// Parameter(s):
//   - theLayer   (string)
//   - theLeft    (int)
function moveLayerX(theLayer, theLeft){
  if (document.layers) document.layers[theLayer].left = theLeft;
  else if (document.all) document.all[theLayer].style.left = theLeft;
  else if (document.getElementById) document.getElementById(theLayer).style.left = theLeft+'px';
}

// ---- Move a layer vertically    ----
// Parameter(s):
//   - theLayer   (string)
//   - theTop     (int)
function moveLayerY(theLayer, theTop){
  if (document.layers) document.layers[theLayer].top = theTop;
  else if (document.all) document.all[theLayer].style.top = theTop;
  else if (document.getElementById) document.getElementById(theLayer).style.top = theTop+'px';
}

// ---- Move a layer anywhere      ----
// Parameter(s):
//   - theLayer   (string)
//   - theLeft    (int)
//   - theTop     (int)
function moveLayerXY(theLayer, theLeft, theTop){
  moveLayerX(theLayer, theLeft);
  moveLayerY(theLayer, theTop);
}

// ---- Change layer width         ----
// Parameter(s):
//   - theLayer   (string)
//   - theWidth   (int)
function changeLayerWidth(theLayer, theWidth){
  if (document.layers) document.layers[theLayer].width = theWidth;
  else if (document.all) document.all[theLayer].style.width = theWidth;
  else if (document.getElementById) document.getElementById(theLayer).style.width = theWidth+'px';
}

// ---- Change layer height        ----
// Parameter(s):
//   - theLayer   (string)
//   - theHeight  (int)
function changeLayerWidth(theLayer, theHeight){
  if (document.layers) document.layers[theLayer].height = theHeight;
  else if (document.all) document.all[theLayer].style.height = theHeight;
  else if (document.getElementById) document.getElementById(theLayer).style.height = theHeight+'px';
}

// ---- Get layer width            ----
// Parameter(s):
//   - theLayer   (string)
function getLayerWidth(theLayer){
  if (document.layers) return document.layers[theLayer].width;
  else if (document.all) return document.all[theLayer].style.width;
  else if (document.getElementById) return document.getElementById(theLayer).style.width;
}

// ---- Get layer height           ----
// Parameter(s):
//   - theLayer   (string)
function getLayerHeight(theLayer){
  if (document.layers) return document.layers[theLayer].height;
  else if (document.all) return document.all[theLayer].style.height;
  else if (document.getElementById) return document.getElementById(theLayer).style.height;
}

// ---- Change the layer's content ----
// Parameter(s):
//   - theLayer   (string)
//   - theHTML    (string)
function changeLayerContent(theLayer, theHTML){
  if (document.layers){
    var sprite;
	  sprite = document.layers[theLayer].document;
  	sprite.open();
  	sprite.write(theHTML);
  	sprite.close();
	}
  else if (document.all)
    document.all[theLayer].innerHTML = theHTML;
  else if (document.getElementById){
    var aRange, anElement, theContent;
  	aRange = document.createRange();
	  anElement = document.getElementById(theLayer);
  	aRange.setStartBefore(anElement);
	  theContent = aRange.createContextualFragment(theHTML)
  	while(anElement.hasChildNodes()) anElement.removeChild(anElement.lastChild);
    anElement.appendChild(theContent);
  }
}
