/*OBJECT DEFINITIONS
for Browsing

*/


function BrowseMenu(aNode) {
	//class for global browseMenu object; holds all functions for 
	//finding the menu item corresponding to a click and for opening the main menu
	this.node = aNode;
	this.menuItemList;
	this.topLevelMenuList;
	this.indexedItems = new Array();
	this.displayState = 0;
	this.setTopLevelMenuList = function(aList) {
		this.topLevelMenuList = aList;
	}
	this.getTopLevelMenuByName = function(aName) {
		if(this.topLevelMenuList){return this.topLevelMenuList[aName];}
	}
	this.setMenuItemList = function(aList){
		this.menuItemList = aList;
	}
	this.setItemForIndex = function(anItem , anIndex) {
		this.indexedItems[anIndex] = anItem;
	}
	
	this.getItemForIndex = function(anIndex){
		return this.indexedItems[anIndex];
	}
	this.clickEvent = function() {
		for (var m=0;m<this.topLevelMenuList.length;m++){
			var currentItem = this.getTopLevelMenuByName(this.topLevelMenuList[m]);
				if(this.displayState == 0){
					document.getElementById(BROWSING_TOOL_ID).style.top = BROWSING_TOOL_INITIAL_OFFSET + 'px';
					currentItem.hideSubMenu();
				}
				else if(this.displayState == 1)
				{
					document.getElementById(BROWSING_TOOL_ID).style.top = BROWSING_TOOL_STAGE_1_OFFSET + 'px';
				}
				else if(this.displayState == 2){
					document.getElementById(BROWSING_TOOL_ID).style.top = BROWSING_TOOL_STAGE_2_OFFSET + 'px';
					document.getElementById(BROWSING_TOOL_ID).style.height = 'auto';
					bookingStages.setBookingDisplayState(false);
          toggleCalendarLink(false);
          toggleTeaserBelowBookingTool(false);
					currentItem.showSubMenu();
				}
				else if(this.displayState == 3){
					document.getElementById(BROWSING_TOOL_ID).style.top = BROWSING_TOOL_STAGE_3_OFFSET + 'px';
				}
		}
		//for (menuNames in this.topLevelMenuList){
		//	var currentItem = this.getTopLevelMenuByName(menuNames);
		//		if(this.displayState == 0){
		//			document.getElementById(BROWSING_TOOL_ID).style.top = BROWSING_TOOL_INITIAL_OFFSET + 'px';
		//			currentItem.hideSubMenu();
		//		}
		//		else if(this.displayState == 1)
		//		{
		//			document.getElementById(BROWSING_TOOL_ID).style.top = BROWSING_TOOL_STAGE_1_OFFSET + 'px';
		//		}
		//		else if(this.displayState == 2){
		//			document.getElementById(BROWSING_TOOL_ID).style.top = BROWSING_TOOL_STAGE_2_OFFSET + 'px';
		//			document.getElementById(BROWSING_TOOL_ID).style.height = 'auto';
		//			bookingStages.setBookingDisplayState(false);
         // toggleCalendarLink(false);
          //toggleTeaserBelowBookingTool(false);
		//			currentItem.showSubMenu();
		//		}
		//		else if(this.displayState == 3){
		//			document.getElementById(BROWSING_TOOL_ID).style.top = BROWSING_TOOL_STAGE_3_OFFSET + 'px';
		//		}
		//}
		return false;
	}
	this.foldUpTopLevelSubMenu = function(aName){
		this.getTopLevelMenuByName(aName).hideSubMenu();
	}
}

function TopLevelMenuItem(aNode , aLink , anIndex , aBrowseMenu){ //instantiated with an IDed LI node , an anchor, and the global menu object
	this.node = aNode;
	this.clickedNode = aLink;
	this.browseMenu = aBrowseMenu;
	this.name = aNode.getAttribute('ID');
	this.menuItem = new MenuItem(aNode , aLink);
	this.clickAction = function() {
		if(this.browseMenu.displayState!=2){
			this.browseMenu.displayState = 2;
		}
		return this.browseMenu.clickEvent();
	}
	this.showSelf = function(){
		this.node.style.display = 'block';
//		this.menuItem.makeVisible();
//		this.menuItem.showSubMenu();
	}
	this.hideSelf = function(){
		this.menuItem.makeInvisible();
	}
	this.showSubMenu = function() {
		for (var i=0; i<this.node.childNodes.length; i++){
			if(this.node.childNodes[i].tagName == 'UL'){
				var currentChild = this.node.childNodes[i];
				currentChild.style.display = 'block';
				for (var j=0; j<currentChild.childNodes.length ; j++){
					if(currentChild.childNodes[j].tagName == 'LI'){
						currentChild.childNodes[j].style.display = 'block';
					}
				}
				
			}
		}
	}
	this.hideSubMenu = function(){
		for (var i=0; i<this.node.childNodes.length; i++){
			if(this.node.childNodes[i].tagName == 'UL'){
				var currentChild = this.node.childNodes[i];
				currentChild.style.display = 'none';
				for (var j=0; j<currentChild.childNodes.length ; j++){
					if(currentChild.childNodes[j].tagName == 'LI'){
						currentChild.childNodes[j].style.display = 'block';
					}
				}
				
			}
		}
		
	}
}

function SubMenu(aNode , aParent) { //instantiated with an UL node and a parent LI
	this.node = aNode;
	this.parent = aParent;
	this.hasMenuItems = false;
	this.menuItemCount = 0;
	this.menuItemList = new Array();
//memberfunctions
	this.testForMenuNodes = function() {
		if(this.node.getElementsByTagName('LI').length > 0){
			this.setupMenuItems();
			this.hasMenuItems = true;
		}else{
			this.hasMenuItems = false;
		}
	}
	this.setupMenuItems = function(){
		var myMenuItems = new Array();
		var myItemCount = 0;
		for (i=0; i<this.node.childNodes.length; i++){
			if(this.node.childNodes[i].tagName == 'LI'){
				var myMenuItem = new MenuItem(this.node.childNodes[i]);
				myMenuItem.setParent(this);
				myMenuItems[myItemCount] = myMenuItem;
				++myItemCount;
			}
		}
		this.menuItemCount = myItemCount;
		this.menuItemList = myMenuItems;
	}
	//done defining setupMenuItems
	this.clickAction = function() {
		//browseMenu.foldUpTopLevelSubMenu('park');
		this.hideSubMenus();
		this.makeVisible();
		this.showMenuItems();
	}
	this.showMenuItems = function(){
		if(this.hasMenuItems){
			for (var i=0 ; i<this.menuItemList.length; i++){
				this.menuItemList[i].makeVisible();
			}
		}
	}
	this.hideSubMenus = function(){
		this.parent.hideOpenMenu();
	}
	//done defining click action
	this.makeVisible = function() {
		this.node.style.display = 'block';
	}
	this.makeInvisible = function() {;
		this.node.style.display = 'none';
	}
	this.testForMenuNodes();

}
function MenuItem(aNode , aLink) { //instantiated with an LI node and an A node and a parent which is a sub menu node
	this.node = aNode;
	this.clickedNode = aLink;
	this.hasSubMenu = false;
	this.parent = false;
	this.setParent = function (aParent){
		this.parent = aParent; //self sent in from the submenu object
	}
	this.subMenuList = new Array();
//memberfunctions
	this.testForSubMenus = function() {
		if (this.node.getElementsByTagName('UL').length > 0 ){
			this.hasSubMenu = true;
			this.setupSubMenu();
		}
	}
	//end definition test for sub menus
	this.makeVisible = function() {
		this.node.style.display = 'block';
	}
	this.makeInvisible = function() {
		this.node.style.display = 'none';
	}
	this.setupSubMenu = function() {
		var menuCount = 0;
		for (i=0; i<this.node.childNodes.length; i++){
			if(this.node.childNodes[i].tagName == 'UL'){
				var subMenu = new SubMenu(this.node.childNodes[i] , this);
				this.subMenuList.push(subMenu);
				++menuCount;
			}
		}
		//this.subMenuList = subMenus;
	}
	//done defining setup submenu
	this.showSubMenu = function() {
		for (var i=0; i<this.subMenuList.length; i++){
			this.subMenuList[i].makeVisible();
			this.subMenuList[i].clickAction();
		}
	}//done defining show submenu
	this.hideSubMenu = function(){
		for (var i=0; i<this.subMenuList.length; i++){
			this.subMenuList[i].makeInvisible();
		}
	}

	this.hideOpenMenu = function() {
		var siblingMenus = this.node.parentNode.childNodes;
		for (var i=0; i<siblingMenus.length ; i++){
			if(siblingMenus[i].tagName == 'LI'){
				var currentMenu = siblingMenus[i].getElementsByTagName('UL');
				for (var j=0; j<currentMenu.length ; j++){
					currentMenu[j].style.display = 'none';
					for (var k=0; k<currentMenu[j].childNodes ; k++){
						if(currentMenu[j].childNodes[k].tagName == 'LI'){
							currentMenu[j].childNodes[k].style.display = 'none';
						}
					}
				}
			}
		}
	}
	this.testForSubMenus();
}

// DM FB-318 toggle the teaser below the bookingTool
function toggleTeaserBelowBookingTool(bShow) {
  if (document.getElementById('teaserBelowBookingTool') != null) {
    var teaserBelowBookingTool = document.getElementById('teaserBelowBookingTool');
    var currentStyle = teaserBelowBookingTool.style['display'];
    if (bShow) {
      if (currentStyle == "none") {
        teaserBelowBookingTool.style['display'] = "block";
      }
    }
    else {
      if (currentStyle == "" || currentStyle == "block") {
        teaserBelowBookingTool.style['display'] = "none";
      }
    }
  }
}
