/* 
 * **************************************************************************************************
 * Widgetpops - general javascript library - version 0.11.0
 * Proprietary and confidential.
 * This code is owned and copyrighted by Xornet, Inc. 2009.
 * Portions are Patent Pending.
 * Use, modification, and distribution is governed by a license agreement.
 * Written by Eric Tirk.
 * **************************************************************************************************
 */ 
if(typeof window.wp == "undefined")
{
	window.wp =
	{
		xhClick:function(url, targetDivId, scrollToId, e)
		{
			return wp.xhPost(null, url, targetDivId, scrollToId, null, e);
		},
		xhPost:function(formObj, url, targetDivId, scrollToId, efa, e)
		{
			if(scrollToId && wp.busy.needsScrolling(targetDivId))
			{
				var scrollToDiv=document.getElementById(scrollToId);
				if(scrollToDiv)
				{
					wp.scrollWinToElement(scrollToDiv);
				}
			}
			
			var busyDivId = wp.busy.display(targetDivId, 'Loading...');
			var busyEle = null;
			if(busyDivId)
			{
				busyEle = document.getElementById(busyDivId);
			}
			
			var xhr=wp.xhGetNewXMLHttpRequest();
			if(!url || url=='')
			{
				wp.xhDisplayError(targetDivId, 'ERROR: No URL found in form action for form to post to.');
				if(busyEle)
				{
					if(busyEle.bImgEle)
					{
						wp.hide(busyEle.bImgEle);
					}
					wp.hide(busyEle);
				}
				return false;
			}
			xhr.open('POST',url,true);
			xhr.onreadystatechange=function()
			{
				if(xhr && xhr.readyState==4 && xhr.status)
				{
					if(xhr.status==200)
					{
						var targetDiv = document.getElementById(targetDivId);
						with(window)
						{
							try
							{
								eval(xhr.responseText);
							}
							catch(error)
							{
								wp.xhDisplayError(targetDivId, error);
							}
							var busyEle = null;
							if(busyDivId)
							{
								busyEle = document.getElementById(busyDivId);
							}
							if(busyEle)
							{
								if(busyEle.bImgEle)
								{
									wp.hide(busyEle.bImgEle);
								}
								wp.hide(busyEle);
							}							
						}
						if(targetDiv)
						{
							targetDiv.style.display='block';
						}
					}
					else
					{
						wp.xhDisplayError(targetDivId, xhr.statusText);
					}
				}
			};
			var incl = wp.ehdf.namedValue("wp:set:locationhref(_SIGNAL)", window.location.href);
			incl += wp.ehdf.namedValue("wp:set:targetDiv(_SIGNAL)", targetDivId);
			incl += wp.js.libKeysAsEhdf();
			var postData = "wp:ehdfpd=" + encodeURIComponent(wp.form.getEhdfEncodedContents(formObj, incl));
			xhr.setRequestHeader('x-wp-xhrequest','true');
			if(efa != null)
				xhr.setRequestHeader('x-wp-efa',efa);
			xhr.setRequestHeader('content-length',postData.length);
			xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
			xhr.setRequestHeader('connection','close');
			xhr.send(postData);
			if(busyEle)
			{
				if(busyEle.bImgEle)
				{
					wp.hide(busyEle.bImgEle);
				}
				wp.hide(busyEle);
			}

			return wp.xhCancel(e);
		},
		xhCancel:function(e)
		{
			if(window.event)
			{
				window.event.cancelBubble = true;
				window.event.returnValue = false;
			}
			if(e && e.preventDefault && e.stopPropagation)
			{
				e.preventDefault();
				e.stopPropagation();
			}
			return false;
		},
		xhGetNewXMLHttpRequest:function()
		{
			if(wp.xhPcGetXMLHttpRequest)
			{
				return wp.xhPcGetXMLHttpRequest();
			}
			try
			{
				var nr = new XMLHttpRequest();
				wp.xhPcGetXMLHttpRequest = function()
				{
					return new XMLHttpRequest();
				}
				return nr;
			}
			catch(e){}
			try
			{
				var nr = new ActiveXObject("MSXML2.XMLHTTP");
				wp.xhPcGetXMLHttpRequest = function()
				{
					return new ActiveXObject("MSXML2.XMLHTTP");
				}
				return nr;
			}
			catch(e){}
			try
			{
				var nr = new ActiveXObject("Microsoft.XMLHTTP");
				wp.xhPcGetXMLHttpRequest = function()
				{
					return new ActiveXObject("Microsoft.XMLHTTP");
				}
				return nr;
			}
			catch(e){}

			// not supported by browser
			throw new Error('xhGetNewXMLHttpRequest.Failed', 'Browser does not provide XMLHttpRequest object.');
		},
		xhDisplayError:function(targetDivId, errorMsg)
		{
			var targetDiv = document.getElementById(targetDivId);
			if(targetDiv)
			{
				if(errorMsg)
				{
					targetDiv.wpErrorMsg = errorMsg;
				}
				targetDiv.innerHTML = "<a href=\"javascript:alert(document.getElementById('" + targetDivId + "').wpErrorMsg);\">Error</a>";
			}
		},
		busy:
		{
			delayMillis:1,
			defaultImageSrc:"//widgetpops.com/images/loader-horzDiag.gif",
			imagePadding:10,
			imageMinWidth:133,
			imageMinHeight:30,
			imageMaxWidth:320,
			imageMaxHeight:73,
			defaultOpacity:40,
			defaultImgOpacity:100,
			minTargetWidthReq:null,
			minTargetHeightReq:null,
			calcMinTargetDims:function()
			{
				if(!wp.busy.minTargetWidth)
				{
					wp.busy.minTargetWidthReq = wp.busy.imageMinWidth + (wp.busy.imagePadding * 2);
					wp.busy.minTargetHeightReq = wp.busy.imageMinHeight + (wp.busy.imagePadding * 2);
				}
			},
			display:function(targetEId, busyMessage)
			{
				wp.busy.calcMinTargetDims();
				var targetDiv = document.getElementById(targetEId);
				if(!targetDiv)
				{
					return null;
				}
				var bDivId = targetEId + 'Busy';
				targetDiv.wpbDivId = bDivId;
				var bDiv = document.getElementById(bDivId);

				targetDiv.wpBusyInit = function()
				{
					var targetDiv = this;
					var targetEId = targetDiv.id;
					var bDivId = targetDiv.wpbDivId;
										
					// get actual position of targetDiv
					var targetDivElementPosition = wp.getElementPosition(targetDiv);
					var targetDivLeft = targetDivElementPosition.left;
					var targetDivTop = targetDivElementPosition.top;

					// see if there is a custom style which we should use for the div and image
					if(!wp.busy.customDivRule)
					{
						wp.busy.customDivRule = wp.getCssRule('div.wploadprogressdiv');
					}
					if(!wp.busy.customImageRule)
					{
						wp.busy.customImageRule = wp.getCssRule('div.wploadprogressimage');
					}
					
					// create div now
					appendElement = false;
					if(!bDiv)
					{
						bDiv = document.createElement('div');
						appendElement = true;
						bDiv.id=bDivId;
						bDiv.style.position='absolute';
						bDiv.style.padding='0px';
						bDiv.style.margin='0px';
						wp.setStyle(bDiv,wp.busy.customDivRule,'background','lightblue');
						wp.setStyle(bDiv,wp.busy.customDivRule,'border','0px');
						var dOpacity = (wp.busy.defaultOpacity==100)?'1':(wp.busy.defaultOpacity/100)+'';
						wp.setStyle(bDiv,wp.busy.customDivRule,'opacity',dOpacity);
						wp.setStyle(bDiv,wp.busy.customDivRule,'filter',"alpha(opacity=" + wp.busy.defaultOpacity + ")");
						wp.setStyle(bDiv,wp.busy.customDivRule,'KhtmlOpacity',dOpacity);
						bDiv.onclick=function(){return false;};
					}
					bDiv.style.height=targetDiv.offsetHeight + 'px';
					bDiv.style.width=targetDiv.offsetWidth + 'px';
					bDiv.style.top=targetDivTop + 'px';
					bDiv.style.left=targetDivLeft + 'px';
					bDiv.style.display='block';
					bDiv.style.zoom=1;


					
					// 'loading' image
					var bImgEle = bDiv.bImgEle
					if(!bDiv.bImgEle)
					{
						bImgEle=document.createElement('img');
						var isrcc = '';
						if(wp.busy.customImageRule && wp.busy.customImageRule.style['fontFamily'])
						{
							var isrc=wp.busy.customImageRule.style['fontFamily'];
							if(isrc.substring(0,1)=='"')
							{
								// remove quotes
								isrcc=isrc.substring(1,isrc.length-1);
							}
							else
							{
								isrcc = isrc;
							}
						}
						if(isrcc.length > 0)
						{
							bImgEle.src=isrcc;
						}
						else
						{
							bImgEle.src=wp.busy.defaultImageSrc;
						}
						bImgEle.style.position='absolute';
						bImgEle.style.padding='0px';
						bImgEle.style.border='0px';
						bImgEle.style.display='none';
						dOpacity = (this.defaultImgOpacity==100)?'1':(this.defaultImgOpacity/100)+'';
						wp.setStyle(bImgEle,wp.busy.customImageRule,'opacity',dOpacity);
						wp.setStyle(bImgEle,wp.busy.customImageRule,'filter',"alpha(opacity=" + this.defaultImgOpacity + ")");
						wp.setStyle(bImgEle,wp.busy.customImageRule,'KhtmlOpacity',dOpacity);
						bImgEle.alt=busyMessage;
					}
					
					// maximize size of image to size of visible portion of div and proportionally
					bDiv.imgPadding=wp.busy.imagePadding;
					bDiv.ttlImagePading = bDiv.imgPadding * 2;
					bDiv.enoughRoomForImage = true;
					bDiv.bImgEle = bImgEle;
					targetDiv.bDiv = bDiv;
					targetDiv.bDiv.targetDivLeft = targetDivLeft;
					targetDiv.bDiv.targetDivTop = targetDivTop;
					bImgEle.iwt = 0;
					bImgEle.iwtMax = 100;
					var bImgEleId = bImgEle.id;
					if(appendElement)
					{
						document.body.appendChild(bDiv);
						document.body.appendChild(bImgEle);
					}
					setTimeout("{var targetDiv=document.getElementById('" + targetDiv.id + "');try{if(targetDiv){targetDiv.wpBusyWaitForImage();}}catch(e){}};",1);
				}
				
				targetDiv.wpBusyWaitForImage = function()
				{
					var targetDiv = this;
					var bDiv = this.bDiv;
					var bImgEle = bDiv.bImgEle;
					if(bImgEle != null)
					{
						if((bImgEle.fileSize && bImgEle.fileSize == 0) || (!bImgEle.fileSize && (bImgEle.width == 0 || bImgEle.height == 0)))
						{
							bImgEle.iwt++;
							if(bImgEle.iwt >= bImgEle.iwtMax)
							{
								// max times waiting
								return;
							}
							setTimeout("{var targetDiv=document.getElementById('" + targetDiv.id + "');try{if(targetDiv){targetDiv.wpBusyWaitForImage();}}catch(e){}};", 1);
						}
						else
						{
							setTimeout("{var targetDiv=document.getElementById('" + targetDiv.id + "');try{if(targetDiv){targetDiv.wpBusyDisplay();}}catch(e){}};",wp.busy.delayMillis);
						}
					}
				}
				
							
				targetDiv.wpBusyDisplay = function()
				{
					var targetDiv = this;
					var bDiv = this.bDiv;
					var bImgEle = bDiv.bImgEle;
					
					// was image loaded
					while(bImgEle != null && ((bImgEle.fileSize && bImgEle.fileSize == 0) || (!bImgEle.fileSize && (bImgEle.width == 0 || bImgEle.height == 0))))
					{
						// no image
						return;
					}
					wp.show(bDiv);
					if(bImgEle.fileSize)
					{
						// IE
						wp.show(bImgEle);
					}

					var vtd = wp.getRelativeDimensions(targetDiv);	// viewable relative target dimensions
					if(vtd.left == -1 || vtd.top == -1 || vtd.width < wp.busy.minTargetWidthReq || vtd.height < wp.busy.minTargetHeightReq)
					{
						// not enough room for image, just show overlay without image
						bDiv.enoughRoomForImage = false;
					}
					
					if(bDiv.enoughRoomForImage)// && bImgEle.width > 0 && bImgEle.height > 0)
					{
						var iw = 0;
						var ih = 0;
						var whp = bImgEle.width/bImgEle.height;
						var spacewh = (vtd.width-bDiv.ttlImagePading)/(vtd.height-bDiv.ttlImagePading);
						if(spacewh > whp)
						{
							// maximize to available vertical space - keep proportional
							ih = Math.min(wp.busy.imageMaxHeight, vtd.height - bDiv.ttlImagePading);
							iw = ih*whp;
							bImgEle.style.height = ih + 'px';
							bImgEle.style.width = iw + 'px';
						}
						else
						{
							// maximize to available horizontal space - keep proportional
							iw = Math.min(wp.busy.imageMaxWidth, vtd.width - bDiv.ttlImagePading);
							ih = iw/whp;
							bImgEle.style.width = iw + 'px';
							bImgEle.style.height = ih + 'px';
						}
						
						// center progress loading visual within visible section of target div
						var imgLeft= vtd.left + bDiv.imgPadding + Math.max(0,((vtd.width-iw-bDiv.ttlImagePading)/2));
						var imgTop = vtd.top + bDiv.imgPadding + Math.max(0,((vtd.height-ih-bDiv.ttlImagePading)/2));
						bImgEle.style.top=(bDiv.targetDivTop + imgTop) + 'px';
						bImgEle.style.left=(bDiv.targetDivLeft + imgLeft) + 'px';
						
						// ensure layer tracker inited
						if(!window['highestBusyZ'])
						{
							window['highestBusyZ'] = 200;
						}
						bDiv.style.zIndex = window['highestBusyZ'];
						window['highestBusyZ'] += 1;
						bImgEle.style.zIndex = window['highestBusyZ'];
						window['highestBusyZ'] += 1;

						wp.show(bImgEle);
					}
				}
				setTimeout("{var targetDiv=document.getElementById('" + targetEId + "');try{if(targetDiv){targetDiv.wpBusyInit();}}catch(e){}};",wp.busy.delayMillis);
				return bDivId;
			},
			needsScrolling:function(targetEId)
			{
				// returns true if the targetDiv is scrolled too far out of view to present the busy image
				this.calcMinTargetDims();
				var targetDiv = document.getElementById(targetEId);
				if(!targetDiv)
				{
					return false;
				}
				var vtd = wp.getRelativeDimensions(targetDiv);	// viewable relative target dimensions
				if(vtd.left == -1 || vtd.top == -1 || vtd.width < wp.busy.minTargetWidthReq || vtd.height < wp.busy.minTargetHeightReq)
				{
					return true;
				}
				return false;
			}
		},
		form:
		{
			getURLEncodedContents:function(formobj)
			{
				var ec = '';
				if(formobj == null)
				{
					return ec;
				}
				if(formobj.elements == null)
				{
					// maybe they passed in an id to a form instead of a form object
					var iformobj = document.getElementById(formobj);
					if(iformobj == null)
					{
						return ec;
					}
					formobj = iformobj;
				}
				var felements = new Array();
				wp.form.getFormElements(formobj, felements);
				var flen = felements.length;
				for (i = 0; i < flen; i++)
				{
					var fe = felements[i];
					var t = fe.type.toLowerCase();
					if((t == 'text' || t == 'textarea' || t == 'password' || t == 'hidden')
					|| ((t == 'checkbox' || t == 'radio') && fe.checked)
					|| (t == 'submit' && fe.name.toLowerCase()=='input' && fe.attributes['wasClicked'])
					)
					{
						ec += (ec!=''?'&':'') + encodeURIComponent(fe.name) + '=' + encodeURIComponent(fe.value);
					}
					else if(t.substring(0,6) == 'select')
					{
			 			for(var si = 0; si < fe.options.length; si++)
						{
							if(fe.options[si].selected)
							{
								ec += (ec!=''?'&':'') + encodeURIComponent(fe.name) + '=' + encodeURIComponent(fe.options[si].value);
							}
						}
					}
			 	}
				return ec;
			},
			getEhdfEncodedContents:function(formobj, incl)
			{
				var ec = wp.ehdf.namedGroup('pd');
				if(incl != null)
				{
					ec += incl;
				}
				if(formobj == null)
				{
					return ec + wp.ehdf.endGroup();
				}
				if(formobj.elements == null)
				{
					// maybe they passed in an id to a form instead of a form object
					var iformobj = document.getElementById(formobj);
					if(iformobj == null)
					{
						return ec + wp.ehdf.endGroup();
					}
					formobj = iformobj;
				}
				var felements = new Array();
				wp.form.getFormElements(formobj, felements);
				var flen = felements.length;
				for (i = 0; i < flen; i++)
				{
					var fe = felements[i];
					var t = fe.type.toLowerCase();
					if((t == 'text' || t == 'textarea' || t == 'password' || t == 'hidden')
					|| ((t == 'checkbox' || t == 'radio') && fe.checked)
					|| (t == 'submit' && fe.value == formobj.submittedButtonValue)
					)
					{
						ec += wp.ehdf.namedValue(fe.name,fe.value);
					}
					else if(t.substring(0,6) == 'select')
					{
			 			for(var si = 0; si < fe.options.length; si++)
						{
							if(fe.options[si].selected)
							{
								ec += wp.ehdf.namedValue(fe.name,fe.options[si].value);
							}
						}
					}
			 	}
				return ec + wp.ehdf.endGroup();
			},
			getFormElements:function(formobj, destArray)
			{
				// returns an array of the input-type elements within a form, looking inside of fieldset tags as well
				var elems = formobj.elements;
				if(!elems || elems == null)
				{
					elems = formobj;
				}
				var ec = elems.length;
				for(var i = 0; i < ec; i++)
				{
					if(elems[i].type)
					{
						destArray.push(elems[i]);
					}
					else
					{
						// recurse to check inner elements for input-type elements
						wp.form.getFormElements(elems[i], destArray);
					}
				}
			}
		},
		setStyle:function(e,cssRule,eProp,defaultValue)
		{
			// set the style s of element e to that found in cssRule or to defaultValue
			if(cssRule && cssRule.style[eProp])
			{
				e.style[eProp] = cssRule.style[eProp];
			}
			else
			{
				e.style[eProp] = defaultValue;
			}
		},		
		getCssRule:function(ruleName)
		{
			// search through sheets and return first found matching rule (lowercase match to deal with uppercase conversion which IE does)
			var lcRuleName = ruleName.toLowerCase();
			for(s = 0; s < document.styleSheets.length; s++)
			{
				var sheet = document.styleSheets[s];
				var rules = null;
				try
				{
					rules = sheet.cssRules?sheet.cssRules:sheet.rules;
				}
				catch(accessException)
				{
					// external style sheet
					rules = null;
				}
				if(rules != null)
				{
					// search through rules
					for(i = 0; i < rules.length; i++)
					{
						if(rules[i].selectorText && rules[i].selectorText.toLowerCase() == lcRuleName)
						{
							return rules[i];
						}
					}
				}
			}
			return null;
		},
		getRelativeDimensions:function(e)
		{
			// return the visible dimentions relative to the inside of element e
			var winScroll = wp.getWinScrollXY();
			var winDim = wp.getWinDimensionsXY();
			var scrollBarAllowance = 15;
			var ril = 0;
			var rit = 0;
			var riw = 0;
			var rih = 0;
			
			// Relative Inside Left - viewable left relative to inside of target
			var ril = 0;
			var trueEPos = wp.getElementPosition(e);
			if(winScroll.x > trueEPos.left)
			{
				// left of box is scrolled left out of view
				ril = wp.getWinScrollXY().x - trueEPos.left;
				if(ril > e.offsetWidth)
				{
					// entire box is scrolled left out of site
					ril = -1;
				}
			}
			else
			{
				if(winScroll.x + winDim.x - scrollBarAllowance < trueEPos.left)
				{
					// entire box is scrolled right out of site
					ril = -1;
				}
			}
			if(ril==-1)return{left:ril, top:rit, width:riw, height:rih};
			
			// Relative Inside Top - viewable top relative to inside of target
			var rit = 0;
			if(winScroll.y > trueEPos.top)
			{
				// top of box is scrolled upward out of view
				rit = wp.getWinScrollXY().y - trueEPos.top;
				if(rit > e.offsetHeight)
				{
					// entire box is scrolled upward out of site
					rit = -1;
				}
			}
			else
			{
				if(winScroll.y + winDim.y - scrollBarAllowance < trueEPos.top)
				{
					// entire box is scrolled downward out of site
					rit = -1;
				}
			}
			if(rit==-1)return{left:ril, top:rit, width:riw, height:rih};
			
			// get Relative visible width
			riw = e.offsetWidth - ril;
			var absTRightEdge = trueEPos.left + e.offsetWidth;
			var absVisibleRightEdge = (winScroll.x + winDim.x) - scrollBarAllowance;
			if(absTRightEdge > absVisibleRightEdge)
			{
				// right edge hidden
				riw = e.offsetWidth - ril - (absTRightEdge - absVisibleRightEdge);
			}

			// get Relative visible height
			rih = e.offsetHeight - rit;
			var absTBottomEdge = trueEPos.top + e.offsetHeight;
			var absVisibleBottomEdge = (winScroll.y + winDim.y) - scrollBarAllowance;
			if(absTBottomEdge > absVisibleBottomEdge)
			{
				// bottom edge hidden
				rih = e.offsetHeight - rit - (absTBottomEdge - absVisibleBottomEdge);
			}
			return{left:ril, top:rit, width:riw, height:rih};
		},
		getWinScrollXY:function()
		{
			var scrOfX = 0;
			var scrOfY = 0;
			if(typeof(window.pageYOffset) == 'number')
			{
				// Netscape
				scrOfY = window.pageYOffset;
				scrOfX = window.pageXOffset;
			} 
			else if(document.body && document.body.scrollTop)
			{
				// DOM
				scrOfY = document.body.scrollTop;
				scrOfX = document.body.scrollLeft;
			} 
			else if(document.documentElement && document.documentElement.scrollTop)
			{
				//IE6
				scrOfY = document.documentElement.scrollTop;
				scrOfX = document.documentElement.scrollLeft;
			}
			return {x:scrOfX, y:scrOfY};
		},
		getWinDimensionsXY:function()
		{
			var wx = 0;
			var wy = 0;
			if(typeof(window.innerWidth) == 'number')
			{
				wx = window.innerWidth;
				wy = window.innerHeight;
			}
			else if(document.documentElement && document.documentElement.clientHeight)
			{
				wx = document.documentElement.clientWidth;
				wy = document.documentElement.clientHeight;
			}
			else if(document.body && document.body.clientHeight)
			{
				wx = document.body.clientWidth;
				wy = document.body.clientHeight;
			}
			return {x:wx, y:wy};
		},
		scrollWinToElement:function(e)
		{
			var curE = e;
			var eX = 0;
			var eY = 0;
			while(curE != null)
			{
				eX += curE.offsetLeft;
				eY += curE.offsetTop;
				curE = curE.offsetParent;
			}
			window.scrollTo(eX,eY);
		},
		getElementPosition:function(e)
		{
			var lpos = 0;
			var tpos = 0;
			if(e.offsetParent)
			{
			    while(e) 
			    {
			        lpos += e.offsetLeft;
			        tpos += e.offsetTop;
			        e = e.offsetParent;
			    }
			}
			else if(e.x || e.y)
			{
			    if(e.x)lpos += e.x;
			    if(e.y)tpos += e.y;
			}
			return {left:lpos, top:tpos};
		},
		show:function(e)
		{
			if(e && e.style)
			{
				if(e.wp_styleForShowing)
				{
					// show using required style for showing
					e.style.display = e.wp_styleForShowing;
				}
				else if(e.style.display && e.style.display != 'none')
				{
					// already shown,  save the style we need to show this element
					e.wp_styleForShowing = e.style.display;
				}
				else
				{
					// default to block
					e.style.display = 'block';
				}
			}
		},
		hide:function(e)
		{
			if(e && e.style)
			{
				if(!e.wp_styleForShowing && e.style.display && e.style.display != 'none')
				{
					// save the style we need to show this element
					e.wp_styleForShowing = e.style.display;
				}
				// hide
				e.style.display = 'none';
			}
		},
		// forceStateTo can be undefined, or 's' for show, or 'h' for hide
		toggleDisplay:function(e,forceStateTo)
		{
			if(e && e.style)
			{
				if(forceStateTo == 't')
				{
					wp.show(e);
				}
				else if(forceStateTo == 'f')
				{
					wp.hide(e);
				}
				else if(!e.style.display || e.style.display == 'none')
				{
					// currently hidden, show now
					wp.show(e);
				}
				else 
				{
					// currently visible, hide now
					wp.hide(e);
				}
			}
		},
		// pass in opacity as a number from 0 to 100
		setOpacity:function(e, opacity)
		{
			var dOpacity = (opacity==100)?1:(opacity/100);
			e.style.opacity = dOpacity;
			e.style.filter = "alpha(opacity=" + opacity + ")";
			e.style.MozOpacity = dOpacity;
			e.style.KhtmlOpacity = dOpacity;
		},
		js:
		{
			libs:[],
			evalLib:function(libId, srcUrl)
			{
				// Loads if needed, then evals a js library
				var protoAndDomain = window.location.protocol + '://' + window.location.host;
				if(srcUrl && (srcUrl.indexOf('http://') == 0 || srcUrl.indexOf('https://') == 0) && !srcUrl.indexOf(protoAndDomain) == 0)
				{
					// External js. Can't retrieve using xmlhttp. Add to head.
					var scriptNode = document.createElement('script');
					scriptNode.type = 'text/javascript';
					scriptNode.src = srcUrl;
					document.getElementsByTagName('head')[0].appendChild(scriptNode);
					return;
				}
				if(!wp.js.libs[libId] && srcUrl)
				{
					// need to load
					var xhr=wp.xhGetNewXMLHttpRequest();
					xhr.open('GET', srcUrl, false);
					xhr.send(null);
					if(xhr.status == 200)
					{
						wp.js.libs[libId] = xhr.responseText;
					}
					else
					{
						alert('Error retrieving: ' + srcUrl + ': ' + xhr.status + ' ' + xhr.statusText);
					}
				}
				if(wp.js.libs[libId])
				{
					setTimeout("eval(wp.js.libs['" + libId + "'])",1);
				}
			},
			loadStyle:function(libId, media, srcUrl)
			{
				if(!wp.js.libs[libId])
				{
					wp.js.libs[libId]='loaded';
					var cssNode = document.createElement('link');
					cssNode.type = 'text/css';
					cssNode.rel = 'stylesheet';
					cssNode.media = media;
					cssNode.title = libId;
					cssNode.href = srcUrl;
					cssNode.id = libId;
					document.getElementsByTagName('head')[0].appendChild(cssNode);
				}
			},
			libKeysAsEhdf:function()
			{
				// return the currently loaded Js/Css Library Keys
				rtn = wp.ehdf.namedGroup("lk");
				if(wp.js.libs && wp.js.libs.length > 0)
				{
					for(var i in wp.js.libs)
					{
						wp.ehdf.value(i);
					}
				}
				rtn += wp.ehdf.endGroup();
				return rtn;
			}
		},
		ehdf:
		{
			// Efficient Hierarchical Data Format (EHDF)
			// Patent Pending.
			namedGroup:function(groupName)
			{
				return '{' + wp.ehdf.lpBlock(groupName);
			},
			endGroup:function()
			{
				return ')';
			},
			namedValue:function(name, val)
			{
				return 'N' + wp.ehdf.lpBlock(name) + wp.ehdf.lpBlock(val);
			},
			value:function(val)
			{
				return 'V' + wp.ehdf.lpBlock(val);
			},
			lpBlock:function(bytes)
			{
				return wp.ehdf.lengthPrefix(bytes.length) + bytes;
			},
			lengthPrefix:function(len)
			{
				var lenstr = "" + len;
				return String.fromCharCode(lenstr.length) + lenstr;
			}
		}
		/*
		,util:
		{
			// generate a stack trace. Author: Eric Wendelin? . From: http://ajaxian.com/archives/getting-a-javascript-stracktrace-in-any-browser
			getStackTrace:function(e)
			{
				var mode = e.stack ? 'Firefox' : window.opera ? 'Opera' : 'Other';
				switch (mode)
				{
					case 'Firefox' : return function()
					{
						try {(0)()} catch (e)
						{
							return e.stack.replace(/^.*?\n/,'').replace(/(?:\n@:0)?\s+$/m,'').replace(/^\(/gm,'{anonymous}(').split("\n");
						}
					};
					case 'Opera' : return function()
					{
						try {(0)()} catch(e)
						{
							var lines = e.message.split("\n"),
							ANON = '{anonymous}',
							lineRE = /Line\s+(\d+).*?in\s+(http\S+)(?:.*?in\s+function\s+(\S+))?/i,
							i,j,len;
							for (i=4,j=0,len=lines.length; i<len; i+=2)
							{
								if (lineRE.test(lines[i]))
								{
									lines[j++] = (RegExp.$3 ? RegExp.$3 + '()@' + RegExp.$2 + RegExp.$1 : ANON + RegExp.$2 + ':' + RegExp.$1) + ' -- ' + lines[i+1].replace(/^\s+/,'');
								}
							}
							lines.splice(j,lines.length-j);
							return lines;
						}
					};
					default : return function()
					{
						var curr = arguments.callee.caller,
						FUNC  = 'function', ANON = "{anonymous}",
						fnRE  = /function\s*([\w\-$]+)?\s*\(/i,
						stack = [],j=0,
						fn,args,i;
						while (curr)
						{
							fn = fnRE.test(curr.toString()) ? RegExp.$1 || ANON : ANON;
							args = stack.slice.call(curr.arguments);
							i = args.length;
							while (i--)
							{
								switch (typeof args[i])
								{
									case 'string': 
										args[i] = '"' + args[i].replace(/"/g,'\\"') + '"'; 
										break;
									case 'function':
										args[i] = FUNC;
										break;
								}
							}
							stack[j++] = fn + '(' + args.join() + ')';
							curr = curr.caller;
						}
						return stack;
					};
				}
			}
		}*/
	}
}
