/*************************************************************************
	dw_write.js	
	write to positioned div (absolute or relative)
	Designed specifically for writing to layer in table (for ns4).
	For writing to absolute-positioned layer you can also	use dw_core.js.
	version date: June 2002
	
	This code is from Dynamic Web Coding 
  at http://www.dyn-web.com/
  Copyright 2001-2 by Sharon Paine 
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  Permission granted to use this code 
  as long as this entire notice is included.	
*************************************************************************/
var banners = new Array();
function initBanner() {
	// args: id, width, height, left, top, delay, class
	// delay is amount of time in milliseconds you linger on each item
	// set up a class for formatting your banner (last argument here)
	banners[0] = new bannerObj('ad1',468,60,80,0,6000);
	banners[0].addItem('<A HREF="http://www.FWDPerformance.com"><IMG SRC="http://www.sdml.org/graphics/fwd_ad_large.gif" WIDTH="468" HEIGHT="60" ALT="" BORDER="0"></A>');
	banners[0].addItem('<A HREF="http://www.sdml.org/pages/mtracker.html"><IMG SRC="http://www.sdml.org/graphics/mt_ad_large.gif" WIDTH="468" HEIGHT="60" ALT="" BORDER="0"></A>');
	banners[0].rotate();

	banners[1] = new bannerObj('ad2',128,80,10,0,8000);
	banners[1].addItem('<A HREF="http://www.mrxmotors.com/"><IMG SRC="http://www.sdml.org/graphics/mrx_ad_small.gif" WIDTH="128" HEIGHT="80" ALT="" BORDER="0"></A>');
	banners[1].addItem('<A HREF="http://www.polybushings.com/"><IMG SRC="http://www.sdml.org/graphics/pb_ad_small.gif" WIDTH="128" HEIGHT="80" ALT="" BORDER="0"></A>');
	banners[1].rotate();
	
	<!-- banners[2] = new bannerObj('ad3',128,80,10,0,8000); -->
	<!-- banners[2].addItem('<A HREF="http://www.SDML.org"><IMG SRC="http://www.sdml.org/small_ad.gif" WIDTH="126" HEIGHT="80" ALT="" BORDER="0"></A>'); -->
	<!-- banners[2].addItem('<A HREF="http://www.SDML.org"><IMG SRC="http://www.sdml.org/small_ad2.gif" WIDTH="126" HEIGHT="80" ALT="" BORDER="0"></A>'); -->
	<!-- banners[2].rotate(); -->
}

// constructor function (x,y optional)
function writeObj(id,wd,ht,x,y) {
	if (!id) return;	// for when writeObj used as prototype
	if (document.getElementById||document.all) {
		this.el = (document.getElementById)? document.getElementById(id): document.all[id];
		this.css = this.el.style;	this.doc = this.el;
		this.css.width=wd+"px"; this.css.height=ht+"px";
  } else if (document.layers) {
		var lyrRef = getLyrRef(id,document);	// in case id nested
		// create layer inside to write to
		// in case id relative positioned
		this.el = new Layer(wd,lyrRef);	
		lyrRef.resizeTo(wd,ht);
		this.el.visibility = "inherit";	// new Layer initially hidden
		this.doc = this.el.document;	// write to inner layer
		// use outer layer for shifting, show/hide
		this.css = this.el.parentLayer; 
	} else return null; // (if not ...byId or ...all or ...layers)
	var px = (document.layers)? "": "px";
	this.x = x || 0;	if (x) this.css.left = this.x+px;
	this.y = y || 0;	if (y) this.css.top = this.y+px;
	this.obj = id+"Object"; eval(this.obj+"=this");	// used by banner
}

//  Methods
function dw_writeLyr(cntnt) {
	if (typeof this.doc.innerHTML!="undefined") {
      this.doc.innerHTML = cntnt;
  } else if (document.layers) {
			this.doc.write(cntnt);
			this.doc.close();
  }
}

function dw_show() { this.css.visibility = "visible"; }
function dw_hide() { this.css.visibility = "hidden"; }

function dw_shiftTo(x,y) {
	if (x!=null) this.x=x; if (y!=null) this.y=y;	
	if (this.css.moveTo) { 
		this.css.moveTo(Math.round(this.x),Math.round(this.y)); 
	} else { 
		this.css.left=Math.round(this.x)+"px"; 
		this.css.top=Math.round(this.y)+"px"; 
	}
}

function dw_shiftBy(x,y) {
	this.shiftTo(this.x+x,this.y+y);
}

// assign methods
writeObj.prototype.writeLyr = dw_writeLyr;
writeObj.prototype.show = dw_show;
writeObj.prototype.hide = dw_hide;
writeObj.prototype.shiftTo = dw_shiftTo;
writeObj.prototype.shiftBy = dw_shiftBy;

// credit to http://www.13thparallel.org for the following 2 functions
// returns amount of vertical scroll
function getScrollY() {
	var scroll_y = 0;
	if (document.documentElement && document.documentElement.scrollTop)
		scroll_y = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop) 
		scroll_y = document.body.scrollTop; 
	else if (window.pageYOffset)
		scroll_y = window.pageYOffset;
	else if (window.scrollY)
		scroll_y = window.scrollY;
	return scroll_y;
}

function getScrollX() {
	var scroll_x = 0;
	if (document.documentElement && document.documentElement.scrollLeft)
		scroll_x = document.documentElement.scrollLeft;
	else if (document.body && document.body.scrollLeft) 
		scroll_x = document.body.scrollLeft; 
	else if (window.pageXOffset)
		scroll_x = window.pageXOffset;
	else if (window.scrollX)
		scroll_x = window.scrollX;
	return scroll_x;
}

// get reference to nested layer for ns4
// from dhtmllib.js by Mike Hall of www.brainjar.com
function getLyrRef(lyr,doc) {
	if (document.layers) {
		var theLyr;
		for (var i=0; i<doc.layers.length; i++) {
	  	theLyr = doc.layers[i];
			if (theLyr.name == lyr) return theLyr;
			else if (theLyr.document.layers.length > 0) 
	    	if ((theLyr = getLyrRef(lyr,theLyr.document)) != null)
					return theLyr;
	  }
		return null;
  }
}

// Begin other included source

// resize fix for ns4
var origWidth, origHeight;
if (document.layers) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

// preload images to be included in banners
var imgAr = new Array(
	"http://www.sdml.org/graphics/small_ad.gif",
	"http://www.sdml.org/graphics/small_ad2.gif",
	"http://www.sdml.org/graphics/small_ad3.gif",
	"http://www.sdml.org/graphics/large_ad.gif",
	"http://www.sdml.org/graphics/large_ad2.gif",
	"http://www.sdml.org/graphics/large_ad3.gif",
	"http://www.sdml.org/graphics/fwd_ad_large.gif",
	"http://www.sdml.org/graphics/tu_ad_large.gif"
);

if (document.images) {
	var imgs = new Array();
	for (var i=0; i<imgAr.length; i++) {
  	imgs[i] = new Image(); 
		imgs[i].src = imgAr[i];
  }
}

function bannerObj(id,w,h,x,y,d,cls) {
	this.bobj=writeObj;
	this.bobj(id,w,h,x,y);
	this.delay=d; this.cls=cls; 
	this.items = new Array(); 
	this.w=w;
	this.obj=id+"bannerObj"; eval(this.obj+"=this"); 
}

function rotate() {
	var cntnt;
	if (document.layers) cntnt = '<table width="'+this.w+'"><tr><td class="' + this.cls + '">' + this.items[this.ctr] + '</td></tr></table>';
	else cntnt = '<div class="' + this.cls + '">' + this.items[this.ctr] + '</div>';
	this.writeLyr(cntnt);
	if (this.ctr < this.items.length-1) this.ctr++;
  else this.ctr = 0;
	setTimeout(this.obj+".rotate()",this.delay);
}

function addBannerItem(txt) {
	this.items[this.items.length] = txt
}

bannerObj.prototype=new writeObj;
bannerObj.prototype.ctr = 0;
bannerObj.prototype.addItem = addBannerItem;
bannerObj.prototype.rotate = rotate;