﻿// 捲動功能
var pos = 1;

function Movement(p){
	$("#video").hide();
	if ( p == 1){
		$("#content").animate({left: '0px'}, "slow");
		Iconset(1);
		pos = 1;
	}else if (p == 2){
		$("#content").animate({left: '-750px'}, "slow");
		Iconset(2);
		pos = 2;
	}else if (p == 3){
		$("#content").animate({left: '-1500px'}, "slow");
		Iconset(3);
		pos = 3;
	}else if (p == 4){
		$("#content").animate({left: '-2250px'}, "slow");
		Iconset(4);
		pos = 4;
	}else if (p == 5){
		$("#content").animate({left: '-3000px'}, "slow");
		Iconset(5);
		pos = 5;
	}else if (p == 6){
		$("#content").animate({left: '-3750px'}, "slow");
		$("#video").toggle();
		Iconset(6);
		pos = 6;
	}else if (p == 7){
		$("#content").animate({left: '-4500px'}, "slow");
		Iconset(7);
		pos = 7;
	}
}

function Iconset(p){
	$(".active").removeClass("active").addClass("inactive");
	if ( p == 1){
		$("#new-tab").removeClass("inactive").addClass("active");
	}else if (p == 2){
		$("#history-tab").removeClass("inactive").addClass("active");
	}else if (p == 3){
		$("#single-tab").removeClass("inactive").addClass("active");
	}else if (p == 4){
		$("#integer-tab").removeClass("inactive").addClass("active");
	}else if (p == 5){
		$("#font-tab").removeClass("inactive").addClass("active");
	}else if (p == 6){
		$("#tutorial-tab").removeClass("inactive").addClass("active");
	}else if (p == 7){
		$("#more-tab").removeClass("inactive").addClass("active");
	}
}

function Arrow(p){
	if(p == 0 && pos != 0)
		Movement(pos - 1);
	else if (p ==1 && pos != 7)
		Movement(pos + 1);
}

//下載
function LinkDownload(url){
	window.dFrame.location = url;
}

//變換開啟連結視窗政策
function LinkTarget(url){
	if(document.targetchk.chk.checked){
		window.open(url);
	}else{
		window.location = url;
	}
}

//IE6（含）以下版本警告，其他版本載入設定作用連結
function ie6check(){
  if (!window.XMLHttpRequest) {
		ieAnn = document.createElement("div");
		ieAnn.id = "ie6announcer";
		ieAnn.style.cssText += 'top: expression(documentElement.scrollTop+documentElement.clientHeight-this.clientHeight-4); filter:alpha(opacity=70);';
		ieAnn.innerHTML ="<center>您的瀏覽器為IE6（含）以下版本，可能會造成閱讀時頁面無捲軸可供捲動的影響（但仍可透過滑鼠滾輪來捲動頁面。）<br>請您<a href='http://www.microsoft.com/taiwan/windows/ie/downloads/default.mspx'>更新至IE7以上版本</a>以獲得更佳瀏覽效果，本人推薦使用<a href='http://www.moztw.org/'>FireFox</a>！</center>";
		document.body.appendChild(ieAnn);
		setupZoom();
	}
}

//對話視窗

var isIe=(document.all)?true:false;


function showMessageBox(wTitle,content)
{
	/*背景半透明黑*/
  closeWindow();
  getSize();

  var back=document.createElement("div");
  back.id="mesBack";
  back.style.cssText += (isIe)? "filter:alpha(opacity=40);" : "opacity:0.40;";
  back.style.height = myScrollHeight + 'px';
  document.body.appendChild(back);

  /*前景對話框*/

  var mesW=document.createElement("div");
  mesW.id="mesWindow";
  mesW.className="mesWindow";
  //依據瀏覽器不同來配置
  if (window.XMLHttpRequest) {
	// Mozilla, Safari, IE7,... 
		mesW.innerHTML="<div class='mesWindowContent' id='mesWindowContent'><p align='center'>"+wTitle+"</p>"+content+"</div><div class='mesWindowBottom' align='center'><img src='./img/closebox.gif' onClick='closeWindow();' onMouseOver='this.src=\"./img/closebox1.gif\"' onMouseOut='this.src=\"./img/closebox.gif\"'></div>";
  }else{
	//IE6
		mesW.style.cssText = "position: absolute;top:expression(documentElement.scrollTop+"+myScrollHeight/6+"+'px');_margin-top:0;width: 404px;border: 0;border-collapse: collapse;z-index: 20;";
		mesW.innerHTML="<div class='mesWindowContent' id='mesWindowContent' ><p align='center'>"+wTitle+"</p>"+content+"</div><div class='mesWindowBottom' align='center'><img src='./img/closebox.gif' onClick='closeWindow();' onMouseOver='this.src=\"./img/closebox1.gif\"' onMouseOut='this.src=\"./img/closebox.gif\"' style='hidden'><br><br><br><br></div>";
  }
  mesW.style.left = myScrollWidth/2 - 202 +"px";
  document.body.appendChild(mesW);
}

function showBackground(obj,endInt)
{
  obj.filters.alpha.opacity+=1;
  if(obj.filters.alpha.opacity<endInt)
  {
    setTimeout(function(){showBackground(obj,endInt)},8);
  }
}

function closeWindow()
{
	$("#mesBack").empty().remove();
	$("#mesWindow").empty().remove();
}

function SetMsgContent(type)
{
	var string;
	if(type == "F"){
		string = "<div id='counttext'><br>請注意，此整合版本因為內容插件種類繁複，請確認每一個插件的作用，並選用適當的插件使用，以避免對遊戲中電腦效能產生不良之影響。<br>安裝前，也請先將舊的插件先行移除。<br>若您有任何疑問，請參考教學，或至本人Blog提問。<br><br></div> ";
		return string;
		
	}else if(type == "N"){
	string = "<div id='counttext'><br>安裝前，請將舊版插件移除後再行安裝。<br>若您覺得功能不足，請自行下載使用。<br>如有何疑問，請參考教學，或至本人Blog提問。<br><br></div> ";
		return string;
	}else if(type == "L"){
	string = "<div id='counttext'><br>此版本為自動安裝版本。再次提醒您，檔案下載完成後，請核對MD5碼，以確保檔案安全。<br>安裝前，請將舊版插件移除後再行安裝。<br>在安裝時，請確認路徑是否正確。<br>如有何疑問，請參考教學，或至本人Blog提問。<br><br></div> ";
		return string;
	}else if(type == "T"){
	string = "<div id='counttext'><br>本字型包中已有安裝批次檔（install.bat）<br>再次提醒您安裝方式：<br><ol id='history_features'><li> 先在魔獸的子目錄下創一個Fonts子目錄。</li><li>將本字型包內的兩個檔案複製到該子目錄中。</li><li>執行install.bat即可。</li></ol>在安裝時，請確認路徑是否正確。<br>如有何疑問，請參考教學，或至本人Blog提問。<br><br></div> ";
		return string;
	}else{
		string = "<div align='center' id='counttext'></div> ";
		return string;
	}
}

function MessageBox(ev,msg,type)
{
	messContent = SetMsgContent(type);
	showMessageBox(msg,messContent);
}



// 擷取畫面大小

function getSize() {

	// Window Size

	if (self.innerHeight) { // Everyone but IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		myScroll = window.pageYOffset;
	} else if (document.documentElement && document.documentElement.clientHeight) { // IE6 Strict
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		myScroll = document.documentElement.scrollTop;
	} else if (document.body) { // Other IE, such as IE7
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
		myScroll = document.body.scrollTop;
	}

	// Page size w/offscreen areas

	if (window.innerHeight && window.scrollMaxY) {	
		myScrollWidth = document.body.scrollWidth;
		myScrollHeight = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // All but Explorer Mac
		myScrollWidth = document.body.scrollWidth;
		myScrollHeight = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		myScrollWidth = document.body.offsetWidth;
		myScrollHeight = document.body.offsetHeight;
	}
}


// 找到網頁中某元素的位置，並回傳座標值（陣列）

function findElementPos(elemFind)
{
	var elemX = 0;
	var elemY = 0;
	do {
		elemX += elemFind.offsetLeft;
		elemY += elemFind.offsetTop;
	} while ( elemFind = elemFind.offsetParent )

	return Array(elemX, elemY);
}

