// RGJ event insert
function RGJ_addEvent( obj, type, fn ) {
	if( obj.attachEvent ) {
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
		obj.attachEvent( 'on'+type, obj[type+fn] );
	} else obj.addEventListener( type, fn, false );
}
// RGJ img dissolver - with preload
function RGJ_PRobj(dir,id,period,dissolve,names,preload){
	this.dir=dir;
	this.id=id;
	this.names=names;
	this.index=this.fimg=this.fstrt=this.fid=0;
	this.preload=preload;
	this.preload_fimg=0;
	this.times=new Array;
	this.dissolves=new Array;
	for( j=0; j<this.names.length; j++ ) {
		d = this.names[j].match(/_d(\d+)/);
		d = d==null ? dissolve : d[1];
		this.dissolves[j] = d;

		t = this.names[j].match(/_t(\d+)/);
		t = t==null ? period : t[1];
		this.times[j] = t;
	}
}
function RGJ_PRinit(i) {
	if( gpr[i].preload ) {
		var pr = new Array;
		for( j=0; j<gpr[i].names.length; j++ ) {
			pr[j] = new Image;
			pr[j].src = gpr[i].dir+'/'+gpr[i].names[j];
		}
	}
	setTimeout('RGJ_PRcallback('+i+')',gpr[i].times[0]);
}
function RGJ_PRsetOp(elem,op){elem.style.opacity=op/100;elem.style.filter="alpha(opacity="+op+")";}
function RGJ_PRcallback(i) {
	if(++gpr[i].index>=gpr[i].names.length) gpr[i].index=0;
	div=document.getElementById(gpr[i].id);
	gpr[i].fimg=div.getElementsByTagName('img')[0];
	div.style.backgroundImage="url('"+gpr[i].fimg.src+"')";
	div.style.backgroundColor="transparent";
	div.style.backgroundRepeat="no-repeat";
	if( gpr[i].dissolves[gpr[i].index] ) {
		if( gpr[i].preload ) RGJ_PRfstart(i);
		else {
			if( gpr[i].preload_fimg ) delete gpr[i].preload_fimg;
			gpr[i].preload_fimg = new Image;
			gpr[i].preload_fimg.src = gpr[i].dir+'/'+gpr[i].names[gpr[i].index];
			gpr[i].preload_fimg.onLoad=RGJ_PRloadedDelay(i);
		}
	}
	setTimeout('RGJ_PRcallback('+i+')',gpr[i].times[gpr[i].index]);
}
function RGJ_PRloadedDelay(i){
	setTimeout('RGJ_PRfstart('+i+')',1000);
}
function RGJ_PRfstart(i){
	gpr[i].fimg.src=gpr[i].dir+'/'+gpr[i].names[gpr[i].index];
	RGJ_PRsetOp(gpr[i].fimg,0);
	gpr[i].fstrt=0;
	gpr[i].fid=setInterval('RGJ_PRfservice('+i+')',50);
}
function RGJ_PRfservice(i) {
	dt=new Date();
	if( gpr[i].fstrt==0 ) gpr[i].fstrt = dt.getTime();
	op=Math.round((dt.getTime()-gpr[i].fstrt)/gpr[i].dissolves[gpr[i].index]*100);
	if(op<=1)op=1;if(op>=100){op=100;clearInterval(gpr[i].fid);}
	RGJ_PRsetOp(gpr[i].fimg,op);
}
var pulse_op,pulse_dir;
function RGJ_Pulse(id,init) {
	div=document.getElementById(id);
	if(div) {
		if(init) pulse_op=100,pulse_dir=1;
		pulse_op += pulse_dir;
		if(pulse_op>140) pulse_dir=-1;
		if(pulse_op<80) pulse_dir=1;
		if(pulse_op<=100) RGJ_PRsetOp(div,pulse_op);
		setTimeout("RGJ_Pulse('"+id+"',0)",20);
	}
}
// ajax
function ajaxDivUpdate( div, url ) {
	var hr,ajax=true;
	try { hr=new XMLHttpRequest(); }
	catch(e) { try { hr=new ActiveXObject("Msxml2.XMLHTTP"); }
	catch(e) { try { hr=new ActiveXObject("Microsoft.XMLHTTP"); }
	catch(e) { ajax = false; } } }
	if( ajax ) {
		hr.onreadystatechange=function() { if( hr.readyState==4 ) document.getElementById(div).innerHTML = hr.responseText; }
		hr.open("GET",url,true);
		hr.send(null);
	}
}
