function GXMenu()
{
	this.Data;
	this.SelectedItem;
	this.Width;
	this.Height;
	this.Type;
	this.DropDownTabsStyle;

	// Databinding for property Data
	this.SetData = function(data)
	{
		///UserCodeRegionStart:[SetData] (do not remove this comment.)
		this.Data = data;
		///UserCodeRegionEnd: (do not remove this comment.)
	}

	// Databinding for property Data
	this.GetData = function()
	{
		///UserCodeRegionStart:[GetData] (do not remove this comment.)
		return this.Data;
		///UserCodeRegionEnd: (do not remove this comment.)
	}

	// Databinding for property SelectedItem
	this.SetSelectedItem = function(data)
	{
		///UserCodeRegionStart:[SetSelectedItem] (do not remove this comment.)
		this.SelectedItem = data;
		///UserCodeRegionEnd: (do not remove this comment.)
	}

	// Databinding for property SelectedItem
	this.GetSelectedItem = function()
	{
		///UserCodeRegionStart:[GetSelectedItem] (do not remove this comment.)
		return this.SelectedItem;
		///UserCodeRegionEnd: (do not remove this comment.)
	}

	this.show = function()
	{
		///UserCodeRegionStart:[show] (do not remove this comment.)
		if (!this.IsPostBack)
		{
			this.InitializeGXMenu();
		}
		///UserCodeRegionEnd: (do not remove this comment.)
	}
	///UserCodeRegionStart:[User Functions] (do not remove this comment.)
	
	this.InitializeGXMenu = function(){
		var file = "";
		var staticDir = gx.staticDirectory.substring(1, gx.staticDirectory.length);	
		switch (this.Type) {
			case "1": //dolphin
				file = "GXMenu/dolphin/dolphin.css";
				this.loadResource(gx.util.resourceUrl(staticDir + file, true), "css", this.CreateDelegate(this, this.OnResourcesLoaded));
				file = "GXMenu/dolphin/dolphin.js";
				this.loadResource(gx.util.resourceUrl(staticDir + file, true), "js", this.CreateDelegate(this, this.OnResourcesLoaded));
				break;
			case "2": //dropdowntabs
				file = "GXMenu/dropdowntabs/DropDownTabsMenu.css";
				this.loadResource(gx.util.resourceUrl(staticDir + file, true), "css", this.CreateDelegate(this, this.OnResourcesLoaded));
				file = "GXMenu/dropdowntabs/dropdowntabs.js";
				this.loadResource(gx.util.resourceUrl(staticDir + file, true), "js", this.CreateDelegate(this, this.OnResourcesLoaded));
				break;
			case "3": //slidedown
				file = "GXMenu/slidedown/sdmenu.css";
				this.loadResource(gx.util.resourceUrl(staticDir + file, true), "css", this.CreateDelegate(this, this.OnResourcesLoaded));
				file = "GXMenu/slidedown/sdmenu.js";
				this.loadResource(gx.util.resourceUrl(staticDir + file, true), "js", this.CreateDelegate(this, this.OnResourcesLoaded));
				break;
			case "4": //smooth multi level
				file = "GXMenu/smoothmultilevel/ddsmoothmenu.css";
				this.loadResource(gx.util.resourceUrl(staticDir + file, true), "css", null);
				file = "GXMenu/smoothmultilevel/ddsmoothmenu-v.css";
				this.loadResource(gx.util.resourceUrl(staticDir + file, true), "css", null);
				file = "GXMenu/smoothmultilevel/jquery.1.2.6.min.js";
				this.loadResource(gx.util.resourceUrl(staticDir + file, true), "js", null);
				file = "GXMenu/smoothmultilevel/ddsmoothmenu.js";
				this.loadResource(gx.util.resourceUrl(staticDir + file, true), "js", this.CreateDelegate(this, this.OnResourcesLoaded));
				break;
			default:
				file = "GXMenu/dolphin/dolphin.css";
				this.loadResource(gx.util.resourceUrl(staticDir + file, true), "css", this.CreateDelegate(this, this.OnResourcesLoaded));
				file = "GXMenu/dolphin/dolphin.js";
				this.loadResource(gx.util.resourceUrl(staticDir + file, true), "js", this.CreateDelegate(this, this.OnResourcesLoaded));
		}
	}
	
	this.loadResource = function(filename, filetype, callback) {
		if (filetype == "js") {
            var fileref = document.createElement('script')
            fileref.setAttribute("type", "text/javascript")
            fileref.setAttribute("src", filename)
        }else{ //if filename is an external CSS file
            var fileref = document.createElement("link")
            fileref.setAttribute("rel", "stylesheet")
            fileref.setAttribute("type", "text/css")
            fileref.setAttribute("href", filename)
        }
		if (typeof fileref != "undefined") {
            fileref.onreadystatechange = function() {
                if (this.readyState == 'loaded' || this.readyState == 'complete') 
					if (typeof(callback) == 'function') {
						callback();
					}
            }
            fileref.onload = callback;
            document.getElementsByTagName("head")[0].appendChild(fileref)
        }
	}
	
	this.CreateDelegate = function(obj, method, args, appendArgs) {
        return function() {
            var callArgs = args || arguments;
            if (appendArgs === true) {
                callArgs = Array.prototype.slice.call(arguments, 0);
                callArgs = callArgs.concat(args);
            } else if (typeof appendArgs == "number") {
                callArgs = Array.prototype.slice.call(arguments, 0);
                var applyArgs = [appendArgs, 0].concat(args);
                Array.prototype.splice.apply(callArgs, applyArgs);
            }
            return method.apply(obj || window, callArgs);
        };
    }
	
	var _mThis = this;
	
	this.OnResourcesLoaded = function(){
		var buffer = new gx.text.stringBuffer();
		buffer.clear();
		switch (_mThis.Type) {
			case "1": //dolphin
				buffer = _mThis.renderDolphin();
				break;
			case "2": //dropdowntabs
				buffer = _mThis.renderDropDownTabs();
				break;
			case "3": //slidedown
				buffer = _mThis.renderSlideDown();
				break;
			case "4": //smooth multi level
				buffer = _mThis.renderSmoothMultilevel();
				break;
			default: //dolphin
				buffer = _mThis.renderDolphin();
		}
		_mThis.getContainerControl().innerHTML = buffer.toString();
		switch (_mThis.Type) {
			case "1":
				buffer = _mThis.initDolphin();
				break;
			case "2":
				buffer = _mThis.initDropDownTabs();
				break;
			case "3":
				buffer = _mThis.initSlideDown();
				break;
			case "4":
				buffer = _mThis.initSmoothMultilevel();
				break;
			default:
				buffer = _mThis.initDolphin();
		}
	}
	
	this.renderDolphin = function(){
		var tmpbuffer = new gx.text.stringBuffer();
		tmpbuffer.clear();
		tmpbuffer.append('<div id="dolphincontainer">'); //open main dolphin container
		tmpbuffer.append('<div id="dolphinnav">');
		tmpbuffer.append('<ul>');
		var i = 0;
		for (i=0;this.Data[i]!=undefined;i++)
		{
			var _item = this.Data[i];
			
			tmpbuffer.append('<li><a href="' + (this.Data[i].Link!=""?this.Data[i].Link:'#') + '" rel="' + this.Data[i].Description + '" onclick="' + this.me() + '.GXMenuOnClick(' + i + ',' + null + ');" title="' + this.Data[i].Description + '"><span>' + this.Data[i].Title + '</span></a></li>');
		}
		tmpbuffer.append('</ul>');
		tmpbuffer.append('</div>');
		tmpbuffer.append('<div id="dolphin_inner">');
		for (i=0;this.Data[i]!=undefined;i++)
		{
			tmpbuffer.append('<div id="' + this.Data[i].Description + '" class="innercontent">' + this.Data[i].Description + '</div>');
		}
		tmpbuffer.append('</div>');
		tmpbuffer.append('</div>'); //close main dolphin container
		return tmpbuffer;
	}
	
	this.initDolphin = function(){
		if(getCookie('"' + this.ContainerName + '"') == null){
			dolphintabs.init("dolphinnav", 0);	
		}else{
			dolphintabs.init("dolphinnav", parseInt(getCookie('"' + this.ContainerName + '"')));		
		}
	}
	
	this.renderSmoothMultilevel = function(){
		var _mClass = this.Orientation=="h"?_mClass="ddsmoothmenu":_mClass="ddsmoothmenu-v";
		var tmpbuffer = new gx.text.stringBuffer();
		tmpbuffer.clear();
		tmpbuffer.append('<div id="' + this.ControlName + '" class="' + _mClass + '">'); //open main container for smooth
		tmpbuffer.append('<ul>');
		this.tbuffer = "";
		this.loadSmoothMenuData(this.Data);
		tmpbuffer.append(this.tbuffer);
		tmpbuffer.append('</ul>');
		tmpbuffer.append('</div>');
		return tmpbuffer;
	}

	var _mThis = this;
	
	this.loadSmoothMenuData = function(data){
		var i = 0;
		for(i=0;data[i]!=undefined;i++){
			if (data[i].Nodes != undefined) {
				this.tbuffer += '<li>';
				this.tbuffer += '<a href="' + data[i].Link + '" onclick="' + this.me() + '.GXMenuSmoothOnClick(\'' + data[i].Id + '\',\'' + data[i].WebComponent + '\');" >' + data[i].Title + '</a>';
				this.tbuffer += '<ul>';
				this.loadSmoothMenuData(data[i].Nodes);
				this.tbuffer += '</ul>';
				this.tbuffer += '</li>';
			}else{
				this.tbuffer += '<li>';
				this.tbuffer += '<a href="' + data[i].Link + '" onclick="' + this.me() + '.GXMenuSmoothOnClick(\'' + data[i].Id + '\',\'' + data[i].WebComponent + '\');" >' + data[i].Title + '</a>';
				this.tbuffer += '</li>';
			}
		}
	}
	
	this.GXMenuSmoothOnClick = function(id, wc) {
		var item = {Id:id,WebComponent:wc};
		if (typeof(this.OnClick) == 'function') {
			this.SelectedItem = item;
			this.OnClick();
		}
	}
	
	this.initSmoothMultilevel = function(){
		_mThis.loadSmoothHeadSection()
	}

	this.loadSmoothHeadSection = function(){
		var myScript = document.createElement('script')	;
		var mClass = _mThis.Orientation=="h"?"ddsmoothmenu":"ddsmoothmenu-v";
		var mjs = 'ddsmoothmenu.init({mainmenuid:"' + _mThis.ControlName + '",orientation:"' + _mThis.Orientation + '",classname:"' + mClass + '",contentsource: "markup"})';
		myScript.value = eval(mjs);
		document.getElementsByTagName("head")[0].appendChild(myScript)
	}
	
	this.renderDropDownTabs = function(){
		var tmpbuffer = new gx.text.stringBuffer();
		tmpbuffer.clear();
		tmpbuffer.append('<div id="' + this.DropDownTabsStyle + '" class="' + this.DropDownTabsStyle +'">');
		tmpbuffer.append('<ul>');
		
		//draw main tabs options
		for(i=0;this.Data[i]!=undefined;i++)
		{
			var vurl = this.Data[i].Link!=""?this.Data[i].Link:'#';
			tmpbuffer.append('<li><a href="' + vurl + '" onclick="' + this.me() + '.GXMenuOnClick(' + i + ',' + null + ');"' + ' title="' + this.Data[i].Description + '" rel="dropmenu' + i + '_' + this.TabMenuCode(this.DropDownTabsStyle) + '"><span>' + this.Data[i].Title + '</span></a></li>');
		}
		tmpbuffer.append('</ul>');
		tmpbuffer.append('</div>'); //close main menu div
		
		if(this.DropDownTabsStyle=="ddcolortabs")
			tmpbuffer.append('<div class="ddcolortabsline">&nbsp;</div>');
		
		//open menu sections div
		for(i=0;this.Data[i]!=undefined;i++)
		{
			if(this.Data[i].Nodes!=undefined){
				var sections = '<div id="dropmenu' + i + '_' + this.TabMenuCode(this.DropDownTabsStyle) + '" class="dropmenudiv_' + this.TabMenuCode(this.DropDownTabsStyle) + '">'
				for(j=0;this.Data[i].Nodes[j]!=undefined;j++)
				{
					sections += '<a href="' + this.Data[i].Nodes[j].Link + '" onclick="' + this.me() + '.GXMenuOnClick(' + i + ',' + null + ');">' + this.Data[i].Nodes[j].Title + '</a>';
    			}
				sections += '</div>';
			}else{
				var sections = '<div id="dropmenu' + i + '_' + this.TabMenuCode(this.DropDownTabsStyle) + '" class="dropmenudivempty">';
				sections += '<a></a>';
				sections += '</div>';
			}
			tmpbuffer.append(sections);
		}		
		return tmpbuffer;
	}
	
	this.initDropDownTabs = function() {
		if(getCookie('"' + this.ContainerName + '"') == null){
			tabdropdown.init(this.DropDownTabsStyle, 0);	
		}else{
			tabdropdown.init(this.DropDownTabsStyle, parseInt(getCookie('"' + this.ContainerName + '"')));		
		}
	}
	
	this.renderSlideDown = function(){
		var tmpbuffer = new gx.text.stringBuffer();
		tmpbuffer.clear();
		tmpbuffer.append('<div style="float: left" id="' + this.ControlName + '" class="sdmenu">'); //open main menu div
		var i = 0;
		var vURL = '';
		
		for(i = 0; this.Data[i].Nodes!= undefined; i++){
			tmpbuffer.append('<div>');
			tmpbuffer.append('<span>' + this.Data[i].Title + '</span>');
			for (j = 0; this.Data[i].Nodes[j]!= undefined; j++) {
				if (this.Data[i].Nodes[j].Link != "") {
					vURL = this.Data[i].Nodes[j].Link;
				}
				else {
					vURL = '#';
				}
				tmpbuffer.append('<a href="' + vURL + '" onclick="' + this.me() + '.GXMenuOnClick(' + i + ',' + j + ');">' + this.Data[i].Nodes[j].Title + '</a>');
			}
			tmpbuffer.append('</div>');
		}
		tmpbuffer.append('</div>'); //close main menu div
		return tmpbuffer;
	}
	
	this.initSlideDown = function() {
		var myMenu = new SDMenu(_mThis.ControlName);
		myMenu.speed = _mThis.Speed; // Menu sliding speed (1 - 5 recomended)
		myMenu.remember = _mThis.Remember; // Store menu states (expanded or collapsed) in cookie and restore later
		myMenu.oneSmOnly = _mThis.OneSubmenuOnly; // One expanded submenu at a time
		myMenu.markCurrent = true; // Mark current link / page (link.href == location.href)
		if (_mThis.Collapsed == "1")
			myMenu.collapseAll();
		myMenu.init();
	}
	
	if (this.Type == "3"){gx.evt.attach(window, 'load', this.initSlideDown);}
	
	this.GXMenuOnClick = function(indexi, indexj) {
		setCookie('"' + this.ContainerName + '"',indexi,null,"/");
		var item;
		(indexj!=undefined?item = this.Data[indexi].Nodes[indexj]:item = this.Data[indexi]);
		if (typeof(this.OnClick) == 'function') {
			this.SelectedItem = item;
			this.OnClick();
		}
	}
	
	this.TabMenuCode = function(style)
	{
		switch(style)
		{
			case "ddcolortabs": return "a"; break;
			case "bluetabs": return "b"; break;
			case "slidetabsmenu": return "c"; break;
			case "glowingtabs": return "d"; break;
			case "halfmoon": return "e"; break;
			default: return "a";
		}
	}
	
	function getCookie(name)
	{
  		var cname = name + "=";               
  		var dc = document.cookie;             
  		if (dc.length > 0) {              
    		begin = dc.indexOf(cname);       
    		if (begin != -1) {           
      			begin += cname.length;       
      			end = dc.indexOf(";", begin);
      			if (end == -1) end = dc.length;
        			return unescape(dc.substring(begin, end));
    		} 
		}
		return null;
  	}
	
	function setCookie(name, value, expires, path, domain, secure) {
  		document.cookie = name + "=" + escape(value) + 
  		((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  		((path == null) ? "" : "; path=" + path) +
  		((domain == null) ? "" : "; domain=" + domain) +
  		((secure == null) ? "" : "; secure");
	}	
	///UserCodeRegionEnd: (do not remove this comment.):
}

