$(document).ready(function(){
    
    /* underline control */
    if($('#header #menu a:eq(0)').hasClass('active')){
        var activeWidth = '64px';
        var activeMargin = '8px';
    }
    if($('#header #menu a:eq(1)').hasClass('active')){
        var activeWidth = '130px';
        var activeMargin = '92px';
    }
    if($('#header #menu a:eq(2)').hasClass('active')){
        var activeWidth = '170px';
        var activeMargin = '240px';
    }
    if($('#header #menu a:eq(3)').hasClass('active')){
        var activeWidth = '100px';
        var activeMargin = '430px';
    }
    $('#header #menu #underline').css({'marginLeft' : activeMargin, 'width' : activeWidth});
    $('#header #menu a:eq(0)').hover(
        function(over){
            $('#header #menu #underline').stop().animate({
                'marginLeft' : '8px',
                'width' : '64px'
            }, 500);
        },
        function(out){
            $('#header #menu #underline').stop().animate({
                'marginLeft' : activeMargin,
                'width' : activeWidth
            }, 500);
        }
    );
    $('#header #menu a:eq(1)').hover(
        function(over){
            $('#header #menu #underline').stop().animate({
                'marginLeft' : '92px',
                'width' : '130px'
            }, 500);
        },
        function(out){
            $('#header #menu #underline').stop().animate({
                'marginLeft' : activeMargin,
                'width' : activeWidth
            }, 500);
        }
    );
    $('#header #menu a:eq(2)').hover(
        function(over){
            $('#header #menu #underline').stop().animate({
                'marginLeft' : '240px',
                'width' : '170px'
            }, 500);
        },
        function(out){
            $('#header #menu #underline').stop().animate({
                'marginLeft' : activeMargin,
                'width' : activeWidth
            }, 500);
        }
    );
    $('#header #menu a:eq(3)').hover(
        function(over){
            $('#header #menu #underline').stop().animate({
                'marginLeft' : '430px',
                'width' : '100px'
            }, 500);
        },
        function(out){
            $('#header #menu #underline').stop().animate({
                'marginLeft' : activeMargin,
                'width' : activeWidth
            }, 500);
        }
    );
        
    /* height fix */
    var contentHeight = $('#main #content').height();
    var sidebarHeight = $('#main #sidebar').height();
    
    if(contentHeight > sidebarHeight){
        var temp_height = parseFloat(contentHeight) + 20;
        $('#main #sidebar').height(temp_height);
    }
    if(sidebarHeight > contentHeight){
        $('#main #content').height(sidebarHeight);
    }
    
    /* object size fix */
    if(document.getElementsByTagName("object")){
        $('object').width('700px').height('525px').parent().height('525px');
    }
    
    /* fancybox [lightbox] */
    $('#content .article').find('img[rel="lightbox"]').each(function(){
        var src = $(this).attr('src');
        var title = $(this).attr('alt');
        $(this).wrap('<a href="'+src+'" title="'+title+'" class="fancybox"></a>');
    });
    $('a.fancybox').fancybox({autoScale : false});
    
});
