var inf_filters = (is_ie5_5up && is_win) ? true : false;   //Are filters supported? Comes from browserCheck.js above

inf_filters = true;
var inf_spinnerCollection = new Array();
window.onload = inf_initSpinners;


/****** FILTERS ******/
var filterList = new Array();

filterList[filterList.length] = 'progid:DXImageTransform.Microsoft.Barn( motion=out,orientation=vertical)';
filterList[filterList.length] = 'progid:DXImageTransform.Microsoft.Fade(Overlap=1.00)';
filterList[filterList.length] = 'progid:DXImageTransform.Microsoft.GradientWipe(GradientSize=0.25,wipestyle=0,motion=forward)';
filterList[filterList.length] = 'progid:DXImageTransform.Microsoft.GradientWipe(GradientSize=0.25,wipestyle=0,motion=reverse)';
filterList[filterList.length] = 'progid:DXImageTransform.Microsoft.Iris(irisstyle=CIRCLE,motion=out)';
filterList[filterList.length] = 'progid:DXImageTransform.Microsoft.Pixelate(duration=2,maxSquare=30)';
filterList[filterList.length] = 'progid:DXImageTransform.Microsoft.RandomDissolve()';
filterList[filterList.length] = 'progid:DXImageTransform.Microsoft.Slide(slidestyle=PUSH,Bands=1)';
filterList[filterList.length] = 'progid:DXImageTransform.Microsoft.Stretch(stretchstyle=PUSH)';
filterList[filterList.length] = 'progid:DXImageTransform.Microsoft.Strips(motion=leftdown)';
filterList[filterList.length] = 'progid:DXImageTransform.Microsoft.Wheel(spokes=6)';
filterList[filterList.length] = 'progid:DXImageTransform.Microsoft.Blinds( Bands=10,direction=up);';
filterList[filterList.length] = 'progid:DXImageTransform.Microsoft.Inset();'
filterList[filterList.length] = 'progid:DXImageTransform.Microsoft.RadialWipe(wipestyle=CLOCK);'
filterList[filterList.length] = 'FILTER: progid:DXImageTransform.Microsoft.Slide(slidestyle=SWAP,Bands=1);'

/****** CONSTRUCTORS ******/
function inf_spinner(name) { 
    this.name = name;
    this.layerId = "inf_spinner_" + name;
    this.delay = "";
    this.color1 = "";
    this.color2 = "";
    this.filterType = "";
    this.content = new Array();
    this.target = null;
		
		//methods
    this.paint = inf_paintSpinner;
    this.getObjStr = inf_getObjStr;
}

/****** METHODS ******/
function inf_paintSpinner() {
  if (is_nav4) {
    var h = (this.height == undefined) ? "150" : this.height;
    document.write ('<ilayer id="' + this.layerId + '_nsOutter" width="100%" height="' + h + '">');
    document.write ('<layer id="' + this.layerId + '_nsInner" height="100%"></layer>');
    document.write ('</ilayer>');
  }
  else {
    document.write ('<div class="commentSpinnerWidget" id="' + this.layerId + '" class="commentSpinnerWidget" ');
    document.write ('style="padding:3px;"></div>');
  }
}

function inf_getObjStr () {
    var str,obj;
    
    if (is_nav4) {
        str = "document." + this.layerId + "_nsOutter.document." + this.layerId + "_nsInner.document";
    }
    else if (is_ie4) str = "document.all." + this.layerId;
    else str = "document.getElementById('"+ this.layerId + "')";
    obj = eval(str);
    
    return obj;
}

/****** FUNCTIONS ******/
function inf_initSpinners() {
  var spinner,myTarget;
  
  for(i=0; i<inf_spinnerCollection.length; i++) {              // for each spinner 
    spinner = inf_spinnerCollection[i];
    spinner.target = eval(spinner.getObjStr());
    var j = 0;
     inf_changeContent(spinner);
  }
}

function inf_writeContent(spinner,txt) {
  if (is_nav4) {
	    spinner.target.open();
	    spinner.target.write('<p class="commentSpinnerWidget">' + txt + '</p>');
	    spinner.target.close();
	}
	else spinner.target.innerHTML = txt;
}

function inf_changeContent(spinner, spinnerCount){
  var spinnerCount = (!spinnerCount || spinnerCount >= spinner.content.length) ? 0 : spinnerCount;
  
  if (inf_filters) {
    var target = spinner.target.parentElement;
    
    var spinnerIndex = (spinner.filterType == "*") ? Math.floor(Math.random()*(filterList.length)) : spinner.filterType;
    target.style.filter = filterList[spinnerIndex];
    target.filters[0].apply();
    var newColor = (target.style.backgroundColor.toUpperCase() == spinner.color1.toUpperCase()) ? spinner.color2 : spinner.color1;
    target.style.backgroundColor = newColor;
    inf_writeContent(spinner,spinner.content[spinnerCount]);
    target.filters[0].play();
  }
  else inf_writeContent(spinner,spinner.content[spinnerCount]);
  
  spinnerCount++;
  var evalStr = 'inf_changeContent(' + spinner.name + ',' + spinnerCount +')';
  setTimeout(evalStr,spinner.delay);
}
