var bfades;
function FadeBanners() {
	if (window.opera) { return; } // exclude opera
	this.pictureMenuItems=[];
	this.deltimer=null;
	this.fadi = 0;
	this.initialisePictureMenu();
}
FadeBanners.prototype.getElementsByClassName = function(clsName) { 
	var arr = [], elems = document.getElementsByTagName("*");
	for ( var cls, i = 0, elem; ( elem = elems[i] ); i++ ) {
		if ( elem.className === clsName ) { arr[arr.length] = elem; }
	}
	return arr;
};
FadeBanners.prototype.initialisePictureMenu = function() {
   this.pictureMenuItems = this.getElementsByClassName('banfader');
	this.deltimer = setTimeout(function(){bfades.initDelay();},4000);

/*	try {
		document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}*/
	
};        
FadeBanners.prototype.initDelay = function() {
	clearTimeout(this.deltimer);
	// Attach event handlers to the menu items:
	this.pictureMenuItems[this.fadi].onmouseover = function() { bfades.fadez(this,100); };
	this.pictureMenuItems[this.fadi].onmouseout = function() { bfades.fadez(this,30); };
	this.pictureMenuItems[this.fadi].opac = 100;
	this.pictureMenuItems[this.fadi].timer = null;
	// Apply initial opacity value to all menu objects:
	this.fadez(this.pictureMenuItems[this.fadi], 40);
	this.fadi++;
	if (this.fadi < this.pictureMenuItems.length) { this.deltimer = setTimeout(function(){ bfades.initDelay(); }, 100); }
};
FadeBanners.prototype.setOpacity = function(obj, value) {
	if (value >= 100) { this.remOpacity(obj); return; }
	obj.style.opacity = value/100;
	obj.style.filter = 'alpha(opacity=' + value + ')';
	obj.sop = parseInt(value,10);
	obj.opac = parseInt(value,10);
};
FadeBanners.prototype.remOpacity = function(obj) {
	obj.style.opacity = 1;
	obj.sop = 100;
	try{ obj.style.removeAttribute("filter"); } catch(err) {} 
	obj.opac = 100;
};
FadeBanners.prototype.fadez = function(obj, destOp) {
 		clearTimeout(obj.timer);
 		var opacity = obj.opac;
		var delta = 8;
		if (opacity === destOp) { return; }
		
		var diff = destOp-opacity;
	    var direction = 1;
		if (opacity > destOp) { direction = -1; }
		delta=Math.min(direction*diff,delta);
		opacity+=direction*delta;
		
        this.setOpacity(obj, opacity);
        obj.timer=setTimeout(function() { bfades.fadez(obj, destOp); }, 20);
};

function stuffAddEvent(el,evname,func,eCap){eCap=eCap===undefined?true:eCap;if(el.attachEvent){el.attachEvent("on"+evname,func);}else if(el.addEventListener){el.addEventListener(evname,func,eCap);}else{el["on"+evname]=func;}EventCache.add(el, evname, func, eCap);}
function stuffRemoveEvent(el,evname,func,eCap){eCap=eCap===undefined?true:eCap;if(el.detachEvent){el.detachEvent("on"+evname,func);}else if(el.removeEventListener){el.removeEventListener(evname,func,eCap);}else{el["on"+evname]=null;}}
EventCache=function(){var listEvents=[];return{listEvents:listEvents,add:function(node,el,evname,func){listEvents.push(arguments);},flush:function(){var i,item;for(i=listEvents.length-1;i>=0;i=i-1){item=listEvents[i];stuffRemoveEvent(item[0],item[1],item[2],item[3]);}listEvents=[];}};}();
stuffAddEvent(window,'unload',function () { EventCache.flush(); });
stuffAddEvent(window,'load',function () { bfades = new FadeBanners(); });