
var a = {
	spec:{id:$("#show_frame1"),prev:$("#prev01")},
	newfeatures:{id:$("#show_frame2"),prev:$("#prev02"),next:$("#next02_frame")},
	medalchallenge:{id:$("#show_frame3"),prev:$("#prev03"),next:$("#next03_frame")},
	adhocmode:{id:$("#show_frame4"),prev:$("#prev04"),next:$("#next04_frame")},
	infrastructuremode:{id:$("#show_frame5"),prev:$("#prev05"),next:$("#next05_frame")},
	screenshot:{id:$("#show_frame6"),prev:$("#prev06"),next:$("#next06_frame")},
	movie:{id:$("#show_frame7"),prev:$("#prev01")}
}
var tops = {id:$("#show_frame0"),lang:$("#language"),next:$("#next00"),prev:$("#prev00")};

var g_flg = {};

jQuery(function($){
	
(function(){
	var ua = navigator.userAgent;
	jQuery.browser["playstation"] = ua.indexOf("PLAYSTATION")!=-1;

	for( var _i in a ){
		if( !!a[_i].prev )
			a[_i].prev.hide();
		if( !!a[_i].next ){
			a[_i].next.hide()
			if( !!jQuery.browser["playstation"] )
				a[_i].next.find("img").attr("src","../Monsters/MonstersImages/next_anim.gif");
		}
	}
})();

(function(name){
	$(name).css("opacity","0").hover(
		function(){ $(this).stop().fadeTo("fast",1.0) },
		function(){ $(this).fadeTo("fast",0) } )
})(".fade,.return");
(function(name){
	$(name).css("opacity","0").hover(
		function(){ $(this).stop().fadeTo(90,1.0) },
		function(){ $(this).fadeTo(90,0) } )
})(".fade_fast");

(function(name){
	$(name).click(function(){
		for(var key in a){
			a[key].id.fadeOut("normal");
			if(!!a[key].next)a[key].next.hide();
			if(!!a[key].prev)a[key].prev.hide();
		}
		tops.lang.show();
		tops.id.show();
		tops.next.hide();
		tops.prev.hide();
	})
})("#next00,#prev00,.return");

(function(){
	tops.lang.show();
	$("#spec").click(function(){ NewAddress().Select.Spec() })
	$("#newfeatures").click(function(){ NewAddress().Select.NewFeatures() })
	$("#medalchallenge").click(function(){ NewAddress().Select.MedalChallenge() })
	$("#adhocmode").click(function(){ NewAddress().Select.AdhocMode() })
	$("#infrastructuremode").click(function(){ NewAddress().Select.InfrastructureMode() })
	$("#screenshot").click(function(){ NewAddress().Select.ScreenShot() })
	$("#movie").click(function(){ NewAddress().Select.Movie() })
	NewAddress().Exec();
})();

(function(){
	if( !!jQuery.browser["playstation"] )return true;
	function fadeLoop(id){
		id.css("opacity","0");
		var fade = function(){ id.fadeTo("slow",1).fadeTo("slow",0,fade) };
		return fade;
//		return function(){ id.hover(fade,function(){ $(this).queue([]).stop().fadeTo("slow",0) }); }
	}
	fadeLoop($("#next02"))();
	fadeLoop($("#next03"))();
	fadeLoop($("#next04"))();
	fadeLoop($("#next05"))();
	fadeLoop($("#next06"))();
})();

new MP3Player("../../movies/PJMD_BGM_menu.mp3","200","20").Write().addSwitchModule("switch")

});

function Switch(a_obj){
	if(!g_flg[a_obj.id.attr("id")])bindCycleImage(a_obj);
	$(a_obj.id.find("div")[0]).cycle(0);
	$(".fade,.return").hide();
	a_obj.id.fadeIn("slow",function(){
		tops.id.hide();
		$(".fade,.return").show();
	});
	tops.lang.hide();
	tops.next.hide();
	tops.prev.show();
	if(!!a_obj.next)a_obj.next.show();
	if(!!a_obj.prev)a_obj.prev.hide();
}

function bindCycleImage(a_obj){
	if( !!g_flg[a_obj.id.attr("id")] )return;
	g_flg[a_obj.id.attr("id")]=true;
	if( a_obj.id.find("img").size()<2 )return;
	
	var fx = "scrollHorz";
	fx = (a_obj.id.attr("id")==a.screenshot.id.attr("id"))?"fade":fx;
	
	$(a_obj.id.find("div")[0]).cycle({
		speed:"normal",
		timeout:0,
		nowrap:1,
		before:function(a,b,c,d){ $(".fade,.return").hide() },
		after:function(a,b,c,d){
			if(c.currSlide==c.slideCount-1){ a_obj.next.fadeOut("fast") }
			else{ a_obj.next.fadeIn("fast") }
			if(c.currSlide==0){ a_obj.prev.hide();tops.prev.show(); }
			else{ a_obj.prev.show();tops.prev.hide() }
			$(".fade,.return").show();
		},
		next:a_obj.next,
		prev:a_obj.prev,
		fx:fx
	}).width(960).height(476).css("position","");
}

function NewAddress(){
	$("a").css("outline","none").focus(function(){ $(this).blur() });

	this._url=document.URL.split("#");
	
	this.movie_flag = false;

	this.Select={
		Spec:function(){ Switch(a.spec) },
		NewFeatures:function(){ Switch(a.newfeatures) },
		MedalChallenge:function(){ Switch(a.medalchallenge) },
		AdhocMode:function(){ Switch(a.adhocmode) },
		InfrastructureMode:function(){ Switch(a.infrastructuremode) },
		ScreenShot:function(){ Switch(a.screenshot) },
		Movie:function(){
			Switch(a.movie)
			if( !this.movie_flag ){
				new FLVPlayer("9.0.115","../../movies/PJ_Monsters_deluxe_web.mp4","../../movies/PJ_monsters_deluxe_web.jpg","../../",480,270).Write("movie_inside");
				this.move_flag = true;
			}
		}
	}
	this.Exec=this.Select[this._url[1]]||function(){return this;};
	return this;
}
