function HappyGo(){
	this.containerId = null;
  this.CID = 10000000;
  this.customize = 'default';
  this.member = null;
  this.rate = null;
  this.bbsid = null;
  this.updated = null;
  this.comment = null;
  //this.ilink = null;
  this.iids = null;
  this.icount = 0;
  this.type = null;
  this.error = 0;

  this.convert = function(){
      this.containerId = this.isNull(this.containerId) ? 'shop_thread_list' : this.containerId;
	    var content = document.getElementById(this.containerId).innerHTML;
	
	    var linkReg1 = /item_detail-(0?db[0-9]{1,2})?-[0-9a-z]{32}\.[htm|jhtml]/g;
	    var linkReg2 = /itemID=[0-9a-z]{32}/g;
    	var linkReg3 = /item_id=[0-9a-z]{32}/g;
    	var linkReg4 = /item\.htm\?id=[0-9]{8,11}/g;
	    var linkReg5 = /item_num_id=[0-9]{8,11}/g;
	    var linkReg6 = /default_item_id=[0-9]{8,11}/g;
	    var iidReg = /[0-9a-z]{32}/;
	    var nidReg = /[0-9]{8,11}/;

        var link;
	    var iid;
	    var nid;
	    var iids = '';
	    var nids = '';
	    var icount = 0;


	while ((link = linkReg1.exec(content)) != null){
		if((iid = iidReg.exec(link)) != null){
			iids += (iids == '')?iid:','+iid;
			icount++;
		}
	}

	while ((link = linkReg2.exec(content)) != null){
		if((iid = iidReg.exec(link)) != null){
			iids += (iids == '')?iid:','+iid;
			icount++;
		}
	}

	while ((link = linkReg3.exec(content)) != null){
		if((iid = iidReg.exec(link)) != null){
			iids += (iids == '')?iid:','+iid;
			icount++;
		}
	}

	while ((link = linkReg4.exec(content)) != null){
		if((nid = nidReg.exec(link)) != null){
			iids += (iids == '')?nid:','+nid;
			icount++;
		}
	}

	while ((link = linkReg5.exec(content)) != null){
		if((nid = nidReg.exec(link)) != null){
			iids += (iids == '')?nid:','+nid;
			icount++;
		}
	}
	
	while ((link = linkReg6.exec(content)) != null){
		if((nid = nidReg.exec(link)) != null){
			iids += (iids == '')?nid:','+nid;
			icount++;
		}
	}
    
    this.iids = iids;
    this.icount = icount;
  }; //end func convert


  this.ilink = function(){
    var link = "http://r.juandou.com/items?iids="+this.iids;
    if(!this.isNull(this.CID)){
      link += '&p='+encodeURIComponent(this.CID);
    }

    if(!this.isNull(this.rate) ){
        link += '&r='+encodeURIComponent(this.rate); 
    }
  
    if(!this.isNull(this.customize) ){
        link += '&s='+encodeURIComponent(this.customize); 
    }

    if(!this.isNull(this.member) ){
        link += '&c='+encodeURIComponent(this.member);
    }
    
    if(!this.isNull(this.type) ){
        link += '&type='+encodeURIComponent(this.type);
    }
    
    if(!this.isNull(this.comment) ){
        link += '&comment='+encodeURIComponent(this.comment);
    }

    //this.ilink = link;
    return link;
  };

  this.iframe = function( link,f ){
    var link_h = link+'&method=height&v=b.js'; 
 
    var _doc = document.getElementsByTagName('head')[0];
    var js = document.createElement('script');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', link_h);
    _doc.appendChild(js);
    
    if (!/*@cc_on!@*/0) { //if not IE
        //Firefox2、Firefox3、Safari3.1+、Opera9.6+ support js.onload
        js.onload = function () {
            if(undefined!=_taoshow_iframe_height){
              f.ccframe(link, _taoshow_iframe_height); 
            return true;
          }
        }
    } else {
        //IE6、IE7 support js.onreadystatechange
        js.onreadystatechange = function () {
            if (js.readyState == 'loaded' || js.readyState == 'complete') {
              if(undefined!=_taoshow_iframe_height){
                  f.ccframe(link, _taoshow_iframe_height); 
              return true;
                }
            }
        }
    }
   
    return false;
  };

  this.ccframe = function(tourl, height){
    var dv = document.getElementById(this.containerId);
    dv.innerHTML = '<iframe src="'+tourl+'" width="610px" height="'+height+'px" allowtransparency="true" style="overflow:hidden;background-color:transparent;" frameborder="0" border="0" scrolling="no" marginwidth="0" framespacing="0" marginheight="0"></iframe>';
  };

  this.clear = function(){
    document.getElementById(this.containerId).innerHTML = '';
  };

  this._run = function(){
    this.convert();
    if(this.icount) {
        this.loading();
        var link = this.ilink();
        this.iframe( link,this );
    }else{
      this.clear();
    }
  };

  this.loading = function(){
	    document.getElementById(this.containerId).innerHTML = '<div style="background: url(http://js.juandou.com/images/loading.png) no-repeat left;width:400px;margin:40px 0 0 40px;"><p style="margin-left:40px;line-height:34px">\u6b63\u5728\u51c6\u5907\u6570\u636e\uff0c\u8bf7\u7a0d\u5019\u2026\u2026</span>';
      
  },

  this.isNull = function(val){
		return (""==val ||null==val ||undefined==val) ? true : false;
	}

}

var Taoshow = new HappyGo();
function convertItemLinks(containerId, juandouid, nav_id, dz_name, rate ){
  Taoshow.containerId = containerId;
  Taoshow.CID = juandouid;
  Taoshow.customize = nav_id;
  Taoshow.member = dz_name;
  if(undefined!=rate){
    if(''==rate)
      rate = 4;
    Taoshow.rate = rate;
  }
  Taoshow._run();
}


