	//---------------------------------------------------------------------------------
	//        File : subMenuObject.js
	//
	// Description : Contains a 'subMenuController' which contains the array of all
	//               subMenuObjects. It also houses the global variables for menu timout
	//               and the current bc menu that is open.
	//
	//	Requirements : Requires Dojo in the header
	//					  dojo.require("dojo.dom");
	//				 	  dojo.require("dojo.json");
	//				  	  dojo.require("dojo.html.*");
	//				      dojo.hostenv.writeIncludes();
	//
	//---------------------------------------------------------------------------------
	
	function subMenuObject(smc){
		var bindedElement = null;
		var submenuController = null;
		var menu_id = null;
		var index = null

		this.submenuController = smc;
	}

	subMenuObject.prototype={
		bindToElement:function(el,i){
			this.bindedElement = el;
			this.index = i;
			this.menu_id = el.getAttribute('menuid');
		},
		applyMouseOver:function(){
			
			if(this.menu_id != -1){
				var _this = this;
				
				this.bindedElement.onmouseover = function(evt){
					
					_this.getSubMenus(evt);
				}
			}
			
		},
		prepFadeOut:function(){
			var _this = this;
			this.submenuController.mt = setTimeout(function(){ _this.killMenu();}, 2000); 
		},
	    killMenu:function(){
			this.ied(this.submenuController.cur_bcs_open);
			this.submenuController.cur_bcs_open = null;
		},
		resetMenu:function(){
			if(this.submenuController.mt){
				clearTimeout(this.submenuController.mt);
			}
		},
		ied:function(el_name){ // If Exists, Deletee
			if(dojo.byId(el_name)){dojo.dom.removeNode(dojo.byId(el_name));}
		},
		creatediv:function(id,html,width,height,left,top) { 
			 var newdiv = document.createElement('div');
			 newdiv.setAttribute('id',id);
			 if(width){newdiv.style.width = width;}
			 if(height){newdiv.style.height = height;}
			 if((left || top)||(left && top)){newdiv.style.position = "absolute";
			   if(left){newdiv.style.left = left;}
			   if(top){newdiv.style.top = top;}
			 }
			 if(html){newdiv.innerHTML = html;
			 }else{newdiv.innerHTML = "nothing"}
			 document.body.appendChild(newdiv);
		},
		setMenuHolder:function(newdiv,width,height,left,top) { 
			 if(width){newdiv.style.width = width;}
			 if(height){newdiv.style.height = height;}
			 if((left || top)||(left && top)){newdiv.style.position = "absolute";
			   if(left){newdiv.style.left = left;}
			   if(top){newdiv.style.top = top;}
			 }
			 document.body.appendChild(newdiv);
		},
		getSubMenus:function(evt){
			  var element = this.bindedElement ; //evt.target || window.event.srcElement;
			  //this.style.cursor='pointer';
			   
			  var _this = this;
			  dojo.io.bind({
                  url: '/LTC/Main_Site/includes/Ajax/getBreadCrumbChildren.aspx?menu_id=' + _this.menu_id,
                  method: "post",
                  sync : true,
                  load: function (type, data, evt) {
					  var menudata = eval('(' + data + ')');   // Convert the string to a JSON object
					  _this.createSubMenus(element,menudata);
                  },
                  sync : false,
                  error: function(type, error){
					  
                      dojo.debug(error);
                  },
                  mimetype: "text/plain"
              });
		},
		hl_menu:function(el,color){el.style.backgroundColor=color;},
		createSubMenus:function(el,subdata){
				
				var mholder = document.createElement('div');
				mholder.setAttribute('id',"tSub_" + el.id);
				var msub ;
				var msubText;
				var _this = this;
				var mlink;
				for(i=0;i<subdata.length;i++){
					msub = document.createElement('div');
					msub.setAttribute('id','submenu' + i);
					msub.className = 'bcMenuObject';
					msub.style.backgroundColor='FFFFFF';
					msubText = document.createTextNode(subdata[i].menuName);
					mlink = subdata[i].menuLink;
					msub.mlink =subdata[i].menuLink;
					
					msub.onmouseover = function(evt){
						_this.hl_menu(this,'FFCC66');
						_this.resetMenu();
						this.style.cursor='pointer';
					};
					msub.onmouseout = function(evt){
						_this.hl_menu(this,'FFFFFF');
						_this.prepFadeOut();
						this.style.cursor='default';
					};
					
					msub.onclick = function(evt){
					    document.location= this.mlink;
					};
					msub.appendChild(msubText);
					mholder.appendChild(msub);
				}
				
				var ret = dojo.html.getAbsolutePosition(el);
				this.ied("startExplode");
				this.creatediv("startExplode","&nbsp;",1,1,ret.left,ret.top+20); 
			

				if("tSub_" + el.id != this.submenuController.cur_bcs_open){
					this.resetMenu();
					this.ied(this.submenuController.cur_bcs_open);
					this.setMenuHolder(mholder,200,200,ret.left+20,ret.top+20);
					this.submenuController.cur_bcs_open = 	"tSub_" + el.id;
					this.prepFadeOut();
					dojo.lfx.explode(dojo.byId("startExplode"), dojo.byId(this.submenuController.cur_bcs_open), 250).play();
					
				}
		}
	};
	
	//----------------------------------------------------------------------------------------
	
	function subMenuController(){
		var mt ;			// Menu Timeout Variable
		var cur_bcs_open;	// Name of the Current bc submenu that is open
		
		arrElements = this.getElementsByClassName(document, "a", "BreadCrumbChildren");
		submenus = new Array();
		for(var i=0;i<arrElements.length;i++){
				submenus.push(new subMenuObject(this));
				submenus[i].bindToElement(arrElements[i],i);
				submenus[i].applyMouseOver();	
		}
	}



	subMenuController.prototype={
			getElementsByClassName:function(oElm, strTagName, strClassName){
					
						/* ------------------------------------------------------------------------------
						 To get all a elements in the document with a "info-links" class.
						 getElementsByClassName(document, "a", "info-links");
						 
						 To get all div elements within the element named "container", with a "col" class.
						 getElementsByClassName(document.getElementById("container"), "div", "col"); 
						 
						 To get all elements within in the document with a "click-me" class.
						 getElementsByClassName(document, "*", "click-me");*/
	
						 var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
						 var arrReturnElements = new Array();
						 strClassName = strClassName.replace(/\-/g, "\\-");
						 var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
						 var oElement;
						 for(var i=0; i<arrElements.length; i++){
							 oElement = arrElements[i];      
							 if(oRegExp.test(oElement.className)){
								 arrReturnElements.push(oElement);
							 }   
						 }
						 return (arrReturnElements)
			}
	}
	
	var bcSubMenus;
	function loadBCMenus(){
		 bcSubMenus = new subMenuController();
	}
	
	
	dojo.addOnLoad(loadBCMenus);
	

