var MaxWordsPerLine = 60, MaxLinesPerPage = 15, DropMenuHeight = 220;
var myDropMenu_show_flag = 0, ClickModeMenu = 0;
var ELEMENT   = (document.compatMode == "CSS1Compat") ? "document.documentElement" : "document.body";
var PID = " progid:DXImageTransform.Microsoft."
var TransitionNumber   = 48;
var TransitionDuration = 0.3;
var TransparencyLevel  = 0;
var ShadowType         = 2;
var ShadowColor        = "";
var TempImage	       = null;
var MenuImage          = [{inuse:0,id:'mm_about',A:'_nusoft_about.gif',B:'nusoft_about_.gif'},{inuse:0,id:'mm_product',A:'_nusoft_product.gif',B:'nusoft_product_.gif'},{inuse:0,id:'mm_download',A:'_nusoft_download.gif',B:'nusoft_download_.gif'},{inuse:0,id:'mm_tutorials',A:'_nusoft_tutorials.gif',B:'nusoft_tutorials_.gif'},{inuse:0,id:'mm_bot',A:'_nusoft_bot.gif',B:'nusoft_bot_.gif'},{inuse:0,id:'mm_demo',A:'_nusoft_demo.gif',B:'nusoft_demo_.gif'},{inuse:0,id:'mm_language',A:'_nusoft_language.gif',B:'nusoft_language_.gif'}];
var Location           = "";

var myDropMenu = {
	DisappearDelay: 250,
	MyDropMenuObj: null, 
	IE: document.all, 
	Firefox: document.getElementById && !document.all,
	GetPositionOffset:function (what, offsettype) {
		var totaloffset = (offsettype == "left") ? what.offsetLeft : what.offsetTop;
		var parentEl = what.offsetParent;
		while (parentEl != null) {
			totaloffset = (offsettype =="left") ? (totaloffset + parentEl.offsetLeft) : (totaloffset + parentEl.offsetTop);
			parentEl = parentEl.offsetParent;
		}
		return totaloffset;
	},

	ShowHideSwitch:function (obj, e, visible, hidden) {
		if (this.IE || this.Firefox)
			this.MyDropMenuObj.style.left = this.MyDropMenuObj.style.top = "-500px";

		if (ClickModeMenu)
			obj.style.visibility = visible;
		else {
			if ((e.type == "click") && (obj.style.visibility == hidden) || (e.type =="mouseover"))
				obj.style.visibility = visible;
			else if (e.type =="click")
				obj.style.visibility = hidden;
		}
	},

	IE_Compat_Test:function () {
		return ((document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body);
	},

	ClearBrowserEdge:function (obj, whichedge) {
		var edgeoffset = 0;
		if (whichedge == "rightedge") {
			var windowedge = this.IE && !window.opera ? (this.IE_Compat_Test().scrollLeft + this.IE_Compat_Test().clientWidth - 15) : (window.pageXOffset + window.innerWidth - 15);
			this.MyDropMenuObj.contentmeasure=this.MyDropMenuObj.offsetWidth;
			if ((windowedge - this.MyDropMenuObj.x) < this.MyDropMenuObj.contentmeasure)
				edgeoffset = (this.MyDropMenuObj.contentmeasure - obj.offsetWidth);
		} else {
			var topedge = this.IE && !window.opera ? this.IE_Compat_Test().scrollTop : window.pageYOffset;
			var windowedge = this.IE && !window.opera ? (this.IE_Compat_Test().scrollTop + this.IE_Compat_Test().clientHeight - 15) : (window.pageYOffset + window.innerHeight - 18);
			this.MyDropMenuObj.contentmeasure = this.MyDropMenuObj.offsetHeight;
			if ((windowedge - this.MyDropMenuObj.y) < this.MyDropMenuObj.contentmeasure) {
				edgeoffset = (this.MyDropMenuObj.contentmeasure + obj.offsetHeight);
				if ((this.MyDropMenuObj.y - topedge) < this.MyDropMenuObj.contentmeasure)
					edgeoffset = (this.MyDropMenuObj.y + obj.offsetHeight - topedge);
			}
		}
		return edgeoffset;
	},

	StartDrop:function (obj, e, dropmenuID) {
		myDropMenu_show_flag = 1;
		if (this.MyDropMenuObj != null) {
			this.MyDropMenuObj.style.visibility = "hidden";
			this.ClearHideMenu();
		}
		if (this.IE || this.Firefox) {
			obj.onmouseout = function() { myDropMenu.DelayHideMenu(); myDropMenu.changeBG('m'+dropmenuID, ""); };
			this.MyDropMenuObj = document.getElementById(dropmenuID);
			this.MyDropMenuObj.onmouseover = function() { myDropMenu.ClearHideMenu() };
			this.MyDropMenuObj.onmouseout = function() { myDropMenu.DynamicHide(e) };
			this.MyDropMenuObj.onclick = function() { myDropMenu.DelayHideMenu() };

			if (this.IE) {
				this.MyDropMenuObj.style.filter = "revealTrans()"+PID+"Fade(Overlap=2.0 enabled=0)"+PID+"Inset(enabled=0)"+PID+"Iris(irisstyle=PLUS,motion=in enabled=0)"+PID+"Iris(irisstyle=PLUS,motion=out enabled=0)"+PID+"Iris(irisstyle=DIAMOND,motion=in enabled=0)"+PID+"Iris(irisstyle=DIAMOND,motion=out enabled=0)"+PID+"Iris(irisstyle=CROSS,motion=in enabled=0)"+PID+"Iris(irisstyle=CROSS,motion=out enabled=0)"+PID+"Iris(irisstyle=STAR,motion=in enabled=0)"+PID+"Iris(irisstyle=STAR,motion=out enabled=0)"+PID+"RadialWipe(wipestyle=CLOCK enabled=0)"+PID+"RadialWipe(wipestyle=WEDGE enabled=0)"+PID+"RadialWipe(wipestyle=RADIAL enabled=0)"+PID+"Pixelate(MaxSquare=35,enabled=0)"+PID+"Slide(slidestyle=HIDE,Bands=25 enabled=0)"+PID+"Slide(slidestyle=PUSH,Bands=25 enabled=0)"+PID+"Slide(slidestyle=SWAP,Bands=25 enabled=0)"+PID+"Spiral(GridSizeX=16,GridSizeY=16 enabled=0)"+PID+"Stretch(stretchstyle=HIDE enabled=0)"+PID+"Stretch(stretchstyle=PUSH enabled=0)"+PID+"Stretch(stretchstyle=SPIN enabled=0)"+PID+"Wheel(spokes=16 enabled=0)"+PID+"GradientWipe(GradientSize=1.00,wipestyle=0,motion=forward enabled=0)"+PID+"GradientWipe(GradientSize=1.00,wipestyle=0,motion=reverse enabled=0)"+PID+"GradientWipe(GradientSize=1.00,wipestyle=1,motion=forward enabled=0)"+PID+"GradientWipe(GradientSize=1.00,wipestyle=1,motion=reverse enabled=0)"+PID+"Zigzag(GridSizeX=8,GridSizeY=8 enabled=0)"+PID+"Alpha(enabled=0)"+PID+"Dropshadow(OffX=3,OffY=3,Positive=true,enabled=0)"+PID+"Shadow(strength=3,direction=135,enabled=0)";


				if (TransitionNumber == 51)
					TransitionNumber = parseInt(Math.random()*50);

				var theTransition1 = ((TransitionNumber > -1) && (TransitionNumber < 24) && (TransitionDuration > 0));
				var theTransition2 = ((TransitionNumber > 23) && (TransitionNumber < 51) && (TransitionDuration > 0));
				var theTransitionElement = this.MyDropMenuObj.filters[theTransition2 ? (TransitionNumber - 23) : 0];

				for (var i = 28; i < 31; i++) {
					this.MyDropMenuObj.filters[i].enabled=0;
				}

				for (var j = 0 ; j < 28; j++) {
					if (this.MyDropMenuObj.filters[j].status)
						this.MyDropMenuObj.filters[j].stop();
				}

				for (var k = 1; k < 3; k++) {
					if (ShadowColor && (ShadowType == k)) {
						with (this.MyDropMenuObj.filters[28 + k]) {
							enabled = 1;
							color   = ShadowColor;
						}
					}
				}

				if ((TransparencyLevel > 0) && (TransparencyLevel < 100)) {
					with (obj.filters[28]) {
						enabled = 1;
						opacity = TransparencyLevel;
					}
				}

				if (theTransition1 || theTransition2) {
					if (theTransition1)
						obj.filters[0].transition = TransitionNumber;
					theTransitionElement.duration = TransitionDuration;
					theTransitionElement.apply();
				}
			}
			
			this.ShowHideSwitch(this.MyDropMenuObj, e, "visible", "hidden");

			if (this.IE) {
				if (theTransition1 || theTransition2)
					theTransitionElement.play();
			}

			this.MyDropMenuObj.x = this.GetPositionOffset(obj, "left");
			this.MyDropMenuObj.y = this.GetPositionOffset(obj, "top");
			this.MyDropMenuObj.style.left = (this.MyDropMenuObj.x - this.ClearBrowserEdge(obj, "rightedge") + "px");
			this.MyDropMenuObj.style.top  = (this.MyDropMenuObj.y - this.ClearBrowserEdge(obj, "bottomedge") + obj.offsetHeight + 1 + (this.IE ? 0 : 10) + "px");
		}
	},

        changeBG:function(imageID, location) {
		if (location.length) {
		    if (!Location.length)
			Location = location;
		}

		if ((document.getElementById(imageID) != null) && (Location.length > 0)) {
		    for (var i = 0; i < MenuImage.length; i++) {
		        if (MenuImage[i].inuse)
			    document.getElementById(MenuImage[i].id).src = Location+MenuImage[i].A;
		    }
		    for (var i = 0; i < MenuImage.length; i++) {
			if (imageID == MenuImage[i].id) {
			    if (!MenuImage[i].inuse) {
                                document.getElementById(MenuImage[i].id).src = Location+MenuImage[i].B;
                                MenuImage[i].inuse = 1;
                            } else {
                                document.getElementById(MenuImage[i].id).src = Location+MenuImage[i].A;
                                MenuImage[i].inuse = 0;
                            }
			    break;
			}
		    }
		}
        },

	contains_Firefox:function(a, b) {
		while (b.parentNode)
			if ((b = b.parentNode) == a)
				return true;
		return false;
	},

	DynamicHide:function(e) {
		var evtobj = window.event ? window.event : e;
		if (this.IE && !this.MyDropMenuObj.contains(evtobj.toElement))
			this.DelayHideMenu();
		else if (this.Firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_Firefox(evtobj.currentTarget, evtobj.relatedTarget))
			this.DelayHideMenu();
	},

	DelayHideMenu:function() {
		myDropMenu_show_flag = 0;
		this.delayhide = setTimeout("myDropMenu.MyDropMenuObj.style.visibility = 'hidden'",this.DisappearDelay);
	},

	ClearHideMenu:function() {
		if (this.delayhide!="undefined")
			clearTimeout(this.delayhide);
	}
}

function SetMyDropMenu(FrameID, FrameWidth)
{
        var ObjFrame = document.getElementById(FrameID);
	ObjFrame.style.width = FrameWidth+'px';
}

function SetMyDropMenuSize(CurrentLineNum, CurrentMaxWords, FrameID, TbID) 
{
	var ObjFrame = document.getElementById(FrameID);
	var ObjTb = document.getElementById(TbID);
	var NewWidth = (parseInt(CurrentMaxWords, 10) > MaxWordsPerLine) ? (MaxWordsPerLine * 10) : (parseInt(CurrentMaxWords, 10) * 10);
	var NewHeight = (parseInt(CurrentLineNum, 10) > MaxLinesPerPage) ? (MaxLinesPerPage * 20) : (parseInt(CurrentMaxWords, 10) * 20);
//	alert('Width:'+NewWidth+'  Height:'+NewHeight);
	if (parseInt(CurrentLineNum, 10) > MaxLinesPerPage)
		ObjFrame.style.height = NewHeight;
	ObjFrame.style.width = NewWidth;
	ObjTb.style.width = '100%';
	return;
}
