// 26/01/2004 Ozan Turksever <ozan@omnis.com.tr>
// use this code as long as this text stands.
// Ex:
// <div onMouseOver='scroll.hold();' onMouseOut='scroll.go();'>
//  <div id='news0'>
//   news 0
//  </div>
//  <div id='news1'>
//   news 1
//  </div>
// </div>
// <script>
// var scroll = new scroller();
// scroll.name  = 'news';
// scroll.speed = 2000; 
// scroll.run();
// </script>

function scroller() {
    this.name      = 'scroll';
    this.speed     = 5000 
    this.selected  = 0;
    this.prev      = 0;
    this.total     = 0;
    this.stop      = false;
}

scroller.prototype.countDivs = function(){
    if(this.total!=0) return;
    for(var i=0;document.getElementById(this.name+i);i++){
	this.total++;
    }
}

scroller.prototype.run = function(){
    this.countDivs();
    if(this.total==1) return;
    var selected = document.getElementById(this.name+this.selected)
    var prev     = document.getElementById(this.name+this.prev)
    if(!this.stop) {
	if(this.prev!=this.selected) {
	    fade(prev,false)
	    prev.style.display="none"
	}
	fade(selected,true)
	selected.style.display="block"
	this.prev    = this.selected
	this.selected=(this.selected<this.total-1)?this.selected+1:0
    }
    setTimeout(this.name+".run()",this.speed)
}

scroller.prototype.hold = function(){
    this.stop = true;
}

scroller.prototype.go = function(){
    this.stop = false;
}

///////////////////////////////////////////////////////////////////////
//     This fade library was designed by Erik Arvidsson for WebFX    //
//                                                                   //
//     For more info and examples see: http://webfx.eae.net          //
//     or contact Erik at http://webfx.eae.net/contact.html#erik     //
//                                                                   //
//     Feel free to use this code as long as this disclaimer is      //
//     intact.                                                       //
//                                                                   //
//     Last updated: 2000-11-22                                      //
///////////////////////////////////////////////////////////////////////


var fadeSteps = 8;				// Number of steps to loop
var fademsec = 50;				// The time between each step (note that most computer have problem
								// handling to small values due to hardware limitations)


var fadeArray = new Array();	// Needed to keep track of wich elements are animating

//////////////////  fade  ////////////////////////////////////////////////////////////
//                                                                                  //
//   parameter: fadeIn                                                              //
// description: A boolean value. If true the element fades in, otherwise fades out  //
//              The steps and msec are optional. If not provided the default        //
//              values are used                                                     //
//                                                                                  //
//////////////////////////////////////////////////////////////////////////////////////

function fade(el, fadeIn, steps, msec) {

	if (steps == null) steps = fadeSteps;
	if (msec == null) msec = fademsec;

	if (el.fadeIndex == null)
		el.fadeIndex = fadeArray.length;
	fadeArray[el.fadeIndex] = el;
	
	if (el.fadeStepNumber == null) {
		if (el.style.visibility == "hidden")
			el.fadeStepNumber = 0;
		else
			el.fadeStepNumber = steps;
		if (fadeIn) {
			el.style.filter = "Alpha(Opacity=0)";
			el.style.MozOpacity = 0;
		}
		else {
			el.style.filter = "Alpha(Opacity=100)";
			el.style.MozOpacity = 1;
		}
	}
	window.setTimeout("repeatFade(" + fadeIn + "," + el.fadeIndex + "," + steps + "," + msec + ")", msec);
}

//////////////////////////////////////////////////////////////////////////////////////
//  Used to iterate the fading

function repeatFade(fadeIn, index, steps, msec) {	
	el = fadeArray[index];

	c = el.fadeStepNumber;
	if (el.fadeTimer != null)
		window.clearTimeout(el.fadeTimer);
	if ((c == 0) && (!fadeIn)) {			//Done fading out!
		el.style.visibility = "hidden";		// If the platform doesn't support filter it will hide anyway
//		el.style.filter = "";
		return;
	}
	else if ((c==steps) && (fadeIn)) {	//Done fading in!
		el.style.filter = "";
		el.style.MozOpacity = 1;
		el.style.visibility = "visible";
		return;
	}
	else {
		(fadeIn) ? 	c++ : c--;
		el.style.visibility = "visible";
		el.style.filter = "Alpha(Opacity=" + 100*c/steps + ")";
		el.style.MozOpacity = c / steps;

		el.fadeStepNumber = c;
		el.fadeTimer = window.setTimeout("repeatFade(" + fadeIn + "," + index + "," + steps + "," + msec + ")", msec);
	}
}

