
// jQueryプラグイン 爽米 
// jQuery 1.2.2 で動作確認
// 作成 相馬稔 (Minoru Sohma) 稲作ファーマー since 2007 ＋ 半導体解析エンジニア until 2007 + ????
// 設定したID内IMGを順に表示する
// 2008/3/5 ver.00 完成間際でIEのz-indexにはまった… 何故IEは独自路線？
// 2008/3/6 ver.01 クロスブラウザで不具合ありまくりなので全体見直し修正 疲れたけど、動作が軽くなった
//                 前がどんだけ重いんだ！！ってことなんですけど。
// 2008/3/8 ver.02 スクリプト内整理 + CSS z-index調整



// 設定
//fixLeft = 300;	// Default Left位置


//メイン関数
function SoMove(idname){
	OutHeight = RemoveStrToInt($(idname).css("height"),"px");	// スタート位置設定用データ
	UpImage(idname,0,OutHeight+80); 							// 画像上昇ルーチン (ID名、画像番号 0スタート、外枠サイズ)
}

// 画像上昇ルーチン
function UpImage(idname,ImgNum,topPos){
	// 画像位置セットへ
	SetImagePos(idname,ImgNum,topPos);
		ImgObj = $(idname + " img").get(ImgNum);					// エレメント情報取得
		$(ImgObj).css("padding","10px 10px 10px 10px");				// このページ専用設定
		$(ImgObj).css("width",280);									// width戻す 現在手動
		$(ImgObj).css("height",210);								// height戻す 現在手動

	OutWidth = RemoveStrToInt($(idname).css("width"),"px");			// 一番外枠のサイズを取得

	if(topPos > 110){	// ここまで左上のポイントが上昇
		topPos -= 2;
		setTimeout("UpImage(\"" +idname+ "\"," +ImgNum+ "," +topPos+ ")", 2);
	}else if(topPos <= OutWidth){
		setTimeout("ImageToMt(\"" +idname+ "\"," +ImgNum+ "," +topPos+ ")", 4000);
		setTimeout("SetImageSize(\"" +idname+ "\"," +ImgNum+ ")", 4000);		// 画像サイズ縮小へ
	}
}

// 画像 上昇ルーチン2
function ImageToMt(idname,ImgNum,topPos){
	SetImagePos(idname,ImgNum,topPos);							// 画像位置セットへ
	OutWidth = RemoveStrToInt($(idname).css("width"),"px");		// 一番外枠のサイズを取得

	if(topPos > 120){
		topPos -= 2;
		setTimeout("ImageToMt(\"" +idname+ "\"," +ImgNum+ "," +topPos+ ")", 2);
	}else if(topPos <= OutWidth){
		setTimeout("ImageToMtLeft(\"" +idname+ "\"," +ImgNum+ ")", 1);
	}
}
// 画像 が山をつたって左に消える
function ImageToMtLeft(idname,ImgNum){
	ImgObj = $(idname + " img").get(ImgNum);					// エレメント情報取得
	LeftPos = RemoveStrToInt($(ImgObj).css("left"),"px");		// 一番外枠の横サイズを取得
	LeftPos -= 4;

	TopPos = RemoveStrToInt($(ImgObj).css("top"),"px");			// 一番外枠の横サイズを取得
	TopPos -= 1;

	$(ImgObj).css("top",TopPos);								// TOPポジション変更
	$(ImgObj).css("left",LeftPos);								// TOPポジション変更

	// 一番外枠のサイズを取得
	OutWidth = RemoveStrToInt($(idname).css("width"),"px");

	if(LeftPos > -55){
		setTimeout("ImageToMtLeft(\"" +idname+ "\"," +ImgNum+ ")", 2);
	}else if(LeftPos <= OutWidth){
		OutHeight = RemoveStrToInt($(idname).css("height"),"px");		// スタート位置設定用データ
		ImgNumLen = $(idname + " img").get().length;					// エレメント情報取得
		if(ImgNum == ImgNumLen-1){
			ImgNum = 0;		// Reset
		}else{
			ImgNum += 1;	// Increment
		}

		setTop = OutHeight + 80;
		setTimeout("UpImage(\"" +idname+ "\"," +ImgNum+ "," +setTop+ ")", 1);
	}
}


// 画像下降ルーチン
function DownImage(idname,ImgNum,topPos){
	SetImagePos(idname,ImgNum,topPos);									// 画像位置セットへ
	OutWidth = RemoveStrToInt($(idname).css("width"),"px");				// 一番外枠のサイズを取得

	if(topPos <= OutWidth){
		topPos += 10;
		setTimeout("DownImage(\"" +idname+ "\"," +ImgNum+ "," +topPos+ ")", 10);
	}else{
		OutHeight = RemoveStrToInt($(idname).css("height"),"px");		// スタート位置設定用データ
		ImgNumLen = $(idname + " img").get().length;					// エレメント情報取得
		if(ImgNum == ImgNumLen-1){
			ImgNum = 0;		// Reset
		}else{
			ImgNum += 1;	// Increment
		}

		setTop = OutHeight + 80;
		setTimeout("UpImage(\"" +idname+ "\"," +ImgNum+ "," +setTop+ ")", 1);
	}
}

// 画像位置設定ルーチン
function SetImagePos(idname, ImgNum, topPos){
	ImgObj = $(idname + " img").get(ImgNum);					// エレメント情報取得
	OutWidth = RemoveStrToInt($(idname).css("width"),"px");		// 一番外枠の横サイズを取得

	$(ImgObj).css("top",topPos);								// TOPポジション変更
	$(ImgObj).css("left",300);								// TOPポジション変更
}

// 画像サイズ設定ルーチン
function SetImageSize(idname, ImgNum){
	ImgObj = $(idname + " img").get(ImgNum);					// エレメント情報取得
	$(ImgObj).css("padding","2px 2px 2px 2px");					// CSSパディング変更

	ImgWidth = RemoveStrToInt($(ImgObj).css("width"),"px") - 4;	// 現行サイズ-4px

	ImgHeight = RemoveStrToInt($(ImgObj).css("height"),"px") - 3;	// 現行サイズ-3px

	if(ImgWidth >= 0){
		$(ImgObj).css("width",ImgWidth);							// width変更
		$(ImgObj).css("height",ImgHeight);							// height変更

		setTimeout("SetImageSize(\"" +idname+ "\"," +ImgNum+ ")", 1);
	}
}


// 文字列のいらない文字を消去＋整数化する
function RemoveStrToInt(Value,RemoveStr){
	Value = Value.replace(RemoveStr, "");
	Value = parseInt(Value);
	return Value;
}


