/**
 * Shorthand for document.getElementById($id) 
 */
function elemById($id) {
  return document.getElementById($id);
}

/**
 * Shorthand for document.getElementById($id).style
 * Return null if style not found
 */
function styleOfId($id) {
  var $e = document.getElementById($id);
  if ($e) return $e.style;
  else return null;
}

function is_array(param) { return typeof(param)=="object" }
function is_string(param) { return typeof(param)=="string" }
function trim($str) { return $str.replace(/^\s*|\s*$/g,"") }

/**
 * Toggle the display style of given element between 'none' and default
 */
function toogleDisplay($elem) {
  $elem.style.display = ($elem.style.display) ? '' : 'none';
}

/**
 * Hide given element.
 * Parameter can be an Element, an array of Element, 
 * element Id, an array of element Id, or 'elem1_id,elem2_id'
 */
function hideElement($elem) {
  if (is_array($elem))
    for ($e in $elem)
      hideElement($elem[$e]);
  else if (is_string($elem))
    if ($elem.indexOf(',')>=0)
      hideElement($elem.split(','));
    else
      styleOfId(trim($elem)).display='none';
  else
    $elem.style.display='none';
}

//=====================================================================
//  DOM Image Rollover v3 (hover)
//
//  Demo: http://chrispoole.com/scripts/dom_image_rollover_hover
//  Script featured on: Dynamic Drive (http://www.dynamicdrive.com)
//=====================================================================
//  copyright Chris Poole
//  http://chrispoole.com
//  This software is licensed under the MIT License 
//  <http://opensource.org/licenses/mit-license.php>
//=====================================================================

function domRollover() {
	if (navigator.userAgent.match(/Opera (\S+)/)) var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
	if (!document.getElementById||operaVersion <7) return;
	var imgarr=document.getElementsByTagName('img');
	var imgPreload=new Array();
	var imgSrc=new Array();
	var imgClass=new Array();
	for (i=0;i<imgarr.length;i++){
		if (imgarr[i].className.indexOf('hsrc')!=-1){
			imgSrc[i]=imgarr[i].getAttribute('src');
			imgClass[i]=imgarr[i].className;
			imgPreload[i]=new Image();
			if (imgClass[i].match(/hsrc (\S+)/)) imgPreload[i].src = imgClass[i].match(/hsrc (\S+)/)[1]
			imgarr[i].setAttribute('xsrc', imgSrc[i]);
			imgarr[i].onmouseover=function(){this.setAttribute('src',this.className.match(/hsrc (\S+)/)[1])}
			imgarr[i].onmouseout=function(){this.setAttribute('src',this.getAttribute('xsrc'))}
		}
	}
}
