// subsequent

window.addEvent('domready', function(){

    Element.implement({
        hasEvent: function(eventType,fn) {
            //get the element's events
            var myEvents = this.retrieve('events');
            //can we shoot this down?
            return myEvents && myEvents[eventType] && (fn == undefined || myEvents[eventType].keys.contains(fn));
        }
    });
    
    var win_size = window.getScrollSize();
    var theCal = $('theCalendar');
    var current_cal = $('theCalendar1');
    var temp_cal = $('theCalendar1');
    var next_cal = $('theCalendar2');
    var theCal_pos = theCal.getCoordinates();
    
   
    
    $('theCalendar1').setStyles({ 
        'opacity': 0, 
        'display': 'block'
      //  'top': theCal_pos.top, 'left': theCal_pos.left
    });
    
    $('theCalendar2').setStyles({ 
        'opacity': 0, 
        'display': 'block'
        // 'top': theCal_pos.top, 'left': theCal_pos.left
    });
    
    var a = 1;
    var b = 2;
    
    function small_links() {
        $$('.small_link').each(function(el) {
            el.addEvent('click', function(e) {
                e.stop();
                theCal_pos = theCal.getCoordinates();
                url = 'content.php?sc=cal&d=' + el.get('name');
                $('theCalendar'+b).load(url);
                $('theCalendar'+a).morph({ 'opacity': 0 });
                $('theCalendar'+b).morph({ 'opacity': 1 });
                c = a;
                a = b;
                b =c;                
            });
        });
    }
    
    $('theCalendar1').set('load', { 'onSuccess': function() { small_links(); remover(); } });
    $('theCalendar2').set('load', { 'onSuccess': function() { small_links(); remover(); } });
    
    current_cal.morph({ 'opacity': 1 });
    
    small_links();
    
     if($('theDay')) {
        $('theDay').setStyles({'opacity': 0, 'display': 'block' });
        var dday = $('theDay');
        
        dday.set('load', { onSuccess: function(responseText, responseXML) { remover(); } });
    }
    
    if($('happy_holidays')) {
        $('happy_holidays').set('morph', {
            link: 'chain', 
            onComplete: function(e) { $('happy_holidays').destroy(); } 
        }); 
    }
    
     if($('theGrayness')) {
        $('theGrayness').setStyles({'opacity': 0 });
        
        $('theGrayness').addEvent('click', function(e) {
            e.stop();
            $('theGrayness').morph({ 'opacity': 0 });
            $('theGrayness').setStyle('display', 'none');
            pp = dday.getCoordinates();
            if($('happy_holidays')) {
                $('happy_holidays').morph({ 'opacity': 0, 'height': 0 });
                $('happy_holidays').morph({ 'display': 'none' });
                
            }
            
            dday.morph({ 'opacity': 0, 'height': 0, 'width': 0, 'left': pp.left+100, 'top': pp.top+100 });
               
        });
        
    }
    
    
    
    
    function remover() {
        
        $$('.close').each(function(el) {
            el.addEvent('click', function(e) {
                e.stop();
                $('theGrayness').setStyle('display', 'none');
                $('theGrayness').morph({ 'opacity': 0 });
                dday.morph({ 'opacity': 0, 'height': 0, 'width': 0 });
            });
        });
        
        $$('a.event_day').each(function(el) {
            if(!el.hasEvent('click')) {
                el.addEvent('click', function(e) {
                    e.stop();
                    factor = $(el.get('id') + '_day').get('name');
                    h = Math.ceil(factor/3) * 220;
                    w = 220;
                    if(factor == 2)
                        w = 440;
                    else if(factor > 2)
                        w = 660;
                    l = w/2;
                    t = h/2;
                    pp = el.getCoordinates();
                    url = 'content.php?ss=day&d=' + el.get('id');
                    $('theGrayness').setStyles({ 'display': 'block', 'height': win_size.y });
                    $('theGrayness').morph({ 'opacity': .7 });
                    dday.setStyles({ 'left': pp.left, 'top': pp.top, 'height': 0, 'width': 0 });
                    dday.morph({ 'opacity': 1, 'height': h, 'width': w, 'left': pp.left-120, 'top': pp.top-t });
                    dday.set('html', '');
                    dday.load(url);
                });
            }
        });

    }
    
    remover();
    
    
    
    
    var slideTimer = 4000;  //time between slides (1 second = 1000), a.k.a. the interval duration  
    var transitionTime = 2000; //transition time (1 second = 1000)  
    var which = 1;
    var maxx = 17;

    $$('#theRotator div').setStyle('opacity', 0);
    $$('#theRotator div').setStyle('display', 'block');
    if($('d1'))
        $('d1').setStyle('opacity', 1);

    var slideFuntion = new function() {
    
        var okgo = function() {
           var outEl = $('d' + which);
            if(which >= maxx)
                which = 1;
            else    
                which++;
            
            var inEl = $('d' + which);
            
              var item_out = new Fx.Morph(outEl, {
                     duration: transitionTime, 
                     transition: Fx.Transitions.Quad.easeInOut, 
                     wait:false
            });
            
            var item_in = new Fx.Morph(inEl, {
                     duration: transitionTime, 
                     transition: Fx.Transitions.Quad.easeInOut, 
                     wait:false
            });
            
             item_out.start({ 
                'opacity':[1,0]
            });
            
            item_in.start({ 
                'opacity':[0,1] 
            });
        };
        
        okgo.periodical(slideTimer, this);
    }
    
    $$('#theRotator_young div').setStyle('opacity', 0);
    $$('#theRotator_young div').setStyle('display', 'block');
    if($('y1'))
        $('y1').setStyle('opacity', 1);
    which_y = 1;
    var slideTimer2 = 5200;  //time between slides (1 second = 1000), a.k.a. the interval duration  
    var transitionTime2 = 2100; //transition time (1 second = 1000)  

    var slideFuntion2 = new function() {
    
        var okgo = function() {
           var outEl = $('y' + which_y);
            if(which_y == 2)
                which_y = 1;
            else    
                which_y++;
            
            var inEl = $('y' + which_y);
            
              var item_out = new Fx.Morph(outEl, {
                     duration: transitionTime2, 
                     transition: Fx.Transitions.Quad.easeInOut, 
                     wait:false
            });
            
            var item_in = new Fx.Morph(inEl, {
                     duration: transitionTime2, 
                     transition: Fx.Transitions.Quad.easeInOut, 
                     wait:false
            });
            
             item_out.start({ 
                'opacity':[1,0]
            });
            
            item_in.start({ 
                'opacity':[0,1] 
            });
        };
        
        okgo.periodical(slideTimer2, this);
    }
    
    
     $$('#theRotator_get_involved div').setStyle('opacity', 0);
    $$('#theRotator_get_involved div').setStyle('display', 'block');
    if($('g1'))
        $('g1').setStyle('opacity', 1);
    which_g = 1;
    var slideTimer3 = 5700;  //time between slides (1 second = 1000), a.k.a. the interval duration  
    var transitionTime3 = 2500; //transition time (1 second = 1000)  

    var slideFuntion3 = new function() {
    
        var okgo = function() {
           var outEl = $('g' + which_g);
            if(which_g == 2)
                which_g = 1;
            else    
                which_g++;
            
            var inEl = $('g' + which_y);
            
              var item_out = new Fx.Morph(outEl, {
                     duration: transitionTime3, 
                     transition: Fx.Transitions.Quad.easeInOut, 
                     wait:false
            });
            
            var item_in = new Fx.Morph(inEl, {
                     duration: transitionTime3, 
                     transition: Fx.Transitions.Quad.easeInOut, 
                     wait:false
            });
            
             item_out.start({ 
                'opacity':[1,0]
            });
            
            item_in.start({ 
                'opacity':[0,1] 
            });
        };
        
        okgo.periodical(slideTimer3, this);
    }
    
        $$('#theRotator_alert div').setStyle('opacity', 0);
    $$('#theRotator_alert div').setStyle('display', 'block');
    if($('a1'))
        $('a1').setStyle('opacity', 1);
    which_a = 1;
    var slideTimer4 = 3700;  //time between slides (1 second = 1000), a.k.a. the interval duration  
    var transitionTime4 = 1800; //transition time (1 second = 1000)  

    var slideFuntion3 = new function() {
    
        var okgo = function() {
           var outEl = $('a' + which_a);
            if(which_a == 1)
                which_a = 1;
            else    
                which_a++;
            
            var inEl = $('a' + which_a);
            
              var item_out = new Fx.Morph(outEl, {
                     duration: transitionTime4, 
                     transition: Fx.Transitions.Quad.easeInOut, 
                     wait:false
            });
            
            var item_in = new Fx.Morph(inEl, {
                     duration: transitionTime4, 
                     transition: Fx.Transitions.Quad.easeInOut, 
                     wait:false
            });
            
             item_out.start({ 
                'opacity':[1,0]
            });
            
            item_in.start({ 
                'opacity':[0,1] 
            });
        };
        
        okgo.periodical(slideTimer4, this);
    }
    
    $$('#theRotator_event div').setStyle('opacity', 1);
    $$('#theRotator_event div').setStyle('display', 'block');
    /*
     $$('#theRotator_event div').setStyle('opacity', 0);
    $$('#theRotator_event div').setStyle('display', 'block');
    if($('e1'))
        $('e1').setStyle('opacity', 1);
    which_e = 1;
    var slideTimer5 = 4000;  //time between slides (1 second = 1000), a.k.a. the interval duration  
    var transitionTime5 = 1800; //transition time (1 second = 1000)  

    var slideFuntion5 = new function() {
    
        var okgo = function() {
           var outEl = $('e' + which_e);
            if(which_e == 1)
                which_e = 1;
            else    
                which_e++;
            
            var inEl = $('e' + which_e);
            
              var item_out = new Fx.Morph(outEl, {
                     duration: transitionTime5, 
                     transition: Fx.Transitions.Quad.easeInOut, 
                     wait:false
            });
            
            var item_in = new Fx.Morph(inEl, {
                     duration: transitionTime5, 
                     transition: Fx.Transitions.Quad.easeInOut, 
                     wait:false
            });
            
             item_out.start({ 
                'opacity':[1,0]
            });
            
            item_in.start({ 
                'opacity':[0,1] 
            });
        };
        
        okgo.periodical(slideTimer5, this);
    }
    */
    
            
            
            

});