//----------------------------------------------------------------------------
// nagashima_top_swf.js
//
// Requires: jQuery 1.1.3+
//----------------------------------------------------------------------------
// Written by BrainPowers
//
// ReleasedDate: 2011-03-16 (iu)
// ChangedDate: ----------
//----------------------------------------------------------------------------

// Flashファイルのパス+ファイル名
var swf_file = '/data/swf/pool_top.swf';
	
// JavaScriptアニメの画像のパス
var img_path = '/data/image/anime/top_pool/';
	
//----------------------------------------------------------------------------

var Flash = function () {
	var o = {installed:0, version:[]}, description, oActiveX, nMajor, nMinor;
	if(navigator.plugins && typeof navigator.plugins["Shockwave Flash"] == "object"){
		o.pluginType = "npapi";
		description = navigator.plugins["Shockwave Flash"].description;
		if(typeof description != "undefined"){
			description = description.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
			nMajor = parseInt(description.replace(/^(.*)\..*$/, "$1"), 10);
			nMinor = /r/.test(description) ? parseInt(description.replace(/^.*r(.*)$/, "$1"), 10) : 0;
			o.version = [nMajor, nMinor];
			o.installed = 1;
		}
	}
	else if(window.ActiveXObject){
		o.pluginType = "ax";
		try{
			oActiveX = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try{
				oActiveX = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				o.version = [6, 0];
				o.installed = 1;
				oActiveX.AllowScriptAccess = "always";
			}catch(e){
				if(o.version[0] == 6) {o.installed=1; return; }
			}
		
			try{
				oActiveX = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			}catch(e){
			}
		}
		
		if(typeof oActiveX == "object"){
			description = oActiveX.GetVariable("$version");
			if(typeof description != "undefined"){
				description = description.replace(/^\S+\s+(.*)$/, "$1").split(",");
				o.version = [parseInt(description[0], 10), parseInt(description[2], 10)];
				o.installed = 1;
			}
		}
	}

	return o;
}();


if(Flash.installed)
{
	document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="471" HEIGHT="261" id="nico" ALIGN="">');
	document.write('<PARAM NAME=movie VALUE="'+swf_file+'"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src="'+swf_file+'" quality=high  WIDTH="471" HEIGHT="261" NAME="nico" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://get.adobe.com/jp/flashplayer/"></EMBED>');
	document.write('</OBJECT>');
}
else
{
	document.write('	<div id="FJ_pool" style="width:471px;height:261px;overflow:hidden;position:relative;">');
	document.write('	<img src="'+img_path+'loading.gif" />');
	document.write('	</div>');
	
	var img_length = 13;
	var img_src = new Array(img_length+1);
	for(var i=0; i<img_length; i++)
	{
		if(i < 9)	img_src[i] = img_path + '0' + (i+1) + '.jpg';
		else		img_src[i] = img_path +  (i+1) + '.jpg';
	}

	img_src.reverse();
	var img_count = img_length;
	for(var i=1; i<=img_length; i++)
	{
		loadImage(img_src[i]);
	}
}

function loadImage(img_path)
{
	var img = document.createElement("img");
	$(img).css("display", "none");
	$(img).attr("src", img_path);
	$("#FJ_pool").append(img);
	$(img).load(function()
				{
					img_count--;
					if(img_count == 1) startSlide();
				}
	);
}

function startSlide()
{
	$("#FJ_pool img").css('position', 'absolute').css('left', '0');

	setTimeout(function(){ $("#FJ_pool img:first-child").fadeOut(1000)}, 600);
	setTimeout(function(){ $("#FJ_pool img:first-child").remove()}, 3900);
	setTimeout(function(){ $("#FJ_pool img:last-child").fadeIn(1000)}, 1500);
	setTimeout(function(){ $("#FJ_pool img").show()}, 3900);
	
	setTimeout(function(){ $("#FJ_pool img:last-child").fadeOut(1000)}, 4000);
	setTimeout(function(){ $("#FJ_pool img:last-child").remove()}, 6400);
	setTimeout(function(){ $("#FJ_pool img:last-child").fadeOut(1000)}, 6500);
	setTimeout(function(){ $("#FJ_pool img:last-child").remove()}, 8900);
	setTimeout(function(){ $("#FJ_pool img:last-child").fadeOut(1000)}, 9000);
	setTimeout(function(){ $("#FJ_pool img:last-child").remove()}, 11400);
	setTimeout(function(){ $("#FJ_pool img:last-child").fadeOut(1000)}, 11500);
	setTimeout(function(){ $("#FJ_pool img:last-child").remove()}, 13900);
	
	setTimeout(function(){
								var timerID = setInterval(function(){
									imgNext()
								},2500);
						}, 14000);
}

function imgNext()
{
	$("#FJ_pool img:eq(3)").show();
	$("#FJ_pool img:last-child").animate({marginLeft: "471px"}, 500, "swing", function(){$("#FJ_pool img:last-child").css('margin-left', '0').hide().prependTo($("#FJ_pool"))});
}

