var REF = {
	referer_url:document.referrer,
	local_url:window.location.href.toLowerCase(),
	page_index:document.getElementsByTagName("body")[0].getAttribute("pageindex"),
	fix_download:function(){
		if(REF.page_index==0){
			
		}else if(REF.page_index==1){
			if(REF.referer_url){
				if(REF.referer_url.indexOf("www.baidu.com")>=0 || REF.referer_url.indexOf("www.soso.com")>=0 || REF.referer_url.indexOf("www.so.com")>=0 || REF.referer_url.indexOf("www.sogou.com")>=0){
					if(REF.local_url.indexOf("media.buy.baidu.sem")>=0){
						REF.set_download(1318);
					}else if(REF.local_url.indexOf("media.buy.baidu.txdngjsem")>=0){
						REF.set_download(1331);
					}else if(REF.local_url.indexOf("media.buy.baidu.dngjsem")>=0){
						REF.set_download(1332);
					}else if(REF.local_url.indexOf("media.buy.baidu.dngjxzsem")>=0){
						REF.set_download(1333);
					}else if(REF.local_url.indexOf("media.buy.baidu.txgjsem")>=0){
						REF.set_download(1334);
					}else if(REF.local_url.indexOf("media.buy.baidu.qqdngjsem")>=0){
						REF.set_download(1335);
					}else{
						REF.set_download(1304);
					}
				}else if(REF.referer_url.indexOf("guanjia.qq.com")>=0){
					if(REF.referer_url.indexOf("guanjia.qq.com/act/")>=0){
						if(REF.local_url.indexOf("web.gj.hddaohang.logo")>=0){
							REF.set_download(1307);
						}else{
							REF.set_download(1306);
						}	
					}else{
						REF.set_download(1322);
					}
				}else{
					REF.set_download(1322);
				}
			}
		}
	},
	set_download:function(sid){
		var f = document.getElementById("banner");
		var d = REF.getByClass(f,"banner_download");
		for (var i=0 ;i<d.length;i++){
			d[i].setAttribute("href","http://dldir2.qq.com/invc/xfspeed/qqpcmgr/download/QQPCDownload"+sid+".exe");
		}
	},
	getByClass:function(oParent, sClass){
            var aEle=oParent.getElementsByTagName('*');
            var aResult=[];
            var re=new RegExp('\\b'+sClass+'\\b', 'i');
            var i=0;
            for(i=0;i<aEle.length;i++){
                    if(re.test(aEle[i].className)){
                            aResult.push(aEle[i]);
                    }
            }
            return aResult;
    }
}
REF.fix_download();