
var menuArray = new Array();

var urlArray = new Array();

var subMenuArray = new Array();

var subMenuOrder = new Array();

 

var buildString = "";


//Global to mark the first menu item for style

var firstFlag = false;

//fn to process array values into the yui menu

//TODO: call portal to retrieve values dynamically

var lastParent="";

var parentCount = 0;

var doneFlag = false;
function menuPanel(name,parent,arr,stylename,elType)
{
this.menuList = arr;
this.name = name;
this.menuContainer= document.createElement("DIV");
this.menuParent = parent.appendChild(this.menuContainer);
this.onstyle = stylename+"On";
this.offstyle = stylename+"Off";
this.elType = elType;
this.menuBody = this.menuItems();

}
menuPanel.prototype.menuItems = function()
{
	for(x=0;x<this.menuList.length;x++)
	{
		el=document.createElement(this.elType);
		el.innerHTML = "&nbsp;&nbsp;&nbsp;"+this.menuList[x][0];
		el.offstyle = this.offstyle;
		el.onstyle = this.onstyle;
		el.className = this.offstyle;
		el.link = this.menuList[x][1];
		if(IsUsingIE())
		{
			el.onmouseover = this.styler;
			el.onmouseout = this.styler;
			el.onclick = this.relay;
		}
		else
		{
 			el.addEventListener("mouseover",this.styler,false);
 			el.addEventListener("mouseout",this.styler,false);
			el.addEventListener("click",this.relay,false);
		}
		this.menuContainer.appendChild(el);
	}
}
menuPanel.prototype.styler = function()
{

	if(this.className == this.onstyle)
	{
		this.className = this.offstyle;
		setCursor(this,0);
	}
	else
	{
		
		this.className = this.onstyle;
		setCursor(this,1);
		
	}

}
menuPanel.prototype.relay = function()
{
var tag = document.getElementById("bd")

	if(this.link.indexOf(".cfm")>-1)
	{
		document.location.href = this.link;
	//tag.src = this.link;

	}
	else
	{
		eval(this.link);
	}

//document.location.href = this.link;
}
 

function initMenu()

{
//Blogs, login, edit pages, admin, etc
var myArray= eval({"menu":[{"name":"TMCC Sites","top_url":"TMOrgindexFrame.cfm",

"elements":[

{"name":"TMCC Family","url":"http://www.tmccfamily.org"},

{"name":"Thunder Mountain","url":"http://www.thundermountain.org"},
{"name":"Students","url":"http://www.regenerationstudentministries.org"},
{"name":"Contribute","url":"https://www.eservicepayments.com/cgi-bin/specialwebapp.vps?appid=eb2b05f1f0f40d1edeea4d27259defa4c95dc6cebafe577f90d5b973bb16107e5a10fdfb7f0fb15e86e6cf19f7a0045a7014ab40b30db7ea4c224790fe6c3709a5cd408f20408500590926c8cba555e0"}
]},

{"name":"Welcome!","top_url":"null.jsp",

"elements":[
{"name":"What to Expect","url":"http://www.thundermountain.org/visitors/whatyoucanexpect.cfm"},
{"name":"Who We Are/What We Believe","url":"http://www.thundermountain.org/visitors/ourbeliefs.cfm"},
{"name":"When and Where We Meet","url":"http://www.thundermountain.org/visitors/directions.cfm"},
{"name":"May We Pray for You?","url":"http://www.thundermountain.org/visitors/prayforyou.cfm"},
{"name":"Radio Broadcasts","url":"http://www.thundermountain.org/messages/radio.cfm"},
{"name":"Recent Teachings","url":"http://www.thundermountain.org/messages/messages.cfm"},
{"name":"Contact Us","url":"http://www.thundermountain.org/visitors/contactus.cfm"}

]},

{"name":"Job Opportunities","top_url":"TMOrgindexFrame.cfm",

"elements":[
{"name":"Publications Assistant","url":"http://www.thundermountain.org/Assistantdescription.pdf"},
{"name":"Summer Intern","url":"http://www.thundermountain.org/InternApplication.pdf"}
]}


]});

 

            for(c=0;c<myArray.menu.length;c++)

            {

                        var hdr = myArray.menu[c].name;

                        menuArray.push(["javascript:nullO()",hdr,hdr,myArray.menu[c].top_url]);

                        fnCall = "test";

                        //various functions for urls

                        //Links opens in a new window

                        if(hdr == "Links")

                        {

                                    fnCall = "javascript:linkme(";

                        }

                        else

                        {

                                    fnCall = "javascript:f(";

                                                            

                        }

                        for(sub=0;sub<myArray.menu[c].elements.length;sub++)

                        {


                                    var subhdr = myArray.menu[c].elements[sub].name;

                                    var appurl = myArray.menu[c].elements[sub].url;

                                    var fnNum = menuArray.length;

                                    menuArray.push( [fnCall+"'"+appurl+"')",hdr,subhdr,appurl]);


                        }

            }

            processMenu();



}

 

function nullO()

{

}

 


 

 

function processMenu()

{


//cycle through menu items to determine if a submenu needs generating or not

for(x=0;x<menuArray.length;x++)
  {           
    urlArray.push(menuArray[x][3]);
        if(menuArray[x][1]!= lastParent)
            {
                 //new main menu item

                                                var ct = x+1;

                                                if(menuArray[x][1]==menuArray[ct][1])

                                                {

                                                //has a submenu

                                                insertMenu(menuArray[x][0],menuArray[x][1]);

                                                lastParent = menuArray[x][1];

                                                doneFlag=false;

                                                }

                                                else

                                                {

                                                // no submenu, move on to next menu item

                                                insertMenu(menuArray[x][0],menuArray[x][1]);

                                                lastParent = menuArray[x][1];

                                                            parentCount=parentCount+1;

                                                            doneFlag = true;

                                                }

                                                

                                    }

                                    else

                                    {

                                    //still working with the submenu items since last parent is same as this menu item

                                                if(doneFlag==false)

                                                {

                                                //fetch the values for the submenu under the given main menu by looping ahead

                                                obj = new Array();

                                                            for(y=x;y<menuArray.length;y++)

                                                            {

                                                                        if(menuArray[y][1]== menuArray[x][1])

                                                                        {

                                                                        

                                                                                    obj[y] =  { text: menuArray[y][2], url: menuArray[y][0]};

                                                                        }

                                                                        else

                                                                        //alert(menuArray[y][2]+" / "+menuArray[x][1]+" // "+lastParent);

                                                                        lastParent=menuArray[x][1];                                                                   

                                                            }

                                                             

                                                            subMenuArray.push(obj);

                                                            subMenuOrder.push(parentCount);

                                                            parentCount=parentCount+1;

                                                            doneFlag = true;

                                                }

                                    }           

            }//end for

            //now that we know what we've got, build the menu

            makeMenu();

}

 

//instantiates the main menu items

function insertMenu(href,label)

{

//var a = null;

 

      var tag1 = document.createElement('li');

                if(firstFlag==false)

                {

                tag1.className = "yuimenubaritem first-of-type";

                firstFlag = true;

                }

                                                else

                {

                tag1.className = "yuimenubaritem";

                }

                //tag1.id = "testit";

 

                                                var tag1a = document.createElement('a');

                                                tag1a.className = "yuimenubaritemlabel";

                                                tag1a.href=href;

                                                tag1a.innerHTML = label;

                                                document.getElementById("tmccitems").appendChild(tag1);

                                                tag1.appendChild(tag1a);

}

 

//combines the main menu with the submenus to generate the menu

function makeMenu() {

 

      function onMenuBeforeRender(p_sType, p_sArgs) {

               var oSubmenuData = new Object();

               for(b=0;b<subMenuArray.length;b++)

                            {

                                oSubmenuData[b] = subMenuArray[b];

                            this.getItem(subMenuOrder[b]).cfg.setProperty("submenu", { id:"menuData"+b, itemdata: oSubmenuData[b],zindex:2 });

                        }

 

                }

                // Initialize the root menu bar

               var oMenuBar = new YAHOO.widget.MenuBar("tmccMenu", { autosubmenudisplay: true, showdelay: 250, hidedelay: 750, lazyload: true });

                // Subscribe to the "beforerender" event

                oMenuBar.beforeRenderEvent.subscribe(onMenuBeforeRender);

                /*

                     Call the "render" method with no arguments since the markup for

                     this menu already exists in the DOM.

                */

                oMenuBar.render();

            }

 

// function linkme simply links/navigates to the page with the url stored in urlArray

function linkme(val)

{

var win = window.open(urlArray[val],'','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');

}

 

// function linkme2 links to external page

function linkme2(val)

{

var win = window.open(urlArray[val],'','');

}

 
function f(url)
{

	if(url.indexOf("http")>-1)
	{
		document.location.href = url;
	}
	else
	{
		//var topBanner = "images/topBannerWide2.jpg"
		//var cssTag = document.getElementById("cssValue");
		//var css = <cfoutput>#session.css#</cfoutput>;
		//var pixtag = document.getElementById("ibd")
		//pixtag.src = url+"&css="+css;
		//if(url.indexOf("dSunday")>-1)
		//{
		//topBanner = "images/topBannerDedication.jpg"
		//}
		//var tagB= document.getElementById("tpB")
		//tagB.src = topBanner;

	}
}




 




