//<script language="javascript">
/*=============================================================================
 WebSolvers Framework Library
 Copyright 2003, WebSolvers, Inc., All Rights Reserved.

 Library Effects
 Provides Menus/links, rollovers, and scrollers.

 Revision History:
 6-30-03 Created

 Public Functions:
	imageObject_MakeSwap(

  Notes:
  To use the scroller place the following in your code
<div id="scroller" 
	style="position: relative; visibility: hidden;
		width: 154px; height: 100px; clip: rect(0, 154, 100, 0); overflow: hidden;"> 
    <div id="content" style="position: absolute; left:0; top:0;" visibility="hidden">
    [ contents ]
    </div></div><script language="javascript"><!--
		if(window.dhtml) {
			dhtml.addBasicInit("document.getElement('scroller')", "elemObject_MakeScroller", 0, 100, true);
		}    
    //-->< /script>
=============================================================================

 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._mnu_hide = this.hide;
	this.hide = menuObject_Hide;
	this._mnu_show = this.show;
	this.show = menuObject_Show;

	this.addEvent("mouseover", menuObject_OnMouseOver);
	this.addEvent("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._mnu_hide();
}

// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

function menuObject_Show() {
	if(this.timer) {
		window.clearTimeout(this.timer);
		this.timer = 0;
	}
	this._mnu_show();
}

// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

function menuObject_OnMouseOver(e) {
	this.mouseover = 1;
	if(this.timer) {
		window.clearTimeout(this.timer);
		this.timer = 0;
	}

	return true;
}

// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

function menuObject_OnMouseOut(e) {
	this.mouseover = 0;
	this.hide(this.timeout);

	return true;
}

// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

function aObject_MakeMenuLink(menu, mAlign, mVAlign, align, vAlign, timeout, shiftX, shiftY) {
	var link;

	dhtml.normalize(this);

	if(this._layer)
		link = this.document.anchors[this.name].link;
	else
		link = this;

	dhtml.normalize(link);

	link.menuLink = this;
	link._menuLink = true;

	this.menu = menu;
	this.mAlign = mAlign;
	this.mVAlign = mVAlign;
	this.align = align;
	this.vAlign = vAlign;
	this.menuTimeout = timeout;
	this.shiftX = shiftX;
	this.shiftY = shiftY;

	link.addEvent("mouseover", menuLinkObject_OnMouseOver);
	link.addEvent("mouseout", menuLinkObject_OnMouseOut);
}

function menuLinkObject_OnMouseOver(e) {
	this.menuLink.menu.alignTo(this.menuLink, this.menuLink.mAlign, this.menuLink.mVAlign, this.menuLink.align, this.menuLink.vAlign, this.menuLink.shiftX, this.menuLink.shiftY);
	this.menuLink.menu.show();

	return true;
}

function menuLinkObject_OnMouseOut(e) {
	this.menuLink.menu.hide(this.menuLink.menuTimeout);

	return true;
}

function aObject_MakeRollOver(status, image) {
	dhtml.quickNorm(this);

	this.status = status;
	this.image = image;

	this.addEvent("mouseover", rollOverObject_OnMouseOver);
	this.addEvent("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();

	return true;
}

// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

function rollOverObject_OnMouseOut(e) {
	window.status = this.ostatus;

	if(this.image)
		this.image.swap();

	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 = 500;

	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 = "";
	var para6 = "";
	var para7 = "";

	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 = 500;

			if(attr = a.getAttribute("shiftx"))
				para6 = attr;
			else
				para6 = 0;

			if(attr = a.getAttribute("shifty"))
				para7 = attr;
			else
				para7 = 0;

			dhtml.setType(link, aObject_MakeMenuLink, menu, para1, para2, para3, para4, para5, para6, para7);
		}
	}

	return a;
}

// --------------------------------------------------------------------------------
//                                  DIV Code
// --------------------------------------------------------------------------------

function elemObject_MakeScroller(direction, speed, autostop) {
	dhtml.normalize(this);

	if(direction)
		this.direction = 1;
	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.addEvent("mouseover", scrollerObject_MouseOver);
		this.addEvent("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.direction && (this.content.getWidth() > this.getWidth())) ||
		(!this.direction && (this.content.getHeight() > this.getHeight())))
			this.scroll();
}

function scrollerObject_MouseOver(e) {
	this.stopScroll();
}

function scrollerObject_MouseOut(e) {
	this.startScroll();
}

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_ScrollEffect(attr, html) {
	var evt = "";

	var id = "";
	var cls = "";
	var width = 0;
	var height = 0;
	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 "speed":
			speed = parseInt(attr[i][2]);
			break;
		case "dir":
			dir = dhtml.procAlign(attr[i][2]);
			if(dir < 0)
				dir = 0;
			break;
		case "stop":
			autos = true;
			break;
		case "width":
			width = parseInt(attr[i][2]);
			html += ' ' + attr[i][0];
			break;
		case "height":
			height = parseInt(attr[i][2]);
			html += ' ' + attr[i][0];
			break
		default:
			html += ' ' + attr[i][0];
		}
	}

	if(!pmtime || !pmtime.length)
		pmtime = 100;

	if(!pmltime || !pmltime.length)
		pmltime = 500;

	if(!isNaN(speed) && id && id.length)
		dhtml.addBasicInit("document.getElement('" + id + "')", "scrollerObject", speed, dir, autos);

	html += "><DIV id=\"" + id + "_content\">" + ihtml + '</DIV></DIV>';

	return html;
}

function proc_ScrollEffect(elem, doc) {
	var attr;

	//If the gecko render is not geater than 20020529 then don't
	// do anythign since that version an prior has issues with this.
	if(dhtml.mozilla && !dhtml.checkVersion(1, 20020529))
		return elem;
	
	dhtml.quickNorm(this);
	
	var id = "";
	var cls = "";
	var param1 = Number.NaN;
	var param2 = 0;
	var param3 = false;
	var width = 0;
	var height = 0;

	if(attr = elem.getAttribute("id"))
		id = attr;

	if(attr = elem.getAttribute("class"))
		cls = attr;

	if(attr = elem.getAttribute("dir")) {
		param1 = dhtml.procAlign(attr);
		if(param1 < 0)
			param1 = 0;
	}

	if(attr = elem.getAttribute("speed"))
		param2 = parseInt(attr);
	
	if(attr = elem.getAttribute("stop")) 
		param3 = true;
	
	if(attr = elem.getAttribute("width"))
		width = parseInt(attr);

	if(attr = elem.getAttribute("height"))
		height = parseInt(attr);
		
	var ep = elem.getParent();
	var frag = document.newFragment();
	var scroller = document.newElement('DIV');
	var content = document.newElement('DIV');

	frag.appendChild(scroller);	
	scroller.id = id;
	scroller.style.position = "relative";
	scroller.appendChild(content);
	scroller.resizeTo(width, height,false);
	scroller.hide();

	content.moveTo(0, 0);
	if(cls)
		content.setClass(cls);
	content.hide();
	
	if(elem.firstChild.nodeType == 8) {
		content.setHTML(elem.firstChild.nodeValue);
	} else
		while(elem.firstChild)
			content.appendChild(elem.removeChild(elem.firstChild));

	ep.replaceElem(frag, elem);

	if(id && !isNaN(param2)) {
		dhtml.setType(scroller, elemObject_MakeScroller, param1, param2, param3);
	}
	
	return frag;
}

// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

if(window.dhtml) {
	dhtml.addTag('A', proc_AnchorEffect, null, preproc_AnchorEffect, -1);
	dhtml.addTag('IMG', proc_ImgEffect, null, preproc_ImgEffect, 0);
	dhtml.addTag('SCROLL', proc_ScrollEffect, null, preproc_ScrollEffect, 1);
}

