// this set of functions powers the class="button" css rollovers
var W3CDOM = (document.createElement && document.getElementsByTagName);

function addButtonRollovers() {
	if (!W3CDOM) return;
	var divs = document.getElementsByTagName("a");
	for (var i=0; i<divs.length; i++) {
		if (divs[i].className.indexOf('button') >= 0) {
			divs[i].rollPosition = "-"+(divs[i].offsetWidth+5)+"px";
			divs[i].onmouseover = buttonRollOver;
			divs[i].onmouseout = buttonRollOut;
		}
	}
}
function buttonRollOver() {
	this.style.backgroundPosition = this.rollPosition;
}
function buttonRollOut() {
	this.style.backgroundPosition = "0 0";
}


/** 
 * function to allow us to add multiple onload events which works on all browsers
 * (including IE / Mac!)
 * From: http://liorean.web-graphics.com/scripts/themeswitch.html 
 **/

var loadEventHandler={  // The Event Handler main object
  Add:function(f){  // Function for adding onload handlers
    loadEventHandler.col[loadEventHandler.col.length]=f;  // Add event handler to collection
    if(typeof window.addEventListener!='undefined')  // If W3C compliant
      window.addEventListener('load',f,false);  // Apply event handler
    else if(!loadEventHandler.ieSet)  // Otherwise, unless already set
      if(typeof document.onreadystatechange!='undefined')  // If supported
        document.onreadystatechange=loadEventHandler.onload;  // Add In event handler handler
    loadEventHandler.ieSet=true;  // Specify that event handler already is set
    return(typeof window.addEventListener!='undefined')  // Return whether W3C compliant
  },
  onload:function(){  // Function for handling multiple onload handlers in IE
    var m=/mac/i.test(navigator.platform);  // Detect whether mac
    if(typeof document.readyState!='undefined')  // If supported
      if(m?document.readyState!='interactive':document.readyState!='complete')  // And not already finished
        return;  // Exit
    for(var i=0,f;(f=(i<loadEventHandler.col.length)?loadEventHandler.col[i]:null);i++)  // For all event handlers
      f();  // Run event handler
    return  // Exit
  },
  ieSet:false,  // Variable to say whether event handler is set or not
  col:[]  // Collection for event handlers
};

loadEventHandler.Add(addButtonRollovers);

// popup window for image galleries
function open_window_html(img_src, width, height, scroll, resize)
{
	if (!scroll) { scroll = "1";}
	if (!resize) { resize = "1";}

    window.open("/includes/popup.php?img=" + img_src + "", /*WARNING -- don't put any spaces in the window name */ "Large_image", "toolbar=0,location=0,directories=0,status=0, menubar=0,scrollbars=" + scroll + ",resizable=" + resize +", width=" + width + ", height=" + height + "");    
}

//
// Format a number as a dollar amount
//
function dollarFormat(dolFloat)
{
    var string = new String(Math.floor((dolFloat * 100))); 
    return string.substring(0, string.length - 2) +"." + string.substring(string.length - 2, string.length)
}
