$(function(){   
var stockData={ 
getData:function (codelist, params, callback) {
	var thsQuote = external.createObject("Quote"); 
	var reqObj = {
		code		: codelist,
		type		: params.join(','),  
		onready		: function () {  
			var codeArr = codelist.split(',');
			var data = {};
			//循环获取各个请求参数数据
			for (var i = 0, pLength = params.length; i < pLength; i++) {
				var param = {
					code		: codelist,		 
					type		: params[i]  
				};
				var retStr = thsQuote.getData(param);   
              	if (retStr != '({})') {
					retObj = eval('(' + retStr + ')');
				
				} else {
					retObj = null;
				} 
				if (retObj !== null) {
				//按股票代码分类获取的数据
					for (var j = 0, cdLength = codeArr.length; j < cdLength; j++) {
						if (typeof data[codeArr[j]] == 'undefined') {
							data[codeArr[j]] = {}; 
						}
						data[codeArr[j]][params[i]] = retObj[codeArr[j]][params[i]];
					}
				} else {
					for (var j = 0, cdLength = codeArr.length; j < cdLength; j++) {
						if (typeof data[codeArr[j]] == 'undefined') {
							data[codeArr[j]] = {};
						}
						data[codeArr[j]][params[i]] = null;
					}
				}
			}
			callback(data);
		}
	};
	var flag = thsQuote.request(reqObj);
}
}; 
var st=null;
function setbg(obj,c,bc){  
	color=obj.css("color");
    bg=obj.css("background"); 
	obj.css({'color':c,'background':bc});
    st=setTimeout(function(){
    	obj.css({'background':''});
        },1000);
	}
var xto=null;
var db=0;
var getDataByCode=function(codelist){  
	var params=['ZQMC',"new",'open'];
	stockData.getData(codelist,params,function(data){ 
			var d=[];     
			if(db==0){
				for (var i in params) {  
		  	d.push(data[codelist][params[i]]);
		  } 
		  $("#new").html(ForDight(d[1],2));
		  $("#zqmc").html(d[0]); 
		  $("#buyprice1").html('\u4e70\u4ef7:&nbsp;&nbsp;'+ForDight(d[1]+5,2));
		  $("#sellprice1").html('\u5356\u4ef7:&nbsp;&nbsp;'+ForDight(d[1],2));
		  var v=ForDight(parseFloat(d[1])-parseFloat(d[2]),2);
		  $("#zhangdie").html(v);
		  $("#zhangdiefu").html(ForDight(parseFloat(v)/parseFloat(d[2])*100,2)+'%');
		  if(parseFloat(v)<0){ 
							setbg($("#new"),'#01D607','');
							setbg($("#zhangdie"),'#01D607','');
							setbg($("#zhangdiefu"),'#01D607',''); 
							setbg($("#buyprice1"),'#01D607',''); 
							setbg($("#sellprice1"),'#01D607',''); 
		      }else if(parseFloat(v)>0){ 
							setbg($("#new"),'#E30102','');
							setbg($("#zhangdie"),'#E30102','');
							setbg($("#zhangdiefu"),'#E30102',''); 
							setbg($("#buyprice1"),'#E30102',''); 
							setbg($("#sellprice1"),'#E30102',''); 
		      }else{
		      	setbg($("#new"),'#FFFFFF','');
							setbg($("#zhangdie"),'#FFFFFF','');
							setbg($("#zhangdiefu"),'#FFFFFF',''); 
							setbg($("#buyprice1"),'#FFFFFF',''); 
							setbg($("#sellprice1"),'#FFFFFF',''); 
		      	}  
		      	d=[]; 
		 	db++;
			}else
			{ 
				for (var i in params) {  
		  	d.push(data[codelist][params[i]]);
		    }  
						$("#new").html(ForDight(d[1],2));  
		  var v=ForDight(parseFloat(d[1])-parseFloat(d[2]),2);
		  $("#zhangdie").html(v);
		   $("#buyprice1").html('\u4e70\u4ef7:&nbsp;&nbsp;'+ForDight(d[3],2));
		  $("#sellprice1").html('\u5356\u4ef7:&nbsp;&nbsp;'+ForDight(d[4],2));
		  $("#zhangdiefu").html(ForDight(parseFloat(v)/parseFloat(d[2])*100,2)+'%');
		  if(parseFloat(v)<0){ 
							setbg($("#new"),'#01D607','url(skin/tbg.png)');
							setbg($("#zhangdie"),'#01D607','url(skin/tbg.png)');
							setbg($("#zhangdiefu"),'#01D607','url(skin/tbg.png)');  
		      }else if(parseFloat(v)>0){ 
							setbg($("#new"),'#E30102','url(skin/tbg.png)');
							setbg($("#zhangdie"),'#E30102','url(skin/tbg.png)');
							setbg($("#zhangdiefu"),'#E30102','url(skin/tbg.png)');  
		      }else{
		      	setbg($("#new"),'#FFFFFF','url(skin/tbg.png)');
							setbg($("#zhangdie"),'#FFFFFF','url(skin/tbg.png)');
							setbg($("#zhangdiefu"),'#FFFFFF','url(skin/tbg.png)');  
		      	}
		      	d=[];    
		   }  
		}
	 );
};   
function t(){
if(xto!=null)clearTimeout(xto);
 getDataByCode("DAYTAG");
 xto=setTimeout(t,4000);
}  
t(); 
}); 