$(document).ready(function(){

    jQuery.easing.def = "easeOutQuart";

    $('[class~="accordionContent"]').each(function(){        
        var holder = $(this).parents('.accordionItem').parent();
        var height = holder.height();
        var items = holder.find('.accordionItem').length;
        height = height - (holder.find('.accordionTitle').outerHeight() * items);
        height = height - holder.find('.titleHolder').outerHeight();
        $(this).height(height);
    });

    $('.accordionTitle').click(function(){
        var holder = $(this).parents('.accordionItem').parent();
        holder.find('[class~="accordionContent"]:visible').slideUp(800);
        $(this).parents('.accordionItem').find('[class~="accordionContent"]').slideDown(800);
    });

    var scroller = new Scroller($('.scroller'));


    //Make the menu drop down work
    $('#dropDowns').hide(); //Make sure they are hidden to start
    $('#menu').find('[class~="subParent"]').mouseenter(function(){
        var width = $(this).width();
        var index = $(this).index();
        if(!$('#dropDowns').is(':visible')){ //Only fire this function if the submenu isn't already visible            
            $(this).find('ul').each(function(){
                var ul = $(this).clone();//Copy the submenus for insertion into the drop down
                ul.css({display: 'block'});//Display them
                $('#dropDown').append(ul);//Put in the submenu
            });
            $('#dropDown').append('<div class="floatFix"><div>');
            $('#dropDowns').css({position: 'absolute', zIndex: 2000, padding: '0 0 0 '+(width * index)+'px', width: (980 - (width * index))+'px'});
            $('#dropDowns').slideDown(300);
        }
    });
    $('#menu').find('.subParent').mouseleave(function(event){
        if(event.relatedTarget.id != 'dropDown'){
            $('#dropDown').mouseleave();
        }
    });
    $('#dropDown').mouseleave(function(){
        $('#dropDowns').slideUp(300, function(){
            $('#dropDown').html('');
        });
    });




    //RSS Scroller
    var rssHeight = $('.rss').height();
    var top = parseInt($('.rss').css('top'));
    var interval = setInterval(function(){        
        top--;
        $('.rss').css({top: top+'px'});
        if(Math.abs(top) == rssHeight){
            top = $('.rssHolder').height();
        }
    },24);

    $('.rssHolder').mouseenter(function(){
        clearInterval(interval);
    });

    $('.rssHolder').mouseleave(function(){
        interval = setInterval(function(){
        top--;
        $('.rss').css({top: top+'px'});
        if(Math.abs(top) == rssHeight){
            top = $('.rssHolder').height();
        }
        },24);
    });


    $('#headerMenu').find('.menuItem').click(function(){
        $(this).parents('tr').find('.on').addClass('off');
        $(this).parents('tr').find('.on').removeClass('on');
        $(this).removeClass('off');
        $(this).addClass('on');
        var i = $(this).index('.menuItem') + 1;
        $(this).parents('#headerMenu').parent().find('#headerText').find('div').hide();
        $(this).parents('#headerMenu').parent().find('#headerText').find('[class~="item'+i+'"]').show();
    })


    $('#ukOffices').find('[class~="btnTable"]').click(function(){
        var a = $(this).parents('#ukOffices').find('div:visible');
        var b = $(this).parents('#ukOffices').find('div:hidden');
        a.hide();
        b.show();
    });

    $('[class~="clientLink"]').click(function(){
        window.location = $(this).find('a.orange').attr('href');
    });


    $('#menu').find('td').click(function(){
        window.location = $(this).find('[class~="krodd"]').attr('href');
    });

});


