var currentPhoto = 0;
var secondPhoto = 1;
var currentOpacity = new Array();
var imgArray = {
	"src" : [
		{
			"l":{"src":"/resource.mapinfo.com/static/hpbanner/us/be_location_intelligent_sub_v2.jpg","alt":"","usemap":""},
			"r":{"src":"/resource.mapinfo.com/static/hpbanner/jp/be_location_intelligent_v2.gif","alt":"ロケーションインテリジェンス","usemap":""}
		},
		{
			"l":{"src":"/resource.mapinfo.com/static/hpbanner/us/builds_relationships_sub_v2.jpg","alt":"","usemap":""},
			"r":{"src":"/resource.mapinfo.com/static/hpbanner/jp/builds_relationships_v2.gif","alt":"ロケーションインテリジェンス リレーションシップを築きます","usemap":""}
		},
		{
			"l":{"src":"/resource.mapinfo.com/static/hpbanner/us/drives_decisions_sub_v2.jpg","alt":"","usemap":""},
			"r":{"src":"/resource.mapinfo.com/static/hpbanner/jp/drives_decisions_v2.gif","alt":"ロケーションインテリジェンス 決断を推進します","usemap":""}
		},
		{
			"l":{"src":"/resource.mapinfo.com/static/hpbanner/us/finds_customers_sub_v2.jpg","alt":"","usemap":""},
			"r":{"src":"/resource.mapinfo.com/static/hpbanner/jp/finds_customers_v2.gif","alt":"ロケーションインテリジェンス お客様を見つけます","usemap":""}
		},
		{
			"l":{"src":"/resource.mapinfo.com/static/hpbanner/jp/mipro10_5_download_v3.jpg","alt":"MapInfo Professional 10.5評価版","usemap":"#mipro10_5_download"},
			"r":{"src":"","alt":"","usemap":""}
		}
	]
}

var FADE_STEP = 2;
var FADE_INTERVAL = 10;
var pause = false;
var arrayLoc = 0;

function init() {
	for(var i=0;i<imgArray.src.length;i++){
		currentOpacity[i] = 0;
	}
	currentOpacity[0]=99;
	mHTML =  "";
	var d = document;
	for(var i=0;i<imgArray.src.length;i++){
		var imgWrapper = d.createElement("div");
		imgWrapper.setAttribute("name","photo");
		imgWrapper.setAttribute("imgclass","photo");
		imgWrapper.className = "mPhoto";
		imgWrapper.style.display = "none";
		if(imgArray.src[i].l.src){
			var Limg = d.createElement("img");
			Limg.style.border = "none";
			Limg.setAttribute("src",imgArray.src[i].l.src);
			if(imgArray.src[i].l.alt){
				Limg.setAttribute("alt",imgArray.src[i].l.alt);
			}
			if(imgArray.src[i].l.usemap){
				Limg.isMap = true;
				Limg.useMap = imgArray.src[i].l.usemap;
			}
			imgWrapper.appendChild(Limg);
		}
		if(imgArray.src[i].r.src){
			var Rimg = d.createElement("img");
			Rimg.setAttribute("src",imgArray.src[i].r.src);
			Rimg.style.border = "none";
			if(imgArray.src[i].r.alt){
				Rimg.setAttribute("alt",imgArray.src[i].r.alt);
			}
			if(imgArray.src[i].r.usemap){
				Rimg.isMap = true;
				Rimg.useMap = imgArray.src[i].l.usemap;
			}
			imgWrapper.appendChild(Rimg);
		}
		
		if(i == currentPhoto){
			imgWrapper.style.display = "block";
		}
		if(document.all) {
			imgWrapper.filter="alpha(opacity=100)";
		} else {
			imgWrapper.style.MozOpacity = .99;
		}
		
		
		document.getElementById("mContainer").appendChild(imgWrapper);
	}

	mInterval = setInterval("crossFade()",FADE_INTERVAL);
}

function crossFade() {
	if(pause)return;
	if(document.all){
		var target_obj = document.getElementById("mContainer").getElementsByTagName("div");
	}else{
		var target_obj = document.getElementsByName("photo")
		
	}
	//document.getElementsByName("photo")[secondPhoto].style.display = "block";
	target_obj[secondPhoto].style.display = "block";
	currentOpacity[currentPhoto]-=FADE_STEP;
	currentOpacity[secondPhoto] += FADE_STEP;

	if(document.all) {
		target_obj[currentPhoto].style.filter = "alpha(opacity=" + currentOpacity[currentPhoto] + ")";
		target_obj[secondPhoto].style.filter = "alpha(opacity=" + currentOpacity[secondPhoto] + ")";
		//document.getElementsByName("photo")[currentPhoto].style.filter = "alpha(opacity=" + currentOpacity[currentPhoto] + ")";
		//document.getElementsByName("photo")[secondPhoto].style.filter = "alpha(opacity=" + currentOpacity[secondPhoto] + ")";

	} else {
		target_obj[currentPhoto].style.MozOpacity = currentOpacity[currentPhoto]/100;
		target_obj[secondPhoto].style.MozOpacity =currentOpacity[secondPhoto]/100;
		//document.getElementsByName("photo")[currentPhoto].style.MozOpacity = currentOpacity[currentPhoto]/100;
		//document.getElementsByName("photo")[secondPhoto].style.MozOpacity =currentOpacity[secondPhoto]/100;
	}

	if(currentOpacity[secondPhoto]/100>=.98) {
		target_obj[currentPhoto].style.display = "none";
		//document.getElementsByName("photo")[currentPhoto].style.display = "none";
		currentPhoto = secondPhoto;
		secondPhoto++;
		if(secondPhoto == imgArray.src.length)secondPhoto=0;
		pause = true;
		xInterval = setTimeout("pause=false",2000);
		
		if (arrayLoc==imgArray.src.length-1) {
			arrayLoc = 0;
		} else {
			arrayLoc++;
		}
	}
}

function goTo() {
  document.location = linkArray[arrayLoc];

} 

function chooseLink() {
  var optionNumber = document.getElementById.selectedIndex
  document.write(i);
}
