/*** This function is necessary, as IE loses the reference to "THIS" when "attachEvent" is used. ***/
function addEvent( obj,type,fn )
{
	if ( obj.attachEvent )
	{
		obj['e'+type+fn] = fn; // This makes the function a child of the specified object. The key, which is placed in the object hash, is (hopefully) unique and won't collide with any other function additions.
		obj[type+fn] = function(){obj['e'+type+fn]( window.event );} // This line creates an anonymous function who, once executed, will fire the previously attached function - passing it the global event object. This whole function is being attached to the object so that it can be removed later, using the removeEvent() function.
		obj.attachEvent( 'on'+type, obj[type+fn] );
	} else
	{
		obj.addEventListener( type, fn, false );
	}
}

function removeEvent( obj,type,fn )
{
	if ( obj.detachEvent ) {
		obj.detachEvent( 'on'+type, obj[type+fn] );
		obj[type+fn] = null;
	} else {
		obj.removeEventListener( type, fn, false );
	}
}

/*** The best function of its kind ;) ***/
function getElementsByClassName(classname)
{
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = this.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}
document.getElementsByClassName=getElementsByClassName; // Activate this function as a method of "document" object. For other objects, it will have to be activated time by time.


function findPos()
{
	obj = this;
	/*** Qs funzione serve perche', a volte, offsetLeft e offsetTop di un oggetto sono solo relativi al padre! A noi invece servono quelli assoluti, rispetto alla pagina. ***/
	myLeft = 0;
	myTop = 0;
	if (obj.offsetParent) // Tutti gli oggetti, a parte "window" (che non ha padre)
	{
		myLeft = obj.offsetLeft;
		myTop = obj.offsetTop;
		while (obj = obj.offsetParent) // La funzione corrente viene richiamata finche' "obj" non ha nessun padre (ovvero, fino all'oggetto "window".
		{
			myLeft += obj.offsetLeft;
			myTop += obj.offsetTop;
		}
	}
	this.posLeft = myLeft+"px";
	this.posTop = myTop+"px";
}

function rollMe(imgObj)
{
	imgObj.src = (imgObj.src.indexOf("_on")!=-1) ? imgObj.src.replace(/_on/,"_off") : imgObj.src.replace(/_off/,"_on");
}

function preloadImgs()
{
	closeImg = new Image(); closeImg.src="img/butt_close_on.gif";
	introBckImg = new Image(); introBckImg.src="img/intro_bck_on.png";
	hImg = new Image(); hImg.src="img/header_bck.png";
	rImg = new Image(); rImg.src="img/header-ritaglio_bck.gif";
	iImg = new Image(); iImg.src="img/inner_bck.png";
	fImg = new Image(); fImg.src="img/footer_bck.png";
}
