// subsequent

window.addEvent('domready', function(){
    
    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($('theGrayness')) {
        $('theGrayness').setStyles({'opacity': 0 });
        
        $('theGrayness').addEvent('click', function(e) {
            e.stop();
            $('theGrayness').morph({ 'opacity': 0 });
            $('theGrayness').setStyle('display', 'none');
            pp = dday.getCoordinates();
            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').morph({ 'opacity': 0 });
                $('theGrayness').setStyle('display', 'none');
                dday.morph({ 'opacity': 0, 'height': 0, 'width': 0 });
            });
        });
        
        $$('a.event_day').each(function(el) {
            el.addEvent('click', function(e) {
                e.stop();
                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': 220, 'width': 220, 'left': pp.left-100, 'top': pp.top-100 });
                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 = 12;

    if($('events')) {
        var co = $('events').getCoordinates();
        var hh = 0 - (co.height);
        var start = 0;
        var box_height = 163;
        var dur = co.height * 60;
        
        $('events').setStyles({'top': 165});
        
        if(co.height > box_height) {
            var events_scroll = new Fx.Morph($('events'), {duration: dur, transition: Fx.Transitions.Linear });
            events_scroll.addEvent('complete', function() {
                        $('events').setStyles({'top': 165});
                        events_scroll.start({ 'top': hh });
                    });
            
            events_scroll.start({ 'top': hh });
            
            $('event_box').addEvent('mouseenter', function() {
                events_scroll.pause();
            });
            
            $('event_box').addEvent('mouseleave', function() {
                events_scroll.resume();
            });
        }
        
        
    }
            

});