
var selector_data = {
	about:		{ click: $("#about_button"), id:$("#show_frame1"), prev:$("#prev01"), next:$("#next01") },
	rule:		{ click: $("#rule_button"), id:$("#show_frame2"), prev:$("#prev02"), next:$("#next02") },
	enemy:		{ click: $("#enemy_button"), id:$("#show_frame3"), prev:$("#prev03"), next:$("#next03") },
	control:	{ click: $("#control_button"), id:$("#show_frame4"), prev:$("#prev04"), next:$("#next04") },
	screenshot:	{ click: $("#screenshot_button"), id:$("#show_frame5"), noscroll: true },
	movie:		{ click: $("#movie_button"), id:$("#show_frame6") },
	fluid:		{ click: $("#fluid_button"), id:$("#show_frame7"), prev:$("#prev07"), next:$("#next07") },
	gimmick:	{ click: $("#gimmick_button"), id:$("#show_frame8"), prev:$("#prev08"), next:$("#next08") },
	score:		{ click: $("#score_button"), id:$("#show_frame9"), prev:$("#prev09"), next:$("#next09") },
	spec:		{ click: $("#spec_button"), id:$("#show_frame_spec") },
	demo_announce:{ click: $("#demo1"), id:$("#show_frame_demo") },
	demo_announce2:{ click: $("#demo2"), id:$("#show_frame_demo") }
}

var tops = {
	id: $("#show_frame0"),
	lang: $("#language"),
	next: $("#next00"),
	prev: $("#prev00"),
	scroll_before: null,
	scroll_nodisplay: false
}

var g_flg = { };

jQuery(function(){
	$("a").css("outline","none").focus(function(){ $(this).blur() });
	
	HoverFade($(".fade"),"fast");

	(function(name){
		$(name).click(function(){
			tops.lang.show();
			tops.id.show();
			tops.next.hide();
			tops.prev.hide();
			$("#movie_frame").html($("<div>").attr("id","movie_inside"));
			if (!!tops.scroll_before) {
				tops.scroll_nodisplay = true;
				tops.scroll_before.id.fadeOut("normal",function(){ $(this).cycle(0) })
				if(!!tops.scroll_before.next)tops.scroll_before.next.hide();
				if(!!tops.scroll_before.prev)tops.scroll_before.prev.hide();
			}
		})
	})("#next00,#prev00");

(function(){
	selector_data.about.func = function(){
		HoverFade(selector_data.about.id.find(".fade"),"fast");
	};
	selector_data.screenshot.func = function(){
		HoverFade(selector_data.screenshot.id.find(".fade"),"fast");
		$(".screenshot").css("cursor","pointer").click(function(){ tops.prev.show();$(this).fadeOut(); });
		for(var i=1;i<=6;i++)
			(function(k){ $("#thumbnail"+i).click(function(){ tops.prev.hide();$("#screenshot"+k).fadeIn(); }); })(i);
	};

	selector_data.movie.func = function(){
		new FLVPlayer("9.0.115","../../movies/PJ_Shooter_Trailer.mp4","../../movies/PixelJunk_Shooter_TGS.jpg","../../",480,270).Write("movie_inside");
		setTimeout(function(){ $("#movie_frame").fadeTo("slow",1) },500);
	};
})();

(function(){
	for( var key in selector_data ){
		(function(k){
			selector_data[k]["click"].click(NewAddress().Select[k]);
		})(key);
	}
	NewAddress().Exec();
})();

});

function HoverFade(target,speed){
	speed = speed || "fast";
	target.hover(
		function(){ $(this).stop().fadeTo(speed,1) },
		function(){ $(this).stop().fadeTo(speed,0) } );
}

function Switch(a_obj){
	bindCycleImage(a_obj);
	tops.scroll_before = a_obj;	
	$(".fade").hide();
	a_obj.id.fadeIn("slow",function(){
		tops.id.hide();
		$(".fade").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){
	var _id = a_obj.id;
	var _id_attr = a_obj.id.attr("id");
	var _func = a_obj.func || function(){};
	if( !!g_flg[_id_attr] ){
		if( selector_data.movie === a_obj )_func();
		return;
	}
	g_flg[_id_attr] = true;

	$.getJSON("dat.php",{map:_id_attr,lang:ln,a:Math.random()*10000},function(e){
		var f = function(tag,child,obj){
			var el = document.createElement(tag);
			if(!!child["@attributes"]){
				var attr = child["@attributes"];
				el.width	= attr.width || 960;
				el.height	= attr.height || 476;
				if(!!el.href)el.href	= attr.href || "";
				el.src		= attr.src || "";
				el.alt		= attr.alt || "";
				el.id		= attr.id || "";
				el.title	= "";
				el.target	= attr.target || "";
				el.className= attr["class"] || "";
				if(!!!a_obj.noscroll&&tag==="img"){
					el.style.opacity = el.style.mozOpacity = 0;
					el.style.filter = "alpha(opacity=0)";
				}
			}
			
			(function(target){
				if(tag!=="img")return;
				if(!!a_obj.noscroll)return;
				$(target).width(el.width).height(el.height);
				setTimeout(function _Local(){
					if(!!target.complete){
						$(target).fadeTo("fast",1).width(target.width).height(target.height);
					}else{
						setTimeout(_Local,500);
					}
				},500);
			})(el);
			
			if(!!obj){
				obj.appendChild(el);
			}

			var reserve_tags = ["div","img","a"];
			for(var i=0;i<reserve_tags.length;i++){
				var res_tag = reserve_tags[i];
				if(!!child[res_tag]){
					if(!!child[res_tag][0]){
						for(var k=0;k<child[res_tag].length;k++)
							f(res_tag,child[res_tag][k],el);
					}else f(res_tag,child[res_tag],el);
				}
			}
			return el;
		};
		
		var element_count = 0;
		for(var key in e){
			if(!!e[key].length){
				for(var i=0;i<e[key].length;i++){
					_id.append(f(key,e[key][i]));
					element_count++;
				}
			}else{
				_id.append(f(key,e[key]));
				element_count++;
			}
		}

		_func();
		
		if( !!a_obj.noscroll )return;
		if( element_count < 2 )return;

		_id.cycle({
			speed: "nomal",
			timeout: 0,
			nowrap: 1,
			before: function(a,b,c,d){
				if(!!tops.scroll_nodisplay)return;
				$(".fade").hide()
			},
			after: function(a,b,c,d){
				$(".fade").show();
				if(!!tops.scroll_nodisplay){ tops.scroll_nodisplay=false; return; }
				if(c.currSlide==c.slideCount-1){ a_obj.next.hide(); tops.next.show() }
				else{ a_obj.next.show(); tops.next.hide() }
				if(c.currSlide==0){ a_obj.prev.hide(); tops.prev.show() }
				else{ a_obj.prev.show(); tops.prev.hide() }
			},
			next: a_obj.next,
			prev: a_obj.prev,
			fx: "scrollHorz"
		}).width(960).height(476).css("position","").find("img").css("opacity","0");
	})
}

function NewAddress(){
this._url=document.URL.split("#");

this.Select = {};
for( var key in selector_data ){
	(function(k){
		this.Select[k] = function(){ Switch(selector_data[k]); };
	})(key);
}
this.Exec = this.Select[this._url[1]] || function(){ return this };
return this;
}
