﻿/***********************************
　home_main.js
************************************/

$(function(){

    //初期化
    $("div#productsarea").show();
    $("p#productstab").css("background-position","0px -28px");
    
    //タブ
    $("p.tabbutton").each(function(){
        $("p#"+$(this).find("a").attr('tabname')+"tab a").click(function(){
            tabclear();
            $("div#"+$(this).attr('tabname')+"area").show();
            $("p#"+$(this).attr('tabname')+"tab").css("background-position","0px -28px");
            return false;
        });
    });
    
    
    // メイン案内切り替え
    var mainInfoCount = 0;
    var mainInfoArray = new Array();
    var topNaviArray = new Array();

    $("div#mainInfoStage div.mainInfoBox").each(function(){
        mainInfoArray.push($(this));
        topNaviArray.push($("#topMenu li."+$(this).attr('globalclass')+" a"));
        $("#topMenu li."+$(this).attr('globalclass')).mouseover(function(){
            clearInterval(timerID);
            mainInfoCount = $(this).attr('maininfocount');
            mainInfoClear();
            mainInfoArray[mainInfoCount].fadeIn('normal');
            topNaviArray[mainInfoCount].css('background-position','0px -31px');
        });
        $("#topMenu li."+$(this).attr('globalclass')).mouseout(function(){
            clearInterval(timerID);
            timerID = window.setInterval(changeMainInfo,5000);
        });
    });
    $("div#mainInfoStage").mouseover(function(){
        clearInterval(timerID);
    });
    $("div#mainInfoStage").mouseout(function(){
        clearInterval(timerID);
        timerID = window.setInterval(changeMainInfo,5000);
    });
    
    var mainInfoClear = function(){
        $("div#mainInfoStage div.mainInfoBox").hide();
        $("#topMenu li a").css('background-position','0px 0px');
    }

    var changeMainInfo = function(){
        mainInfoClear();
        mainInfoCount++;
        if($("div#mainInfoStage div.mainInfoBox").length - 1 < mainInfoCount){
            mainInfoCount = 0;
        }
        mainInfoArray[mainInfoCount].fadeIn('normal');
        topNaviArray[mainInfoCount].css('background-position','0px -31px');
    }
    
    var initRollOverImages = function(){
        var image_cache = new Object();
        $("img.swap").each(function(i){
            var imgsrc = this.src;
            var dot = this.src.lastIndexOf('.');
            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; });
        });
    }
    
    //初期化
    mainInfoClear();
    mainInfoArray[0].fadeIn('normal');
    topNaviArray[0].css('background-position','0px -31px');
    clearInterval(timerID);
    var timerID = window.setInterval(changeMainInfo,5000);
    
    initRollOverImages();
    
});

function tabclear(){
    $("div.tablist").hide();
    $("p.tabbutton").each(function(){
        $("p#"+$(this).find("a").attr('tabname')+"tab").css('background-position','0px 0px');
    });
}





//*----宣伝部制作1----*//
//*ーーーーーーーーメニューポップアップ用ーーーーーーーー*//

var mmOpenContainer = null;
var mmOpenMenus = null;
var mmHideMenuTimer = null;

function MM_menuStartTimeout(hideTimeout) {
	mmHideMenuTimer = setTimeout("MM_menuHideMenus()", hideTimeout);	
}

function MM_menuHideMenus() {
	MM_menuResetTimeout();
	if(mmOpenContainer) {
		var c = document.getElementById(mmOpenContainer);
		c.style.visibility = "inherit";
		mmOpenContainer = null;
	}
	if( mmOpenMenus ) {
		for(var i in mmOpenMenus) {
			var m = document.getElementById(mmOpenMenus[i]);
			m.style.visibility = "hidden";			
		}
		mmOpenMenus = null;
	}
}

function MM_menuHideSubmenus(menuName) {
	if( mmOpenMenus ) {
		var h = false;
		var c = 0;
		for(var i in mmOpenMenus) {
			if( h ) {
				var m = document.getElementById(mmOpenMenus[i]);
				m.style.visibility = "hidden";
			} else if( mmOpenMenus[i] == menuName ) {
				h = true;
			} else {
				c++;
			}
		}
		mmOpenMenus.length = c+1;
	}
}

function MM_menuOverMenuItem(menuName, subMenuSuffix) {
	MM_menuResetTimeout();
	MM_menuHideSubmenus(menuName);
	if( subMenuSuffix ) {
		var subMenuName = "" + menuName + "_" + subMenuSuffix;
		MM_menuShowSubMenu(subMenuName);
	}
}

function MM_menuShowSubMenu(subMenuName) {
	MM_menuResetTimeout();
	var e = document.getElementById(subMenuName);
	e.style.visibility = "inherit";
	if( !mmOpenMenus ) {
		mmOpenMenus = new Array;
	}
	mmOpenMenus[mmOpenMenus.length] = "" + subMenuName;
}

function MM_menuResetTimeout() {
	if (mmHideMenuTimer) clearTimeout(mmHideMenuTimer);
	mmHideMenuTimer = null;
}

function MM_menuShowMenu(containName, menuName, xOffset, yOffset, triggerName) {
	MM_menuHideMenus();
	MM_menuResetTimeout();
	MM_menuShowMenuContainer(containName, xOffset, yOffset, triggerName);
	MM_menuShowSubMenu(menuName);
}

function MM_menuShowMenuContainer(containName, x, y, triggerName) {	
	var c = document.getElementById(containName);
	var s = c.style;
	s.visibility = "inherit";
	
	mmOpenContainer = "" + containName;
}

//*----宣伝部制作1----*//

