window.addEvent('domready', function() {

    //book online
    var myPages = $$('.bookLink');
    var myBubbles = $$('.bubble');
    var myBookPanelClose = $$('#CloseBTu');
    var myMembersClickLink = $$('#MembersClickLink');
    var toggle = 'true';

    //book online submenu
    var myMenu = $$('.PromoTitle');
    var myMenuTitle = $$('.PromoOfferDescriptionHolder');
    var myMenuArea = $$('.SMOBPHWrapper');


    //offers
    var myOffer = $$('.offerLink'); var myPanel = $$('.offersSlide'); var open = 'true';
    //offer flyout
    var offersPullout = $$('.offerPullout'); var flyoutOffer = $$('.bubble-flyout'); var flyout = 'true';

    /*promo flyout
    var promoPullout = $$('.promoLink'); var myPromo = $$('.promoSlide'); var mouseOn = 'true';*/

    //promo flyout
    var promoPullout = $$('.promoLink'); myPromo = $$('.promoSlide'); var opnOut = 'true';

    //news flyout
    var newsPullout = $$('.newsLink'); myNews = $$('.newsSlide'); var openOut = 'true';

    //search open
    //var searchOpen = $$('.input_search'); var searchBtn = $$('.submit_search'); var slide = 'true';

    //content open
    var contentOpen = $$('.slidePanel'); var showContent = $$('.showContent'); var display = 'true';

    myPanel.setStyle('opacity', 0);
    myBubbles.setStyle('opacity', 0);
    myMenuTitle.setStyle('opacity', 0);

    //flyoutOffer.setStyle('opacity', 0);
    //searchOpen.setStyle('opacity', 0);	searchOpen.setStyle('width', 2);
    contentOpen.setStyle('height', '0px');







    /*--------------------------------------------------Big Green Book Online Button---------------------------*/
    myPages.each(function(el, i) {
        el.set('morph', { link: 'cancel' });
        //try { Custom.init(); }	catch(e) {}
        el.addEvents({
            'domready': function() {
                toggle = 'false'; myBubbles[i].morph({ 'opacity': 1, 'display': 'block', 'margin-left': '-25px' });
                //Just show it

            }
        });
    });

    myPages.each(function(el, i) {
        el.set('morph', { link: 'cancel' });
        //try { Custom.init(); }	catch(e) {}
        el.addEvents({
            'click': function() {
                if (toggle == 'true') { toggle = 'false'; myBubbles[i].morph({ 'opacity': 1, 'display': 'block', 'margin-left': '-25px' }); }
                //else { toggle = 'false'; myBubbles[i].morph({ 'opacity': 0, 'margin-top': '0' }); }
            }
        });
    });

    myPages.each(function(el, i) {
        el.set('morph', { link: 'cancel' });
        //try { Custom.init(); }	catch(e) {}
        el.addEvents({
            'mouseenter': function() {
                if (toggle == 'true') { toggle = 'false'; myBubbles[i].morph({ 'opacity': 1, 'display': 'block', 'margin-left': '-25px' }); } //Just show it
                //else { toggle = 'false'; myBubbles[i].morph({ 'opacity': 0, 'margin-top': '0' }); }
            }
        });
    });
    /*--------------------------------------------------/Big Green Book Online Button---------------------------*/



    myBookPanelClose.each(function(el, i) {
        el.set('morph', { link: 'cancel' });
        //try { Custom.init(); }	catch(e) {}
        el.addEvents({
            'click': function() {
                myBubbles[i].morph({ 'opacity': 0, 'margin-left': '0' });


            }
        });
    });





    

    //book online submenu--

    // mouse enter function

    myMenu.each(function(el, i) {
        el.set('morph', { link: 'cancel' });
        //try { Custom.init(); }	catch(e) {}

        el.store('isOpen', false);
        el.addEvents
	    ({
	        'mouseenter': function() {
	            // var submenuHeight = document.getElementById('SubMenuOnBookPanel').offsetHeight; // if SubMenuOnBookPanel heigher than 150 click not work

	   
	            if (!el.retrieve("isOpen")/* & submenuHeight < 150*/) {
	                el.store('isOpen', true);
	                myMenuTitle[i].morph({ 'opacity': 1, 'height': '87', 'display': 'block' });

	            }

	            else {
	                el.store('isOpen', false);
	                myMenuTitle[i].morph({ 'opacity': 0, 'height': '0' });

	            }

	            //  myMenuTitle[i].morph({ 'opacity': 1, 'display': 'block' })
	            // myMenuArea[]

	            
	        }

	    });

    });
    //--mouse enter function






    myMenuTitle.each(function(el, i) {
        el.set('morph', { link: 'cancel' });
        //try { Custom.init(); }	catch(e) {}
        
        el.addEvents
	    ({
	        'click': function() {
	            var submenuHeight = document.getElementById('SubMenuOnBookPanel').offsetHeight; // if SubMenuOnBookPanel heigher than 150 click not work

	            if (toggle == 'true' & submenuHeight < 150) {
	                toggle = 'false';
	                myMenuTitle[i].morph({ 'opacity': 1, 'height': '87' });
	                submenuHeight = submenuHeight + 87;
	            } else {
	                toggle = 'true'; myMenuTitle[i].morph({ 'opacity': 0, 'height': '0' });
	            }
	        }

	    });

	    el.getParent().addEvents
	    ({
	        'mouseleave': function() {
	            myMenuTitle[i].morph({ 'opacity': 0, 'height': '0' });
	        }

	    });

    });
    //--mouse enter function






    //if the mouse leave PromoOfferDescriptionHolder layer or SubMenuOnBookPanelHolder, the code to close it.

    //    myMenu.each(function(el, i) {
    //        el.set('morph', { link: 'cancel' });
    //        el.addEvents({

    //            'mouseleave': function() {
    //                myMenuTitle[i].morph({ 'opacity': 0, 'height': 0 });
    //            }
    //        });
    //    });
    //    
    //    myMenuTitle.each(function(el, i) {
    //        el.set('morph', { link: 'cancel' });
    //        el.addEvents({

    //            'mouseleave': function() {
    //                myMenuTitle[i].morph({ 'opacity': 0, 'height': 0 });
    //            }
    //        });
    //    });

    /* myMenuArea.each(function(el, i) {
    el.set('morph', { link: 'cancel' });
    el.addEvents({
    //'click': function() { myMenuTitle[i].morph({ 'opacity': 1, 'display': 'block' }); },
    'mouseleave': function() {
    myMenuTitle[i].morph({ 'opacity': 0, 'height': '0' });
    }
    });
    });*/

    // end book online submenu






    /* Offers slide */


    myOffer.each(function(el, i) {
        el.set('morph', { link: 'cancel' });

        el.addEvents({
            'click': function() {
                if (open == 'true') {
                    open = 'false';  //close promo first
                    myPromo[0].morph({ 'opacity': 0, 'height': '0' });
                    myNews[0].morph({ 'opacity': 0, 'height': '0' });
                    mouseOn = 'true';
                    myPanel[i].morph({ 'opacity': 1, 'height': '105px' });
                }
                else { open = 'true'; myPanel[i].morph({ 'opacity': 0, 'height': '0' }); }
            }
        });
    });

    /* Promo slide 
    promoPullout.each(function(el, i) { el.set('morph', {link : 'cancel' });
		
	el.addEvents({
    'click': function() {
    if (mouseOn == 'true') { 
    mouseOn = 'false';  //close offers first
    myPanel[0].morph({ 'opacity': 0, 'height': '0' });
    myNews[0].morph({ 'opacity': 0, 'height': '0' });
    open = 'true';
    myPromo[i].morph({'opacity' : 1, 'height' : '105px'}); }
    else {mouseOn = 'true'; myPromo[i].morph({'opacity' : 0, 'height' : '0'}); }
    }
    });
    });*/



    /* promo slide */
    promoPullout.each(function(el, i) {
        el.set('morph', { link: 'cancel' });

        el.addEvents({
            'click': function() {
                if (opnOut == 'true') {
                    opnOut = 'false';  //close offers first
                    myPanel[0].morph({ 'opacity': 0, 'height': '0' });
                    myNews[0].morph({ 'opacity': 0, 'height': '0' });
                    open = 'true';
                    myPromo[i].morph({ 'opacity': 1, 'height': '70px' });
                }
                else { opnOut = 'true'; myPromo[i].morph({ 'opacity': 0, 'height': '0' }); }
            }
        });
    });



    /* News slide */
    newsPullout.each(function(el, i) {
        el.set('morph', { link: 'cancel' });

        el.addEvents({
            'click': function() {
                if (openOut == 'true') {
                    openOut = 'false';  //close offers first
                    myPanel[0].morph({ 'opacity': 0, 'height': '0' });
                    myPromo[0].morph({ 'opacity': 0, 'height': '0' });
                    open = 'true';
                    myNews[i].morph({ 'opacity': 1, 'height': '105px' });
                }
                else { openOut = 'true'; myNews[i].morph({ 'opacity': 0, 'height': '0' }); }
            }
        });
    });



    /* Individual offer flyout */
    offersPullout.each(function(el, i) {
        el.set('morph', { link: 'cancel' });
        el.addEvents({
            'mouseenter': function() {
                flyoutOffer[i].morph({ 'opacity': 1, 'margin-left': '35px' });
            },
            'mouseleave': function() {
                flyoutOffer[i].morph({ 'opacity': 0, 'margin-left': 0 });
            }
        });
    });



    /* Print popout */
    var abbOpen = $$('.abb'); var showTheContent = $$('.abb_over');
    showTheContent.setStyle('opacity', 0);

    /* Individual offer flyout */
    abbOpen.each(function(el, i) {
        el.set('morph', { link: 'cancel' });
        el.addEvents({
            'mouseenter': function() { showTheContent[i].morph({ 'opacity': 1, 'display': 'block' }); },
            'mouseleave': function() { showTheContent[i].morph({ 'opacity': 0, 'display': 'none' }); }
        });
    });


    /* Searchbar slide */
    /*	searchBtn.each(function(el, i) { el.set('morph', {link : 'cancel' });
    el.addEvents({
    'mouseenter': function() {
    searchOpen[i].morph({ 'opacity' : 1, 'width' : '130px' }); 
    },
    'mouseleave' : function() {
    searchOpen[i].morph({ 'opacity' : 0, 'width' : '2px' }); }
    });
    });*/

    /* Home content slide */
    showContent.each(function(el, i) {
        el.set('morph', { link: 'cancel' });
        el.addEvents({
            'click': function() {
                if (open == 'true') { open = 'false'; contentOpen[i].morph({ 'opacity': 1, 'height': '181px' }); g('showContent').innerHTML = 'Close'; }
                else { open = 'true'; contentOpen[i].morph({ 'opacity': 0, 'height': '0' }); showContent.setStyle('height', '28px'); g('showContent').innerHTML = 'More Info &#187;'; }
            }
        });
    });
});
