var reposterVer = '1,0,0,8';

function load() {
	var wantInstall = Cookie.get("NTES_TARGETGO");
	Cookie.clear("NTES_TARGETGO");
	if (wantInstall == '1') {
		installReposter();		
	}else {
		$('targetGoDiv').innerHTML = '<object id="targetGo" name="targetGo" width="0" height="0"></object>';
	}
	
	setTimeout(loadReposter, 250);
}

var hasInstalled = false;
function installReposter() {
	if (!isIE) {
		alert("当前浏览器不支持网易博客一键转贴功能\n建议下载安装Internet Explorer 6.0及以上版本");
		return false;
	}
	$('targetGoDiv').innerHTML = '<object id="targetGo" name="targetGo" width="0" height="0" classid="clsid:540FB5DD-CFAC-4238-8F00-55CB05C6B11D" codebase="http://st.blog.163.com/bin/TargetGo.cab#Version=' + reposterVer + '"></object>';
	if (isNewestVersion()) { // 精彩猎人活动支持
		hasInstalled = true;
	}
	var expire = 1;
	Cookie.set("NTES_TARGETGO", 1, expire);
}


var intervalHandler = null;
function loadReposter(){
	if(window.ActiveXObject){
		try{
			if (isNewestVersion()) { // installed
				$('divNotInstalled').style.display = "none";
				$('divInstalled').style.display = "";
				clearInterval(intervalHandler);
				Cookie.clear("NTES_TARGETGO");
				if (!hasInstalled) { // 精彩猎人活动支持
					var search = window.location.search;
					if (search != null) {
						var index = search.indexOf('userName=');
						var userName = search.substr(index + 9);
						var volumnSerial = "";
						if (targetGo.getVolumnSerialNumber != undefined)
							volumnSerial = targetGo.getVolumnSerialNumber();
						var url = "http://blog.163.com/activities/hunter/hunter.do?action=recomDown&userName=" + userName + "&volumnSerial=" + volumnSerial;
						dynamic_javascript_load_hunter(url);
					}
				}
			} else if (intervalHandler == null) {
				intervalHandler = setInterval(loadReposter, 1000);
			}
		}
		catch(e){
			setTimeout(loadReposter, 1000);
		}
	}
	else{
		//actionsWhenNotSupport();
	}
}

function isNewestVersion() {
	return targetGo != undefined && targetGo.Installed != undefined && targetGo.Installed() == 1 
					&& targetGo.GetVer != undefined && targetGo.GetVer() == reposterVer;
}

function dynamic_javascript_load_hunter(jsurl)
{
    var head = document.getElementsByTagName('head').item(0);
    var script = document.createElement('script');
    script.src = jsurl;
    script.type = 'text/javascript';
    head.appendChild(script);
}