/*
 * lib.js
 * generic script library
 * Nick Nettleton, www.nicknettleton.com / copyright 2003
 */

var dom = ( document.getElementById ) ? 1:0 ;
var ie = ( document.all ) ? 1:0 ;

/**
 * to queue up an onload event, use window.queue( function_name ) ;
 * or window.queue( function(){ commands_in_here(); } ) ;
 */
document.loadQueue = [] ;
document.queue = function( f ){
	this.loadQueue[this.loadQueue.length] = f ;
}
document.init = function(){
	for( var i = 0 ; i < this.loadQueue.length ; i++ ){
		this.loadQueue[i]() ;
	}
}

/**
 * auto rollovers, applying img oversrc attribute
 * if selected="true" is set, oversrc is applied as down image
 * set window.queue( autoRolls ) to use.
 */
function autoRolls(){
	if( !dom ) return false ;
	var els = document.images ;
	for( var i = 0 ; i < els.length ; i++ ){
		var img = els[i] ;
		var oversrc ;
		if( oversrc = img.getAttribute( "oversrc" ) ){
			if( img.getAttribute( "selected" ) ){
				var downsrc = img.getAttribute( "downsrc" ) ;
				if( downsrc ){
					img.src = downsrc ;
				} else {
					img.src = oversrc ;
				}
			} 
			img.oversrc = oversrc ;
			img.outsrc = img.src ;
			img.onmouseout = function(){ this.src = this.outsrc; } ;
			img.onmouseover = function(){ this.src = this.oversrc } ;
			img.onclick = function(){
				this.onmouseover = null ;
				this.onmouseout = null ;
				this.src = this.oversrc ;
			} // onclick
			img.preloader = new Image() ;
			img.preloader.src = img.oversrc ;	

		} // if
	} // for
} // autoRolls


/* page tools */

function bookmark(){
	if(window.external) window.external.AddFavorite(location.href, document.title) ;
}
function write_bookmark( html ){
	if(window.external) document.write("\n" + html + "\n") ;
}

function printDoc(){
	if(window.print) window.print() ;
}
function write_print( html ){
	if(window.print) document.write("\n" + html + "\n") ;
}


/* new windows */
function openWin(url, width, height){
	if(!width) var width = 400 ;
	if(!height) var height = 400 ;
	var props = ""
		+ "width=" + width + ","
		+ "height=" + height + ","
		+ "scrollbars,"
		+ "toolbar=no,location=no,directories=no,"
		+ "menubar,status,resizable"
		; //dependant?
	window.open(url , '' , props ) ;
}

