//utility functions


if(document.images){
	
infomenu_on = new Image; infomenu_on.src = "infomenu_on.gif";
infomenu_off = new Image; infomenu_off.src = "infomenu_off.gif";

setupsmenu_on = new Image; setupsmenu_on.src = "setupsmenu_on.gif";
setupsmenu_off = new Image; setupsmenu_off.src = "setupsmenu_off.gif";

retouchingmenu_on = new Image; retouchingmenu_on.src = "retouchingmenu_on.gif";
retouchingmenu_off = new Image; retouchingmenu_off.src = "retouchingmenu_off.gif";

portfoliomenu_on = new Image; portfoliomenu_on.src = "portfoliomenu_on.gif";
portfoliomenu_off = new Image; portfoliomenu_off.src = "portfoliomenu_off.gif";

contactmenu_on = new Image; contactmenu_on.src = "contactmenu_on.gif";
contactmenu_off = new Image; contactmenu_off.src = "contactmenu_off.gif";

contact_main_off = new Image; contact_main_off.src = "contact_main_off.gif";
contact_main_on = new Image; contact_main_on.src = "contact_main_on.gif";

}

function chgImg(imgField,newImg){
	if(document.images){
	 document[imgField].src=eval(newImg +".src");
	
	}
}

/**
 * Retrieve the absolute coordinates of an element.
 *
 * @param element
 *   A DOM element.
 * @return
 *   A hash containing keys 'x' and 'y'.
 */
function getAbsolutePosition(element) {
  var r = { x: element.offsetLeft, y: element.offsetTop };
  if (element.offsetParent) {
    var tmp = getAbsolutePosition(element.offsetParent);
    r.x += tmp.x;
    r.y += tmp.y;
  }
  return r;
};

/**
 * Retrieve the coordinates of the given event relative to the center
 * of the widget.
 *
 * @param event
 *   A mouse-related DOM event.
 * @param reference
 *   A DOM element whose position we want to transform the mouse coordinates to.
 * @return
 *    A hash containing keys 'x' and 'y'.
 */
function getRelativeCoordinates(event, reference) {
  var x, y;
  event = event || window.event;
  var el = event.target || event.srcElement;

  if (!window.opera && typeof event.offsetX != 'undefined') {
    // Use offset coordinates and find common offsetParent
    var pos = { x: event.offsetX, y: event.offsetY };

    // Send the coordinates upwards through the offsetParent chain.
    var e = el;
    while (e) {
      e.mouseX = pos.x;
      e.mouseY = pos.y;
      pos.x += e.offsetLeft;
      pos.y += e.offsetTop; 
      e = e.offsetParent;
    }

    // Look for the coordinates starting from the reference element.
    var e = reference;
    var offset = { x: 0, y: 0 }
    while (e) {
      if (typeof e.mouseX != 'undefined') {
        x = e.mouseX - offset.x;
        y = e.mouseY - offset.y;
        break;
      }
      offset.x += e.offsetLeft;
      offset.y += e.offsetTop;
      e = e.offsetParent;
    }

    // Reset stored coordinates
    e = el;
    while (e) {
      e.mouseX = undefined;
      e.mouseY = undefined;
      e = e.offsetParent;
    }
  }
  else {
    // Use absolute coordinates
    var pos = getAbsolutePosition(reference);
    x = event.pageX  - pos.x;
    y = event.pageY - pos.y;
  }
  // Subtract distance to middle
  return { x: x, y: y };
}
