var muser = null;
var en_id = $('#en_id').html();
var entry = $('#entry').html();
var en_url = document.location.href;

// catalog list
//function G(id){return document.getElementById(id);}
if(G("cat")){
var lItems=G("cat").getElementsByTagName("DD");
var lItemnum=lItems.length-1;
var catList={dir:G("dir"),cat:G("cat"),temp:G("temp"),data:G("data"),catCon:"",t:null,h:0,tempH:0,items:lItems,itemnum:lItemnum,shownum:8};
function hideCat(){
    if(catList.itemnum<=catList.shownum){
        return false
    }
    catList.cat.className="arr";
    var B=catList.cat.offsetWidth;
    catList.cat.style.width=B+"px";
    catList.data.style.width=B+"px";
    for(var A=catList.shownum; A<catList.itemnum; A++){
        catList.catCon+="<li>"+catList.items[A].innerHTML+"</li>";
        catList.items[A].style.display="none"
    }
    catList.data.innerHTML=catList.catCon;
    catList.tempH=catList.data.offsetHeight;
    catList.data.style.marginTop=-catList.tempH+"px"
}
function maxCat(){
    if(catList.h<catList.tempH){
        catList.h+=10;
        catList.temp.style.height=catList.h+"px";
        catList.data.style.marginTop=catList.h-catList.tempH+"px";
        catList.t=setTimeout("maxCat()",10)
     }
     if(catList.h==20){
        catList.temp.style.borderBottom="1px dotted #59381F"
     }
}
function minCat(){
    if(catList.h>0){
        catList.h-=10;
        catList.temp.style.height=catList.h+"px";
        catList.data.style.marginTop=-(catList.tempH-catList.h)+"px";
        catList.t=setTimeout("minCat()",10)
     }
     if(catList.h==20){
        catList.temp.style.borderBottom="none"
     }
}

function contains2(B,A){while(A){A=A.parentNode?A.parentNode:A;if(A==B){return true}return false}}
catList.dir.onmouseover=function(A){clearTimeout(catList.t);catList.t=setTimeout("maxCat()",100)};
catList.dir.onmouseout=function(A){
if(document.all){
    clearTimeout(catList.t)
}else{
    if(A.currentTarget!=A.relatedTarget&&!contains2(A.currentTarget,A.relatedTarget)){
    clearTimeout(catList.t)
    }
}
catList.t=setTimeout("minCat()",100)};

hideCat()

}

// base info
$.ajax({
  type: "GET",
  url: "/dic/?controller=entry&action=getinfo&en_id="+en_id,
  dataType: "json",
  error: function(XMLHttpRequest, textStatus, errorThrown){
    alert('get base info failed: '+textStatus);
    },
  success: function(edata){
    muser = edata.muser;    
    $('#vnum').html(edata.views);
    show_up(edata.up_stat, edata.ups);
    if (edata.mention != '') {
        var mul=$('<ul></ul>');
        for(var k in edata.mention) {
            mul.append('<li><a href="'+edata.mention[k]+'" target="_blank">'+k+'</a></li>');
        }
        mul.append('<li><a href="'+edata.men_more+'" target="_blank">more>> </a></li>');
        $('#mention').append(mul);
        $('#mlist').attr('style', 'display:block');
    }

    if (edata.delurl != '') {
        $('#delrev').html('<a href="'+edata.delurl+'&keepThis=true&TB_iframe=true&height=210&width=390&modal=true" title="Delete current version" class="thickbox">Delete current version</a> &nbsp;|&nbsp;');
    }
    $('#total_words').html(edata.total_words);
  }
});

    $('#addfav').html('<a href="javascript: addToBookmark();" title="Add to Favorite">Add to Favorite</a>');
// comment num
if ($('#comment_url')[0] != null) {
    document.write('<IFRAME style="display:none" src="../../ocommentsend.html" width=0 height=0></IFRAME>');
}

// go to top
$('.text_edit').each(function(i) {
    if (i>0) {
        this.outerHTML = '<a href="#" class="text_edit"><img border="0" src="http://images.mmosite.com/www/images/totop.gif"></a>'+this.outerHTML;
    }
});

function popUrl(purl, ptitle, pw, ph) {
    g_pop=new Popup({ contentType:1, isReloadOnClose:false,scrollType:false, width:pw, height:ph });
    g_pop.setContent("title",ptitle);
    g_pop.setContent("contentUrl",purl); 
    g_pop.build();
    g_pop.show();
    return false;
}


function g_close_pop() {
    g_pop.close();
}


function dict_relogin() {
    alert('Please login to continue');
    document.location.href="http://"+mdomain+"/dic/?action=login&backurl="+en_url;
    return;
}

function do_up(num) {
    $.get("/dic/?controller=entry&action=doup&en_id="+en_id,
      { 'en_id': en_id},
      function(edata){
        edata?show_up(1, num+1):alert('Up Failed, Please Try Again...');
    }); 
}
function show_up(up_stat, ups) {
    uhtm = ups;

    if (up_stat == 1) {
        uhtm = "<a href='#' onclick='return false;' title='voted'>"+uhtm+"</a>";
        $('#unum').html(uhtm);
    } else {
        doFun = up_stat==-1?'dict_relogin()':'do_up('+ups+')';
        
        uhtm = "<a href='javascript:"+doFun+"' title='Digg it'>"+uhtm+"</a>";
        $('#unum').html(uhtm);
    }
}