$(document).ready(function(){

    var i=10;
    $("#menu a>span").each(function(){
        var name = $(this).text();
        menuItem($(this).parent(), name, false);
        $(this).parent().hover(function(){
            menuItem($(this),name,true);
        },function(){
            menuItem($(this),name,false);
        });
        $(this).parent().css({position:"relative"});
        $(this).text('');
    });
    var focus = $("#menu a.focus");
    var f_name = focus.css("background-image");
    if( f_name ) {
        var f_bg = f_name.replace(/\.(gif)|(png)/i,"b.$1");
        focus.css("background-image",f_bg);
    }

    var newsitems;
    var curritem=0;

    newsitems = $("#ticker li").hide().size();
    $("#ticker li:eq("+curritem+")").slideDown('slow');
    /*$("#ticker li:eq("+(curritem+1)+")").show();*/
    setInterval(ticknews,4000); //time in milliseconds
    function ticknews() {
        curritem = (curritem)%newsitems;
        $("#ticker li:eq("+(curritem++)+")").hide('slow',function(){
            curritem = (curritem)%newsitems;
            $("#ticker li:eq("+curritem+")").show('slow');
        });
    }

    $(".slide").hide();
    $("#show").removeClass('hidshow').append("<ul class='sub_mid'></ul>").find("ul.sub_mid")
              .html( $(".slide:first").html() );
    $("#sub_left span.subsec").click(function(){
        var target = $(this).attr('target');
        var next_node = $("#subs #"+target);
        
        $("#show>ul").fadeOut('slow',function(){
            $("#show>ul").remove();
            $("#show").append("<ul class='sub_mid'></ul>").find("ul")
                .html( next_node.html()).fadeIn('normal');
        });
    });

    var j=0;
    var total = $("#comments>div").length;
    $(".news_border .next").click(function(){
        $("#showhere *").fadeOut();
        var tuple = $("#comments div").eq(j++).html();
        $("#showhere").html(tuple);
        j %= total;
    }).trigger('click');
    
});


function menuItem(obj,name,is_in)
{
    var name = name.toLowerCase();
    var len = name.length<14? 89 : 146;
    obj.css({height:"27px"});
    if(is_in){
        obj.css({ background:"url(/images/"+name+"b.gif) no-repeat",width: len+"px" });
    }else{
        obj.css({ background:"url(/images/"+name+".gif) no-repeat",width:len+"px" });
    }
}
