function imgRollover() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");

		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("src").match("__roll."))
			{
				images[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace("__roll.", "__rollon."));
				}
				images[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace("__rollon.", "__roll."));
				}
			}
		}
	}
}

if(window.addEventListener) {
	window.addEventListener("load", imgRollover, false);
}
else if(window.attachEvent) {
	window.attachEvent("onload", imgRollover);
}

//-----------------------------------------------------------------------
//	ロールオーバーで画像を変更
//-----------------------------------------------------------------------
function initRollOverImages() {
	//プリロード用オブジェクトを定義
	var image_cache = new Object();
	
	//ロールオーバー処理する画像を指定
 	$("div.index > ul.main_navi > li > a > img").each(function(i) {
		//src属性を取得
		var imgsrc = this.src;
		
		//拡張子前の「.」間での文字数を取得
		var dot = this.src.lastIndexOf('.');
		
		//「.」前までの文字列に「_ov」を付加して、最後に拡張子を足して変数に格納
		//(ロールオーバー後の画像のsrc属性を生成)
		var imgsrc_on = this.src.substr(0, dot) + '_ov' + this.src.substr(dot, 4);
		
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_on;
		
		//ロールオーバー処理
		$(this).hover(
			function() { this.src = imgsrc_on; },
			function() { this.src = imgsrc; });
		});
		var image_cache = new Object();
	
	//ロールオーバー処理する画像を指定
 	$("div.index > div.sub_navi > ul.btn > li > a > img").each(function(i) {
		//src属性を取得
		var imgsrc = this.src;
		
		//拡張子前の「.」間での文字数を取得
		var dot = this.src.lastIndexOf('.');
		
		//「.」前までの文字列に「_ov」を付加して、最後に拡張子を足して変数に格納
		//(ロールオーバー後の画像のsrc属性を生成)
		var imgsrc_on = this.src.substr(0, dot) + '_ov' + this.src.substr(dot, 4);
		
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_on;
		
		//ロールオーバー処理
		$(this).hover(
			function() { this.src = imgsrc_on; },
			function() { this.src = imgsrc; });
		});
}

//クリックでメニュー折りたたみ
function show(inputData) {
	if(document.getElementById( "layer_" + inputData ) != null){
		var objID=document.getElementById( "layer_" + inputData );
	}else{
		return;	
	}
	//var buttonID=document.getElementById( "category_" + inputData );
	
	if(objID.className=='close') {
		objID.style.display='block';
		objID.className='open';
	}else{
		objID.style.display='none';
		objID.className='close';
	}
}

//-----------------------------------------------------------------------
//	ドキュメント(ページ)ロード時に関数を実行
//-----------------------------------------------------------------------
$(document).ready(initRollOverImages);

$(document).ready(function(){
	docURL = location.href;
	
	if(docURL.match("\/tv_antenna\/")!=null){
		show(1);
	}if(docURL.match("\/tv_saitama\/")!=null){
		show(2);
	}if(docURL.match("\/faq\/")!=null){
		show(3);
	}if(docURL.match("\/case\/")!=null){
		show(4);
	}if(docURL.match("\/service\/")!=null){
		show(5);
	}if(docURL.match("\/now\/")!=null){
		show(6);
	}if(docURL.match("\/beginner\/")!=null){
		show(7);
	}if(docURL.match("\/form\/")!=null){
		show(8);
	}if(docURL.match("\/reserve\/")!=null){
		show(9);
	}if(docURL.match("\/link\/")!=null){
		show(10);
	}
});


$(document).ready(function(){
	$("a img").hover(function(){
		if(!$(this).attr("class").match("nohover")){
			$(this).parent().addClass('imgHover');
			$(this).animate({opacity:0.6},100);
		}
	},
	function(){
		$(this).animate({opacity:1.0},100,function(){$(this).parent().removeClass('imgHover');});
	}
	);
});
