var d3 = d3 || {};
d3.structure = 
{
    init        : function()
    {
        d3.structure.header.init();
        d3.structure.login.init();
        d3.structure.footer.init();
        d3.structure.overs();
    },
    
    
    overs: function()
    {
        var dur    = 200,
            easing = 'easeInOutQuad';
        
        $('a.rep').animate({ backgroundColor: '#239F9E'},{queue: false, duration:  dur, easing: easing})
        $('a.rep').hover(function(){                                               
            $(this).animate({ backgroundColor: '#f4864a'},{queue: false, duration: dur, easing: easing})
        },function(){                                                              
            $(this).animate({ backgroundColor: '#239F9E'},{queue: false, duration: dur, easing: easing})
        });   
    },
    
    
    header      :
    {
        
		init            : function()
        {
            
            
            
            
/*
            var timeout;
            
            $('#header li.subnav,  #header li.subnav a').hover(function(){
                $('#header li.subnav ul').animate({ height: 60 }, { queue: false, duration: 300, easing: 'easeInOutQuad' });
                clearTimeout(timeout);
                $(this).addClass('current');
            },function(){    
                timeout = setTimeout(function() {
                    $('#header li.subnav ul').animate({ height: 0 }, { queue: false, duration: 300, easing: 'easeInOutQuad' });
                }, 200);
                $(this).removeClass('current');
            });
            
            $('#header li.subnav, #header li.subnav a, #header li.subnav ul, #header li.subnav ul li, #header li.subnav ul li a').hover(function(){
                clearTimeout(timeout);
            });*/

            
            $.each($('#header ul > li > strong'),function(obj){
                $(this).attr('rel',$(this).css('width'));
            });
            
            $('#header ul > li').hover(function(){
                //$(this).addClass('current');
                var $wing = $(this).find('span');
                var $bar  = $(this).find('strong');
                $(this).find('a').animate({color:'#f26622'},{queue: false, duration: 300, easing: 'easeInOutQuad'});
                $wing.css({left:0,top:10}).animate({ top: 0, left: 10, opacity: 1 },{queue: false, duration: 300, easing: 'easeInOutQuad'});
                $bar.css({width:0,top:40,height:14,left:7});
                $bar.animate({ width: $bar.attr('rel'), opacity: 1 },{queue: false, duration: 300, easing: 'easeInOutQuad'});
                
                $(this).find('ul').animate({ height: 60 }, { queue: false, duration: 300, easing: 'easeInOutQuad' });
                

            },function(){
                //$(this).removeClass('current');
                var $wing = $(this).find('span');
                var $bar = $(this).find('strong');
                $(this).find('a').animate({color:'#666666'},{queue: false, duration: 300, easing: 'easeInOutQuad'});
                $wing.animate({ top: -10, left: 15, opacity: 0 },{queue: false, duration: 300, easing: 'easeInOutQuad'});
                $bar.css({top:40});
                $bar.animate({ top:50, opacity: 0 },{queue: false, duration: 300, easing: 'easeInOutQuad', complete: function(){$bar.css({top:40});}});
                
                $(this).find('ul').animate({ height: 0 }, { queue: false, duration: 300, easing: 'easeInOutQuad' });
            });
        }
    },
    
    
    login      :
    {
        
		init            : function()
        {
            $('#login dt').live('click',function(){
                var $dd = $(this).next();
                var dur = 300;
                $dd.is(':visible') ? $dd.slideUp(dur) : $dd.slideDown(dur);
            });
        }
    },
    
    
    footer      :
    {
        

		init            : function()
        {
            d3.structure.footer.updateYear();
        },
        
        updateYear     : function()
        {
            var curdate = new Date(),
                year    = curdate.getFullYear();
            
            function update(date)
            {
                $('#footer .year').animate({ delay: 1 },{ duration: 100, queue: true, complete: function() {
                    if(date<=year)
                    {
                        $('#footer .year').text(date++);
                        update(date);
                    }
                }});
            }
            update(1950);
        }
    }
};
$(document).ready(function() {
    d3.structure.init();
});