jQuery(function() {

    //Set up slider if it exists on the page
    if(jQuery('#slider').length > 0) {

        jQuery('#slider').cycle({ 
        fx: 'fade',
        speed: 2000,
        timeout: 8000,
        delay: -2000
        });
    
    }
    
    //Set up fancybox if the #table exists
    if(jQuery('#table').length > 0) {
        
        jQuery('#table').fancybox();
        
    }
    
    
    //Footer menus
    jQuery('#footer-main').removeClass('no-js');
    
    var fheight = jQuery('#footer-main').height();
        
    var submenus = jQuery('.submenu');
    
    submenus.parent().addClass('arrow');
    
    jQuery('ul > li.arrow a').live("click", function(e) {
        
        e.preventDefault();
        
        if( jQuery('.open') != null ) {
            jQuery('.arrow-down').trigger('click');
        }
        
        var el = jQuery(this).parent();
        var submenu = jQuery(this).parent().find('.submenu');
        var sheight = submenu.height();
        
        el.removeClass('arrow').addClass('arrow-down');
        
        submenu.slideDown();
        
        submenu.addClass('open');
        
        jQuery('#footer-main').animate({ height: fheight+sheight+'px' });
        
    });
    
    jQuery('ul > li.arrow-down a').live("click", function(e) {
        
        e.preventDefault();
        
        var el = jQuery(this).parent();
        var submenu = jQuery(this).parent().find('.submenu');
        var sheight = submenu.height();
        
        el.removeClass('arrow-down').addClass('arrow');
        
        submenu.slideUp();
        
        jQuery('#footer-main').animate({ height: fheight+'px' });
        
       
    });
    
    
    jQuery('#logo').data( 'origTop', jQuery('#logo').css('top') ).css({ top: '-1000px' }).show();
    
    //jQuery('.phone').data( 'origRight', jQuery('.phone').css('right') ).css({ right: '-1000px' }).show();
    
    jQuery('#logo-sub').data('origRight', jQuery('#logo-sub').css('right') ).css({ right: '-1000px' }).show();
    
    jQuery('.login').data('origTop', jQuery('.login').css('top') ).css({ top: '-300px' }).show();
    
    jQuery('#logo').delay(1500).animate({ top: jQuery('#logo').data('origTop') }, 900, 'easeOutExpo');
        
    jQuery('#logo-sub').delay(2000).animate({ right: jQuery('#logo-sub').data('origRight') }, 600, 'easeOutExpo');
        
    //jQuery('.phone').animate({ right: jQuery('.phone').data('origRight') }, 600, 'easeOutExpo');
            
    jQuery('.phone').delay(2200).fadeIn();
            
    jQuery('.login').delay(2300).animate({ top: jQuery('.login').data('origTop') });
        
    //setInterval(animLogo, 5000);
    
 


});

function animLogo() {
    
    var logo = jQuery('#logo'),
        logowidth = logo.width(),
        logoleft = logo.css('left'),
        logosrc = logo.find('img').attr('src'),
        logonewsrc = logosrc.replace('logo.png', 'logo-rev.png');
    
    logo.animate({ opacity: 0.4 }, 1000).animate({ opacity: 1 }, 1000);
    
}
