var overKey = "_on";
var activeKey = "_active";

// 無衝突モードにする
jQuery.noConflict();

/*
 * ロード時の自動ロールオーバー
 */
jQuery(function() {
	var classname = ".rollover";
	jQuery(classname).hover(
		function() {
			swapImg(jQuery(this).find("img, input:image"), overKey);
		},
		function() {
			swapImg(jQuery(this).find("img, input:image"), "");
		}
	);
	jQuery(classname).focus(function() {
			swapImg(jQuery(this).find("img, input:image"), overKey);
	});
	jQuery(classname).blur(function() {
			swapImg(jQuery(this).find("img, input:image"), "");
	});

    classname = ".rolloverarea";
	jQuery(classname).hover(
		function() {
			swapMap(jQuery(this).find("area"), overKey);
		},
		function() {
			swapMap(jQuery(this).find("area"), "");
		}
	);
	jQuery(classname).focus(function() {
			swapMap(jQuery(this).find("area"), overKey);
	});
	jQuery(classname).blur(function() {
			swapMap(jQuery(this).find("area"), "");
	});
});


/*
 * ロード時の自動プリロード
 */
jQuery(function() {
	var images = jQuery('img.preload, input.preload:image');
	for (var i = 0; i < images.length; i++) {
		var path = images[i].src;
		var suffix = path.substr(path.lastIndexOf("."));
		var basename = getBasename(path, overKey, activeKey);
		var img = document.createElement('img');
		if( img != null )
			img.src = basename + overKey + suffix;
	}
});

var navInitializer = function() {
	jQuery('img, input:image, map area').each(function(i) {
		if (jQuery(this).attr("id")) {
			var path = jQuery(this).attr("src");
			var suffix = path.substr(path.lastIndexOf("."));
			var basename = getBasename(path, overKey, activeKey);
			var img = document.createElement('img');
			if( img != null )
				img.src = basename + overKey + suffix;
			var classname = "." + jQuery(this).attr("id");
			
			// 画像のIDと同じclassの要素が親要素にあった場合は、activeにする。
			// IDと同じclass名の要素がなく、かつactiveKeyをもつsrcの画像の場合は、ノーマルにする
			if (jQuery(this).parents(classname).length > 0) {
				jQuery(this).attr("src", basename + activeKey + suffix);
			} else if (jQuery(this).attr("src").indexOf(activeKey) > 0) {
				jQuery(this).attr("src", basename + suffix);
			}
		}
	});
};

/*
 * ロード時の自動ナビゲーション要素変化
 */
jQuery(navInitializer);

function swapImg(img, key) {
	var path = img.attr("src");
	var basename = getBasename(path, overKey, activeKey);
	var suffix = path.substr(path.lastIndexOf("."));
	
	
	path = img.attr("id") && jQuery.find("."+img.attr("id")).length > 0
		 ? basename + activeKey + suffix
		 : basename + key + suffix;

	img.attr("src", path);
}

function swapMap(elm, key) {
    var img = jQuery(elm).parents(".rolloverarea").prev("img");
    swapImg(img, key);
}

/*
 * ベース名を取り出す
 */
function getBasename(src, key, activeKey) {
	var path = src.substr(0, src.lastIndexOf('.'));
	if (path.lastIndexOf(key) == (path.length - key.length)) {
		path = path.substr(0, path.length - key.length);
	}
	if (path.lastIndexOf(activeKey) == (path.length - activeKey.length)) {
		path = path.substr(0, path.length - activeKey.length);
	}
	return path;
}

/*
 * 透過ロールオーバー
 */
var ua = navigator.userAgent;
if(ua.indexOf("MSIE") != -1 && ua.indexOf("6.0") != -1) {
  var ie6 = true;
}
jQuery(function(){
  if(ie6 && IEPNGFIX) {
    jQuery('.rollover.clrpng img').each(function() {
      var classes = this.getAttribute('href'); /* href内に*/
      if(classes.indexOf("_on.png") == -1 && classes.indexOf(".png") != -1) { /*---「_over.png」が無くて、「.png」がある場合 ---*/
        var imgout = this.getAttribute('href');
        var imgovr = imgout.replace('.png', '_on.png');
        IEPNGFIX.hover(this, imgovr);
      }
	  else {
        IEPNGFIX.fix(this);
      }
    });
  }
});


if(typeof IEPNGFIX=='undefined'){var IEPNGFIX={blank:'/img/common/blank.gif',filter:'DXImageTransform.Microsoft.AlphaImageLoader',fixit:function(elem,src,method){if(elem.filters[this.filter]){var filter=elem.filters[this.filter];filter.enabled=true;filter.src=src;filter.sizingMethod=method}else{elem.style.filter='progid:'+this.filter+'(src="'+src+'",sizingMethod="'+method+'")'}},fixwidth:function(elem){if(elem.currentStyle.width=='auto'&&elem.currentStyle.height=='auto'){elem.style.width=elem.offsetWidth+'px'}},fixchild:function(elem,recursive){if(!/MSIE (5\.5|6\.|7\.)/.test(navigator.userAgent))return;for(var i=0,n=elem.childNodes.length;i<n;i++){var childNode=elem.childNodes[i];if(childNode.style){if(childNode.style.position){childNode.style.position=childNode.style.position}else{childNode.style.position='relative'}}if(recursive&&childNode.hasChildNodes()){this.fixchild(childNode,recursive)}}},fix:function(elem){if(!/MSIE (5\.5|6\.|7\.)/.test(navigator.userAgent))return;var bgImg=elem.currentStyle.backgroundImage||elem.style.backgroundImage;if(elem.tagName=='IMG'){if((/\.png$/i).test(elem.src)){this.fixwidth(elem);this.fixit(elem,elem.src,'scale');elem.src=this.blank;elem.runtimeStyle.behavior='none'}}else if(bgImg&&bgImg!='none'){if(bgImg.match(/^url[("']+(.*\.png)[)"']+$/i)){var s=RegExp.$1;this.fixwidth(elem);elem.style.backgroundImage='none';this.fixit(elem,s,'scale');if(elem.tagName=='A'&&elem.style){if(!elem.style.cursor){elem.style.cursor='pointer'}}this.fixchild(elem);elem.runtimeStyle.behavior='none'}}},hover:function(elem,hvImg){var bgImg=elem.style.backgroundImage;if(!bgImg&&elem.currentStyle)bgImg=elem.currentStyle.backgroundImage;if(elem.tagName=='IMG'&&hvImg){var image=elem.src;elem.onmouseover=function(){elem.src=hvImg;IEPNGFIX.fix(elem)};elem.onmouseout=function(){elem.src=image;IEPNGFIX.fix(elem)}}else if(bgImg&&bgImg!='none'&&hvImg){elem.onmouseover=function(){elem.style.backgroundImage='url('+hvImg+')';IEPNGFIX.fix(elem)};elem.onmouseout=function(){elem.style.backgroundImage=bgImg;IEPNGFIX.fix(elem)}}IEPNGFIX.fix(elem)}}}

// 交互にテーブルにクラスを設定するのスクリプト
// evenCellとoddCellの装飾はCSSで設定してください
jQuery(function() {
  jQuery('.striped').find('tr:odd').addClass('evenCell');
  jQuery('.striped').find('tr:even').addClass('oddCell');
});

// ポップアップの表示
jQuery(function() {
	jQuery('.popup a, .popup area').click(function(){
		var h = screen.height * 0.6;
		var myTarget = this.target;
		if( myTarget == null || myTarget == "" )
			myTarget = "_blank";
		var win = window.open(this.href, myTarget, 'width=734,height=' + h + ',status=0,scrollbars=1,menubar=0,toolbar=0,resizable=1');
		win.focus();
		return false;								
	});
})

jQuery(function() {
	jQuery('.windowBlank a').click(function(){
		var winwin = window.open(this.href, this.target, 'status=1,scrollbars=1,menubar=1,toolbar=1,resizable=1');
		winwin.focus();
		return false;								
	});
})

// ポップアップクローズ
jQuery(function() {
	jQuery('.close a').click(function(){	
		window.close();	
		return false;								
	});
})

// ゲームリストの表示
jQuery(function() {
	jQuery("#gameListBtn").hover(
	function(){
		clearInterval( gameListId );
		jQuery("#gameList").css( "visibility", "visible" );
	}, 
	function (){ 
		fadeTimer(); 
	} );
	
	jQuery( "#gameList" ).hover(
	function(){
		clearInterval( gameListId );
	},
	function (){
		fadeTimer();
	} );
	
	jQuery("#gameList").css( "visibility", "hidden" );
});

gameListId = 0;

function fadeTimer()
{
	clearInterval( gameListId );
	gameListId = setInterval( "fadeList()", 500 );
}

function fadeList()
{
	clearInterval( gameListId );
	jQuery("#gameList").css( "visibility", "hidden" );
}


// コミュニティリストの表示
jQuery(function() {
	jQuery("#commuListBtn").hover(
	function(){
		clearInterval( commuListId );
		jQuery("#commuList").css( "visibility", "visible" );
	}, 
	function (){ 
		fadeTimer2(); 
	} );
	
	jQuery( "#commuList" ).hover(
	function(){
		clearInterval( commuListId );
	},
	function (){
		fadeTimer2();
	} );
	
	jQuery("#commuList").css( "visibility", "hidden" );
});

commuListId = 0;

function fadeTimer2()
{
	clearInterval( commuListId );
	commuListId = setInterval( "fadeList2()", 500 );
}

function fadeList2()
{
	clearInterval( commuListId );
	jQuery("#commuList").css( "visibility", "hidden" );
}




// ゲームの特徴表示
jQuery(function() {
	var iconNames = "#doki,#team,#strategy,#story,#action,#raging,#funtasy,#casual";
	jQuery( iconNames ).find( ".on" ).css( "visibility", "hidden" );

	var names = iconNames.split( "," );
	for( var i = 0; i < names.length; i++ )
		iconPopup( names[ i ] );
});

function iconPopup( ele )
{
	jQuery( ele ).find( "a" ).hover(
		function ()
		{
			jQuery( ele ).find( ".on" ).css( "visibility", "visible" );
		},
		function ()
	{
		jQuery( ele ).find( ".on" ).css( "visibility", "hidden" );
	});
}

// FAQ
jQuery(function(){
	var faqArray = jQuery( '.faqInIn' );
	if( faqArray != null )
	{
		for( var i = 0; i < faqArray.length; i++ )
		{
			var item = faqArray[ i ];
			var linkItem = jQuery(item).find( "h3 a" );
			var openItem = jQuery(item).find( ".open" );
			setFAQOpenAction( linkItem, openItem );
		}
	}
});

function setFAQOpenAction( linkItem, openItem )
{
	jQuery(linkItem).click( function ()
	{
		if( jQuery( openItem ).is(":hidden") )
		{
			jQuery(linkItem).addClass( "active" );
			jQuery( openItem ).slideDown();
		}
		else
		{
			jQuery(linkItem).removeClass( "active" );
			jQuery( openItem ).slideUp();
		}
		return false;
	});
}

var css_browser_selector = function() { var ua=navigator.userAgent.toLowerCase(), is=function(t){ return ua.indexOf(t) != -1; }, h=document.getElementsByTagName('html')[0], b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/')? 'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'', os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':''; var c=b+os+' js'; h.className += h.className?' '+c:c; }();

