var cycflg={};
jQuery(function($){
	$("a,map").each(function(){
	$(this).css("outline","none").focus(function(){ $(this).blur() }) })
	
	$("#download").css("opacity","0").hover(
		function(){ $(this).stop().fadeTo("fast",1.0) },
		function(){ $(this).fadeTo("fast",0) } );

	new MP3Player("../../movies/PJM_BGM_menu.mp3","200","20").Write().addSwitchModule("switch")

	setCycle("#charlie",true,"#show_frame1");
	setCycle("#alfa",true,"#show_frame2");
	setCycle("#echo",true,"#show_frame3");
	setCycle("#bravo",true,"#show_frame4");
	setCycle("#foxtrot",true,"#show_frame5");
	setCycle("#golf",false,"#show_frame6");

	var a = {
		"alfa": {
			"0": new AnimationXY($("#alfa_anim"),{"0":[ [0,0],[34,0],[68,0],[102,0] ]}),
			"speed": 100,"r":0},
		"bravo": {
			"0": new AnimationXY($("#bravo_anim"),{"0":[ [0,34],[34,34],[68,34],[102,34],[136,34],[170,34],[204,34],[238,34] ]}),
			"speed": 100,"r":0},
		"charlie": {
			"0": new AnimationXY($("#charlie_anim"),{"0":[ [0,102],[34,102],[68,102],[102,102],[136,102],[170,102] ]}),
			"speed": 100,"r":0},
		"delta": {
			"0": new AnimationXY($("#delta_anim"),{"0":[ [136,0],[170,0],[204,0],[238,0],[204,102] ]}),
			"speed": 100,"r":0},
		"echo": {
			"0": new AnimationXY($("#echo_anim"),{"0":[ [0,136],[34,136],[68,136],[102,136],[136,136],[170,136] ]}),
			"speed": 150,"r":0},
		"foxtrot": {
			"0": new AnimationXY($("#foxtrot_anim"),{"0":[ [0,68],[34,68],[68,68],[102,68],[136,68],[170,68],[204,68],[238,68] ]}),
			"speed": 66,"r":0},
		"hotel": {
			"0": new AnimationXY($("#hotel_anim"),{"0":[ [272,0],[272,34],[272,68],[272,102],[272,136] ]}),
			"speed": 100,"r":2}
	};
	if( false ){
		for(var key in a ){ a[key][0].On("0",a[key].speed) }
	}else{
		for(var key in a ){
			$("#"+key+"_anim").hover(
				function(){ var buf=$(this).attr("id").split("_");a[buf[0]][0].On("0",a[buf[0]].speed,a[buf[0]].r) },
				function(){ var buf=$(this).attr("id").split("_");a[buf[0]][0].Off(1) } );
			$("#"+key).hover(
				function(){ var buf=$(this).attr("id");a[buf][0].On("0",a[buf].speed,a[buf].r) },
				function(){ var buf=$(this).attr("id");a[buf][0].Off(1) } );
		}
	}
	NewAddress().Exec();
});

function setCycleCompart(a_id,a_flag,a_cycle_id){
	$(a_id).attr("href","#").click(function(){ set($(a_cycle_id).find("div"),true) });
	if( a_flag )
		$(a_id+"_anim").find("a").attr("href","#").click(function(){ set($(a_cycle_id).find("div"),true) });
}


function setCycle(a_id,a_flag,a_cycle_id){
	$(a_id).attr("href","#").click(function(){ set($(a_cycle_id)) });
	if( a_flag )
		$(a_id+"_anim").find("a").attr("href","#").click(function(){ set($(a_cycle_id)) });
}

function set(a_id,a_child_flag){
	a_child_flag = a_child_flag || false;
	$("#anim").hide();
	$("#language").hide();
	$("#monsters").fadeIn();
	returnTop(a_id,a_child_flag);
	
	(function(a_flg){return a_flg?a_id.parent():a_id;})(a_child_flag).fadeIn("slow");

	if(a_id.find("img").size()<=1)return;
	
	$("#next").fadeIn();
	
	var n = a_id.attr("id");
	if(typeof(cycflg[n])!=undefined&&cycflg[n])return;
	cycflg[n]=true;

	a_id.cycle({
		fx: a_child_flag?"fade":"scrollHorz",
		speed: "normal",
		timeout: 0,
		nowrap: 1,
		after: function(a,b,c,d){
			if(c.slideCount!=2){
				if(c.currSlide==c.slideCount-1){
					$("#next").fadeOut();
					if(a_child_flag){
						$(b).one("click",function(){
							$("#monsters").fadeOut(function(){a_id.cycle(0)}); $("#language").fadeIn();
							$("#next").hide(); $("#prev").fadeOut();
							(function(a_flg){return a_flg?a_id.parent():a_id})(a_child_flag).fadeOut();
							$("#anim").fadeIn();
						})
					}
				}else if(c.currSlide==0)$("#prev").fadeOut();
				else{ $("#next").fadeIn();$("#prev").fadeIn(); }
			}else{
				if(d)
				if(c.currSlide==c.slideCount-1){
					$("#next").fadeOut();$("#prev").fadeIn();
				}else if(c.currSlide==0){
					$("#next").fadeIn();$("#prev").fadeOut();
				}
			}
		},
		prev: "#prev",
		next: ".next"
	});
}
function returnTop(a_id,a_child_flag){
	$("#monsters").one("click",function(){
		$(this).fadeOut(function(){a_id.cycle(0)}); $("#language").fadeIn();
		$("#next").hide(); $("#prev").fadeOut();
		(function(a_flg){return a_flg?a_id.parent():a_id})(a_child_flag).fadeOut();
		$("#anim").fadeIn();
	});
}

function NewAddress(){
	this._url = document.URL.split("#");

	this.Select = {
		"deluxe": function(){ set($("#show_frame8").find("div"),true);return this; }
	};
	
	this.Exec = this.Select[this._url[1]] || function(){ return this; };
	return this;
}