/*fader.js
 * by Peter Belesis. v3.0 991130
 * Copyright (c) 1999 Peter Belesis. All Rights Reserved.
 * Originally published and documented at http://www.dhtmlab.com/
 * License to use is granted if and only if this entire copyright notice
 * is included.
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
*/

//3.0 added more browser checks:
NS4 = (document.layers);
IE4 = (document.all);

FDRboxWid = 500;
FDRboxHgt = 145;
FDRbackCol = "#E7DED6";
FDRborWid = 1;
FDRborSty = "solid";
FDRborCol = "maroon";
FDRboxPad = 7;

FDRtxtAln = "left";
FDRlinHgt = "11pt";
FDRfntFam = "Arial Narrow,Geneva,Arial,sans-serif";
FDRfntSiz = "10pt";
FDRfntWgh = "normal";
FDRfntSty = "normal";
FDRfntCol = "#800000";
FDRlnkDec = "none";
FDRlnkCol = "#FF0000";
FDRhovCol = "#800000";

// 3.1 added TIT* values to adjust the title settings
TITtxtAln = "left";
TITlinHgt = "11pt";
TITfntFam = "Arial Narrow,Geneva,Arial,sans-serif";
TITfntSiz = "10pt";
TITfntWgh = "normal";
TITfntSty = "normal";
TITfntCol = "#FF0000";
TITlnkDec = "underline";
TITlnkCol = "#FF0000";
TIThovCol = "#800000";

FDRblendInt = 7;
FDRblendDur = 2;
FDRmaxLoops = 99;
FDRendWithFirst = true;
FDRreplayOnClick = true;
FDRjustFlip = false;
FDRhdlineCount = 1;

FDRgifSrc = "images/fade.gif";
FDRgifInt = 60

appVer = navigator.appVersion;
IEmac = (IE4 && appVer.indexOf("Mac") != -1);
IE4mac = (IEmac && appVer.indexOf("MSIE 4") != -1);
IE40mac = (IE4mac && appVer.indexOf("4.0;") != -1);
IE45mac = (IE4mac && appVer.indexOf("4.5;") != -1);
NSpre401 = (NS4 && (parseFloat(appVer) <= 4.01));
NSpre403 = (NS4 && (parseFloat(appVer) <= 4.03));

//3.0 added next 2 line for backward compatibility
FDRjustFlip = (window.FDRjustFlip) ? FDRjustFlip : false;
FDRhdlineCount = (window.FDRhdlineCount) ? FDRhdlineCount : 1;

FDRfinite = (FDRmaxLoops > 0);
FDRisOver = false;
FDRloadCount = 0;

//3.0 set blendTimer to null for IE40mac
blendTimer = null;

if (!window.prefix) prefix = "";
window.onload = FDRcountLoads;

//3.0 modified NS-only code to account for flipper and lack of NS onload/onerror handlers
if (NS4) 
{
	if (FDRjustFlip || NSpre403) 
	{
		totalLoads = 1;
		FDRfadeImg = new Object();
		FDRfadeImg.width = FDRboxWid - (FDRborWid*2);;
	}
	else 
	{
		totalLoads = 2;
		FDRfadeImg = new Image();
		FDRfadeImg.onload = FDRcountLoads;
		FDRfadeImg.onerror = FDRcountLoads;
		FDRfadeImg.src = FDRgifSrc;
	}
}

//3.0 added event argument for NS
function FDRcountLoads(e) 
{
	if (IE4) 
	{
		setTimeout("FDRinit()",1);
	}
	else 
	{
//3.0 check for event type
		if (e.type == "error") FDRjustFlip = true; 
		FDRloadCount++;
		if (FDRloadCount == totalLoads) 
		{
			origWidth = innerWidth;
			origHeight = innerHeight;
			window.onresize = function()
			{
				if (innerWidth==origWidth && innerHeight==origHeight) return;
				location.reload();
			}
			FDRinit();
		}
	}
}

function FDRinit()
{
	if (!window.arNews) 
	{
		if (!window.arTXT || !window.arURL) return;
		if (arTXT.length != arURL.length) return;
		arNews = [];
		for (i=0; i<arTXT.length; i++)
		{
			arNews[arNews.length] = arTXT[i];
			arNews[arNews.length] = arURL[i];
		}
	}

  if (NS4) 
  {
    if (!document.elFader) return;
// 3.1 modified newlink class to accept the TIT* values
		with(document.classes.newslink.A) 
		{
			textDecoration = TITlnkDec;
			color = TITfntCol;
			fontWeight = TITfntWgh;
			fontSize = TITfntSiz;
			fontStyle = TITfntSty;
			fontFamily = TITfntFam;
			lineHeight = TITlinHgt;
			textAlign = TITtxtAln;
		}
// 3.1 Added news class
		with(document.classes.news) 
		{
			color = FDRfntCol;
			fontWeight = FDRfntWgh;
			fontSize = FDRfntSiz;
			fontStyle = FDRfntSty;
			fontFamily = FDRfntFam;
			lineHeight = FDRlinHgt;
			textAlign = FDRtxtAln;
		}
// 3.1 modified nolink class to accept the TIT* values
		with(document.classes.nolink.A) 
		{
			textDecoration = FDRlnkDec;
			color = TITfntCol;
			fontWeight = TITfntWgh;
			fontSize = TITfntSiz;
			fontStyle = TITfntSty;
			fontFamily = TITfntFam;
			lineHeight = TITlinHgt;
			textAlign = TITtxtAln;
		}
    elFader = document.elFader;
		with (elFader) 
		{
			document.write(" ");
			document.close();
			bgColor = FDRborCol;
			clip.width = FDRboxWid;
			clip.height = FDRboxHgt;
		}

		contWidth = 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)) 
		{
// 3.1 "newslink" is now using TIT* values
//			addRule("A.newslink","text-decoration:"+FDRlnkDec+";color:"+ FDRlnkCol);
//			addRule("A.newslink:hover","color:"+ FDRhovCol);
			addRule("A.newslink","text-decoration:" + TITlnkDec + ";color:" + TITlnkCol);
			addRule("A.newslink:hover","color:" + TIThovCol);
			addRule("A.nolink","text-decoration:" + FDRlnkDec + ";color:" + TITlnkCol);
			addRule("A.nolink:hover","color:" + TIThovCol);
  	}

		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*2000)
}

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 = "";
	URLPrefixStr = "";
	for (i=0; i<FDRhdlineCount; i++)
	{
		if (newsCount >= arNews.length) break;
//3.1 added titleStr to have a title and message functionality
//3.2 added bUsePrefix to be able to reroute to links other than CFSA
		titleStr = arNews[newsCount];
		dispStr = arNews[newsCount+1];
		linkStr = arNews[newsCount+2];
		targetStr = arNews[newsCount+3];
		bUsePrefix = arNews[newsCount+4]
		isLink = linkStr.length;
//3.2
		if (bUsePrefix == "TRUE")
		{
		  URLPrefixStr = prefix;
		}
		else
		{
		  URLPrefixStr = "http://";
		}
		if (isLink) 
		{
//3.1 added titleStr to have a title and message functionality
//			tempStr += "<P><A CLASS=newslink " + "HREF='" + prefix + linkStr + "'>" + dispStr + "</A></P>"
//3.2 adjusted for the new prefix
//			tempStr += "<P><A CLASS=newslink " + "HREF='" + prefix + linkStr + "'" + ((targetStr.length) ? "target=" + targetStr : "")+ ">" + titleStr + "</A><BR><SPAN class=news>" + dispStr + "</SPAN></P>"
			tempStr += "<P><A CLASS=newslink " + "HREF='" + URLPrefixStr + linkStr + "'" + ((targetStr.length) ? "target=" + targetStr : "")+ ">" + titleStr + "</A><BR><SPAN class=news>" + dispStr + "</SPAN></P>";
		}
		else 
		{
//3.1 added titleStr to have a title and message functionality
//			tempStr += ((NS4) ? "<P CLASS=nolink>" : "<P>") + dispStr + "</P>";
			tempStr += "<P><A CLASS=nolink>" + titleStr + "<BR></A>" + dispStr + "</P>";
		}
    if (IE40mac) tempStr +="<BR>";
//3.1 need to increment by 4 since we added a 4th column to the array
//		newsCount += 2;
//3.2 need to increment by 5 since we added a 5th column to the array
		newsCount += 5;
	}
	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;
		}
  }
}








