$(function(){   
	var thsQuote = external.createObject("Quote");
	$("[tid]").bind("click",function(){  
		 		thsQuote.switchPage(parseInt($(this).attr("tid"))+6500);
				return false;
		});
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','zhangdie'];
	stockData.getData(codelist,params,function(data){ 
			var d=[];     
			if(db==0){
				for (var i in params) {  
		  	d.push(data[codelist][params[i]]);
		  }  
		  $("#code").html(codelist); 
		  $("#codename").html(d[0]); 
           if(d[1]==null||isNaN(d[1])){
			   $("#new").html('0');
		  $("#zhangdie").html('0');
		  $("#zhangdiefu").html('0');
		  $("#bigpic").attr('src','skin/ba.jpg');
		  return;
		  } 
		  $("#new").html(ForDight(d[1],2));
		 // $("#buyprice1").html('买价:&nbsp;&nbsp;'+(ForDight(d[1],2)+5));
		 // $("#sellprice1").html('卖价:&nbsp;&nbsp;'+ForDight(d[1],2));
		  var //v=ForDight(parseFloat(d[1])-parseFloat(d[2]),2);
		  v=ForDight(parseFloat(d[3]),2);
		  
		  $("#zhangdie").html(v);
		  $("#zhangdiefu").html(ForDight(parseFloat(v)/parseFloat(d[2])*100,2)+'%');
		  if(parseFloat(v)<0){ 
			     $("#bigpic").attr('src','skin/lv.jpg');
							setbg($("#new"),'#01D607','');
							setbg($("#zhangdie"),'#01D607','');
							setbg($("#zhangdiefu"),'#01D607',''); 
							//setbg($("#buyprice1"),'#01D607',''); 
							//setbg($("#sellprice1"),'#01D607',''); 
		      }else if(parseFloat(v)>0){ 
				  $("#bigpic").attr('src','skin/red.jpg');
							setbg($("#new"),'#E30102','');
							setbg($("#zhangdie"),'#E30102','');
							setbg($("#zhangdiefu"),'#E30102',''); 
							//setbg($("#buyprice1"),'#E30102',''); 
							//setbg($("#sellprice1"),'#E30102',''); 
		      }else{$("#bigpic").attr('src','skin/ba.jpg');
		      	setbg($("#new"),'#FFFFFF','');
							setbg($("#zhangdie"),'#FFFFFF','');
							setbg($("#zhangdiefu"),'#FFFFFF',''); 
							//setbg($("#buyprice1"),'#FFFFFF',''); 
							//setbg($("#sellprice1"),'#FFFFFF',''); 
		      	}  
		      	d=[]; 
		 	db++;
			}else
			{   
				 if(data[codelist][params[1]]==null||isNaN(data[codelist][params[1]])){
			   $("#new").html('0');
		  $("#zhangdie").html('0');
		  $("#zhangdiefu").html('0');
		  $("#bigpic").attr('src','skin/ba.jpg');
		  return;
		  } 

		  
		   // if($("#zhangdie").html()==v) return;		
				for (var i in params) {  
				  	d.push(data[codelist][params[i]]);
		    }  
		 $("#new").html(ForDight(d[1],2));  
		  var 
		  v=ForDight(d[3],2);
		  $("#zhangdie").html(v);
		  // $("#buyprice1").html('买价:&nbsp;&nbsp;'+(ForDight(d[1],2)+5));
		  //$("#sellprice1").html('卖价:&nbsp;&nbsp;'+ForDight(d[1],2));
		  $("#zhangdiefu").html(ForDight(parseFloat(v)/parseFloat(d[2])*100,2)+'%');
		  if(parseFloat(v)<0){ 
			    $("#bigpic").attr('src','skin/lv.jpg');
							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){ 
				    $("#bigpic").attr('src','skin/red.jpg');
							setbg($("#new"),'#E30102','url(skin/tbg.png)');
							setbg($("#zhangdie"),'#E30102','url(skin/tbg.png)');
							setbg($("#zhangdiefu"),'#E30102','url(skin/tbg.png)');  
		      }else{$("#bigpic").attr('src','skin/ba.jpg');
		      	setbg($("#new"),'#FFFFFF','url(skin/tbg.png)');
							setbg($("#zhangdie"),'#FFFFFF','url(skin/tbg.png)');
							setbg($("#zhangdiefu"),'#FFFFFF','url(skin/tbg.png)');  
		      	}
		      	d=[];    
		   }
		   cover();
		}
	 );
};   
var _GET=function(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    };
function t(){
if(xto!=null)clearTimeout(xto);
try{
var c=_GET("code");
 getDataByCode(c);
 xto=setTimeout(t,600);
}catch(e){
   xto=setTimeout(t,600);
}
}  
$("[tid]").click(function(){
	var tid=$(this).attr('tid');
 var thsQuote = external.createObject("Quote");
        thsQuote.switchPage({
            id:tid,
            code:_GET("code")
        });
        thsQuote = null;
});
t(); 

}); 