// Initialize and render the menu bar when it is available in the DOM

YAHOO.util.Event.onContentReady("subnav", function () {

	// "beforerender" event handler for the menu bar

	function onMenuBarBeforeRender(p_sType, p_sArgs) {

		var oSubmenuData = {
		
			"menuproperties": [ 
			
				{ text: ">> Open Houses", url: "properties-open.html" },
				{ text: ">> New Listings", url: "properties-new.html" },
				{ text: ">> All Listings", url: "properties-listings.html" },
				{ text: ">> Smart Search", url: "properties-search.html" }
			],

			"menufinehomes": [

				{ text: ">> Overview", url: "finehomes.html" },
				{ text: ">> Fine Homes Open Houses", url: "finehomes-open.html" },
				{ text: ">> Fine Homes Listings", url: "finehomes-listings.html" },
				{ text: ">> Fine Homes Agents", url: "finehomes-agents.html" }

			],
			
			"menuagents": [

				{ text: ">> Find an Agent", url: "agents.html" }
			
			],
			
			"menuservices": [

				{ text: ">> Overview", url: "services.html" },
				{ text: ">> Buyers", url: "services-buyers.html" },
				{ text: ">> Sellers", url: "services-sellers.html" },
				{ text: ">> Relocation", url: "services-relocation.html" }
			
			],
			
			"menuabout": [

				{ text: ">> Overview", url: "about.html" },
				{ text: ">> Management", url: "about-management.html" }
			
			],
			
			"menucareers": [

				{ text: ">> Overview", url: "careers.html" },
				{ text: ">> Benefits", url: "careers-benefits.html" }
			
			],
			
			"menucontact": [

				{ text: ">> Contact Us", url: "contact.html" },
				{ text: ">> Directions", url: "contact-directions.html" }
			
			]
		
		};

		// Add a submenu to each of the menu items in the menu bar
		this.getItem(0).cfg.setProperty("disabled", true);
		this.getItem(1).cfg.setProperty("submenu", { id: "menuproperties", itemdata: oSubmenuData["menuproperties"] });
		this.getItem(2).cfg.setProperty("submenu", { id: "menufinehomes", itemdata: oSubmenuData["menufinehomes"] });
		this.getItem(3).cfg.setProperty("submenu", { id: "menuagents", itemdata: oSubmenuData["menuagents"] });
		this.getItem(4).cfg.setProperty("submenu", { id: "menuservices", itemdata: oSubmenuData["menuservices"] });
		this.getItem(5).cfg.setProperty("submenu", { id: "menuabout", itemdata: oSubmenuData["menuabout"] });
		this.getItem(6).cfg.setProperty("submenu", { id: "menucareers", itemdata: oSubmenuData["menucareers"] });
		this.getItem(7).cfg.setProperty("submenu", { id: "menucontact", itemdata: oSubmenuData["menucontact"] });
		this.getItem(8).cfg.setProperty("disabled", true);
	}


	/*
		 Instantiate the menubar.  The first argument passed to the 
		 constructor is the id of the element in the DOM that 
		 represents the menubar; the second is an object literal 
		 representing a set of configuration properties for 
		 the menubar.
	*/

	var oMenuBar = new YAHOO.widget.MenuBar("subnav", { autosubmenudisplay: true, showdelay: 250, hidedelay:  750, lazyload: true });


	// Subscribe to the "beforerender" event

	oMenuBar.beforeRenderEvent.subscribe(onMenuBarBeforeRender);


	/*
		 Call the "render" method with no arguments since the markup for 
		 this menu already exists in the DOM.
	*/

	oMenuBar.render();

	var currentpage = document.body.id;
	switch(currentpage){
		case "properties":
			currentpage = "navprop";
			break;
		case "finehomes":
			currentpage = "navfinehomes";
			break;
		case "agents":
			currentpage = "navagents";
			break;
		case "services":
			currentpage = "navservices";
			break;
		case "about":
			currentpage = "navabout";
			break;
		case "careers":
			currentpage = "navcareers";
			break;
		case "contact":
			currentpage = "navcontact";
			break;
	}
	
	var currentmenu = YAHOO.util.Dom.get(currentpage);
	var currentlink = YAHOO.util.Dom.getFirstChild(currentmenu);
	YAHOO.util.Dom.addClass(currentlink, "currentsection");
});

function safarifix() {
	
	isSafari3 = false;
	if(window.devicePixelRatio) isSafari3 = true;

	if(isSafari3) {
		var headID = document.getElementsByTagName("head")[0];         
		var cssNode = document.createElement('link');
		cssNode.type = 'text/css';
		cssNode.rel = 'stylesheet';
		cssNode.href = 'safari.css';
		cssNode.media = 'screen';
		headID.appendChild(cssNode);
	}
}

safarifix();