/***********************************************
* AnyLink Drop Down Menu-  Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/


// Usage: <a onmouseover='doDropDown(this,event,"contentDivId")'>Link Text</a> 


var DropDown = {};
/***
*** These are values that will determine the size, css, position & sliding effects of the menu.
*** Defaults & expanations are here.  You can override these for any one menu by passing in the 
*** hash obj hPassedOptions or for your document by setting DropDown.defaults.xxx = ?
***/
DropDown.defaults = {

	hideMenuOnClick:false,      //Does a click (anywhere) close the menu?
	clearOthers:false,       //Menu opens on right of parent
	noIframe:false,         //Forces no iframe to be generated (for pages without select fields beneith the menus; otherwise, will make a blocking iFrame in IE only

	extraClasses:'',           //Add extra classes to a menu
	replaceParamsArray:[],     //You can replace anything in the HTML in your content div [[findstr1,replacestr1],[findstr2,replacestr2]]

	addedWidthToMenu:0,        //Menus by default will use the width of the parent element.  You can add (or subtract) to that here (only affects right side)
	offsetX:0,                 //Horizantal Offset of menu
	offsetY:0,                 //Vertical Offset
	minWidth:'parent',         //Menu will be this width (if > 0) unless an item is longer, in which case the menu will be the item width.
								//{minWidth:'parent'} will make the minwidth the width of the parent element.  

	openRight:false,       //Menu opens on right of parent

	dropDownTime:1,          //How long (in milliseconds) does the slide take to finish?  Put in 1 here for no slide
	disappearDelay:250,         //The menu will hang around for this amount of time (in milliseconds) after it's been told to hide

	passedInnerHTML: false,
	useElement: false,
	showOverflow:false,

	cacheInnerContent: true
};

DropDown.instances = [];
DropDown.hInnerIdToInstance = {};



/***
*** Accessor Functions:  These functions create/handle instances of the menu behind the scenes.  Use 
***/
var idsToDropObjs = {};


/*
* Will call doDropDownActivate, plus set onmouseout if you're so inclined/lazy
* 
*  To Be called onclick or onmouseover by activating element
*  Parameters
*   oMenuParent: the element (object or id) to be used for the menu (usually 'this');
*   e: event
*   oMenuContents: the div element (object or id) to be used for menu content
*   Options (optional): see "defaults" above for available options
*   oThis (not needed): The calling object. Used in behind-the-scenes calls 
*/
function doDropDown(e, targetEle, contentSourceEle, options, triggerEle) {

	var id = initDropDownEvents(targetEle, contentSourceEle, options, triggerEle);
	if(!(idsToDropObjs[id].menuIsOn())) 
		idsToDropObjs[id].showDD(e);
		
	return idsToDropObjs[id];
	
}



/*
* Easy-to-use call/shortcut for Related Links
*/
function doDropDownRelatedLinks(e,sTargetId) {

	var triggerEle = Event.element(e);
	return doDropDown(triggerEle, e, sTargetId, {minWidth:0,dropDownTime:1,hideMenuOnClick:false},triggerEle);

}


/*
* Easy-to-use call/shortcut for Related Links
*/
function doDropDownTabs(e,sTargetId) {

	var triggerEle = Event.element(e);
	return doDropDown(triggerEle.parentNode, e, sTargetId, {dropDownTime:1,hideMenuOnClick:false,offsetX:1,addedWidthToMenu:-5},triggerEle);

}


function doDropDownHideAll(excepting) {
	for (var i in idsToDropObjs)
		if(i != excepting)
			idsToDropObjs[i].hideMenu({hideNow:true});
}

function preloadDropDown(targetEle, contentSourceEle, options, triggerEle) {
	
	var id = initDropDownEvents(targetEle, contentSourceEle, options, triggerEle);
	var dropObj = idsToDropObjs[id];
	
	dropObj.drawMenu();
	dropObj.positionMenuAtInit();
	dropObj.menuElements.menuDivOuter.style.display="none"; 
	dropObj.menuElements.menuDivInner.style.display="none"; 
	if(dropObj.menuElements.menuIframe != null) dropObj.menuElements.menuIframe.style.display="none";
	dropObj.bMenuIsDrawn = true;

	return dropObj;

}

function initDropDownEvents(targetEle, contentSourceEle, options, triggerEle) {
	
	targetEle = $(targetEle);
	triggerEle = triggerEle || targetEle;
	options = options || {};

	if(!triggerEle.id)  triggerEle.id = "DropDownMenuButton"+DropDown.instances.length; 

	if(!idsToDropObjs[triggerEle.id]) {
		var newDropDown = new DropDownObj(targetEle, contentSourceEle, options);
		
		idsToDropObjs[triggerEle.id] = newDropDown;
		newDropDown.triggerEleId = triggerEle.id;
				
		newDropDown.observe(triggerEle,'mouseout',newDropDown.hideMenuOnTimeout.bindAsEventListener(newDropDown));
		newDropDown.observe(triggerEle,'mouseover',newDropDown.clearHideMenuTimeout.bindAsEventListener(newDropDown));
		//newDropDown.observe(triggerEle,'click',newDropDown.clearHideMenuTimeout.bindAsEventListener(newDropDown));

		if(triggerEle != targetEle) {
			if(targetEle.id == null || targetEle.id == "")  { targetEle.id = "DropDownTarget"+DropDown.instances.length; } 
			if(!idsToDropObjs[targetEle.id]) {
				newDropDown.observe(targetEle,'mouseout',newDropDown.hideMenuOnTimeout.bindAsEventListener(newDropDown));
				newDropDown.observe(targetEle,'mouseover',newDropDown.clearHideMenuTimeout.bindAsEventListener(newDropDown));
				newDropDown.observe(targetEle,'click',newDropDown.clearHideMenuTimeout.bindAsEventListener(newDropDown));
			}
		}
	}

	return targetEle.id;
}




/***
 *** DropDown Object: creates a div structure.  Function showDD will show that object.
 ***/

var DropDownObj = Class.create();

Object.extend(DropDownObj.prototype,{

	initialize: function (targetEle, contentSourceEle, options) {
		
		this.menuElements = {
			menuDivOuter: null,
			menuDivInner: null,
			menuIframe: null,
			contentSourceEle: null,
			activeTargetEle: null
		};
		this.outerPos = null;
		this.isReversedX = null;
		this.isReversedY = null;
		
		this.bMenuIsOn = false;
		this.bMenuIsSliding = false;
		this.bMenuIsDrawn = false;
		
		this.iInstance = 0;
		this.oAccel = null;
		this.parentMenusIndex = null;
		this.delayHideTimeout = null;
		
		this.events = [];

		this.options = {};
	
		this.iInstance = DropDown.instances.length;
		DropDown.instances.push(this);
		
		this.setOptions(Object.extend(Object.extend({},DropDown.defaults),options || {})); 
		this.setContentSource(contentSourceEle);
		this.setTarget(targetEle);
		this.createDiv();
	
	},

	// Create dropdown div, without content
	createDiv: function () {

		var top_div = new Element('div',{
			style: (this.options.showOverflow ? "" : "overflow:hidden;")+"background-color:transparent;display:none;position:absolute"
		});
		Event.observe(top_div,'mouseover',this.clearHideMenuTimeout.bindAsEventListener(this));
		Event.observe(top_div,'mouseout',this.dynamicHide.bindAsEventListener(this));

		if(this.options.useElement) {
			var inner_div = this.menuElements.contentSourceEle;
			inner_div.parentNode.removeChild(inner_div);
			top_div.appendChild(inner_div);
			if(this.options.extraClasses) Element.addClassName(inner_div,this.options.extraClasses);
		} else {
			var inner_div = new Element('div',{
				style: 	"display:none;overflow:visible;top:20px;position:relative",
				id: 	"mgicdropinnerdiv_"+this.iInstance
			});
		}
		Event.observe(inner_div,'mouseover',this.clearHideMenuTimeout.bindAsEventListener(this));
		Event.observe(inner_div,'mouseout',this.dynamicHide.bindAsEventListener(this));
		Event.observe(inner_div,'click',doDropDownHideAll);

		if(!inner_div.id) inner_div.id = "DropDownMenuInnerDiv"+DropDown.instances.length;
		DropDown.hInnerIdToInstance[inner_div.id] = this.iInstance;

		var iframe_block = null;
		if(!this.options.noIframe && Prototype.Browser.IE) {
			var iframe_block = new Element('iframe',{
				style: 	"allowTransparency:true;backgroundColor:transparent;display:none;"+
				"position: absolute;filter: Alpha(opacity=0);",
				frameBorder: 0,
				border: 0,
				src: "/blank.html"
			})
		}

		if(!$('DropDown_holder')) 
			document.body.appendChild(new Element('div',{
				style: 	"width:1px;height:1px",
				id: 	"DropDown_holder"
			}));

		top_div.appendChild(inner_div);
		if(iframe_block) $('DropDown_holder').appendChild(iframe_block);
		$('DropDown_holder').appendChild(top_div);

		this.menuElements.menuDivOuter = top_div;
		this.menuElements.menuDivInner = inner_div;
		this.menuElements.menuIframe = iframe_block;
	},

	setOptions: function (passedOptions,resetToDefaults) {
		if(!resetToDefaults) this.options = Object.extend(this.options,passedOptions || {});
		else this.options = Object.extend(Object.extend({},DropDown.defaults),passedOptions || {});
	},

	setContentSource: function (contentSource) {
		this.menuElements.contentSourceEle = this.options.passedInnerHTML ? contentSource : $(contentSource);
	},

	setTarget: function (activeTargetEle) {
		this.menuElements.activeTargetEle = $(activeTargetEle);
		this.parentMenusIndex = null;
		if(!this.menuElements.activeTargetEle.parentNode.id)
			this.menuElements.activeTargetEle.parentNode.id = "DropDownMenuButtonParent"+DropDown.instances.length;
		if(DropDown.hInnerIdToInstance[this.menuElements.activeTargetEle.parentNode.id] != null) {
			this.parentMenusIndex =  DropDown.hInnerIdToInstance[this.menuElements.activeTargetEle.parentNode.id];
		}
	},
	

	showDD: function (e) {

		var options = this.options;

		if(e) Event.stop(e);
		if(e && e.type=="click" && options.hideMenuOnClick && this.menuIsOn()) {
			this.hideMenu();
			return false;
		}

		// Needed?
		if(!this.menuElements.activeTargetEle || !this.menuElements.contentSourceEle) return true;			

		if (options.hideMenuOnClick) Event.observe(document,'click',doDropDownHideAll);
//		else Event.stopObserving(document,'click',doDropDownHideAll);

		// Make sure we don't clear the currently showing menu; if we're hiding, it'll be done immediately
		this.clearHideMenuTimeout(e);

		if (!this.menuElements.menuDivOuter.visible() && (this.parentMenusIndex == null || DropDown.instances[this.parentMenusIndex].bMenuIsOn)) {
			if(options.clearOthers) doDropDownHideAll(this.triggerEleId);
			if(!options.cacheInnerContent || !this.bMenuIsDrawn) {
				this.drawMenu();
				this.positionMenuAtInit();
				this.bMenuIsDrawn = true;
			} else {
				var newOuterPos = this.checkIfParentMoved();
				if(newOuterPos) this.setOuterDivPos(newOuterPos);
				
				this.menuElements.menuDivOuter.style.display="block";
				this.menuElements.menuDivInner.style.display="block";
			}
			this.runMenu();
		}
		
		return clickReturnValue();
	},

	setOuterPositionRight: function (iMenuParentWidth,iMenuWidth,iOuterDivLeft) {

		var oDoc = (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;

		var iCorrectLeft = iOuterDivLeft + iMenuParentWidth;
		this.isReversedX = false;

		var iRightEdge = Prototype.Browser.IE ? oDoc.scrollLeft + oDoc.clientWidth-5 : window.pageXOffset + window.innerWidth-5;
		var iLeftEdge = Prototype.Browser.IE ? oDoc.scrollLeft : window.pageXOffset;

		if (iMenuWidth + iOuterDivLeft + iMenuParentWidth > iRightEdge) { //Move left?
			iCorrectLeft = (this.options.openRight)? iOuterDivLeft - iMenuWidth : iRightEdge - iMenuWidth;
			this.isReversedX = true;

			if(iCorrectLeft < iLeftEdge) {  //left no good either?
				iCorrectLeft = iRightEdge-iMenuWidth;
				this.isReversedX = false;
			}

		}
		return iCorrectLeft;

	},

	setOuterPositionTop: function (iMenuParentHeight,iMenuHeight,iOuterDivTop,iRealParentHeight) {

		var oDoc = (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body

		var iTopEdge = oDoc.scrollTop;
		var iRightEdge = Prototype.Browser.IE && !window.opera ? oDoc.scrollTop + oDoc.clientHeight-15 : window.pageXOffset + window.innerWidth-15
		var iBottomEdge = oDoc.scrollTop + oDoc.clientHeight-15;

		var iCorrectTop = iOuterDivTop + iMenuParentHeight;
		this.isReversedY = false;

		if (iBottomEdge - iOuterDivTop < iMenuHeight){  //move up?                 btm of window - top of btn < height of menu
			iCorrectTop = iOuterDivTop - iMenuHeight + ((this.options.openRight)? iRealParentHeight : 0);   // menu height + item height
			this.isReversedY = true;
			if ((iOuterDivTop - iTopEdge) < iMenuHeight) { // up no good either?      top of btn - top of window < height of btn
				iCorrectTop = iTopEdge; // top of btn + height of menu - top of window
				this.isReversedY = false;
			}
		}
		return iCorrectTop;

	},

	populateMenu: function (content_obj,classextra,replace_params){
		if(this.options.useElement) return;
		var content_html = (this.options.passedInnerHTML ? content_obj : content_obj.innerHTML);
		if(replace_params && replace_params.length) {
			for(var i=0; i<replace_params.length; i++) {
				var myregexp = typeof(replace_params[i][0]) == 'string' ? new RegExp(replace_params[i][0], "g") : replace_params[i][0];
				content_html = content_html.replace(myregexp,replace_params[i][1]);
			}
		}
		//this.menuElements.menuDivInner = this.menuElements.menuDivInner.replaceHTML(content_html);
		this.menuElements.menuDivInner.innerHTML = content_html;
		if(classextra != "") classextra = " " + classextra;
		this.menuElements.menuDivInner.className = content_obj.className + classextra;
		//this.menuElements.menuDivInner.style.positioning = 'relative';
		//this.menuElements.menuIframe.style.positioning = 'relative';
	},
	
	calculateMenuWidth: function (menuwidth) {
		
		var outerDiv = this.menuElements.menuDivOuter;
		var innerDiv = this.menuElements.menuDivInner;
		var iframeBacker = this.menuElements.menuIframe;
		var options = this.options;
		
		outerDiv.style.left=outerDiv.style.top="-500px";
		innerDiv.style.visibility="visible";
		outerDiv.style.display="block";
		innerDiv.style.display="block";

		if(iframeBacker) {
			iframeBacker.style.left=iframeBacker.style.top="-500px";
			iframeBacker.style.display="inline";
		}

		var addwidth = true;

		if (options.minWidth || options.minWidth==0) {

			var collapse_menuwidth = 0;
			var all = innerDiv.childNodes;

			innerDiv.style.width = "1px";

			if(!Prototype.Browser.IE || all[0].offsetWidth <= 5) {
				innerDiv.style.width = 0;
				outerDiv.style.width = 0;
				innerDiv.style.width = "";
				outerDiv.style.width = "";
			}
			for (var i = 0;i<all.length;i++) {
				if(all[i].offsetWidth > collapse_menuwidth) {
					collapse_menuwidth = all[i].offsetWidth;
				}
			}

			if(options.minWidth == 'parent' && menuwidth + options.addedWidthToMenu >= collapse_menuwidth) {
				innerDiv.style.width = menuwidth + "px";

			} else if(options.minWidth + options.addedWidthToMenu >= collapse_menuwidth) {
				innerDiv.style.width = options.minWidth + "px";

			} else {
				innerDiv.style.width=collapse_menuwidth + "px";
				addwidth = false;
			}

		} else if(menuwidth!="") {

			innerDiv.style.width=menuwidth+"px";

		}

		var addedwidth = (addwidth)? options.addedWidthToMenu : 0;
		innerDiv.style.width = (parseInt(innerDiv.style.width) + addedwidth) + "px";

		outerDiv.style.width=innerDiv.offsetWidth+"px";
		outerDiv.style.height=innerDiv.offsetHeight+"px";

		if(iframeBacker != null) {
			iframeBacker.style.height = innerDiv.offsetHeight + "px";
			iframeBacker.style.width = innerDiv.offsetWidth+"px";
		}
			
	},
	
	getMenuWidth: function () {
		return this.menuElements.menuDivInner.offsetWidth;
	},

	drawMenu: function () {
		this.populateMenu(this.menuElements.contentSourceEle,this.options.extraClasses,this.options.replaceParamsArray);	
		this.calculateMenuWidth(this.menuElements.activeTargetEle.offsetWidth)
		this.menuwidth = this.getMenuWidth();
	},

	positionMenuAtInit: function () {
		// Our menu is already built??  
		//if(!this.delayHideTimeout || previousTargetEle != this.menuElements.activeTargetEle) {

		var outerDiv = this.menuElements.menuDivOuter;
		var innerDiv = this.menuElements.menuDivInner;
		var iframeBacker = this.menuElements.menuIframe;
		var options = this.options;

		if (this.oAccel != null) this.oAccel.stop();
		if(!options.openRight) {
			innerDiv.style.top = -innerDiv.offsetHeight+"px";
		} else {
			innerDiv.style.left = -innerDiv.offsetWidth+"px";
			innerDiv.style.top = "0px";
		}
		
		var newOuterPos = this.checkIfParentMoved();
		if(newOuterPos) this.setOuterDivPos(newOuterPos);

		if(this.menuElements.menuIframe) {
			this.menuElements.menuIframe.style.left =  outerDiv.style.left;
			this.menuElements.menuIframe.style.top =  outerDiv.style.top;
		}

		if(!options.openRight) {
			this.x0 = this.isReversedY ? parseInt(outerDiv.offsetHeight) : parseInt(innerDiv.style.top);
		} else {
			this.x0 = this.isReversedX ? parseInt(outerDiv.offsetWidth) : parseInt(innerDiv.style.left);
		}

	},
	
	setOuterDivPos: function (passedPos) {

		var outerDiv = this.menuElements.menuDivOuter;
		var menuDivInner = this.menuElements.menuDivInner;
		var activeTargetEle = this.menuElements.activeTargetEle;
		var options = this.options;
		
		var outerPos = passedPos ? passedPos : activeTargetEle.cumulativeOffset();
		if(options.offsetX) outerPos[0] += options.offsetX;
		if(options.offsetY) outerPos[1] += options.offsetY;

		this.outerPos = outerPos;

		if(options.openRight) {
			outerDiv.style.left = this.setOuterPositionRight(activeTargetEle.offsetWidth,this.menuwidth,outerPos[0]) + "px";
			outerDiv.style.top  = this.setOuterPositionTop(0,menuDivInner.offsetHeight,outerPos[1],activeTargetEle.offsetHeight) + "px";
		} else {
			outerDiv.style.left = this.setOuterPositionRight(0,this.menuwidth,outerPos[0]) + "px";
			outerDiv.style.top  = this.setOuterPositionTop(activeTargetEle.offsetHeight,menuDivInner.offsetHeight,outerPos[1]) + "px";
		}
		if(this.isReversedX || this.isReversedY)
			Element.addClassName(outerDiv,'dropdown_reverse')
		else
			Element.removeClassName(outerDiv,'dropdown_reverse')
			
	},
	
	checkIfParentMoved: function () {
		var newOuterPos = this.menuElements.activeTargetEle.cumulativeOffset();
		if(!this.outerPos) return newOuterPos;
		if(this.outerPos[0] == newOuterPos[0] && this.outerPos[1] == newOuterPos[1]) return false;
		return newOuterPos;
	},
	
	runMenu: function () {

		this.oAccel = new Accelimation(this.x0, 0, this.options.dropDownTime, -1, this);
		this.oAccel.onframe = this.options.openRight ? this.slideFrameX : this.slideFrameY;
		this.oAccel.onend = this.slideEnd;

		this.oAccel.start();
		this.bMenuIsSliding = true;

	},

	menuIsOn: function () {
		return (this.menuElements.menuDivInner && this.menuElements.menuDivOuter.visible() && this.bMenuIsOn);
	},

	/* Hide */
	dynamicHide: function (e) {
		if(!e) e = window.event;
		if (Prototype.Browser.IE && !(this.menuElements.menuDivInner.contains(e.toElement))) { 
			this.hideMenuOnTimeout();
		} else if (!Prototype.Browser.IE && e.currentTarget != e.relatedTarget && !contains_ns6(e.currentTarget, e.relatedTarget)) { 
			this.hideMenuOnTimeout();
		}
	},

	// Hide current menu after delay
	hideMenuOnTimeout: function (e,speed){ 

		var sp = (typeof speed != "undefined" ? speed : this.options.disappearDelay);
		if(this.options.disappearDelay == -1) return;
		if(!this.menuIsOn() && !this.bMenuIsSliding) return;
		if(!this.delayHideTimeout) 
			this.delayHideTimeout = setTimeout(this.hideMenu.bind(this),sp);

		if (this.parentMenusIndex != null) {
			DropDown.instances[this.parentMenusIndex].hideMenuOnTimeout(e,sp);
		}

	},

	// Forget about hiding the menu on the delay
	clearHideMenuTimeout: function (e){
		
		if (typeof this.delayHideTimeout != "undefined") {
			clearTimeout(this.delayHideTimeout);
			this.delayHideTimeout = false;
			if(e) e.stop();
		}

		if (this.parentMenusIndex != null && DropDown.instances[this.parentMenusIndex]) {
			DropDown.instances[this.parentMenusIndex].clearHideMenuTimeout(e);
			if(e) e.stop();
		}

	},

	hideMenu: function (hideOptions){ 
		
		hideOptions = hideOptions || {};
		if (this.menuElements.menuDivOuter){ 

			if (this.oAccel!= null) this.oAccel.stop();
			this.delayHideTimeout = null;

			var x0,x1;

			if(!this.options.openRight) {
				x0 = parseInt(this.menuElements.menuDivInner.style.top);
				x1 = -this.menuElements.menuDivInner.offsetHeight;
				if(this.isReversedY) {
					x0 = 0;
					x1 = this.menuElements.menuDivOuter.offsetHeight;
				}
			} else {
				x0 = parseInt(this.menuElements.menuDivInner.style.left);
				x1 = -this.menuElements.menuDivInner.offsetWidth;
				if(this.isReversedX) {
					x0 = 0;
					x1 = this.menuElements.menuDivOuter.offsetWidth;
				}
			}

			xer = 0;
			this.oAccel = new Accelimation(x0, x1, hideOptions.hideNow ? 1 : this.options.dropDownTime, -1, this);
			this.oAccel.onframe = (this.options.openRight)? this.slideFrameX : this.slideFrameY;
			this.oAccel.onend = this.finishHideMenu.bind(this);
			this.oAccel.start();
			this.bMenuIsOn = false;
			this.bMenuIsSliding = true;

		} 
	},

	finishHideMenu: function (){ 
		
		this.menuElements.menuDivOuter.style.display="none"; 
		this.menuElements.menuDivInner.style.display="none"; 
		if(this.menuElements.menuIframe != null) this.menuElements.menuIframe.style.display="none";
		this.bMenuIsSliding = false;
		
	},



	observe: function (element,trigger,func) {
		Event.observe(element,trigger,func);
		this.events.push({element:element,trigger:trigger,func:func});
	},

	stopObserveAll: function () {
		for(var i=0,len=this.events.length; i<len; i++) {
			var hash = this.events[i];
			Event.stopObserving(hash.element,hash.trigger,hash.func);
		}
	},

	slideFrameY: function (x) {
		this.menuElements.menuDivInner.style.top = x + "px";
		if(Prototype.Browser.IE && !this.options.noIframe && this.isReversedY && x + this.menuElements.menuDivInner.offsetHeight > 0) this.menuElements.menuIframe.style.height = x + this.menuElements.menuDivInner.offsetHeight + "px";
	},

	slideFrameX: function (x) {
		this.menuElements.menuDivInner.style.left = x + "px";
		if(Prototype.Browser.IE && !this.options.noIframe && !this.isReversedX && x + this.menuElements.menuDivInner.offsetWidth > 0) this.menuElements.menuIframe.style.width = x + this.menuElements.menuDivInner.offsetWidth + "px";
	},

	slideEnd: function () {
		this.bMenuIsOn = true;
		this.bMenuIsSliding = false;
	}
});


function getposOffset (element, offsettype){

	var valueT = 0, valueL = 0;
	do {
		valueT += element.offsetTop  || 0;
		valueL += element.offsetLeft || 0;
		element = element.offsetParent;
		} while (element);
	return (offsettype=="left"? valueL : valueT);
	
}

function contains_ns6 (a, b) {
	if(!a||!b) return false;
	while (b=b.parentNode) if (b == a) return true;
	return false;
}

function clickReturnValue () { 
	return !DropDown.dropdownIsSupported; 
}


/* 
 * This part is:
 * Copyright 2003-2004, Aaron Boodman (www.youngpup.net)
 * =================================================================================================
 * 
 * Use of this library is governed by the Creative Commons Attribution 2.0 License. You can check it 
 * out at: http://creativecommons.org/licenses/by/2.0/
 */

//=====================================================================
// Accel[erated] [an]imation object
// change a property of an object over time in an accelerated fashion
//=====================================================================
// obj  : reference to the object whose property you'd like to animate
// to   : final value of prop
// time : time the animation should take to run
// zip	: optional. specify the zippiness of the acceleration. pick a 
//		  number between -1 and 1 where -1 is full decelerated, 1 is 
//		  full accelerated, and 0 is linear (no acceleration). default
//		  is 0.
//=====================================================================
// bezier functions lifted from the lib_animation.js file in the 
// 13th Parallel API. www.13thparallel.org
//=====================================================================

function Accelimation(from, to, time, zip, parentObj) {
	if (typeof zip  == "undefined") zip  = 0;
	if (typeof unit == "undefined") unit = "px";

        this.x0         = from;
        this.x1		= to;
	this.dt		= time;
	this.zip	= -zip;
	this.unit	= unit;
	this.timer	= null;
	this.onend	= new Function();
        this.onframe    = new Function();
		this.parentObj = parentObj || function () {};
}



//=====================================================================
// public methods
//=====================================================================

// after you create an accelimation, you call this to start it-a runnin'
Accelimation.prototype.start = function() {
	this.t0 = new Date().getTime();
	this.t1 = this.t0 + this.dt;
	var dx	= this.x1 - this.x0;
	this.c1 = this.x0 + ((1 + this.zip) * dx / 3);
	this.c2 = this.x0 + ((2 + this.zip) * dx / 3);
	Accelimation._add(this);
}

// and if you need to stop it early for some reason...
Accelimation.prototype.stop = function() {
	Accelimation._remove(this);
}



//=====================================================================
// private methods
//=====================================================================

// paints one frame. gets called by Accelimation._paintAll.
Accelimation.prototype._paint = function(time) {
	if (time < this.t1) {
		var elapsed = time - this.t0;
	        this.onframe.call(this.parentObj,Accelimation._getBezier(elapsed/this.dt,this.x0,this.x1,this.c1,this.c2));
        }
	else this._end();
}

// ends the animation
Accelimation.prototype._end = function() {
	Accelimation._remove(this);
    this.onframe.call(this.parentObj,this.x1);
	this.onend.call(this.parentObj);
}




//=====================================================================
// static methods (all private)
//=====================================================================

// add a function to the list of ones to call periodically
Accelimation._add = function(o) {
	var index = this.instances.length;
	this.instances[index] = o;
	// if this is the first one, start the engine
	if (this.instances.length == 1) {
		this.timerID = window.setInterval("Accelimation._paintAll()", this.targetRes);
	}
}

// remove a function from the list
Accelimation._remove = function(o) {
	for (var i = 0; i < this.instances.length; i++) {
		if (o == this.instances[i]) {
			this.instances = this.instances.slice(0,i).concat( this.instances.slice(i+1) );
			break;
		}
	}
	// if that was the last one, stop the engine
	if (this.instances.length == 0) {
		window.clearInterval(this.timerID);
		this.timerID = null;
	}
}

// "engine" - call each function in the list every so often
Accelimation._paintAll = function() {
	var now = new Date().getTime();
	for (var i = 0; i < this.instances.length; i++) {
		this.instances[i]._paint(now);
	}

}


// Bezier functions:
Accelimation._B1 = function(t) { return t*t*t }
Accelimation._B2 = function(t) { return 3*t*t*(1-t) }
Accelimation._B3 = function(t) { return 3*t*(1-t)*(1-t) }
Accelimation._B4 = function(t) { return (1-t)*(1-t)*(1-t) }


//Finds the coordinates of a point at a certain stage through a bezier curve
Accelimation._getBezier = function(percent,startPos,endPos,control1,control2) {
	return endPos * this._B1(percent) + control2 * this._B2(percent) + control1 * this._B3(percent) + startPos * this._B4(percent);
}


//=====================================================================
// static properties
//=====================================================================

Accelimation.instances = [];
Accelimation.targetRes = 10;
Accelimation.timerID = null;

if(typeof(LoadedScripts) == 'undefined') LoadedScripts = {}; LoadedScripts["dropdownmenu.js"] = true;
