


function mImg(odds, url, alt, link, height) {
        this.odds = odds;
        this.url = url;
        this.alt = alt;
        this.link = link;
        this.height = height;
}

function chgTopImage(){


$("#mainimage")
	.css({height: 183});

	var totalodds = 0;
	var rdimg = 0;
	var defImg = '/eng/common/images/top_img.jpg';
	var Imgs = new Array();
	var html;

	



	Imgs[0] = new mImg('80','/eng/common/images/top_img.jpg','NIMS is the research institute that do a fundamental research and generic / infrastructural technology research and development of the materials.','', 183);
	



	Imgs[1] = new mImg('10','/eng/common/images/top_img2.jpg','NIMS is the research institute that do a fundamental research and generic / infrastructural technology research and development of the materials.','', 183);
	



	Imgs[2] = new mImg('10','/eng/common/images/top_img3.jpg','NIMS is the research institute that do a fundamental research and generic / infrastructural technology research and development of the materials.','', 183);
	
	for(i=0; i < Imgs.length ; i++) {
		totalodds += parseInt(Imgs[i].odds);
	}

        rdimg=Math.floor(totalodds * Math.random());
	totalodds = 0;
	for(i=0; i < Imgs.length ; i++) {
	totalodds += parseInt(Imgs[i].odds);     
		if (rdimg <= totalodds) {
			rdimg = i;
			break;
		}
	}

	if(Imgs[rdimg].link != null && Imgs[rdimg].link != ""){
		html = "<a href=\""+Imgs[rdimg].link+"\"><img src=\""+Imgs[rdimg].url+"\" width=\"890\" height=\""+Imgs[rdimg].height+"px\" alt=\""+Imgs[rdimg].alt+"\" /></a>";
	} else {
		html = "<img src=\""+Imgs[rdimg].url+"\" width=\"890\"  height=\""+Imgs[rdimg].height+"px\" alt=\""+Imgs[rdimg].alt+"\" />";
	}

	$("#mainimg-inner").html(html);



}


function detectLang(){
	var ua = navigator.userAgent
	var bl = navigator.browserLanguage;
	var ref = document.referrer
	if(ua.indexOf("ja")==-1){
		if((!bl || bl!="ja") && ref.indexOf("/eng/")==-1 && location.href.indexOf("/eng/")==-1){
			location.replace(/eng/);
		}
	}

}

function inithome(){
	detectLang();
	chgTopImage();
}

$(document).ready(inithome);