var windowWidth;
var timerNum = 3000;
var timer1;
var timer1_1;
var timer2;
var timer3;
var fadeNum = 1000;
var bgAnimateNum = 500;
var hallNum;

$(function(){
	windowWidth = $(window).width();
	topContentsXPosChange();
	getFirstNum();
	ua();
});

$(window).resize(function() {
	windowWidth = $(window).width();
	topContentsXPosChange();
});

function ua(){ //UA”»’è    
    if(navigator.platform == "iPad" || navigator.platform == "iPhone"){
    }else{
		setMenuMouseOver();
    }
}

function setMenuMouseOver(){
	var mouseX;
	var mouseY;
	$('#buttonMiru').mouseover(function(){
		$('#fukidashiMiru').css("display", "block");
		$('#buttonMiru').attr("src", "menu_img/buttonMiru_o.gif");
		$('#buttonMiru').css("cursor", "pointer");
	});
	$('#buttonMiru').mousemove(function(e){
		mouseX = e.pageX;
		mouseY = e.pageY;
		$('#fukidashiMiru').css("left", mouseX + 10);
		$('#fukidashiMiru').css("top", mouseY - 60);
	});
	$('#buttonMiru').mouseout(function(){
		$('#fukidashiMiru').css("display", "none");
		$('#buttonMiru').attr("src", "menu_img/buttonMiru.gif");
	});
	
	$('#buttonSankasuru').mouseover(function(){
		$('#fukidashiSankasuru').css("display", "block");
		$('#buttonSankasuru').attr("src", "menu_img/buttonSankasuru_o.gif");
		$('#buttonSankasuru').css("cursor", "pointer");
	});
	$('#buttonSankasuru').mousemove(function(e){
		mouseX = e.pageX;
		mouseY = e.pageY;
		$('#fukidashiSankasuru').css("left", mouseX + 10);
		$('#fukidashiSankasuru').css("top", mouseY - 60);
	});
	$('#buttonSankasuru').mouseout(function(){
		$('#fukidashiSankasuru').css("display", "none");
		$('#buttonSankasuru').attr("src", "menu_img/buttonSankasuru.gif");
	});
	
	$('#buttonShiru').mouseover(function(){
		$('#fukidashiShiru').css("display", "block");
		$('#buttonShiru').attr("src", "menu_img/buttonShiru_o.gif");
		$('#buttonShiru').css("cursor", "pointer");
	});
	$('#buttonShiru').mousemove(function(e){
		mouseX = e.pageX;
		mouseY = e.pageY;
		$('#fukidashiShiru').css("left", mouseX + 10);
		$('#fukidashiShiru').css("top", mouseY - 60);
	});
	$('#buttonShiru').mouseout(function(){
		$('#fukidashiShiru').css("display", "none");
		$('#buttonShiru').attr("src", "menu_img/buttonShiru.gif");
	});
	
	$('#buttonTsukau').mouseover(function(){
		$('#fukidashiTsukau').css("display", "block");
		$('#buttonTsukau').attr("src", "menu_img/buttonTsukau_o.gif");
		$('#buttonTsukau').css("cursor", "pointer");
	});
	$('#buttonTsukau').mousemove(function(e){
		mouseX = e.pageX;
		mouseY = e.pageY;
		$('#fukidashiTsukau').css("left", mouseX + 10);
		$('#fukidashiTsukau').css("top", mouseY - 60);
	});
	$('#buttonTsukau').mouseout(function(){
		$('#fukidashiTsukau').css("display", "none");
		$('#buttonTsukau').attr("src", "menu_img/buttonTsukau.gif");
	});
}

function topContentsXPosChange() {
	var leftValue;
	var contentsWidth = 950;
	
	var defaultY = 101;
	
	if(windowWidth > contentsWidth){
		leftValue = (windowWidth - contentsWidth)/2;
	}else{
		leftValue = 0;
	}
	
	$('#bg_color_box').css("left", 0);
	$('#bg_color_box').css("width", windowWidth);
	
	$('#top_contents_gt1').css("left", leftValue);
	$('#top_contents_gt2').css("left", leftValue);
	$('#top_contents_gt3').css("left", leftValue);
	$('#top_contents_p1').css("left", leftValue);
	$('#top_contents_p2').css("left", leftValue);
	$('#top_contents_p3').css("left", leftValue);
	
	$('#btnP').css("top", defaultY + 10);
	$('#btnGT').css("top", defaultY + 10);
	$('#btnP_o').css("top", defaultY + 10);
	$('#btnGT_o').css("top", defaultY + 10);
	$('#btnP').css("left", leftValue + 678);
	$('#btnGT').css("left", leftValue + 814);
	$('#btnP_o').css("left", leftValue + 678);
	$('#btnGT_o').css("left", leftValue + 814);
}

function getFirstNum(){
	hallNum = Math.floor(Math.random()*2);
	if(hallNum == 0){
		gtStart();
	}else if(hallNum == 1){
		pStart();
	}
}

function hallNumChange() {
	clearTimeout(timer1);
	clearTimeout(timer2);
	clearTimeout(timer3);
	$('#top_contents_p1').fadeOut(50);
	$('#top_contents_p2').fadeOut(50);
	$('#top_contents_p3').fadeOut(50);
	$('#top_contents_gt1').fadeOut(50);
	$('#top_contents_gt2').fadeOut(50);
	$('#top_contents_gt3').fadeOut(50);
	$('#bg_color_box').animate({ 
		width: 0,
		}, 50, "easeOutExpo");
	if(hallNum == 0){
		gtStart1();
	}else if(hallNum == 1){
		pStart1();
	}
}

function btnChange() {
	if(hallNum == 0){//GT
		$('#btnP').css("display", "block");
		$('#btnGT').css("display", "none");
		$('#btnP_o').css("display", "none");
		$('#btnGT_o').css("display", "block");
		
		$('#btnP').mouseover(function(){
			$('#btnP').css("display", "none");
			$('#btnP_o').css("display", "block");
			$('#btnP_o').css("cursor", "pointer");
		})
		$('#btnP_o').mouseout(function(){
			$('#btnP').css("display", "block");
			$('#btnP_o').css("display", "none");
		})
		$('#btnGT').unbind();
		$('#btnGT_o').unbind();
		$('#btnP_o').mousedown(function(){
			hallNum = 1;
			hallNumChange();
			$('#btnP').unbind();
			$('#btnP_o').unbind();
		})
		
	}else if(hallNum == 1){
		$('#btnP').css("display", "none");
		$('#btnGT').css("display", "block");
		$('#btnP_o').css("display", "block");
		$('#btnGT_o').css("display", "none");
		
		$('#btnGT').mouseover(function(){
			$('#btnGT').css("display", "none");
			$('#btnGT_o').css("display", "block");
			$('#btnGT_o').css("cursor", "pointer");
		})
		$('#btnGT_o').mouseout(function(){
			$('#btnGT').css("display", "block");
			$('#btnGT_o').css("display", "none");
		})
		$('#btnP').unbind();
		$('#btnP_o').unbind();
		$('#btnGT_o').mousedown(function(){
			hallNum = 0;						 
			hallNumChange();
			$('#btnGT').unbind();
			$('#btnGT_o').unbind();
		})
	}
}

function gtStart() {
	btnChange();
	$('#bg_color_box').css("background-color", "#009943");
	$('#bg_color_box').css("width", 0);
	$('#bg_color_box').animate({ 
		width: windowWidth,
	}, bgAnimateNum);
	$('#top_contents_gt1').fadeIn(fadeNum, function() {
		timer1 = setTimeout(gtStart2, timerNum);
	});
}

function gtStart1() {
	hallNum = 0;
	btnChange();
	clearTimeout(timer3);
	$('#top_contents_p3').fadeOut(500);
	$('#bg_color_box').animate({ 
		width: 0,
	}, bgAnimateNum, "easeOutExpo", function(){
		timer1_1 = setTimeout(gtStart1_1, 1000);
	});
}

function gtStart1_1(){
	clearTimeout(timer1_1);
	$('#bg_color_box').css("background-color", "#009943");
	$('#bg_color_box').animate({ 
		width: windowWidth,
	}, bgAnimateNum, "easeOutExpo");
	$('#top_contents_gt1').fadeIn(fadeNum, function() {
		timer1 = setTimeout(gtStart2, timerNum);
	});
}

function gtStart2() {
	clearTimeout(timer1);
	$('#top_contents_gt1').fadeOut(fadeNum);
	$('#top_contents_gt2').fadeIn(fadeNum, function() {
		timer2 = setTimeout(gtStart3, timerNum);
	});
}

function gtStart3() {
	clearTimeout(timer2);
	$('#top_contents_gt2').fadeOut(fadeNum);
	$('#top_contents_gt3').fadeIn(fadeNum, function() {
		timer3 = setTimeout(pStart1, timerNum);
	});
}

function pStart() {
	btnChange();
	$('#bg_color_box').css("background-color", "#ed6d00");
	$('#bg_color_box').css("width", 0);
	$('#bg_color_box').animate({ 
		width: windowWidth,
	}, bgAnimateNum);
	$('#top_contents_p1').fadeIn(fadeNum, function() {
		timer1 = setTimeout(pStart2, timerNum);
	});
}


function pStart1() {
	hallNum = 1;
	btnChange();
	clearTimeout(timer3);
	$('#top_contents_gt3').fadeOut(500);
	$('#bg_color_box').animate({ 
		width: 0,
	}, bgAnimateNum, "easeOutExpo", function(){
		timer1_1 = setTimeout(pStart1_1, 1000);
	});
}

function pStart1_1(){
	clearTimeout(timer1_1);
	$('#bg_color_box').css("background-color", "#ed6d00");
	$('#bg_color_box').animate({ 
		width: windowWidth,
	}, bgAnimateNum, "easeOutExpo");
	$('#top_contents_p1').fadeIn(fadeNum, function() {
		timer1 = setTimeout(pStart2, timerNum);
	});
}

function pStart2() {
	clearTimeout(timer1);
	$('#top_contents_p1').fadeOut(fadeNum);
	$('#top_contents_p2').fadeIn(fadeNum, function() {
		timer2 = setTimeout(pStart3, timerNum);
	});
}

function pStart3() {
	clearTimeout(timer2);
	$('#top_contents_p2').fadeOut(fadeNum);
	$('#top_contents_p3').fadeIn(fadeNum, function() {
		timer3 = setTimeout(gtStart1, timerNum);
	});
}


