﻿var mSecond = ((Math.floor(Math.random()*256)&0xFF)<<16)|((new Date().getTime())&0xFFFF);
var flashvars = {uniqid:mSecond}


var params = {};
params.bgcolor = "#000000";
params.wmode="transparent";
params.base="/";

var attributes = {};
var isIE6 =0;
var isGamemodeWait = 0;
var isGamemode = 0;


function openPopupWindow(url, width, height) {
	if (!width) var width = window.innerWidth || document.documentElement.clientWidth;
	if (!height) var height = window.innerHeight || document.documentElement.clientHeight;
	if (!windowName) var windowName = "popup";
	var x = (screen.availWidth - width)/2;
	var y = (screen.availHeight - height)/4;
	var blockMessage = "ウィンドウがお使いのブラウザでポップアップブロックされました。\nポップアップブロックを解除してください。";
	var windou = window.open(url, windowName, "menubar=no, toolbar=no, location=yes, status=yes, scrollbars=no, resizable=no, width="+width+", height="+height+", left="+x+", top="+y+"");
	if (windou) win.focus();
	else alert(blockMessage);
}


function gamemodeOn() {
	j$("#gameButton").removeClass("off");
	j$("#gameButton").addClass("on");
	j$.cookie("gamemode",1,{expires:7,path:'/'});
}

function gamemodeOff() {
	j$("#gameButton").removeClass("on");
	j$("#gameButton").addClass("off");
	j$.cookie("gamemode",0,{expires:7,path:'/'});
}

function gamemodeWaitUnLock() {
	isGamemodeWait = 0;
	j$("#gameButton").css("cursor","pointer");
}

function gamemodeWaitLock() {
	isGamemodeWait = 1;
	j$("#gameButton").css("cursor","default");
}

function changeGamemode() {
	
	//window.alert(isGamemode);
	
	if(isGamemodeWait==1) return;
	gamemodeWaitLock();
	
	if (j$.cookie("gamemode")) {
		isGamemode=j$.cookie("gamemode");
		isGamemode=(isGamemode==1)?0:1;
		j$.cookie("gamemode",isGamemode,{expires:7,path:'/'});
		
		if(isGamemode==1) {
			// クラス名の書き換え
			j$("#gameButton").removeClass("off");
			j$("#gameButton").addClass("on");
			
		}
		else {
			j$("#gameButton").removeClass("on");
			j$("#gameButton").addClass("off");
		}
	}
	else {
		j$.cookie("gamemode",1,{expires:7,path:'/'});
		isGamemode=1;
	}
	
	var swf = swfobject.getObjectById("cardmenu");
	swf.changeGameMode(isGamemode);
}
	
// init
j$(document).ready(function(){
	
	gamemodeWaitLock();
	
	// ie6 用のフラグ
	if(j$.browser.msie && parseInt(j$.browser.version.substr(0,1))<7) isIE6 = 1;
	
	if(isIE6==1) {
		j$("#cardmenuContainer").css("position","absolute");
		var arr = getPageSize();
		j$("#cardmenuContainer").css("top",(getScrollPosition()+arr[3]-220)+"px");
		j$("#cardmenuContainer").css("height","220px");
		j$("#cardmenu").css("top","110px");
	}
	else {
		j$("#cardmenuContainer").css("position","fixed");	
		j$("#cardmenuContainer").css("height","110px");
		j$("#cardmenu").css("height","110px");
	}
	
	if(isIE6==1) {
		j$(window).bind("resize", overlayResize);
		j$(window).bind("scroll", overlayScroll);
	}
	
	if ( j$.cookie("gamemode") ) {
		isGamemode=j$.cookie("gamemode");
		
	}
	else { // ゲームモードは最初は 0 == off
		j$.cookie("gamemode",0,{expires:7,path:'/'});
		isGamemode=0;
	}
	
	if(isGamemode==1) {
		j$("#gameButton").removeClass("off");
		j$("#gameButton").addClass("on");		
	}
	else {
		j$("#gameButton").removeClass("on");
		j$("#gameButton").addClass("off");
	}
	
	initOverlayHandler();
	// swf の読み込み
	swfobject.embedSWF("/assets/swf/menu.swf", "menuFla", "100%", "52", "9", "", flashvars, params, attributes);
	swfobject.embedSWF("/assets/swf/top.swf", "topFla", "100%", "516", "9", "", flashvars, params, attributes);
	swfobject.embedSWF("/assets/swf/cardanime.swf?01", "cardanimeFla", "100%", "100%", "9", "", flashvars, params, attributes);
	//
	flashvars.gamemode = isGamemode;
	swfobject.embedSWF("/assets/swf/cardmenu.swf", "cardmenuFla", "100%", "260", "9", "", flashvars, params, attributes);
	
});

function naviRollOver() {j$("#menuFla").css("height","302px");}
function naviRollOut() {j$("#menuFla").css("height","52px");}

//function naviRollOut() {
//	j$("#menuFla").css("height","232px");
//}

// footer menu - fl 2 js 
function enterCardmenu() { 
	if(isIE6==1) {
		j$("#cardmenu").css("top","0px");
	}
	else {
		j$("#cardmenu").css("height","220px"); 
		j$("#cardmenuContainer").css("height","220px");
	}
}
function leaveCardmenu() { 
	if(isIE6==1) {
		j$("#cardmenu").css("top","110px"); 
	}
	else {
		j$("#cardmenu").css("height","110px"); 
		j$("#cardmenuContainer").css("height","110px");
	}			
}

// オーバーレイ
var isOverlay = 0;

function viewCardAnime() {
	showOverlayHandler();	
}

// オーバレイ初期設定
function initOverlayHandler(){
	
	if(!j$("#cardanime").length) return;
	
	j$("#cardanime").css("display","block");
	
	if(isIE6==1) {
		j$("#cardanime").css("position","absolute");	
		j$("#cardanime").css("top","0px");
		j$("#cardanime").css("left","0px");
	}
	else {
		j$("#cardanime").css("position","fixed");
		j$("#cardanime").css("top","0");
		j$("#cardanime").css("left","0");
	}
	
	j$("#cardanime").css("width","1px");
	j$("#cardanime").css("height","1px");
	j$("#cardanime").css("overflow","hidden");
	j$("#cardanime").css("z-index","8000");	
}

function overlayResize() {
	if(isOverlay==1) {
		var arr = getPageSize();
		j$("#cardanime").css("height",arr[3]+"px");
		j$("#cardanime").css("top",getScrollPosition()+"px");
	}
	
	if(isIE6==1) {
		var arr = getPageSize();
		j$("#cardmenuContainer").css("top",(getScrollPosition()+arr[3]-220)+"px");		
	}
}
function overlayScroll() {
	if(isOverlay==1) {
		var arr = getPageSize();
		j$("#cardanime").css("height",arr[3]+"px");
		j$("#cardanime").css("top",getScrollPosition()+"px");
	}
	
	if(isIE6==1) {
		var arr = getPageSize();
		j$("#cardmenuContainer").css("top",(getScrollPosition()+arr[3]-220)+"px");
	}
}
//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight,xScroll,yScroll) 
	return arrayPageSize;
}

function getScrollPosition() { 
	return document.documentElement.scrollTop || document.body.scrollTop; 
} 

// 表示設定
function showOverlayHandler(){
	isOverlay = 1;
	if(!j$("#cardanime").length) return;
	
	if(isIE6==1) {
		var arr = getPageSize();
		j$("#cardanime").css("height",arr[3]+"px");
		j$("#cardanime").css("top",getScrollPosition()+"px");
	}
	else {
		j$("#cardanime").css("height","100%");
	}
	
	j$("#cardanime").css("width","100%");
}

// 非表示設定
function hideOverlayHandler(){
	isOverlay =0;
	if(!j$("#cardanime").length) return;
	
	j$("#cardanime").css("width","1px");
	j$("#cardanime").css("height","1px");
}
