var curUrl = window.location.href;
var curTitle = document.title;
var enUrl = encodeURIComponent(curUrl);
var enTitle = encodeURIComponent(curTitle);

if (top.location != self.location) {
  top.location=self.location;
}

function tags(items,length,value){
  for(var i=1;i<=length;i++){
    if(value==i){
      document.getElementById(items+"_tag_"+value).className='this';
      document.getElementById(items+"_"+value).style.display="block";
    } else{
      document.getElementById(items+"_tag_"+i).className='';
      document.getElementById(items+"_"+i).style.display="none";
    }
  }
}
function pickScroll(){
  var $img = $("#picView img");
  var $x = $img.offset().left;
  var $y = $img.offset().top;
  var $w = $img.width();
  var $h = $img.height();
  var ISIE = $.browser.msie < 7.0 ? false : true;
  if ($(window).scrollTop() > $y && $(window).scrollTop() < $y+$h) {
    if (ISIE) {
      var $cfg = {
        position : "absolute",
        top : document.documentElement.scrollTop+$y
      }
    } else {
      var $cfg = {
        position : "fixed",
        top : "0px"
      }
    }
  } else {
    var $cfg = {
      position : "absolute",
      top : $y+"px"
    }
  }
  $cfg['left'] = $x+$w-98;
  var btn = $("#pickHuaban");
  btn.css($cfg);
}
function pickHuaban(obj){
  var $img = $("#picView img");
  obj.hover(function(){
    var btn = '';
    var $description = $("meta[name=description]").attr("content");
    if ($("#pickHuaban").length == 0) {
      btn = $("<div />");
      btn.attr("id","pickHuaban").html('<a title="²É¼¯µ½»¨°êÍø" href="http://huaban.com/bookmarklet/?url='+enUrl+'" target="_blank"></a>');
      $("body").append(btn);
    } else {
      btn = $("#pickHuaban");
    }
    pickScroll();
    btn.show().hover(function(){
      $(this).show();
    },function(){
      $(this).hide();
    });
  },function(){
    $("#pickHuaban").hide();
  });
  $(window).scroll(function(){
    pickScroll();
  }).resize(function(){
    pickScroll();
  });
}