/**
 * @author Mousebomb
 */
var title = "Mousebomb's Blog.";
var fullTitleLen = title.length;
var i = -10;
var titleItv = null;
var introopen = false;
var introOffsetTop = 0;
var sitemapopen = false;
var sitemapOffsetTop = 0;
var linkOpen = false;
var linkOffsetTop = 0;
$(document).ready(function(){
    introOffsetTop = $("#intro").offset().top;
    sitemapOffsetTop = introOffsetTop;
    linkOffsetTop = introOffsetTop;
    $('#title').html('');
    titleItv = setInterval(titleGrow, 50);
	
    $('#intro').hide();
    $('#sitemap').hide();
    var ld = $('#links');
    ld.hide();
    
    $('#personalDiv a').mouseover(function(){
        $('#wrap').addClass('wrapper2');
    });
    $('#personalDiv a').mouseout(function(){
        $('#wrap').removeClass('wrapper2');
    });
    $('#personalDiv a').click(function(){
        var curEle = $('#personalDiv');
        $('#status').text('刚刚打开了私人博客');
    });
    
    $('#flashjDiv a').mouseover(function(){
        $('#wrap').addClass('wrapper1');
    });
    $('#flashjDiv a').mouseout(function(){
        $('#wrap').removeClass('wrapper1');
    });
    $('#flashjDiv a').click(function(){
        var curEle = $('#flashjDiv');
        $('#status').text('刚刚打开了闪界博客');
    });
    $('#sayHi').click(function(){
        if (introopen) {
            $('#intro').hide('slow');
            $('html,body').animate({
                scrollTop: 0
            }, 600);
            introopen = false;
        }
        else {
            closeAllIntro();
            $('#intro').show('fast', function(){
                $('html,body').animate({
                    scrollTop: introOffsetTop
                }, 600);
                introopen = true;
            });
        }
    });
    $('#seeMap').click(function(){
        if (sitemapopen) {
            $('#sitemap').hide('slow');
            $('html,body').animate({
                scrollTop: 0
            }, 600);
            sitemapopen = false;
        }
        else {
            closeAllIntro();
            $('#sitemap').show('fast', function(){
                $('html,body').animate({
                    scrollTop: sitemapOffsetTop
                }, 600);
                sitemapopen = true;
            });
        }
    });
    
    $("#linkBtn").click(function(){
        if (linkOpen) {
            ld.hide('slow');
            $('html,body').animate({
                scrollTop: 0
            }, 600);
            linkOpen = false;
        }
        else {
            closeAllIntro();
            ld.show('fast', function(){
                $('html,body').animate({
                    scrollTop: linkOffsetTop
                }, 600);
                linkOpen = true;
            });
        }
    });
    
    $('#yanyu').hide();
    $('#yanyu').load('/yanyu.php', {}, function(){
        $('#yanyu').show('fast');
    });
    
    $(".intro a").attr("target", "_blank");
	
    ld.load("link.html #linkUL");
});

function closeAllIntro(){
    if (sitemapopen) {
        $('#sitemap').hide('slow');
        sitemapopen = false;
    }
    if (introopen) {
        $('#intro').hide('slow');
        introopen = false;
    }
    if (linkOpen) {
        $('#links').hide('slow');
        linkOpen = false;
    }
}

function titleGrow(){
    if (i < fullTitleLen) {
        if (i < 0) {
            $('#title').html((++i % 2 ? '　' : '_'));
        }
        else {
            if (i == 0) {
                $('#title').html('');
            }
            $('#title').html($('#title').html() + title.substr(i++, 1));
        }
    }
    else {
        clearInterval(titleItv);
    }
}
