/********************************************************************
  allbrowsers_fader.mod
  v2.02 01/12/2002
  YaBB integration & modification: NRg (yabb_fader@gmx.de)
  Latest version: http://www.talknet.de/~norbru/

  based upon:
  Fading Scroller by DynamicDrive.com  http://www.dynamicdrive.com
*********************************************************************/

// You can changes these three values to modify the output:
var frame = 50;	// frame-range. standard = 50
var st = 30;	// milliseconds between frames. standard = 30
var wait = 50;	// value to display the full text without fade
			// 1 = approx. 60 milliseconds. standard = 50

ie4 = document.all&&!document.getElementById;
ns4 = document.layers;
DOM2 = document.getElementById;

bR = HexToR(bcolor);
bG = HexToG(bcolor);
bB = HexToB(bcolor);
tR = HexToR(tcolor);
tG = HexToG(tcolor);
tB = HexToB(tcolor);
bR_m = bR;
bG_m = bG;
bB_m = bB;
tR_m = tR;
tG_m = tG;
tB_m = tB;

function HexToR(h) { return parseInt((cutHex(h)).substring(0,2),16) }
function HexToG(h) { return parseInt((cutHex(h)).substring(2,4),16) }
function HexToB(h) { return parseInt((cutHex(h)).substring(4,6),16) }
function cutHex(h) { return (h.charAt(0)=="#") ? h.substring(1,7) : h}

dir = ((tR+tG+tB) > (bR+bG+bB)) ? "up" : "down";
dirback = ((tR+tG+tB) < (bR+bG+bB)) ? "up" : "down";
dir_m = dir;
index = 0;
frame_m = frame;
framehalf = frame / 2;
wait_m = wait;
stepR = Math.abs(tR - bR) / framehalf;
stepG = Math.abs(tG - bG) / framehalf;
stepB = Math.abs(tB - bB) / framehalf;
step = Math.min(Math.round(Math.max(stepR,Math.max(stepG,stepB))),(240/framehalf));

function fade() {
 if (index>=fcontent.length)
  index = 0;
  if (DOM2) {
   document.getElementById("fscroller").innerHTML=begintag+fcontent[index]+closetag;
   index++;
   colorfade();
  }
  else if (ie4) {
   document.all.fscroller.innerHTML=begintag+fcontent[index]+closetag;
   index++;
   setTimeout("fade()",Math.max(delay,2500));
  }
  else if (ns4) {
   document.fscrollerns.document.fscrollerns_sub.document.write(begintag+fcontent[index]+closetag);
   document.fscrollerns.document.fscrollerns_sub.document.close();
   index++;
   setTimeout("fade()",Math.max(delay,2500));
  }
}

function colorfade() {
 if (frame>0) {
  if (frame==framehalf && wait>0) {
   document.getElementById("fscroller").style.color="rgb("+wR+","+wG+","+wB+")";
   wait--;
   setTimeout("colorfade()",50);
  }
  else {
   if (dir=="down") {
    if (bR>tR) bR-=step;
    if (bG>tG) bG-=step;
    if (bB>tB) bB-=step;
    bR = Math.max(bR,1);
    bG = Math.max(bG,1);
    bB = Math.max(bB,1);
    }
   else {
    if (bR<tR) bR+=step;
    if (bG<tG) bG+=step;
    if (bB<tB) bB+=step;
    bR = Math.min(bR,255);
    bG = Math.min(bG,255);
    bB = Math.min(bB,255);
   }
   document.getElementById("fscroller").style.color="rgb("+bR+","+bG+","+bB+")";
   if (frame==framehalf+1) {
    document.getElementById("fscroller").style.color="rgb("+tR+","+tG+","+tB+")";
    dir = dirback;
    wR = tR;
    wG = tG;
    wB = tB;
    tR = bR_m;
    tG = bG_m;
    tB = bB_m;
   }
   frame--;
   setTimeout("colorfade()",st);
  }
 }
 else {
  document.getElementById("fscroller").innerHTML=" ";
  dir = dir_m;
  frame = frame_m;
  wait = wait_m;
  tR = tR_m;
  tG = tG_m;
  tB = tB_m;
  bR = bR_m;
  bG = bG_m;
  bB = bB_m;
  setTimeout("fade()",delay);
 }
}ntWidth = FDRboxWid - (FDRborWid*2);
		contHeight = FDRboxHgt - (FDRborWid*2);
		elCont = new Layer(contWidth,elFader);
		with (elCont) {
			top = FDRborWid;
			left = FDRborWid;
			clip.width = contWidth;
			clip.height = contHeight;
			bgColor = FDRbackCol;
			visibility = "inherit";
		}

		newsWidth = contWidth - (FDRboxPad*2);
		newsHeight = contHeight - (FDRboxPad*2);
        elNews = new Layer(newsWidth,elCont);
		with (elNews) {
			top = FDRboxPad;
			left = FDRboxPad;
			clip.width = newsWidth ;
			clip.height = newsHeight;
		}

//3.0 made NS GIF use conditional on flipper choice		
		if (!FDRjustFlip) {
			elGif = new Layer(contWidth,elCont); 
	        imStr = "<IMG SRC='" + FDRgifSrc +"' WIDTH="+ Math.max(FDRfadeImg.width,(FDRboxWid - (FDRborWid*2)));
//3.0 onError handler added to in-line GIF code for NS 4.03-
			imStr += (NSpre403) ? " onError='window.FDRjustFlip = true'>" : ">";
	        with (elGif) {
				document.write(imStr);
	        	document.close();
				moveAbove(elNews);
			}
	
			imgHeight = elGif.document.height;
			slideInc = (imgHeight/(FDRblendDur*1000/FDRgifInt));
			startTop = -(imgHeight - FDRboxHgt);
		}

		elFader.visibility =  "show";
    }
    else {
        if (!window.elFader) return;
		elFader.innerHTML ="";
		if(IE4mac) {
			document.body.insertAdjacentHTML("BeforeBegin","<STYLE></STYLE>");
		}
		else {
			if (!document.styleSheets.length) document.createStyleSheet();
		}
		with (document.styleSheets(document.styleSheets.length-1)) {
			addRule("A.newslink","text-decoration:"+FDRlnkDec+";color:"+ FDRlnkCol);
			addRule("A.newslink:hover","color:"+ FDRhovCol);
		}

		with (elFader.style) {
//3.0 added box width/height adjustments for IEmac
			errorOffset = (IE4mac) ? (FDRboxPad + FDRborWid) : 0;
			width = FDRboxWid - (errorOffset * 2);
			height = FDRboxHgt - (errorOffset * 2);
			if(IE4mac && !IE45mac){
				pixelLeft = elFader.offsetLeft + errorOffset;
				pixelTop = elFader.offsetTop + errorOffset;
			}

			backgroundColor = FDRbackCol;
			overflow = "hidden";
			color = FDRfntCol;
			fontWeight = FDRfntWgh;
			fontSize = FDRfntSiz;
			fontStyle = FDRfntSty;
			fontFamily = FDRfntFam;
			lineHeight = FDRlinHgt;
			textAlign = FDRtxtAln;
			cursor = "default";
			visibility = "visible";
			borderWidth = FDRborWid;
			borderStyle = FDRborSty;
			borderColor = FDRborCol;
			padding  = FDRboxPad;

//3.0 filter application conditional on fader use
			if(!FDRjustFlip) filter = "blendTrans(duration=" + FDRblendDur + ")";
		}
		elFader.onselectstart = function(){return false};

		IEhasFilters = (elFader.filters.blendTrans) ? true : false;

    }

//3.0 NS mouseover/out handlers applied only in 4.02+
	if (!NSpre401) {
		elFader.onmouseover = function (){
			FDRisOver = true;
		}
		elFader.onmouseout = function(){
			FDRisOver = false;
			status = "";
		}
	}
	
	FDRstart(0);
}

function FDRstart(ind){
    newsCount = ind;
    if (FDRfinite) loopCount = 0;
    FDRdo();
    blendTimer = setInterval("FDRdo()",FDRblendInt*1000)
}

function FDRdo() {
//3.0 check for blendTimer value for IE40mac:
	if(!blendTimer && loopCount>0) return;

    if (FDRfinite && loopCount==FDRmaxLoops) {
        FDRend();
		return;
    }
	FDRfade();
//3.0 omitted next line; newsCount incremented elsewhere
//    newsCount += 2;

    if (newsCount == arNews.length) {
        newsCount = 0;
        if (FDRfinite) loopCount++;
    }
}

//3.0 added function for display string creation
function FDRmakeStr(){
	tempStr = "";
	for (i=0;i<FDRhdlineCount;i++){
		if(newsCount>=arNews.length)break;
		dispStr = arNews[newsCount];
		linkStr = arNews[newsCount+1];
		isLink = linkStr.length;
		if (isLink) {
			tempStr += "<P><A CLASS=newslink "
					+ "HREF='" + prefix + linkStr + "'>"
		            + dispStr + "</A></P>"
		}
		else {
			tempStr += ((NS4) ? "<P CLASS=nolink>" : "<P>") +dispStr+"</P>";

		}
        if(IE40mac) tempStr +="<BR>";
		newsCount += 2;
	}
	return tempStr;
}

function FDRfade(){
//3.0 newsStr now created in other function and returned here
	newsStr = FDRmakeStr();

    if (NS4) {
//3.0 made GIF manipulation conditional on fader use
		if (!FDRjustFlip) {
			elGif.top = startTop;
			elGif.visibility = "inherit";
		}

		elNews.visibility = "hide";
        with (elNews.document) {
            write(newsStr);
            close();
        }
		elNews.visibility = "inherit";
    }
    else {
        if(IEhasFilters)elFader.filters.blendTrans.Apply();
        elFader.innerHTML = newsStr;
        if(IEhasFilters)elFader.filters.blendTrans.Play();
    }

//3.0 status bar display now only when single headline displayed
	if(FDRhdlineCount==1) window.status = (FDRisOver && isLink) ? (prefix + linkStr) : "";

//3.0 NS GIF sliding condiional on fader use
    if (NS4 && !FDRjustFlip) FDRslide();
}

function FDRslide(){
    elGif.top += slideInc;
    if (elGif.top >= 0) {elGif.visibility = "hide";return}
    setTimeout("FDRslide()",FDRgifInt);
}

//3.0 new function for NS to avoid literal function declaration
//    and allow double-click for 4.01a- versions
function FDRdblClickNS(){
	elFader.releaseEvents(Event.DBLCLICK);
	FDRstart(startIndex);
	return false;
}

function FDRend(){
	clearInterval(blendTimer);

//3.0 set blendTimer to null for IE40mac
	blendTimer = null;

	if (FDRendWithFirst) {
		newsCount = 0;
		FDRfade();
	}
	if (FDRreplayOnClick) {

//3.0 startIndex dependent on headline count
		startIndex = FDRendWithFirst ? (FDRhdlineCount * 2) : 0;
		if (IE4) {
			elFader.title = "Double click to replay";
			elFader.ondblclick = function(){
				this.ondblclick = null;
				this.title = "";
				FDRstart(startIndex);
			}
		}
		else {
			elFader.captureEvents(Event.DBLCLICK);

//3.0 moved handler to new function
			elFader.ondblclick = FDRdblClickNS;

		}
    }
}


