/**
 * トップページメイン画像のランダム切替
 * 
 * @return none
 */
function TopPageImgRandom(){
	// トップページ判定
	if($('TopPage')){
		var top_main_img = document.getElementById("TopPage").getElementsByClassName("top_main_img");
		var top_main_alt = document.getElementById("TopPage").getElementsByClassName("top_main_alt");
		var top_main_height = document.getElementById("TopPage").getElementsByClassName("top_main_height");
		var top_main_link = document.getElementById("TopPage").getElementsByClassName("top_main_link");
		var i = top_main_img.length;

		num = Math.floor(Math.random()*i);
		
		html = '';
		html_img = '<img src="' + $F(top_main_img[num]) + '" alt="' + $F(top_main_alt[num]) + '" width="950" height="' + $F(top_main_height[num]) + '" />';

		if($F(top_main_link[num]) != ""){
			html = '<a href="' + $F(top_main_link[num]) + '">' + html_img + '</a>';
		}else{
			html = html_img;
		}
		
		Element.update($('TopMainImg'), html);
	}
}

/**
 * ロールオーバー画像の切り替え
 * 
 * @param classname 対象となるクラス
 * @param prefix ロールオーバー画像のプレフィックス
 * @return none
 */
function ROfunction(classname, prefix){

	var imgNum = document.getElementsByTagName("img");
	var inputNum = document.getElementsByTagName("input");
	
	overNum = new Array;
	
	if(prefix == ''){
		prefix = '_o';
	}
	
	for (i = 0; i < imgNum.length; i++) {
		overNum[i] = imgNum[i];
	}
	
	for (i = 0; i < inputNum.length; i++) {
		overNum[i + imgNum.length] = inputNum[i];
	}
	
	for (i = 0; i < overNum.length; i++) {
		if (overNum[i].className.indexOf(classname) != -1 && overNum[i].src.indexOf(prefix + ".") == -1) {
			overNum[i].overimg = new Image();
			if (overNum[i].className.indexOf(":") != -1) {
				Replace = overNum[i].className.split(":");
				Replace = Replace[1].split(" ");
				overNum[i].overimg.src = Replace[0];
			}
			else {
				Replace = overNum[i].src.length;
				overNum[i].overimg.src = overNum[i].src.substring(0, Replace - 4) + prefix + overNum[i].src.substring(Replace - 4, Replace);
			}
			overNum[i].setAttribute("out", overNum[i].src);
			overNum[i].onmouseover = new Function('this.src=this.overimg.src;');
			overNum[i].onmouseout = new Function('this.src=this.getAttribute("out");');
		}
	}
}

window.onload = function(){
	// トップページメイン画像ランダム表示
	TopPageImgRandom();
	
	// ロールオーバー処理初期化
	ROfunction('ROVER', '');
}

