var istartindex = 0;
var itemListTags;
var imgListTags;
var data1ListTags;
var data2ListTags;
var data3ListTags;
var dom = document.all?(document.getElementById?3:2)
                  :(document.getElementById?4
                  :(document.layers?1:0));
var httpObj;
var iflg;
function loadXMLFile(f)
{
	iflg = f;
	httpObj = createXMLHttpRequest(displayData);
	if (httpObj)
	{
		httpObj.open("GET", "item.xml", true);
		httpObj.send("");
	}
}

function loadXMLFile2(f, file)
{
	istartindex = 0;
	iflg = f;
	httpObj = createXMLHttpRequest(displayData);
	if (httpObj)
	{
		httpObj.open("GET", file, true);
		httpObj.send("");
	}
}

function displayData()
{
	if ((httpObj.readyState == 4) && (httpObj.status == 200))
	{
		xmlData = httpObj.responseXML;
		itemListTags = xmlData.getElementsByTagName("item");
		imgListTags = xmlData.getElementsByTagName("img");
		data1ListTags = xmlData.getElementsByTagName("data1");
		data2ListTags = xmlData.getElementsByTagName("data2");
		data3ListTags = xmlData.getElementsByTagName("data3");
		
		ilen = itemListTags.length;
		icur = istartindex + 1;
		if (iflg == 0 || iflg == 2)
		{
			spage = icur + ' / ' + ilen;
			loadDivText($("itemcounter"), spage);
			if (iflg == 0)
			{
				loadDivText($("caption"), data1ListTags[istartindex].childNodes[0].nodeValue + 
						"<br>" + data2ListTags[istartindex].childNodes[0].nodeValue + 
						"<br>" + data3ListTags[istartindex].childNodes[0].nodeValue);
			} else {
				loadDivText($("caption"), data1ListTags[istartindex].childNodes[0].nodeValue);
			}
		} else {
			loadDivText($("News_pic_box_cap"), data1ListTags[istartindex].childNodes[0].nodeValue + 
					"<br>" + data2ListTags[istartindex].childNodes[0].nodeValue + 
					"<br>" + data3ListTags[istartindex].childNodes[0].nodeValue);
		}
		document.getElementById('itembackbtn').style.visibility = 'visible';
		document.getElementById('itemnextbtn').style.visibility = 'visible';
		if (iflg == 0 || iflg == 2)
		{
			loadDivImage($("itemphoto"), imgListTags[istartindex].childNodes[0].nodeValue, 0, 0);
			if (ilen < 2) document.getElementById('itemnextbtn').style.visibility = 'hidden';
			document.getElementById('itembackbtn').style.visibility = 'hidden';
		} else {
			imginit();
			document.getElementById('itembackbtn').style.visibility = 'hidden';
			if (ilen <= 5) document.getElementById('itemnextbtn').style.visibility = 'hidden';
			loadDivImage($("News_pic_box_img"), imgListTags[istartindex].childNodes[0].nodeValue, 0, 0);
			if (istartindex < ilen) loadImage($("select_1"), imgListTags[istartindex].childNodes[0].nodeValue, 78, 78);
			if (istartindex+1 < ilen) loadImage($("select_2"), imgListTags[istartindex+1].childNodes[0].nodeValue, 78, 78);
			if (istartindex+2 < ilen) loadImage($("select_3"), imgListTags[istartindex+2].childNodes[0].nodeValue, 78, 78);
			if (istartindex+3 < ilen) loadImage($("select_4"), imgListTags[istartindex+3].childNodes[0].nodeValue, 78, 78);
			if (istartindex+4 < ilen) loadImage($("select_5"), imgListTags[istartindex+4].childNodes[0].nodeValue, 78, 78);
		}
	}
}

function imginit() 
{
	document.getElementById('image0').style.borderColor = "#FFFFFF";
	document.getElementById('image1').style.borderColor = "#FFFFFF";
	document.getElementById('image2').style.borderColor = "#FFFFFF";
	document.getElementById('image3').style.borderColor = "#FFFFFF";
	document.getElementById('image4').style.borderColor = "#FFFFFF";
	document.getElementById('image0').style.borderColor = "#888";
	loadImage($("select_1"), './img/78white.jpg', 78, 78);
	loadImage($("select_2"), './img/78white.jpg', 78, 78);
	loadImage($("select_3"), './img/78white.jpg', 78, 78);
	loadImage($("select_4"), './img/78white.jpg', 78, 78);
	loadImage($("select_5"), './img/78white.jpg', 78, 78);
}

function displayPageData(ii)
{
	document.getElementById('itembackbtn').style.visibility = 'visible';
	document.getElementById('itemnextbtn').style.visibility = 'visible';
	if ((istartindex == 1) && (ii < 0)) document.getElementById('itembackbtn').style.visibility = 'hidden';
	if ((istartindex == ilen-2) && (ii > 0)) document.getElementById('itemnextbtn').style.visibility = 'hidden';

	istartindex = istartindex + ii;
	ilen = itemListTags.length;
	icur = istartindex + 1;
	spage = icur + ' / ' + ilen;
	loadDivText($("itemcounter"), spage);
	loadDivText($("caption"), data1ListTags[istartindex].childNodes[0].nodeValue + 
					"<br>" + data2ListTags[istartindex].childNodes[0].nodeValue + 
					"<br>" + data3ListTags[istartindex].childNodes[0].nodeValue);
	loadDivImage($("itemphoto"), imgListTags[istartindex].childNodes[0].nodeValue, 0, 0);
}

function displayPageData2(ii)
{
	document.getElementById('itembackbtn').style.visibility = 'visible';
	document.getElementById('itemnextbtn').style.visibility = 'visible';
	if ((istartindex == 1) && (ii < 0)) document.getElementById('itembackbtn').style.visibility = 'hidden';
	if ((istartindex == ilen-2) && (ii > 0)) document.getElementById('itemnextbtn').style.visibility = 'hidden';
	istartindex = istartindex + ii;
	ilen = itemListTags.length;
	icur = istartindex + 1;
	spage = icur + ' / ' + ilen;
	loadDivText($("itemcounter"), spage);
	loadDivText($("caption"), data1ListTags[istartindex].childNodes[0].nodeValue);
	loadDivImage($("itemphoto"), imgListTags[istartindex].childNodes[0].nodeValue, 0, 0);
}

function displayThumData(ii)
{
	istartindex = istartindex + ii;
	document.getElementById('itembackbtn').style.visibility = 'visible';
	document.getElementById('itemnextbtn').style.visibility = 'visible';
	if ((istartindex == 0) && (ii < 0)) document.getElementById('itembackbtn').style.visibility = 'hidden';
	if ((istartindex+5 >= ilen) && (ii > 0)) document.getElementById('itemnextbtn').style.visibility = 'hidden';
	imginit();
	ilen = itemListTags.length;
	if (istartindex < ilen) loadImage($("select_1"), imgListTags[istartindex].childNodes[0].nodeValue, 78, 78);
	if (istartindex+1 < ilen) loadImage($("select_2"), imgListTags[istartindex+1].childNodes[0].nodeValue, 78, 78);
	if (istartindex+2 < ilen) loadImage($("select_3"), imgListTags[istartindex+2].childNodes[0].nodeValue, 78, 78);
	if (istartindex+3 < ilen) loadImage($("select_4"), imgListTags[istartindex+3].childNodes[0].nodeValue, 78, 78);
	if (istartindex+4 < ilen) loadImage($("select_5"), imgListTags[istartindex+4].childNodes[0].nodeValue, 78, 78);

}

function displayMainImg(index)
{
	if (istartindex+index >= ilen) return;
	document.getElementById('image0').style.borderColor = "#FFFFFF";
	document.getElementById('image1').style.borderColor = "#FFFFFF";
	document.getElementById('image2').style.borderColor = "#FFFFFF";
	document.getElementById('image3').style.borderColor = "#FFFFFF";
	document.getElementById('image4').style.borderColor = "#FFFFFF";
	document.getElementById('image' + index).style.borderColor = "#888";

	loadDivImage($("News_pic_box_img"), imgListTags[istartindex+index].childNodes[0].nodeValue, 0, 0);
	loadDivText($("News_pic_box_cap"), data1ListTags[istartindex+index].childNodes[0].nodeValue + 
			"<br>" + data2ListTags[istartindex+index].childNodes[0].nodeValue + 
			"<br>" + data3ListTags[istartindex+index].childNodes[0].nodeValue);
}

function createXMLHttpRequest(cbFunc)
{
	var XMLhttpObject = null;
	try{
		XMLhttpObject = new XMLHttpRequest();
	}catch(e){
		try{
			XMLhttpObject = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				XMLhttpObject = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				return null;
			}
		}
	}
	if (XMLhttpObject) XMLhttpObject.onreadystatechange = cbFunc;
	return XMLhttpObject;
}

function loadDivImage(div, filename, width, height){
	
	if(dom==4)
	{
		var img = document.createElement('IMG');
		if (width > 0) img.setAttribute('width', width);
		if (height > 0) img.setAttribute('height', height);
		img.src = filename;
		try
		{
			div.removeChild(div.firstChild);
		}
		catch(e){}
		div.appendChild(img);
		return;
	}
	var s='<img src=' + filename;
	if (width > 0) s+= ' width=' + width;
	if (height > 0) s+= ' height=' + height;
	s+= '>';
	if(dom==3 || dom==2)
	{
		div.innerHTML = s;
		return;
	}
	if(dom==1){
		div.document.open('text/html');
		div.document.write(s);
		div.document.close();
		return;
	}
}

function loadImage(img, filename, width, height){
	
	if(dom==4 || dom==3 || dom==2 || dom==1)
	{
		if (width > 0) img.setAttribute('width', width);
		if (height > 0) img.setAttribute('height', height);
		img.src = filename;
		return;
	}
}

function loadDivText(div, sstr)
{
	div.innerHTML = sstr;
}

function $(tagId)
{
	return document.getElementById(tagId);
}

function collectionshow()
{
	if (document.getElementById('line1').style.display == 'none')
		document.getElementById('line1').style.display='block';
	else
		document.getElementById('line1').style.display='none';
}

function itemshow()
{
	if (document.getElementById('line2').style.display == 'none')
		document.getElementById('line2').style.display='block';
	else
		document.getElementById('line2').style.display='none';
}