/**
Rollover is a static class providing a function to automatically install rollover capabilities on 
arbitrary images in the page. The function is automatically run onload. It scans the page for images 
with a src which ends in _ro. it then installs the necessary mouseovers/mousouts to do
rollovers on the image. if you have an image with name ending _ro, you must have a corresponding image 
with name _omo. for example nice_ro.gif needs nice_omo.gif.

@usage: just include rollover.js in the header. functions.js is also required . if you had to make a fake functions.js
in an emergency to suit this you would at least need the event_install and ctad_error functions.
you would also need the settings.js file setting functions_debug. this script also requires
getElementsByTagName which the normal functions.js 'repairs' for older IE browsers

@author: jo frudd
@author: jon halle

	$Id: rollover.js,v 1.3 2005/03/16 16:18:43 jonh Exp $
*/
function Rollover(){

}

/**
setting for time to wait before checking if preload worked (in ms)
*/
Rollover.wait_for_preload=5000;
	
/**
installs rollovers on images which fit the naming scheme
*/
Rollover.install= function(){

	
	var imgs = document.getElementsByTagName('img');
	for (var i=0;i<imgs.length;i++){
		if (imgs[i].src.match(/_ro\..*$/i)){
			var img=imgs[i];
			img.i_src=img.src;
			img.r_src=img.i_src.replace(/_ro\./i,"_over.");
			event_install(img,"onmouseover",function(){this.src=this.r_src;});
			event_install(img,"onmouseout",function(){this.src=this.i_src;});
			Rollover.preload(img.i_src);
			Rollover.preload(img.r_src);
		}
	}

}
	
	
	


/**
preload an arbitrary src
*/
Rollover.preload=function(src){
	var img = new Image();
	
	//test for success
	//img.onerror would be easiest but mozilla does not support it for local files
	img.onload=function(){this.loaded=true;};
	window.setTimeout(function(){Rollover.check_loaded(img)},Rollover.wait_for_preload)	;
	
	img.src=src;
	
}

/**
show developer error for any image which doesnt preload
*/
Rollover.check_loaded=function(img){
	if (!img.loaded){
		alert("Image "+img.src.split("/").pop()+" does not exist but rollover wants to preload it. Full path is:\n"+img.src);
	}

}

//install this onload
event_install(window,"onload",Rollover.install);
function event_install(obj,event_name,f){
	if (obj.addEventListener){	//W3C
		obj.addEventListener(event_name.substr(2), f,false);
	}else if (obj.attachEvent){	 //IE 
		obj.attachEvent(event_name, function(){obj._f=f;obj._f();obj_f=null});
	}
}

var newwindow2 = '';
function popUp(URL) {
	
var winleft = (screen.width - 720) / 2;
var winUp = (screen.height - 540) / 2;

	if (!newwindow2.closed && newwindow2.location)
	{
		newwindow2.location.href = URL;
	}
	else
	{
		newwindow2=window.open(URL, 'name', 'toolbar=0,scrollbars=0,location=0,status=0,menubar=0,resizable=1,width=720,height=540,left="+winleft+",top="+winUp+"');
		if (!newwindow2.opener) newwindow2.opener = self;
	}
	if (window.focus) {newwindow2.focus()}
}

function newwindow(mypage,myname,w,h,scroll,top){

	

	var winl = (screen.width-w)/2;

	if (typeof(top)!="undefined"){

		var wint = (screen.height-h)*top;

	}else{

		var wint = (screen.height-h)/2;

	}



	settings='height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',toolbar=no,location=no,status=no,menubar=no,resizable=yes,dependent=no'

	win=window.open(mypage,myname,settings)

	if(parseInt(navigator.appVersion) >= 4){win.window.focus();}

	

	//return false;

}
