
// mouseover script
// @param なし
// @return なし
$(function imgOver() {
    $('#TPBOX .newbox dl dt ul.tab li img').each(function() {
        var node = this;
        if(node.src.match("_off.")) {
            node.originalSrc = node.src;
            node.temporarySrc = node.originalSrc.replace(/_off/,'');
            node.rolloverSrc = node.temporarySrc.replace(/(\.gif|\.jpg|\.png)/,'_on'+"$1");
            node.activeSrc = node.temporarySrc.replace(/(\.gif|\.jpg|\.png)/,'_active'+"$1");
            //画像のプリロード処理開始
            preloadImage(node.rolloverSrc);
            //Mouseover
            node.onmouseover = function() {
                if(this.className!='active') {
                    this.src = this.rolloverSrc;
                }
            }
            //Mouseout
            node.onmouseout = function() {
                if(this.className!='active') {
                    this.src = this.originalSrc;
                }
            }
        }
    });
});


// 画像のプリロードを行う関数
// @param string 画像のパス
// @return なし
preloadImages = [];
preloadImage = function(path) {
    var pre = preloadImages;
    var len = pre.length;
    pre[len] = new Image();
    pre[len].src = path;
}

$(function NewsTab() {


   	
	//ID取得(リストBOX)
	var nwlistbox_i;
	var nwlength;
	$("#TPBOX .newbox dl").each(function(nwlistbox_i) {		
		nwlistbox_i = nwlistbox_i+1;
		$(this).attr("id","nlistwbox"+ nwlistbox_i);
	});

	
    for(i = 0; i < 10; i++) {
		//ID取得(BOX)
		$("#TPBOX .newbox dl#nlistwbox"+ i +" dd ul").each(function(nwbox_i) {		
			nwbox_i = nwbox_i+1;
			$(this).attr("class","nwnum"+ nwbox_i);
		});
	
		//ID取得(ボタン)
		var nwtab_i;
		$("#TPBOX .newbox dl#nlistwbox"+ i +" dt ul.tab li").each(function(nwtab_i) {		
			nwtab_i = nwtab_i+1;
			$(this).attr("class","nwnum"+ nwtab_i);
		});

		//デフォルト
		$("#TPBOX .newbox dl#nlistwbox"+ i +" dd ul.nwnum1").show();
		$("#TPBOX .newbox dl#nlistwbox"+ i +" dt ul.tab li.nwnum1 img").addClass('active');
		$("#TPBOX .newbox dl#nlistwbox"+ i +" dt ul.tab li.nwnum1 img").attr({src:'/images/top_nwtab_so_active.png'});


//   	$("#TPBOX .newbox dl#nlistwbox"+ i +" dt ul.tab").each(function() {
	   	$("#TPBOX .newbox dl dt ul.tab").each(function() {
//		    $("#TPBOX .newbox dl#nlistwbox"+ i +" dt ul.tab li a img").click(function(){
		    $("#TPBOX .newbox dl dt ul.tab li a img").click(function(){
 			  	var tab = this.parentNode.parentNode;
				var idName = tab.className;
				
//				$(this).parent("a").parent("li").parent("ul").parent("dt").siblings("dd").children("ul").hide();
				$("#TPBOX .newbox dl dd ul").hide();
				
//				$(this).parent("a").parent("li").parent("ul").parent("dt").siblings("dd").children("ul."+idName).hide();
				$("#TPBOX .newbox dl dd ul."+idName).show();
				
//				var tab =$(this).parent("a").parent("li").parent("ul").children("li").children("a").children("img");
				var tab =$("#TPBOX .newbox dl dt ul.tab li a img")
				
				tab.each(function() {
					this.src = this.originalSrc;
					$(this).removeClass('active');
				});
				
				var btn =$("#TPBOX .newbox dl dt ul li."+idName+" a img");

				btn.each(function() {
					this.src = this.activeSrc;
					$(this).addClass('active');
				});
								
				
				
				return false;
		    });
	    });
		
	}
	

});
