function getFlashMovieObject(movieName) {
   if (window.document[movieName]) {
      return window.document[movieName];
   }
   if (navigator.appName.indexOf("Microsoft Internet") == -1) {
      if (document.embeds && document.embeds[movieName])
         return document.embeds[movieName];
   }
   else {
      return document.getElementById(movieName);
   }
}


window.addEvent('domready', function() {

    //book online
    var myPages = $$('.bookLink'); var myBubbles = $$('.bubble'); var toggle = 'true';
    //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';

    //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';
    var imagesAreSkiped = false;

    myPanel.setStyle('opacity', 0);
    myBubbles.setStyle('opacity', 0);
    flyoutOffer.setStyle('opacity', 0);
    //searchOpen.setStyle('opacity', 0);	searchOpen.setStyle('width', 2);
    contentOpen.setStyle('height', '0px');

    /* book online */
    myPages.each(function(el, i) {
        el.set('morph', { link: 'cancel' });
        //try { Custom.init(); }	catch(e) {}
        el.addEvents({
            'click': function() {
                if (imagesAreSkiped === false) {
                    if (Browser.Engine.trident && Browser.Engine.version < 7) {
                        if (getFlashMovieObject("mainPanelSecondary") == undefined) {
                            getFlashMovieObject("siteHolder").skipImagesExt();
                            imagesAreSkiped = true;
                        }
                        else {
                           try { getFlashMovieObject("mainPanelSecondary").skipImagesExt();
                            imagesAreSkiped = true; }
                            catch(e) {}
                        }
                    }
                }
                if (toggle == 'true') {
                    toggle = 'false'; myBubbles[i].morph({ 'opacity': 1, 'margin-top': '-25px' });
                } else { toggle = 'true'; myBubbles[i].morph({ 'opacity': 0, 'margin-top': '0' }); }
            }
        });
    });

    /* 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' }); }
            }
        });
    });

    /* 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' }); }
        });
    });

    /* 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': '190px' }); g('showContent').innerHTML = 'CLOSE'; showContent.setStyle('bottom', '51px'); }
                else { open = 'true'; contentOpen[i].morph({ 'opacity': 0, 'height': '0' }); showContent.setStyle('height', '14px'); showContent.setStyle('bottom', '51px'); g('showContent').innerHTML = 'MORE INFO +'; }
            }
        });
    });
});
