var toPhotoName = 'mainPhoto';		//メイン画像名
var photoTitle = 'title';		//タイトル名
var listName = 'photoList';		//ul名

//===========================================================
var photoLength;


var toPhotoName = 'mainPhoto';		//メイン画像名
var photoTitle = 'title';		//タイトル名
var listName = 'photoList';		//ul名

//===========================================================
var photoLength;
var browserID;

function xmlLoad() {
	var xmlname = "index.xml";
	var xmlhttp = false;

	if(window.ActiveXObject){
		try {
			//MSXML2以降用
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				//旧MSXML用
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				xmlhttp = false;
			}
		}
		browserID = 'ie';
	}
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		//safari,firefox
		xmlhttp = new XMLHttpRequest();
	}
	if (xmlhttp) {
		xmlhttp.open('GET', xmlname);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				xmlDoc = xmlhttp.responseXML;
				photoLength = xmlDoc.getElementsByTagName('photo').length;


				var ulName = document.getElementById(listName);
				var liA = new Array();
				var thumbA = new Array();
				var imgA = new Array();
				var ttlA = new Array();
				var imgPret = new Array();
				var imgPre = new Array();

				for (i=0; i<photoLength; i++) {
					thumbA[i] = xmlDoc.getElementsByTagName('thumbnail')[i].firstChild.nodeValue;
					imgA[i] = xmlDoc.getElementsByTagName('image')[i].firstChild.nodeValue;
					ttlA[i] = xmlDoc.getElementsByTagName('title')[i].firstChild.nodeValue;

					//画像先読み
					imgPret[i] = new Image();
					imgPret[i].src = imgA[i];
					imgPre[i] = new Image();
					imgPre[i].src = thumbA[i];

					var li = document.createElement('li');
					var a = document.createElement('a');
					var imgt = document.createElement('img');
					var img = document.createElement('img');

					//ブラウザ判定
					if (browserID == 'ie') {
						a.setAttribute("onclick", new Function ("clickStyle(this.id,'" + imgA[i] + "','" + ttlA[i] + "'); return false;"));
					}
					else {
						a.setAttribute("onclick","clickStyle(this.id,'" + imgA[i] + "','" + ttlA[i] + "'); return false;");
					}

					//サムネイル画像タグ作成
					a.setAttribute('id','photo' + i);
					a.setAttribute('href','javascript:void(0)');
					imgt.setAttribute('src',thumbA[i]);
					ulName.appendChild(li);
					a.appendChild(imgt);
					li.appendChild(a);
				}
				//メイン画像追加
				var img = document.createElement('img');
				img.setAttribute('src',imgA[0]);
				document.getElementById(toPhotoName).appendChild(img);

				document.getElementById(photoTitle).innerHTML = ttlA[0];
				document.getElementById('photo0').firstChild.setAttribute("style", "background-color: #FFFF00;");
				document.getElementById('photo0').firstChild.style.cssText = "background-color: #FFFF00;"
			}
		}
		xmlhttp.send(null);
	}
}

function clickStyle(id,url,ttl) {
	//メイン画像削除
	var parent = document.getElementById(toPhotoName);
	parent.removeChild(parent.firstChild);

	//メイン画像追加
	var img = document.createElement('img');
	img.setAttribute('src',url);
	document.getElementById(toPhotoName).appendChild(img);

	document.getElementById(photoTitle).innerHTML = ttl;

	//default
	for (i=0; i<photoLength; i++) {
		var photoName = 'photo' + i;
		document.getElementById(photoName).firstChild.setAttribute("style", "background-color: #CECBBF;");
		document.getElementById(photoName).firstChild.style.cssText = "background-color: #CECBBF;"
	}
	document.getElementById(id).firstChild.setAttribute("style", "background-color: #FFFF00;");
	document.getElementById(id).firstChild.style.cssText = "background-color: #FFFF00;"
}

function swapImage(obj, img) {
	document.images[obj].src = img;
}

// +++++++++++++++++++++++++++++++++++
// window.open
// +++++++++++++++++++++++++++++++++++

function openWindow(url,n,w,h) {
	window.open(url,n,"width=" + w + ", height=" + h + ", menubar=yes, toolbar=no, scrollbars=yes");
}

function miniWinOpen(dispUrl){
	windowOpen(dispUrl,'miniWin',680,650,'disp','');
}

function flashWinOpen01(dispUrl){
	windowOpen(dispUrl,'flashWin01',775,570,'del','');
}

function flashWinOpen02(dispUrl){
	windowOpen(dispUrl,'flashWin02',775,604,'del','');
}

function flashWinOpen03(dispUrl){
	windowOpen(dispUrl,'flashWin03',770,570,'del','');
}

function flashWinOpen04(dispUrl){
	windowOpen(dispUrl,'flashWin04',680,680,'del','');
}

//::::Window Open
var winOpen = new Array();
function windowOpen(uri, winName, w, h, which, stName) {
	var stVal0, stVal1;
	var setW = parseInt(w);
	var setH = parseInt(h);
	var winStatus, winSize, winValue;
	var wOpen;

// Set Status Value(1 or 0)
	if (which == 'disp') {
		stVal0 = 0;
		stVal1 = 1;
	}
	if (which == 'del') {
		stVal0 = 1;
		stVal1 = 0;
	}

// Set default Status Value
	var directoriesVal = stVal0;
	var statusVal = stVal0;
	var scrollbarsVal = stVal0;
	var toolbarVal = stVal0;
	var locationVal = stVal0;
	var menubarVal = stVal0;
	var resizableVal = stVal0;
	stName.indexOf('directories') != -1 ? directoriesVal = stVal0 : directoriesVal = stVal1;
	stName.indexOf('status') != -1 ? statusVal = stVal0 : statusVal = stVal1;
	stName.indexOf('scrollbars') != -1 ? scrollbarsVal = stVal0 : scrollbarsVal = stVal1;
	stName.indexOf('toolbar') != -1 ? toolbarVal = stVal0 : toolbarVal = stVal1;
	stName.indexOf('location') != -1 ? locationVal = stVal0 : locationVal = stVal1;
	stName.indexOf('menubar') != -1 ? menubarVal = stVal0 : menubarVal = stVal1;
	stName.indexOf('resizable') != -1 ? resizableVal = stVal0 : resizableVal = stVal1;
	winStatus =
		'directories=' + directoriesVal +
		',status=' + statusVal +
		',scrollbars=' + scrollbarsVal +
		',toolbar=' + toolbarVal +
		',location=' + locationVal +
		',menubar=' + menubarVal +
		',resizable=' + resizableVal;

// Window width & height adjust
	if (setW + setH > 0) {
		//Status : YES
		if (statusVal == 1) {
			//IE4 for Mac
			if (gMacC  && gIE4) {
				setH += 16;
			}
		}
		//Scroll : YES
		if (scrollbarsVal == 1) {
			//IE4 for Mac
			if (gMacC  && gIE4) {
				setW -= 1;
			}
			//NN4 for Mac
			if (gMacC && gNN4) {
				setW += 15;
			}
			//IE5 for Win
			else if (gWin && (gIE4 || gIE5 || gIE6)) {
				setW += 16;
			}
		}
		//Location : YES
		if (locationVal == 1) {
			//IE4 for Mac
			if (gMacC  && gIE4) {
				setH += 24;
			}
		}
		//Menu : YES
		if (menubarVal == 1) {
			//IE4 for Mac
			if (gWin && (gIE4 || gIE5 || gIE6)) {
				setH -= 19;
			}
		}
	}

	if (h != 0) {
		winSize = 'width=' + setW;
	}
	else if (w != 0) {
		winSize = 'height' + setH;
	}
	if (w != 0 && h != 0) {
		winSize = 'width=' + setW + ',height=' + setH;
	}
	if (setW + setH > 0) {
		winValue = winStatus + ',' + winSize;
	}
	else {
		winValue = winStatus;
	}
	winOpen[winName] = window.open(uri, winName, winValue);
}
