﻿    var bgSlide;
    var dd;

    var Page = {
        CurrentPage: 0,
        TransitionLength: 11000,
        Animating: false,
        Timer: null,
        Setup: function() {
            new Dropdown();
        
        var search = $$('.search');
        
            search.addEvent('focus', function(y) {
                if (y.target.get('value') == 'Coffee Search')
                    y.target.set('value', '');
            });
            search.addEvent('blur', function(y) {
            if (y.target.get('value') == '')
                y.target.set('value', 'Coffee Search');
            });
        

        Page.Pages = $$('.imageslide div.page');

        if (Page.Pages.length > 0) {


            var left = 0;
            Page.Pages.setStyles({ 'opacity': '0', 'display': 'block', 'visibility': 'visible' }).each(function(y) {
                y.setStyle('left', left + 'px');
                left += y.getSize().x;
            });

            if (Page.Pages.length > 1) {
                var pn = new Element('div', { 'id': 'promonav' });
                pn.inject('promosection');

                var i = 0;
                Page.Pages.each(function(y) {
                    var el = new Element('div');
                    el.inject(pn);
                    el.set('text', i + 1);
                    var j = i;
                    el.addEvent('click', function(x) {
                        Page.CurrentPage = j;
                        Page.ShowPage(j);
                    });
                    i++;
                });
            }
        }

        Page.PromoNav = $$('#promonav div');
        Page.SetPromoNav(0);

        Page.Pages.set('tween', { 'duration': '1500' });
        Page.Pages.fade(1);

        if ($('promoinner') != null) {
            Page.Scroller = new Fx.Scroll('promoinner', { 'duration': '1500', onComplete: Page.AnimEnd, onStart: Page.AnimStart });
            Page.Timer = Page.NextPage.delay(Page.TransitionLength);
        }

    },
    NextPage: function() {
        if (!Page.Animating) {
            Page.CurrentPage++;
            if (Page.CurrentPage >= Page.Pages.length)
                Page.CurrentPage = 0;
            Page.ShowPage(Page.CurrentPage);

        }
    },
    SetPromoNav: function(y) {
        var i = 0;
        Page.PromoNav.each(function(z) {
            if (z.hasClass('doselected') && i != y) {
                z.removeClass('doselected');
                z.morph({ 'background-color': '#ecd9ba', 'width': '20px', 'height': '20px', 'margin-top': '3px', 'color': '#2B0C68', 'padding-top': '3px' });
            }
            if (i == y) {
                z.addClass('doselected');
                z.morph({ 'background-color': '#2B0C68', 'width': '23px', 'height': '21px', 'margin-top': '0', 'color': '#ecd9ba', 'padding-top': '5px' });
            }
            i++;
        });

    },
    ShowPage: function(y) {
        if (!Page.Animating) {

            Page.SetPromoNav(y);

            $clear(Page.Timer);

            Page.Scroller.toElement(Page.Pages[y]);
        }
    },
    AnimStart: function() { Page.Animating = true; },
    AnimEnd: function() { Page.Animating = false; Page.Timer = Page.NextPage.delay(Page.TransitionLength); }

}

/*************************************************************/

document.addEvent('domready', function() {


   // bgSlide = new mooSizer({ bgElement: '#bg img' });
    
    Page.Setup();
    


    

});
