$(document).ready(function(){
    $(".search-box .kw").click(function(){    
        var defVal = $(".search-box input[name='def_val']").val();
        if (this.value == defVal) {
            this.value = "";
        }
    });
    $(".search-box .kw").blur(function(){
        window.setTimeout(function(){
            var defVal = $(".search-box input[name='def_val']").val();
            $(".search-box .kw").val(defVal);
        }, 1000);
    });
//    $(".search-box .btn").click(function(){
//        var url = $(".search-box input[name='url']").val();
//        var kw = $(".search-box input[name='kw']").val();
//        if (kw != "") {
//            window.location.href = (url+kw);
//        }
//    });

    $(".blogview > .blogitem").hover(function(){
        $("ul > li[class!=active]", this).css("visibility", "visible");
        //$("ul > li[class!=active]", this).fadeIn('slow');        
    },function(){
        $("ul > li[class!=active]", this).css("visibility", "hidden");
        $("ul.bong-do > li", this).css("visibility", "visible");
        //$("ul > li[class!=active]", this).fadeOut('slow');
    });
    $(".blogview > .blogitem ul").each(function(){
        if ($(this).attr("class") != "bong-do") {
            if($("li[class!=active]", this).size() <= 6) {
                $("li[class!=active]", this).css("padding-left", "10px");
                $("li[class!=active]", this).css("padding-right", "10px");
            }
        }
    });
    
    var currentBoxID = $(".frontpage-box .content .current").attr("id");    
    $(".frontpage-box .nav ul li span").hover(function(){
        if (this.id != ("nav-"+currentBoxID)) {
            $(this).addClass("current");
        }
    },function(){
        if (this.id != ("nav-"+currentBoxID)) {
            $(this).removeClass("current");
        }
    });
    var displayBox = function(boxID){
        $(".frontpage-box .nav ul li span").removeClass("current");
        $((".frontpage-box .nav ul li #nav-"+boxID)).addClass("current");

        
        $(".frontpage-box .content .item").removeClass("current");
        $((".frontpage-box .content #"+boxID)).addClass("current");
        
        //$(".frontpage-box .content .item").fadeOut('slow');
        //$(".frontpage-box .content .item").removeClass("current");
        //var selector = ".frontpage-box .content #"+boxID;
        //window.setTimeout(function(){
        //    $(selector).fadeIn('slow');
        //},1000);
        
    };
    $(".frontpage-box .nav ul li span").click(function(){
        currentBoxID = this.id.split("-").pop();
        displayBox(currentBoxID);
    });
    var maxHeight = -1;
    $(".frontpage-box .content .item").each(function(){
        maxHeight = $(this).height() > maxHeight ? $(this).height() : maxHeight;
    });
    if (maxHeight < 275){
        maxHeight = 275;
    }
    $(".frontpage-box .content").height(maxHeight);
    $(".frontpage-box .content .item").height(maxHeight);

    var autoDisplayBox = function(){
        var curID = $(".frontpage-box .content .current").attr("id");
        if (curID) {
            curID = parseInt((curID.substr(3)));
            var nextID = curID < $(".frontpage-box .content .item").size() ? curID+1 : 1;
            displayBox("box"+nextID);
            boxTimer = window.setTimeout(autoDisplayBox, 3000);
        }
    }
    window.setTimeout(autoDisplayBox, 5000);
    
    //
    $("#ImgNewsID").hover(function(){
        if (this.stop)this.stop();        
    },function(){
        if (this.start)this.start();
    });
    
});

