(function() {
    var Dom = YAHOO.util.Dom,
        Event = YAHOO.util.Event;

        var initTopMenu = function() {
			
			//subscribe to the menu click event and this will cause the right action
			var onMenuItemClick = function () {
				switch(this.cfg.getProperty("text"))
				{
					case "Login":
						//redirect to login page if not logged on	
						window.location = "register_property.php";
						//alert("Click button to login");				
						break;
					default : 
						alert("Clicked on " + this.cfg.getProperty("text"));
						break;				
				}		
			};
                /*
                     Instantiate a MenuBar:  The first argument passed to the 
                     constructor is the id of the element in the page 
                     representing the MenuBar; the second is an object literal 
                     of configuration properties.
                */
                var oMenuBar = new YAHOO.widget.MenuBar("productsandservices", { 
                                                            autosubmenudisplay: true, 
                                                            hidedelay: 750, 
                                                            lazyload: false,
                                                            effect: {															                                                                effect: YAHOO.widget.ContainerEffect.FADE,
                                                                duration: 0.25
                                                            } 
                                                        });
                      
                /*
                     Call the "render" method with no arguments since the 
                     markup for this MenuBar instance is already exists in 
                     the page.
                */

                oMenuBar.render();         
        };       

		//Functrino called when document finishes loading
		Event.onDOMReady(function() {								  		
		if(page == "home")
		{
			var layout = new YAHOO.widget.Layout('mainDoc',{
				height: Dom.getClientHeight(), //Height of the viewport
	            width: Dom.getClientWidth(),
			   units: [
			   { position: 'top', height: 120, body: 'top1', scroll: null, zIndex: 2 },
			   { position: 'right', header: 'Shopping Cart', width: 200, resize: true, footer: 'Footer', 
					collapse: true, scroll: true, body: 'right1', animate: true, gutter: '2' },
			   { position: 'bottom', height: 120, body: 'bottom1' },
			   { position: 'left', width: 150, body: 'left1', 
					gutter: '2', scroll: true, zIndex: 1 }, 
			   { position: 'center',  body: 'center1', gutter: '1 0', scroll: true }
				]
			});
				
		}//end switch
		else if(page =="account")
		{
			var layout = new YAHOO.widget.Layout({
			   units: [
			   { position: 'top', height: 120, body: 'top1', scroll: null, zIndex: 2 },
			   { position: 'right', header: 'Shopping Cart', width: 200, resize: true, footer: 'Footer', 
					collapse: true, scroll: true, body: 'right1', animate: true, gutter: '5' },
			   { position: 'bottom', height: 60, body: 'bottom1' },
			   { position: 'left', width: 150, body: 'left1', 
					gutter: '2', scroll: true, zIndex: 1 }, 
			   { position: 'center',  body: 'center1', gutter: '5 0', scroll: true }
				]
			});
			
			initFormHandlers();
		}
		
		//Initialise the brandsearch treeview
		brandSearchTreeInit();		
				
        layout.on('beforeResize', function() {
            Dom.setStyle('mainDoc', 'height', (Dom.getClientHeight() * 1.5) + 'px');
			Dom.setStyle('mainDoc', 'width', (Dom.getClientWidth() * 1) + 'px');
        });
		
	    layout.on('render', function() {
	    YAHOO.util.Event.onContentReady("productsandservices", initTopMenu);  								
	  }); //end ondomready
        
  	  layout.render();
	});
})();

