//Custom

$(function(){
  $('#now1').click(function(){
    $(this).addClass('now1');
    $('#now2').removeClass();
    $('#now3').removeClass();
    $('#now1_ul').show()
    $('#now2_ul').hide();
    $('#now3_ul').hide().removeClass();
  });
  $('#now2').click(function(){
    $('#now1').removeClass();
    $(this).addClass('now2');
    $('#now3').removeClass();  
    $('#now1_ul').hide();
    $('#now2_ul').show();
    $('#now3_ul').hide();
  });
  $('#now3').click(function(){
    $('#now1').removeClass();
    $('#now2').removeClass();
    $(this).addClass('now3');  
    $('#now1_ul').hide();
    $('#now2_ul').hide();
    $('#now3_ul').show();
  });
  
   
  $('input[name="pj"]').click(function(){
    if( $('#bad').attr("checked") == true ){
      $('.mb6').show();
    }else{
      $(':checkbox').attr('checked', false);
      $('.mb6').hide();      
    }
  });
  
  
  $('.at').click(function(e){
    dialog("添加标签", this.id, 'addtag', e);
  });
  
  $('.et').click(function(e){
    dialog("添加站名", this.id, 'editutitle', e);
  });
  
  $("#tip").popDiv({"targetDiv" : "pop"});
  $("#tip2").popDiv({"targetDiv" : "pop2"});

});



function ajPost(urlstr, type, istipbar){
    $.ajax({
        url: urlstr,
        success: function(msg){
            alert(msg);
            if (type == '1') {
                var o = parseInt($('#likeval').text());
                o++;
                $('#likeval').empty().append(o);

            }
            else 
                if (type == '2') {
                    var o = parseInt($('#unlikeval').text());
                    o++;
                    $('#unlikeval').empty().append(o);
                }
            
            if (istipbar == '1') {
                var o = parseInt($('#likec').val());
                var t = parseInt($('#tc').val());
                o++; t++;
                var rCount = Math.round((o / t)*100) ;
                $('#tc').val(t);
                $('#likec').val(o);
                $('#dlikec').val(t-o);
                $('#like').empty().append(rCount);
                $('#dislike').empty().append(100 - rCount);
                $('.topb_9').css("width", (rCount * 2) + "px" );

            } else if (istipbar == '2') {
                var o = parseInt($('#dlikec').val());
                var t = parseInt($('#tc').val());
                o++; t++;
                var rCount = Math.round((o / t)*100) ;
                $('#tc').val(t);
                $('#likec').val(t-o);
                $('#dlikec').val(o);
                $('#like').empty().append(100 - rCount);
                $('#dislike').empty().append(rCount);
                $('.topb_9').css("width", ((100 - rCount) * 2) + "px" );
            }
        }
    });
}


function addBookmark(url, title){
    if (window.sidebar) {
        window.sidebar.addPanel(title, url, "");
    }
    else 
        if (document.all) {
            window.external.AddFavorite(url, title);
        }
        else 
            if (window.opera && window.print) {
                return true;
            }
}


$.fn.popDiv = function(options) {
    //设置默认值
    options = $.extend({
        targetDiv : "popDiv"
    },options);

    $("#"+options.targetDiv).bgiframe();
    this.each(function(){
        var _self = $(this);
        _self.hover(function(e){
        $("#"+options.targetDiv).css({
                        "position":"absolute",
                        "top": _self.offset().top+_self.outerHeight() ,
                        "left": _self.offset().left 
                    }).show();
        },function(e){
            if( $(e.relatedTarget).attr("id")!= options.targetDiv && $(e.relatedTarget).attr("class")!="bgiframe" ){ // 注释1
                $("#"+options.targetDiv).hide();	
            }
        });

        $("#"+options.targetDiv).bind("mouseleave",function(){  //注释2 
            $(this).hide();
        });
    });
    return this;
}

