// Dissolvenza Backgroud IE 5.5+
function initArray()
{
  this.length = initArray.arguments.length
  for (var i = 0; i < this.length; i++)
    this[i+1] = initArray.arguments[i]
}
var hexChars = "0123456789ABCDEF";
 function Dec2Hex (Dec)
 {
  var a = Dec % 16;
  var b = (Dec - a)/16;
  hex = "" + hexChars.charAt(b) + hexChars.charAt(a);
  return hex;
}
  function fadeIE(begin, end, steps) {   steps = steps -1 ;
  redA     = begin.charAt(0) + begin.charAt(1);
  red_valA = parseInt(redA,'16');
  redB     = end.charAt(0) + end.charAt(1);
  red_valB = parseInt(redB,'16');
  red_int  = ((red_valB - red_valA) / steps) * -1;
  grnA     = begin.charAt(2) + begin.charAt(3);
  grn_valA = parseInt(grnA,'16');
  grnB     = end.charAt(2) + end.charAt(3);
  grn_valB = parseInt(grnB,'16');
  grn_int  = ((grn_valB - grn_valA) / steps) * -1;
  bluA     = begin.charAt(4) + begin.charAt(5);
  blu_valA = parseInt(bluA,'16');
  bluB     = end.charAt(4) + end.charAt(5);
  blu_valB = parseInt(bluB,'16');
  blu_int  = ((blu_valB - blu_valA) / steps) * -1;
  step = 2;
  red = red_valA;
  grn = grn_valA;
  blu = blu_valA;
  document.bgColor = begin;
  while ( steps >= step ) 
  {
    red -= red_int;
    red_round = Math.round(red);
    red_hex = Dec2Hex(red);
    grn -= grn_int;
    grn_round = Math.round(grn);
    grn_hex = Dec2Hex(grn);
    blu -= blu_int;
    blu_round = Math.round(blu);
    blu_hex = Dec2Hex(blu);
    document.bgColor = red_hex + grn_hex + blu_hex;
    step++;
  }
  window.bgColor = end;
}
// Dissolvenza Backgroud NS 6.0+
hexa = new Array(16);
for(var i = 0; i < 10; i++) hexa[i] = i;
hexa[10]="a"; hexa[11]="b"; hexa[12]="c";
hexa[13]="d"; hexa[14]="e"; hexa[15]="f";

function hex(i) {
	if (i < 0) return "00";
	else if (i > 255) return "ff";
	else return "" + hexa[Math.floor(i/16)] + hexa[i%16];
}

function setbgColor(r, g, b) {
	var hr = hex(r); var hg = hex(g); var hb = hex(b);
	document.bgColor = "#"+hr+hg+hb;
}

var sr,sg,sb,er,eg,eb,step,at;

function setBg() {
	setbgColor(
		Math.floor(sr * ((step-at)/step)  + er * (at/step)),
		Math.floor(sg * ((step-at)/step) +  eg * (at/step)),
		Math.floor(sb * ((step-at)/step) +  eb * (at/step)));
	at++;
	if (at<=step) setTimeout("setBg()",1);
	}

function fadeNS(a,b,c,d,e,f,g) {
	sr=a;sg=b;sb=c;er=d;eg=e;eb=f;step=g;at=1;
	setBg();
	}

function fading(color) {
	if (color == 'orange') {
		var r = 255;
		var g = 102;
		var b = 0;
		var hex = 'FF6600';
	} else if (color == 'dark') {
		var r = 0;
		var g = 0;
		var b = 0;
		var hex = '000000';	
	}

	var NS = (navigator.appName.indexOf("Netscape")>=0)? true : false;	
	if (NS){
		fadeNS(r,g,b,255,255,255,20);
	} else {
		fadeIE(hex,'FFFFFF',20);
	}
}

//************************************************************************************************
// Progress Bar
var barheight=15;                       // HEIGHT OF PROGRESS BAR IN PIXELS (MIN 25)
var barwidth=350; 						// WIDTH OF THE BAR IN PIXELS 
//var yposition=270;
var yposition=(screen.height) ? ((screen.height)/2)-barheight : 0;                     //POSITION OF LOAD BAR FROM TOP OF WINDOW, IN PIXELS
var loadedcolor='#FF6900';              // PROGRESS BAR COLOR
var unloadedcolor='black';              // BGCOLOR OF UNLOADED AREA
var bordercolor='white';                // COLOR OF THE BORDER

var NS4 = (navigator.appName.indexOf("Netscape")>=0 && parseFloat(navigator.appVersion) >= 4 && parseFloat(navigator.appVersion) < 5)? true : false;
var IE4 = (document.all)? true : false;
var NS6 = (parseFloat(navigator.appVersion) >= 5 && navigator.appName.indexOf("Netscape")>=0 )? true: false;
var imagesdone=false;
var blocksize=barwidth/(imagenames.length);
	barheight=Math.max(barheight,25);
var loaded=0, perouter, perdone, images=new Array();
var txt=(NS4)?'<layer name="perouter" bgcolor="'+bordercolor+'" visibility="hide">' : '<div id="perouter" style="position:absolute; visibility:hidden; background-color:'+bordercolor+'">';
	txt+='<table cellpadding="0" cellspacing="1" border="0"><tr><td width="'+barwidth+'" height="'+barheight+'" valign="center">';
if(NS4)txt+='<ilayer width="100%" height="100%"><layer width="100%" height="100%" bgcolor="'+unloadedcolor+'" top="0" left="0">';
	txt+='<table cellpadding="0" cellspacing="0" border="0"><tr><td valign="center" width="'+barwidth+'" height="'+barheight+'" bgcolor="'+unloadedcolor+'"><center><font color="'+loadedcolor+'" size="1" face="sans-serif">Caricamento skin "' + tema +'"</font></center></td></tr></table>';
if(NS4) txt+='</layer>';
	txt+=(NS4)? '<layer name="perdone" width="100%" height="'+barheight+'" bgcolor="'+loadedcolor+'" top="0" left="0">' : '<div id="perdone" style="position:absolute; top:1px; left:1px; width:'+barwidth+'px; height:'+barheight+'px ????????A; background-color:'+loadedcolor+'; z-index:100">';
	txt+='<table cellpadding="0" cellspacing="0" border="0"><tr><td valign="center" width="'+barwidth+'" height="'+barheight+'" bgcolor="'+loadedcolor+'"><center><font color="'+unloadedcolor+'" size="1" face="sans-serif">Caricamento skin "' + tema +'"</font></center></td></tr></table>';
	txt+=(NS4)? '</layer></ilayer>' : '</div>';
	txt+='</td></tr></table>';
	txt+=(NS4)?'</layer>' : '</div>';
document.write(txt);
function loadimages(){
	if(NS4){
		perouter=document.perouter;
		perdone=document.perouter.document.layers[0].document.perdone;
	}
	if(NS6){
		perouter=document.getElementById('perouter');
		perdone=document.getElementById('perdone');
	}
	if(IE4){
		perouter=document.all.perouter;
		perdone=document.all.perdone;
	}
	cliplayer(perdone,0,0,barheight,0);
	window.onresize=setouterpos;
	setouterpos();
	for(n=0;n<imagenames.length;n++){
		images[n]=new Image();
		images[n].src=imagenames[n];
		setTimeout('checkload('+n+')' ,n*100);
	}
}
function setouterpos(){
	var ww=(IE4)? document.body.clientWidth : window.innerWidth;
	var x=(ww-barwidth)/2;
	if(NS4){
		perouter.moveTo(x,yposition);
		perouter.visibility="show";
	}
	if(IE4||NS6){
		perouter.style.left=x+'px';
		perouter.style.top=yposition+'px';
		perouter.style.visibility="visible";
	}
}
function dispbars(){
	loaded++;
	cliplayer(perdone, 0, blocksize*loaded, barheight, 0);
	if(loaded>=imagenames.length)setTimeout('hideperouter()', 800);
}
function checkload(index){
	(images[index].complete)? dispbars() : setTimeout('checkload('+index+')', 100);
}
function hideperouter(){
	(NS4)? perouter.visibility="hide" : perouter.style.visibility="hidden";
	imagesdone=true;
}
function cliplayer(layer, ct, cr, cb, cl){
	if(NS4){
	layer.clip.left=cl;
	layer.clip.top=ct;
	layer.clip.right=cr;
	layer.clip.bottom=cb;
	}
	if(IE4||NS6)layer.style.clip='rect('+ct+' '+cr+' '+cb+' '+cl+')';
}
window.onload=loadimages;