//<script language="javascript">
/*=============================================================================
 WebSolvers Framework Library
 Copyright 2003, WebSolvers, Inc., All Rights Reserved.

 Library DHTML (Effects)
 Cross-Browser/Platform common DHTML library
 Provides Menus/links, rollovers, and scrollers.

 Revision History:
 5-20-03 Revamped code to new specifications

 Public Functions:

  Notes:
=============================================================================

 The WebSolvers Framework Library may be used and/or modified by anyone owning
 the original work as it was incorporated into an original development project
 so long as this copyright notice and the comments above remain intact.

 By using this code you agree to indemnify WebSolvers, Inc. from any liability
 that might arise from its use.

 This code may not be sold exclusively or as a part of other code without prior
 written consent and is expressly forbidden.

 Obtain permission before redistributing this software over the Internet or
 in any other medium. In all cases the copyright and header must remain intact.
============================================================================= */

//======================================================================================
//                                 Internal Routines
//======================================================================================

// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

function imgObject_MakeSwap(src) {
	if(window.Image) {
		this.Image = new Image();
		this.Image.src = src;
	} else
		this.altsrc = src;

	this.swap = swapObject_Swap;
}

function swapObject_Swap() {
	var src = this.src;

	if(this.Image) {
		this.src = this.Image.src;
		this.Image.src = src;
	} else if(this.altsrc) {
		this.src = this.altsrc;
		this.altsrc = src;
	}
}

// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------
function elemObject_MakeMenu(timeout) {
	this._menu = true;

	dhtml.normalize(this);

	this.timeout = timeout;

	this._hide = this.hide;
	this.hide = menuObject_Hide;
	this._show = this.show;
	this.show = menuObject_Show;

	this._mnu_onmouseover = this.getEvent("mouseover");
	this.setEvent("mouseover", menuObject_OnMouseOver);

	this._mnu_onmouseout = this.getEvent("mouseout");
	this.setEvent("mouseout", menuObject_OnMouseOut);
}

function menuObject_Hide(timeout) {
	if(this.timer) {
		this.document.parentWindow.clearTimeout(this.timer);
		this.timer = 0;
	}
	if(timeout)
		this.timer = this.document.parentWindow.setTimeout('document.getElement("' + this.id + '").hide();', timeout);
	else if(!this.mouseover && !this.nohide)
		this._hide();
}

// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

function menuObject_Show() {
	if(this.timer) {
		window.clearTimeout(this.timer);
		this.timer = 0;
	}
	this._show();
}

// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

function menuObject_OnMouseOver(e) {
	this.mouseover = 1;
	if(this.timer) {
		window.clearTimeout(this.timer);
		this.timer = 0;
	}

	if(this._mnu_onmouseover)
		return this._mnu_onmouseover(e);
	else
		return true;
}

// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

function menuObject_OnMouseOut(e) {
	this.mouseover = 0;
	this.hide(this.timeout);

	if(this._mnu_onmouseout)
		return this._mnu_onmouseout(e);
	else
		return true;
}

// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

function aObject_MakeMenuLink(menu, mAlign, mVAlign, align, vAlign, timeout) {
	var link;

	dhtml.normalize(this);

	if(this._layer)
		link = this.document.anchors[this.name].link;
	else
		link = this;

	link.menuLink = this;

	link._menuLink = true;

	this.menu = menu;
	this.menuAlign = mAlign;
	this.menuVAlign = mVAlign;
	this.linkAlign = align;
	this.linkVAlign = vAlign;
	this.menuTimeout = timeout;

	link._mlk_onmouseover = link.getEvent("mouseover");
	link.setEvent("mouseover", menuLinkObject_OnMouseOver);
	link._mlk_onmouseout = link.getEvent("mouseout");
	link.setEvent("mouseout", menuLinkObject_OnMouseOut);
}

function menuLinkObject_OnMouseOver(e) {
	this.menuLink.menu.alignTo(this.menuLink, this.menuLink.menuAlign, this.menuLink.menuVAlign, this.menuLink.linkAlign, this.menuLink.linkVAlign);
	this.menuLink.menu.show();

	if(this._mlk_onmouseover)
		return this._mlk_onmouseover(e);
	else
		return true;

}

function menuLinkObject_OnMouseOut(e) {
	this.menuLink.menu.hide(this.menuLink.menuTimeout);

	if(this._mlk_onmouseout)
		return this._mlk_onmouseout(e);
	else
		return true;
}

function aObject_MakeRollOver(status, image) {
	dhtml.quickNorm(this);

	this.status = status;
	this.image = image;

	this._onmouseover = this.getEvent("mouseover");
	this.setEvent("mouseover", rollOverObject_OnMouseOver);
	this._onmouseout = this.getEvent("mouseout");
	this.setEvent("mouseout", rollOverObject_OnMouseOut);
}

function rollOverObject_OnMouseOver(e) {
	this.ostatus = window.status;
	if(!this.ostatus)
		this.ostatus = '';

	if(this.status)
		window.status = this.status;

	if(this.image)
		this.image.swap();

	if(this._onmouseover)
		this._onmouseover(e);

	return true;
}

// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

function rollOverObject_OnMouseOut(e) {
	window.status = this.ostatus;

	if(this.image)
		this.image.swap();

	if(this._onmouseout)
		return this._onmouseout(e);

	return true;
}

// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

function preproc_ImgEffect(attr) {
	var name = "";
	var altsrc = "";

	html = "<IMG";

	for(var i = 0; i < attr.length; i++) {
		switch(attr[i][1].toLowerCase()) {
		case "altsrc":
			altsrc = attr[i][2];
			break;
		case "name":
			name = attr[i][2];
			html += ' ' + attr[i][0];
			break;
		default:
			html += ' ' + attr[i][0];
		}
	}

	if(name && name.length && altsrc && altsrc.length)
		dhtml.addBasicInit("document.images['" + name + "']", "imgObject_MakeSwap", altsrc);

	return html + ">";
}

// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

function proc_ImgEffect(img) {
	var attr;

	if(attr = img.getAttribute("altsrc"))
		dhtml.setType(img, imgObject_MakeSwap, attr);

	return img;
}

// --------------------------------------------------------------------------------
//                                  Anchor Code
// --------------------------------------------------------------------------------

function preproc_AnchorEffect(attr, html) {
	var evt = "";

	var pid = "";
	var pname = "";
	var pstatus = "";
	var pswap = "";
	var pmenu = "";
	var pmtime = 0;
	var pmlink = "";
	var pmltime = 0;
	var pma = "";
	var pmva = "";
	var pla = "";
	var plva = "";
	var dblclick = "";

	var ihtml = html;
	html = "<A";

	for(var i = 0; i < attr.length; i++) {
		switch(attr[i][1].toLowerCase()) {
		case "id":
			pid = attr[i][2];
			break;
		case "name":
			pname = attr[i][2];
			html += ' ' + attr[i][0];
			break;
		case "ondblclick":
			dblclick = attr[i][2];
			break;
		case "status":
			pstatus = attr[i][2];
			break;
		case "swapimg":
			pswap = attr[i][2];
			break;
		case "showmenu":
			pmenu = attr[i][2];
			break;
		case "menutimeout":
			pmtime = attr[i][2];
			break;
		case "menulink":
			pmlink = attr[i][2];
			break;
		case "linktimeout":
			pmltime = attr[i][2];
			break;
		case "menualign":
			pma = attr[i][2];
			break;
		case "menuvalign":
			pmva = attr[i][2];
			break;
		case "linkalign":
			pla = attr[i][2];
			break;
		case "linkvalign":
			plva = attr[i][2];
			break;
		default:
			html += ' ' + attr[i][0];
		}
	}

	if(!pname || !pname.length) {
		if(pid && pid.length)
			pname = pid;
		else
			pname = "nlnk" + Math.round(Math.random()*1000);

		html += ' name="' + pname + '"';
	}

	if(!pmtime || !pmtime.length)
		pmtime = 100;

	if(!pmltime || !pmltime.length)
		pmltime = 100;

	html += ' ondblclick="' + pname + '"';
	dhtml.addBasicInit("document.anchors['" + pname + "']", "fix_Anchor", "[eval]document",dblclick);

	if((pstatus && pstatus.length) || (pswap && pswap.length))
		dhtml.addBasicInit("(document.anchors['" + pname + "'] ? document.anchors['" + pname + "'].link : null)", "aObject", pstatus, "[eval]document.images['" + pswap + "']");

	if(pmenu && pmenu.length)
		dhtml.addBasicInit("document.getElement('" + pmenu + "')", "menuObject", pmtime);

	if(pmlink && pmlink.length)
		dhtml.addBasicInit("document.getElement('" + pmlink + "')", "menuLinkObject", "[eval]document.getElement('" + pmenu + "')", pma, pmva, pla, plva, pmltime);

	if(pmlink && pmlink.length && pid == pmlink)
		html = '<ilayer name="' + pid + '">' + html;

	html += ">" + ihtml + '</A>';

	if(pmlink && pmlink.length && pid == pmlink)
		html += "</ilayer>";

	return html;
}

// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

function fix_Anchor(doc, dblClick) {
	var link = null;
	var i = 0;

	this.link = null;

	for(i = 0; i < doc.links.length && !this.link; i++) {
		link = doc.links[i];
		if(link.ondblclick && link.ondblclick.toString().indexOf(this.name) > -1) {
			if(dblClick && dblClick.length)
				eval("link.ondblclick=function anonymous(e) { " + dblClick + " };");
			else
				link.ondblclick = null;
			link.name = this.name;
			this.link = link;
		}
	}
}

function proc_AnchorEffect(a, doc) {
	var attr;

	dhtml.quickNorm(this);

	var image = null;
	var menu = null;
	var link = null;

	var para1 = "";
	var para2 = "";
	var para3 = "";
	var para4 = "";
	var para5 = "";

	if(attr = a.getAttribute("status"))
		para1 = attr;

	if(attr = a.getAttribute("swapimg"))
		para2 = attr;

	if(para1 || para2) {
		image = doc.images[para2];
		dhtml.setType(a, aObject_MakeRollOver, para1, image);
	}

	if(attr = a.getAttribute("showmenu")) {
		menu = doc.getElement(attr);
		if(menu) {
			if(attr = a.getAttribute("menutimeout"))
				para1 = attr;
			else
				para1 = 100;

			dhtml.setType(menu, elemObject_MakeMenu, para1);
		}
	}

	if(attr = a.getAttribute("menulink")) {
		link = doc.getElement(attr);
		if(menu && link) {
			if(attr = a.getAttribute("menualign"))
				para1 = attr;
			else
				para1 = null;
			if(attr = a.getAttribute("menuvalign"))
				para2 = attr;
			else
				para2 = null;

			if(attr = a.getAttribute("linkalign"))
				para3 = attr;
			else
				para3 = null;
			if(attr = a.getAttribute("linkvalign"))
				para4 = attr;
			else
				para4 = null;

			if(attr = a.getAttribute("linktimeout"))
				para5 = attr;
			else
				para5 = 100;

			dhtml.setType(link, aObject_MakeMenuLink, menu, para1, para2, para3, para4, para5);
		}
	}

	return a;
}

// --------------------------------------------------------------------------------
//                                  DIV Code
// --------------------------------------------------------------------------------

function elemObject_MakeScroller(direction, speed, autostop) {
	dhtml.normalize(this);

	if(direction)
		this.direction = direction;
	else
		this.direction = 0;

	if(speed)		
		this.speed = speed;
	else
		this.speed = 1;

	this.startScroll = scrollerObject_StartScroll;
	this.stopScroll = scrollerObject_StopScroll;
	this.scrolling = scrollerObject_Scrolling;
	this.scroll = scrollerObject_Scroll;

	if(autostop) {
		this._scl_onmouseover = this.getEvent("mouseover");
		this.setEvent("mouseover", scrollerObject_MouseOver);
		this._scl_onmouseout = this.getEvent("mouseout");
		this.setEvent("mouseout", scrollerObject_MouseOut);
	}

	if(this.speed > 1000)
		this.speed = 1000;

	this.show();

	window.setTimeout("document.getElement('" + this.id + "').startScroll();", 1000 - this.speed);
}

function scrollerObject_StartScroll() {
	if(!dhtml)
		return;

	if(!this.content) {
		if(dhtml.NN4)
			this.content = dhtml.normalize(this.document.layers[0], this.document);
		else
			this.content = dhtml.normalize(this.firstChild, this.document);
	}
	
	if(!this.content)
		return;

	if(this.speed > 0)
		this.scrollStep = -1;
	else if(this.speed < 0) {
		this.scrollStep = 1;
		this.speed = -this.speed;
	} else
		this.scrollStep = 0;
	
	if(!dhtml.NN4) {
		if(this.direction)
			this.content.resizeTo(this.content.getWidth(), this.getHeight());
		else
			this.content.resizeTo(this.getWidth(), this.content.getHeight());
	}

	this.content.show();
	
	if((this.dir && (this.content.getWidth() > this.getWidth())) ||
		(!this.dir && (this.content.getHeight() > this.getHeight())))
			this.scroll();
}

function scrollerObject_MouseOver(e) {
	this.stopScroll();
	
	if(this._scl_onmouseover)
		this._scl_onmouseover(e);
}

function scrollerObject_MouseOut(e) {
	this.startScroll();
	
	if(this._scl_onmouseout)
		this._scl_onmouseout(e);
}

function scrollerObject_StopScroll() {
	if(this.timer)
		window.clearTimeout(this.timer);
	this.timer = 0;
}

function scrollerObject_Scrolling() {
	return (this.timer != 0);
}

function scrollerObject_Scroll() {
	var x = this.content.getX(true);
	var y = this.content.getY(true);
	
	if(this.direction) {
		if(x < -this.content.getWidth() || x > this.content.getWidth())
			x = this.getWidth() * -this.scrollStep;
		else
			x += this.scrollStep;
	} else {
		if(y < -this.content.getHeight() || y > this.content.getHeight())
			y = this.getHeight() * -this.scrollStep;
		else
			y += this.scrollStep;
	}

	this.content.moveTo(x, y, true);
	
	this.timer = window.setTimeout("document.getElement('" + this.id + "').scroll();", this.speed);
}

function preproc_DivEffect(attr, html) {
	var evt = "";

	var id = "";
	var speed = Number.NaN;
	var dir = 0;
	var autos = false;

	var ihtml = html;
	html = "<DIV";

	for(var i = 0; i < attr.length; i++) {
		switch(attr[i][1].toLowerCase()) {
		case "id":
			id = attr[i][2];
			html += ' ' + attr[i][0];
			break;
		case "name":
			id = attr[i][2];
			html += ' ' + attr[i][0];
			break;
		case "scrollspeed":
			speed = parseInt(attr[i][2]);
			break;
		case "direction":
			dir = dhtml.procAlign(attr[i][2]);
			if(dir < 0)
				dir = 0;
			break;
		case "autostop":
			autos = true;
			break;
		default:
			html += ' ' + attr[i][0];
		}
	}

	if(!pmtime || !pmtime.length)
		pmtime = 100;

	if(!pmltime || !pmltime.length)
		pmltime = 100;

	if(!isNaN(speed) && id && id.length)
		dhtml.addBasicInit("document.getElement('" + id + "')", "scrollerObject", speed, dir, autos);

	html += ">" + ihtml + '</DIV>';

	return html;
}

function proc_DivEffect(elem, doc) {
	var attr;
	
	dhtml.quickNorm(this);
	
	var param1 = Number.NaN;
	var param2 = 0;
	var param3 = false;
	

	if(attr = elem.getAttribute("scrollspeed"))
		param1 = parseInt(attr);
	
	if(attr = elem.getAttribute("direction")) {
		param2 = dhtml.procAlign(attr);
		if(param2 < 0)
			param2 = 0;
	}

	if(attr = elem.getAttribute("autostop")) 
		param3 = true;
	
	
	if(!isNaN(param1)) {
		dhtml.setType(elem, elemObject_MakeScroller, param1, param2, param3);
	}
}

// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

if(window.dhtml) {
	dhtml.addTag('A', proc_AnchorEffect, null, preproc_AnchorEffect, -1);
	dhtml.addTag('IMG', proc_ImgEffect, null, preproc_ImgEffect, 0);
	dhtml.addTag('DIV', proc_DivEffect, null, preproc_DivEffect, -1);
}
