﻿//
var isChecked = false;
var isIE = false
var anchorSeparator  = "#";
var anchorConnector = "-";
var webTitle ="Sony VAIO 台灣官網";
var connectStr = " - ";
var defaultUnit = "index";
var historyAry = new Array();
var checkInt;
var checkMs = 200;
var SN=-1;


  
/////
function callMe(a,b){
//alert(a);
//alert(b);
}
function setAnchor(a,b){
	if(a==undefined){
		return;
	}
	var myURL = new String(document.location);
	var oldPath = myURL.split(anchorSeparator)[1];
	myURL = myURL.split(anchorSeparator)[0]; //remove any anchors
	var path = a;
	

	var newtitle = webTitle+connectStr+a

	//2006_11_12 q:doublePush;
	if(b==undefined){
		SN++;
		historyAry[SN] = path
	}
        ////
	if (oldPath != path) { 
		document.location = myURL + anchorSeparator + path; 
	}
	document.title = newtitle;	
}

function getAnchor(){
	sUrl = new String(document.location);
	aUrl = sUrl.split(anchorSeparator);
	if(aUrl.length > 1){
		return aUrl[1];
	}else{
		return false;
	}
}

function checkAnchor(){	
//document.testForm.aa.value = ''
//document.testForm.bb.value = getAnchor()
//document.testForm.cc.value = historyAry
//document.testForm.dd.value = SN;
//document.testForm.ee.value = historyAry[SN]
	if(historyAry[SN] != getAnchor()){			
		if(historyAry[SN-1] == getAnchor()){
			//回上頁
			SN--;
			callExternalInterface("anchor","")
			//document.testForm.cc.value ="back"
		}else if(historyAry[SN+1] == getAnchor()){
			//回下頁
			SN++;			
			callExternalInterface("anchor","")
		//	document.testForm.cc.value ="next"
		}else{
			
			//新進來
			if(SN==-1){	
			 SN++;
			 historyAry[SN] = getAnchor();
	
             setAnchor(getAnchor());

			}else{
				 SN=-1
				 location.href= "index.html?"+getAnchor();
				// historyAry = new Array();
				// setAnchor(getAnchor());
				 //callExternalInterface("anchor","")
				 //SN++;
				// document.stat.getAnchor();
				//document.testForm.cc.value ="a"

			}
			//SN++;
			//historyAry[SN] = getAnchor();
			//callExternalInterface("anchor","")
			//刪掉紀錄
			//historyAry.splice(SN+1,historyAry.length);
		}		
	}else{
	
	}

}
function callExternalInterface(mode,value){
	var obj = thisMovie("mySWF");
	switch(mode){
		case "anchor":
			obj.changeUnit(historyAry[SN]);
		break;
		case "setIE":
			obj.setBrowser(value);
		break;
	}
}
function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}
function checkBrowser(){
	if(isChecked==false){
		isChecked = true;
		if (navigator.appName.indexOf("Microsoft") != -1) {
			 isIE = true;
		}
		callExternalInterface("setIE",isIE)
	}	
}	 
function startRecordAnchor(){
	if(!getAnchor()){
		setAnchor(defaultUnit);
	}
	checkInt = setInterval("checkAnchor()",checkMs) ;

}
function init(){
	
	checkBrowser()
	startRecordAnchor();
	
}
///////