(function ($) {
    
    var TIMER = 300,
        container;
    
    $(function() {
        
        if ($('.noticewrap').height() < 500) {
            $('.noticewrap').css({height: '500px'});
        }
        
        throbber = $('<div>').addClass('noticedetail-throbber').html('<p>loading...</p>').css({
            height: $('.noticewrap').height() + 'px'
        });
        $('.noticewrap').append(throbber);
        throbber.hide();
        
        container = $('<div>').addClass('noticedetail-inline').css({
            height: $('.noticewrap').height() + 'px'
        });
        $('.noticewrap').append(container);
        container.hide();
        

        function image_transport() {
            var div = $(this).parents('.images').find('.image:visible');
            if ($(this).hasClass('prev')) {
                if (div.prev('.image').length) {
                    div.prev('.image').fadeIn(TIMER);
                }
                else {
                    div.parent().find('.image:last').fadeIn(TIMER);
                }
            }
            else {
                if (div.next('.image').length) {
                    div.next('.image').fadeIn(TIMER);
                }
                else {
                    div.parent().find('.image:first').fadeIn(TIMER);
                }            
            }
            div.fadeOut(TIMER);
        };
        
        function image_init() {
            container.find('.images .image').hide().css({
                position: 'absolute',
                top: 0,
                left: '60px'
            });
            container.find('.images .image:first-child').show();
            if (container.find('.images .image').length > 1) {
                container.find('.images').append($('<a>').html('Previous').addClass('transport prev'));
                container.find('.images').append($('<a>').html('Next').addClass('transport next'));
                container.find('.images .transport').click(image_transport);
            }
        };
        
        
        $('.noticelist a').click(function() {
            
            var throbbertimer = setTimeout(function() {
                throbber.fadeIn(TIMER);
                $.scrollTo(throbber, TIMER);
            },100);
            
            container.load($(this).attr('href'), {}, function() {
                clearTimeout(throbbertimer);
                container.find('.noticedetail').css({
                    height: ($('.noticewrap').height() - 70) + 'px'
                });
                image_init();
                container.fadeIn(TIMER);
                $.scrollTo(container, TIMER);
                throbber.fadeOut(TIMER);
                container.find('.closelink').click(function() {
                    container.fadeOut(TIMER);
                });
            });
            return false;
        });
        
      
        if (!$.browser.msie || $.browser.msie && parseInt($.browser.version) > 6) {
            $('.archive-dropdown').fancyDropdown();
            $('.archive-dropdown').show();
            $('.archive-link').hide();
        }
        
    });
    
// END
}) ($);
