////////// COMMON SCRIPTS ////////////////////////////////////////
//　各頁共通で利用されるスクリプトセット：js/common.js
//　moveToTech()：技術一覧のページに移動
//　openTechWords()：用語解説のポップアップを開く
//　openTechno(番号)：技術アイコンのポップアップを開く
//　利用出来る関数 ----------
//　levelCheck()：rootフォルダまでのパス(../../../とか)を返す関数
//　openZoom()：同階層にある「zoom_1.html」をポップアップで表示
//　jumpToPT()：ページトップへスクロールアップ
//////////////////////////////////////////////////////////////////


var agent = navigator.userAgent ;

var appve = navigator.appVersion ;

var appna = navigator.appName ;

var userOs = null ;

var browser = null ;

var version = null ;


// -- クライアントOSを取得

if ( agent.indexOf('Win') != -1 ){
	userOs = "Win";
}else if ( agent.indexOf('Mac') != -1 ){
	userOs = "Mac" ;
}else{
	userOs = "other" ;
}


// -------------------- 階層チェック用JS --------------------

function levelCheck(){

	var myRoot = 'carrozzeria';

	var myPath = location.pathname;	//このドキュメントのパスを取得

	var myURL = document.URL;

	var pathToRoot ='';

	myPlace = myURL.match(/(http|https):\/\/.+/);

	//alert(myPlace);

	if(myPlace!=null){	//オンラインの場合

		myArray = myPath.split('/');	//「/」で区切って配列に格納する

	}else{	//オフラインの場合

		if (navigator.userAgent.indexOf("MSIE")>=0 && userOs=="Win") {

			myArray = myPath.split('\\');	//「\」で区切って配列に格納する
		} else {
			myArray = myPath.split('/');	//「/」で区切って配列に格納する
		}
	}

	for(i=0;i<100;i++){	//linit = 100

		myData = myArray[myArray.length-1-i].match(/carrozzeria/);

		if(myData){

			myLevel = i;

			break;
		}

	}

	var pathToRoot = '';

	for(i=1;i<myLevel;i++){

		pathToRoot += '../';

	}

	return pathToRoot;

}


// -------------------- MMスクリプト用JSセット  --------------------

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}


function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}


function MM_findObj(n, d) { //v4.01

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;

}


function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}


 // pagetop scroller

function getScrollLeft() {

 if ((navigator.appName.indexOf("Microsoft Internet Explorer",0) != -1)) {

  return document.body.scrollLeft;

 } else if (window.pageXOffset) {

  return window.pageXOffset;

 } else {

  return 0;

 }

}


function getScrollTop() {

 if ((navigator.appName.indexOf("Microsoft Internet Explorer",0) != -1)) {

  return document.body.scrollTop;

 } else if (window.pageYOffset) {

  return window.pageYOffset;

 } else {

  return 0;

 }

}


var pageScrollTimer;

function pageScroll(toX,toY,frms,cuX,cuY) { // 020314

 if (pageScrollTimer) clearTimeout(pageScrollTimer);

 if (!toX || toX < 0) toX = 0;

 if (!toY || toY < 0) toY = 0;

 if (!cuX) cuX = 0 + getScrollLeft();

 if (!cuY) cuY = 0 + getScrollTop();

 if (!frms) frms = 6;

 if (toY > cuY && toY > (getAnchorPosObj('end','enddiv').y) - getInnerSize().height) toY = (getAnchorPosObj('end','enddiv').y - getInnerSize().height) + 1;

 cuX += (toX - getScrollLeft()) / frms; if (cuX < 0) cuX = 0;

 cuY += (toY - getScrollTop()) / frms;  if (cuY < 0) cuY = 0;

 var posX = Math.floor(cuX);

 var posY = Math.floor(cuY);

 window.scrollTo(posX, posY);

 if (posX != toX || posY != toY) {

  pageScrollTimer = setTimeout("pageScroll("+toX+","+toY+","+frms+","+cuX+","+cuY+")",16);

 }

}


 // pagetop scroller

function jumpToPT() {

// if (!MacIE3 && !MacIE4 && !NN && window.scrollTo || NN && (Vminor >= 4.75) && window.scrollTo) {

  pageScroll(0,0,5);

// } else {

//  location.hash = "top";

// }

}


// 拡大画像

function openZoom(){
		ZoomWin = window.open('zoom_1.html',"zoom","width=540,height=460,left=30,top=20,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no");
		ZoomWin.focus();
  	}


// 仕様Pop Up　タイプ1

function spec_win(path){
	if(navigator.userAgent.indexOf("Win")!=-1){
		openwin=window.open("../spec.html?"+path,"spec","width=700,height=460,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no");
	}else{
		openwin=window.open("../spec.html?"+path,"spec","width=700,height=460,toolbar=no,location=no,directories=no,status=no,menubar=yes,resizable=no,scrollbars=no");
	}
	openwin.focus();
}


// 仕様Pop Up　タイプ2

function spec_win02(path){
	if(navigator.userAgent.indexOf("Win")!=-1){
		openwin=window.open("../../../../spec.html?"+path,"spec","width=550,height=460,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no");
	}else{
		openwin=window.open("../../../../spec.html?"+path,"spec","width=550,height=460,toolbar=no,location=no,directories=no,status=no,menubar=yes,resizable=no,scrollbars=no");
	}
	openwin.focus();
}


// Pure Component　360度・close up・装着例用

function openPopPure(dispFile){
		NewWin = window.open(dispFile,"pure","width=400,height=470,left=30,top=20,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes");
		NewWin.focus();
  	}



//AD ギャラリーHTML版用ポップアップ
function openAdhtml(dispFile){
	newWinAdhtml = window.open(dispFile,"1","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=no,width=650,height=560");
	newWinAdhtml.focus();	
}


//AD ギャラリー用ポップアップ
function openAd(){
	var thePath = levelCheck();
	var x_pos = (screen.width / 2) - 330;
	var y_pos = (screen.height / 2)-300;
	dispFile = thePath + 'museum/ad_gallery/index.html';
	openString = 'width=650,height=470,left='+x_pos+',top='+y_pos+',toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no';
	newWinAd = window.open(dispFile,"AD",openString);
	newWinAd.focus();	
}


//ブランドヒストリー用ポップアップ
function openBh(){
	var thePath = levelCheck();
	var x_pos = (screen.width / 2) - 330;
	var y_pos = (screen.height / 2)-300;
	dispFile = thePath + 'museum/brandhistory/index.html';
	openString = 'width=650,height=470,left='+x_pos+',top='+y_pos+',toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no';
	newWinBh = window.open(dispFile,"Bh",openString);
	newWinBh.focus();	
}


//クラフトマンシップ用ポップアップ
function openCs(){
	var thePath = levelCheck();
	var x_pos = (screen.width / 2) - 330;
	var y_pos = (screen.height / 2)-300;
	dispFile = thePath + 'museum/craftsmanship/index.html';
	openString = 'width=650,height=470,left='+x_pos+',top='+y_pos+',toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no';
	newWinCs = window.open(dispFile,"Cs",openString);
	newWinCs.focus();	
}


//サウンドテクノロジー用ポップアップ
function openST(){
	var thePath = levelCheck();
	var x_pos = (screen.width / 2) - 330;
	var y_pos = (screen.height / 2)-300;
	dispFile = thePath + 'interface/technology/sound_technology.html';
	openString = 'width=694,height=450,left='+x_pos+',top='+y_pos+',toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no';
	newWinST = window.open(dispFile,"ST",openString);
	newWinST.focus();	
}


//サウンドテクノロジー詳細用ポップアップ
function openTechno(num){
	var thePath = levelCheck();
	dispFile = thePath + 'interface/technology/tech_'+num+'.html';
	newWinTechIco = window.open(dispFile,"Technology","width=370,height=440,left=30,top=20,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes");
	newWinTechIco.focus();	
}


//サウンドテクノロジー詳細用ポップアップ2
function openTechIco(num){
	var thePath = levelCheck();
	dispFile = thePath + 'interface/technology/tech_'+num+'.html';
	newWinTechIco = window.open(dispFile,"Technology","width=370,height=440,left=30,top=20,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes");
	newWinTechIco.focus();	
}



//技術一覧用ポップアップ
function moveToTech(){
	var thePath = levelCheck();
	dispFile = thePath + 'interface/technology/index.html';
	location.href = dispFile;
}



//イベントインフォメーション用ポップアップ
function event(){
	var thePath = levelCheck();
	var x_pos = (screen.width / 2) - 330;
	var y_pos = (screen.height / 2)-300;
	dispFile = thePath + 'museum/event/index.html';
	openString = 'width=550,height=440,left='+x_pos+',top='+y_pos+',toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes';
	newWinevent = window.open(dispFile,"event",openString);
	newWinevent.focus();	
}


//用語解説用ポップアップ
function openTechWords(){
	var thePath = levelCheck();
	dispFile = thePath + 'support/word.html';
	newWinTechWords = window.open(dispFile,"Technologies","width=650,height=550,left=30,top=20,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes");
	newWinTechWords.focus();	
}


//インナーバッフルポップアップ
function innerbaffle(dispFile){
	newWininnerbaffle = window.open(dispFile,"innerbaffle","width=650,height=560,left=30,top=20,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes");
	newWininnerbaffle.focus();	
}


//汎用ポップアップ

function openNews(dispFile){
	newWinNews = window.open(dispFile,"news","width=650,height=580,left=200,top=90,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes");
	newWinNews.focus();	
}


//アナログ放送停止ポップアップ
function openanalog(){
	var thePath = levelCheck();
	dispFile = thePath + 'popup/analog.html';
	newWinTechWords = window.open(dispFile,"Technologies","width=800,height=580,left=30,top=20,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no");
	newWinTechWords.focus();	
}

// 装着例
function openEquip(){
		ZoomWin = window.open('equip_1.html',"equip","width=540,height=460,left=30,top=20,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no");
		ZoomWin.focus();
  	}

function openWin(url,wname,size,pos,resizable,toolbar,scrollbars){
	var sw;
	var sh;
	if (size == 'full'){
		sw = screen.availWidth;
		sh = screen.availHeight;
	}else{
		sw = size.w;
		sh = size.h;
		if (sh >= (screen.height-30)){
			sh = screen.height-100;
			sw += 18;
			scrollbars = 1;
		}
	}
	var w = window.open(url,wname,'width=' + sw + ',height=' + sh + ',resizable=' + resizable + ',toolbar=' + toolbar + ',scrollbars=' + scrollbars + ',fullscreen=no');
	w.moveTo(pos.x, pos.y);
	w.focus();
}

//Flash呼び出し用
//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}



//v1.1
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AX_RunContent(){
  var ret = AC_AX_GetArgs(arguments);
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_AX_GetArgs(args){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "pluginspage":
      case "type":
      case "src":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "data":
      case "codebase":
      case "classid":
      case "id":
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  return ret;
}

