/**
 * Top City Application Framework JavaScript
 *
 * @package Application
 * @category JavaScript
 * @subpackage Album
 * @author Rick
 * @version $0.3$
 * @copyright 2007-04-17 15:00:30
 * @last modified 2007-09-06
 */
var vote={_setting:{"ItemType":"a","MenuClass":"VoteMenu","MiniHolder":"MiniMenu","MiniMenuLinks":"MiniMenuLinks"},_votenums:["All",1,2,5,10,20,50,100,200,500,1000],Run:function(of,om,ol){
    this._setting.voteup=makex("img");
    this._setting.voteup.className = 'up';
    this._setting.voteup.src="/images/icon/voted_up.gif";
    this._setting.votedown=makex("img");
    this._setting.votedown.className = 'down';
    this._setting.votedown.src="/images/icon/voted_down.gif";
    if(getx(of)){
      if(of=="NetworkBlogs"||of=="BlogList"){
        //this.linkPrefix="?"+trigger+"=Network/VoteBlog";
        this.linkPrefix="/Network/VoteBlog";
      }else {
        if(of=="PhotoBar"||of=="PhotoList"){
          //this.linkPrefix="?"+trigger+"=Network.VotePhoto";
          this.linkPrefix="/network/votephoto";
        }else {
          this.linkPrefix=false;
          return ;
        }
      }
      this.hands=getx(of).getElementsByTagName("img");
      for(var i=0;i<this.hands.length;i++){
        var _i=this.hands[i];
        if(_i.alt.indexOf("Vote")>=0&&!isNaN(_i.alt.substring(5))){
          _i.style.cursor="pointer";
          _i.onclick=function(){
            vote.submit(this);
          };
        }
      }
    }
    if(om&&getx(om)){
      getx(om).className=this._setting.MenuClass;
      getx(om).onmouseover=function(){
        vote.draw(this,ol||false);
      };
    }
    return ;
  },Login:function(of,om,ol){
    this.hands=getx(of).getElementsByTagName("img");
    for(var i=0;i<this.hands.length;i++){
      var _i=this.hands[i];
      if(_i.alt.indexOf("Vote")>=0&&!isNaN(_i.alt.substring(5))){
        _i.style.cursor="pointer";
        _i.onclick=function(){
          $.get("/CheckIn/GotoLogin/href:"+window.location.href,gotoUrl);
        };
      }
    }
    if(om&&getx(om)){
      getx(om).className=this._setting.MenuClass;
      getx(om).onmouseover=function(){
        vote.draw(this,ol||false);
      };
    }
  },getPage:function(){
    _href=window.location.href;
    if(_href.indexOf("Page")<0){
      return "";
    }
    _href=_href.split("/");
    for(var i=0;i<_href.length;i++){
      if(_href[i].indexOf("Page"+":")==0){
        return "/"+_href[i];
      }
    }
  },draw:function(o,_link){
    var op=o.parentNode;
    op.style.position="relative";
    _baselink=o.href+"/Votes:";
    _page=this.getPage();
    _holder=addx(op.parentNode,makex("div"));
    _holder.className=this._setting.MiniHolder;
    var _pop=this.PopWindow(_holder);
    _pop._core.style.textAlign="right";
    if(_link){
      var _a=addx(_pop._core,makex("a"));
      _a.innerHTML=_link.text;
      _a.href="#"+_link.href;
      _a.className="border";
      _a.onclick=function(){
        var _href=o.href+_page;
        document.cookie="Votes="+this.href.substring(this.href.indexOf("#")+1)+";domain="+domain+";path=/";
        gotoUrl(_href);
        return false;
      };
    }
    for(i=0;i<this._votenums.length;i++){
      var _a=addx(_pop._core,makex("a")),votetext=this._votenums[i];
      if(isNaN(votetext)){
        _a.innerHTML=votetext+getJs(1909);
      }else {
        _a.innerHTML=votetext+getJs(1910);
      }
      _a.href="#"+votetext;
      _a.onclick=function(){
        var _href=o.href+_page;
        document.cookie="Votes="+this.href.substring(this.href.indexOf("#")+1)+";domain="+domain+";path=/";
        gotoUrl(_href);
        return false;
      };
    }
    if(_pop._core.offsetWidth<o.offsetWidth-12){
      _pop._core.style.width=o.offsetWidth-12+"px";
    }
    if(_pop._shadow)
    {
    	_pop._shadow.style.width = _pop._core.offsetWidth + 'px';
    	_pop._shadow.style.height = _pop._core.offsetHeight + 'px';
    }
    _holder.style.top=o.offsetHeight+op.offsetTop+"px";
    //_holder.style.paddingLeft=o.offsetLeft+o.offsetWidth-_holder.offsetWidth+"px";
    _holder.style.left=o.offsetLeft+o.offsetWidth+op.offsetLeft-_pop._core.offsetWidth+"px";
    op.style.position="static";
    o._holder=_holder;
    o.onmouseover=function(){
      cleartimer(this._holder._timer);
      this._holder.style.display="block";
    };
    o.onmouseout=function(){
      cleartimer(this._holder._timer);
      var _holder=this._holder;
      _holder._timer=setTimeout(function(){
        _holder.style.display="none";
      },500);
    };
    _pop.onmouseover=function(){
      cleartimer(this.parentNode._timer);
    };
    _pop.onmouseout=function(){
      cleartimer(this.parentNode._timer);
      var _holder=this.parentNode;
      _holder._timer=setTimeout(function(){
        _holder.style.display="none";
      },500);
    };
  },PopWindow:function(x){
    var _table=makex("table",{"id":"PopWindow"});
    var _tbody=addx(_table,makex("tbody"));
    var _tr=addx(_tbody,makex("tr"));
    var PopArea=addx(_tr,makex("td"));
    addx(x,_table);
    var _shadowDiv = addx(PopArea,makex('div',{'id':'lw_shadowDiv'}));
    with (_shadowDiv.style)
    {
    	position 	= 'absolute';
    	zIndex 		= '1';
    	left		='2px';
    	top			='2px';
    	margin		='0px';
    	backgroundColor = '#c0c0c0';
    	opacity		='0.6';
    	fontSize	='1px';	
    }
    if(Version.ie)
    {
    	_shadowDiv.style.filter = "alpha(opacity=60)";
    }
    _table._shadow = _shadowDiv;
    var _div=addx(PopArea,makex("div"));
    _div.className=this._setting.MiniMenuLinks;
    with(_div.style)
    {
    	position 	= 'absolute';
    	zIndex 		= '2';
    	left		= '0px';
    	top			= "0px";
    	backgroundColor = 'white';
    }
    _table._core=_div;
    return _table;
  },submit:function(o){
    var voteid=parseInt(o.alt.substring(5))||false;
    if(o.alt=="Vote Done"||o.done||!voteid||!vote.linkPrefix){
      $.matrix.Float.Tip(getJs(1881),1500);
    }else {
      this._setting[voteid]=o;
      var url=false;
      if(o.title=="Vote Up"){
        url="Up/Vote:"+voteid;
      }else {
        if(o.title=="Vote Down"){
          url="Down/Vote:"+voteid;
        }
      }
      if(url){
        $.get(vote.linkPrefix+url,vote.result);
      }
    }
  },result:function(data){
    var _tiptext=getJs(1880);
    if(data.indexOf("'Result'")==1){
      var result=eval("("+data+")");
      var vp=vote._setting[result.VoteID].parentNode;
      var pp=vp.getElementsByTagName("img");
      vp.replaceChild(vote._setting.voteup.cloneNode(true),pp[0]);
      vp.replaceChild(vote._setting.votedown.cloneNode(true),pp[1]);
      th=vp.parentNode.getElementsByTagName("th")[0];
      //td=vp.parentNode.parentNode.getElementsByTagName("td")[1];
	  content = result.Vnum + '<br /><span class=votetext>'+ result.Vtext + '</span>';
      if(result.Result=="VotedDown"){
        _tiptext=getJs(1882);
        //th.innerHTML=result.Vnum;
        //td.innerHTML=result.Vtext;
        th.innerHTML=content;
      }else {
        if(result.Result=="VotedUp"){
          _tiptext=getJs(1883);
          //th.innerHTML=result.Vnum;
          //td.innerHTML=result.Vtext;
          th.innerHTML=content;
        }else {
          if(result.Result=="Voted"){
            _tiptext=getJs(1881);
          }
        }
      }
    }
    $.matrix.Float.Tip(_tiptext,1500);
  }};
