(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
            }
        });


        /*
        Subscribe to the "beforerender" event, adding a submenu 
        to each of the items in the MenuBar instance.
        */
        oMenuBar.subscribe("beforeRender", function () {
            if (this.getRoot() == this) {
            }
        });





        /*
        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({

                units: [

			   { position: 'top', height: 120, body: 'top1', scroll: null, zIndex: 2 },

			   { position: 'right', header: '12V Accessories', width: 200, resize: true,

			       collapse: false, scroll: true, body: 'right1', animate: true, gutter: '5'

			   },

			   { position: 'bottom', height: 60, body: 'bottom1' },

			   { position: 'left', width: 155, body: 'left1',

			       gutter: '1', scroll: false, zIndex: 1

			   },

			   { position: 'center', body: 'center1', gutter: '5 0', scroll: true }

				]

            });

        }

        else if (page = "amazonproducts") {

            var layout = new YAHOO.widget.Layout({

                units: [

			           { position: 'top', height: 120, body: 'top1', scroll: null, zIndex: 2 },

			           { position: 'right', header: '12V Accessories', width: 200, resize:false,

			               collapse: false, body: 'right1', animate: false, 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 }

				        ]

            });

        }

        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('render', function () {

            YAHOO.util.Event.onContentReady("productsandservices", initTopMenu);

        }); //end ondomready



        layout.render();

    });

})();

