// 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();
        
     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 myTips = new Tips('.front_alerts');
    
	var luncheon2010_show = { 'sitephoto1.jpg': { caption: '', href: 'http://thenyhc.shutterfly.com' }, 'sitephoto2.jpg': { caption: '', href: 'http://thenyhc.shutterfly.com' }, 'sitephoto3.jpg': { caption: '', href: 'http://thenyhc.shutterfly.com' }, 'sitephoto4.jpg': { caption: '', href: 'http://thenyhc.shutterfly.com' }, 'sitephoto5.jpg': { caption: '', href: 'http://thenyhc.shutterfly.com' }, 'sitephoto6.jpg': { caption: '', href: 'http://thenyhc.shutterfly.com' }, 'sitephoto7.jpg': { caption: '', href: 'http://thenyhc.shutterfly.com' }, 'sitephoto8.jpg': { caption: '', href: 'http://thenyhc.shutterfly.com' }, 'sitephoto9.jpg': { caption: '', href: 'http://thenyhc.shutterfly.com' }, 'sitephoto10.jpg': { caption: '', href: 'http://thenyhc.shutterfly.com' }, 'sitephoto11.jpg': { caption: '', href: 'http://thenyhc.shutterfly.com' }, 'sitephoto12.jpg': { caption: '', href: 'http://thenyhc.shutterfly.com' } };
	
	var our_donors_show = {	
		"bofa.jpg": { caption: '' }, 
		"Citi.jpg": { caption: ''},
		"nwa.jpg": { caption: '' },  
		"wf.jpg": { caption: '' },  
		"richman_housing.jpg": { caption: '' },  
		"capital_one_bank.jpg": { caption: '' },
		"nixon_peabody.jpg": { caption: '' }
	};
	
	var apply_show = { "young_leader_apply_now.jpg": { caption: '', href: 'ylc_application.html'}, "young_leader_council.jpg": { caption: '', href: 'young_leadership_council.html' }};
	
	var get_show = { "donate_here.jpg": { caption: '', href: 'http://www.nycharities.org/donate/c_donate.asp?CharityCode=2649'}, "get_involved.jpg": { caption: '', href: 'get_involved.html'} };
	
	var baml_show = { 
		"baml_logo.jpg": {caption: '', href: 'http://www.thenyhc.org/DumontGreenSpotlight' },
		"baml1.jpg": {caption: '', href: 'http://www.thenyhc.org/DumontGreenSpotlight' },
		"baml2.jpg": {caption: '', href: 'http://www.thenyhc.org/DumontGreenSpotlight' },
		"baml3.jpg": {caption: '', href: 'http://www.thenyhc.org/DumontGreenSpotlight' },
		"baml4.jpg": {caption: '', href: 'http://www.thenyhc.org/DumontGreenSpotlight' },
		"baml5.jpg": {caption: '', href: 'http://www.thenyhc.org/DumontGreenSpotlight' }
		
	}
	
	
	
	
	
	new Slideshow.KenBurns('theRotator_Luncheon', luncheon2010_show, { duration: 1500, height: 194, hu: 'images/luncheon2010/home_show/', width: 260, controller: false, linked: true, thumbnails: false });
	
	new Slideshow('theRotator_donors', our_donors_show, { duration: 1500, hu: 'images/donor_logos2/', width: 260, height: 194, controller: false, resize: 'fit', overlap: false, thumbnails: false });
	
	new Slideshow('theRotator_young2', apply_show, { duration: 1500, hu: 'images/home_images/', width: 260, height: 194, controller: false, resize: 'fit', linked: true, thumbnails: false });
	
	new Slideshow('theRotator_get_involved2', get_show, { duration: 1500, hu: 'images/home_images/', width: 260, height: 194, controller: false, resize: 'fit', linked: true, thumbnails: false });
	
	new Slideshow('theRotator_baml', baml_show, { duration: 1500, hu: 'images/baml/', width: 260, height: 195, controller: false, resize: 'fit', linked: true, thumbnails: false });
 

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

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

    var slideFuntion = new function() {
    
        var okgo = function() {
           var outEl = $('dd' + which);
           which++;
            if(!$('dd' + which))
                which = 1;
            
            var inEl = $('dd' + 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);
    }
    
    if($('calendaralertslist')) {
    	
        var co = $('calendaralertslist').getCoordinates();
        var hh = 0 - (co.height);
        var start = 0;
        var box_height = 175;
        var dur = co.height * 60;
        
        $('calendaralertslist').setStyles({'top': 0});
        
       
        if(co.height > box_height) {
            var events_scroll = new Fx.Morph($('calendaralertslist'), {duration: dur, transition: Fx.Transitions.Linear });
            events_scroll.addEvent('complete', function() {
                        $('calendaralertslist').setStyles({'top': 175});
                        events_scroll.start({ 'top': hh });
                    });
            
            events_scroll.start({ 'top': hh });
            
            $('calendaralertslist').addEvent('mouseenter', function() {
                events_scroll.pause();
            });
            
            $('calendaralertslist').addEvent('mouseleave', function() {
                events_scroll.resume();
            });
        }
     }

            
            

});
