function znzHDStock(swfID, divID, stockCode, stockName, stockType, dataRecvFunc, interval, data, w, h, barW, barH, kLineType, addLogo, withBar, indList, theme)
{
    this.swfID = swfID;
    this.divID = divID;
    this.stockCode = stockCode || '000001';
    this.stockName = stockName || '上证指数';
    this.stockType = stockType || 'SH';
    this.kLineType = kLineType || "";
    this.indList = indList || ["kline", "kline-ma", "vol"];
    this.stockURL = this._realURLGet();    
    this.dataRecvFunc = dataRecvFunc || null;
    this.interval = interval;
    this.w = w || 910;
    this.h = h || 393;
    this.barW = barW || 1.0;
    this.barH = barH || 0.12;
    this.mWithBar = typeof(withBar) != "undefined" ? withBar : 1;
    if(data) this.initData = data.substr(0, data.length-1);;
    this.dataStr = this.initData;
    this.addLogo = addLogo || false;
    this.mTheme = theme || 'znz';
    this.timeInfo = ['00000000', '000000'];
    this.sNumber = '0';
    
    this.running = false;
    this.timer = null;
    
    this.olddata = [];
    this.historydata = null;
    
    if (this.initData)
        this.olddata.push(this.initData);
    
    this.myAjaj = null;   
    this.inited = false;
    this._init();
    
    this.stop = false;
}


znzHDStock.prototype._init = function()
{
    //add timer to start swf
    this.timer = window.setTimeout(this._start.bind(this), 100);
    // data update
    this._update();
    this.inited = true;
}

znzHDStock.prototype.resize = function(w, h)
{
    if (!this.running)
        return;
    
    this.w = w || this.w;
    this.h = h || this.h;
        
    var realSwf = $(this.swfID);
    if(!realSwf)
        realSwf = document[this.swfID];
    
    try{
        realSwf.resize(this.w, this.h);
    }catch(E){
    }
}

znzHDStock.prototype.destroy = function()
{
   this.stop = true;
   if (this.timer){
      window.clearTimeout(this.timer);
   }
   if (this.myAjaj){
      this.myAjaj.destroy();
      this.myAjaj.onComplete = function(){};
   }
   this.close();
}

znzHDStock.prototype._update = function()
{
    if (this.stop)
       return;
        // set init data to ui
    if(this.initData)
    {        
        this._upd2ui(this.initData);
        
        var retObj = this.initData.parseJSON();
        if( retObj && retObj['ret'] == 'OK')
        {
            this.timeInfo = retObj['info']['timeInfo'];
            this.sNumber = retObj['info']['sNumber'];
        }

        this.initData = null;
    }
    else
    {
        if(!this.inited || inHqTime())
        {
            this._refresh();
        }
    }   
    
    
    this.timer = window.setTimeout(this._update.bind(this), this.interval);
}

znzHDStock.prototype._refresh = function()
{
    if (this.myAjaj){
        this.myAjaj.destroy();
        this.myAjaj = null;
    }
    var args = {
        method : 'get', onComplete : function(rep){
            this.dataStr = rep;
            
            // update ui  update swf
            var retObj = this.dataStr.parseJSON();
            if( retObj && retObj['ret'] == 'OK')
            {
                this._upd2ui(this.dataStr);
                this.olddata.push(this.dataStr);
            }

            this._upd2swf();

            // for next fetch
            if( retObj && retObj['ret'] == 'OK')
            {
                this.timeInfo = retObj['info']['timeInfo'];
                this.sNumber = retObj['info']['sNumber'];
            }               
        }.bind(this)
    };
   
    var infoURL = this.stockURL + '?cmd=' + this.stockType.toLowerCase() + this.stockCode + '|' + this.timeInfo[0] + '|' + this.timeInfo[1] + '|' + this.sNumber + '|' + Math.random().toString(); 
         
    this.myAjaj = new Ajaj(infoURL, args);    
}

znzHDStock.prototype._upd2ui = function(dataStr)
{
    var dataObj = dataStr.parseJSON();
    try
    {
        this.dataRecvFunc(dataObj);
    }
    catch(e)
    {        
    }
}

znzHDStock.prototype._upd2swf = function()
{
    if (this.olddata.length == 0){
        return;
    }

    if (!this.running)
        return;
        
    var dataStr = this.olddata[0];    
    var realSwf = $(this.swfID);
    if(!realSwf)
        realSwf = document[this.swfID];
    
    try{
        realSwf.update("k-day-current", dataStr);
        this._updateHistoryData(dataStr);
        this.olddata.shift(); 
        this.running = true;   
    }
    catch(E)
    {
        this.running = false;
    }
    
    if (this.olddata.length > 0){
        this._upd2swf();
    }
}

znzHDStock.prototype._updateHistoryData = function(dataStr)
{
    var lastData = dataStr.parseJSON();
    if(!lastData || lastData["ret"] != "OK")
    {
        return;
    }
    //change day
    if(this.timeInfo[0] != lastData['info']['timeInfo'][0] && this.timeInfo[0] != '00000000')
    {
        this.historydata = null;
    }
    if(!this.historydata)
    {
        this.historydata = lastData;
        return;
    }
    
    var hisData = this.historydata["info"]["history"];
    var currHis = lastData["info"]["history"];
    var start = lastData["info"]["start"];
    
    var i;
    for(i = 0; i < currHis.length; i ++)
    {
        hisData[i + start] = currHis[i];
    }
    this.historydata = lastData;
    this.historydata["info"]["history"] = hisData;
    this.historydata["info"]["start"] = 0;
}

znzHDStock.prototype.updateSpecial = function(typename)
{
    if (!this.running)
        return;

    var typen = typename || "k-day-current";
    
    var realSwf = $(this.swfID);
    if(!realSwf)
        realSwf = document[this.swfID];
    try{
        realSwf.update(typen, this.historydata.toJSONString());
        this.running = true;     
    }catch(E){
        
        this.running = false;
    }   
}

var ierr = 1;

znzHDStock.prototype._start = function()
{    
    var realSwf = $(this.swfID);
    if(!realSwf)
        realSwf = document[this.swfID];

    try{
        realSwf.start(rdmDataDomainNameGet(), this.kLineType, this.stockCode,
            this.stockType + "HQ", this.stockName, this.kLineType ? this.indList:["real", "rvol"],
            ["k-day-current"], this.mWithBar == 1 ? (this.kLineType ? 1 : -1) : 0, 
            this.barW, this.barH, this.w, this.h, this.addLogo, false, this.mTheme);       
        this.running = true;
        this._upd2swf();
    }catch(E)
    {
        this.running = false;
        if (ierr % 10 == 0){
           throw(E);
           //return;
        }
        ierr ++;
        this.timer = window.setTimeout(this._start.bind(this), 100);
    }

}

znzHDStock.prototype.restart = function(kLineType, stockCode, stockType, stockName)
{
    if (typeof kLineType != "undefined"){
        this.kLineType = kLineType;
    }
    this.stockCode = stockCode || this.stockCode;
    this.stockType = stockType || this.stockType;
    this.stockName = stockName || this.stockName;
        
    var kLineSwf = $(this.swfID);
    if(!kLineSwf)
        kLineSwf = document[this.swfID];
    
    try
    {    
       //alert("dd" + this.kLineType);
        kLineSwf.restart(rdmDataDomainNameGet(), this.kLineType, this.stockCode,
            this.stockType + 'HQ', this.stockName, 
            this.kLineType ? this.indList : ["real", "rvol"], ["k-day-current"],
            this.mWithBar == 1 ? (this.kLineType ? 1 : -1) : 0, this.barW, this.barH, 
            this.w, this.h, this.addLogo, false, this.mTheme);
        this.running = true;
    }
    catch(E)
    {
        this.running = false;
        this.timer = window.setTimeout(this.restart.bind(this), 100);
    }
}

znzHDStock.prototype.indAdd = function(indicator, noReload)
{
    this.indList.push(indicator);
    if (!noReload)
        this._indSet(); 
}

znzHDStock.prototype.indRemove = function(indicator, noReload)
{
    for(var i=0; i< this.indList.length; i++)
    {
       if(indicator == this.indList[i])
       {
            this.indList.remove(i); 
            break;
       }
    }
    if (!noReload)
        this._indSet();    
}

znzHDStock.prototype.updateIndc = function(){
    var kLineSwf = $(this.swfID);
    if(!kLineSwf)
        kLineSwf = document[this.swfID];
    if(this.running == true)
    {
        try{
            var indcs = kLineSwf.indget();
            var newindcs = [];
            for (var i = 0; i < this.indList.length; i++){
                for (var j = 0; j < indcs.length; j++){
                    if (this.indList[i] == indcs[j]){
                        newindcs.push(indcs[j]);
                        break;
                    }
                }
            }
            this.indList = newindcs;
        }catch(E)
        {
        }
    }
}

znzHDStock.prototype._indSet = function()
{  
    var kLineSwf = $(this.swfID);
    if(!kLineSwf)
        kLineSwf = document[this.swfID];
    if(this.running == true)
    {
        try{
            kLineSwf.indset(this.indList);
        }catch(E)
        {
        }
    }
    else
         window.setTimeout(this._indSet.bind(this), 1000);
}

znzHDStock.prototype.close = function()
{
    var realSwf = $(this.swfID);
    if(!realSwf)
        realSwf = document[this.swfID];
    if(realSwf && this.running == true)
    {
        try{
            this.running = false;
        }catch(E)
        {
        }
    }
}

znzHDStock.prototype._realURLGet = function()
{
    return 'http://' + rdmDataDomainNameGet()+ '/test/data.py/quick';
}

znzHDStock.prototype.postIndSet = function(indName, stockType, stockCode, flag)
{
    var parasList = {'stocktype':stockType, 'stockcode': stockCode};
    
    var kLineSwf = $(this.swfID);
    if(!kLineSwf)
        kLineSwf = document[this.swfID];
    if(this.running == true)
    {
        try{
            if(flag)
            {
                kLineSwf.postIndSet(indName, parasList);
            }
            else
            {
                kLineSwf.postIndRemove(indName, parasList);
            }
        }catch(E)
        {
        }
    }
}

// 清空flash中缓存数据
znzHDStock.prototype.swfDataClear = function()
{
    var kLineSwf = $(this.swfID);
    if(!kLineSwf)
        kLIneSwf = document[this.swfID];
    try
    {
        kLineSwf.clear();
    }
    catch(E)
    {
        // do nothing
    }
}