//==========================================
//「今月のおすすめ情報」ローテーション用
//==========================================

//=== ランダムに表示 ===========================================================
this.randomImage = function(){
	//piczone内のpicLotation数を取得
	var length = $("div.piczone div.picLotation").length;
	var temp = -1;

	//--- div要素数以下の値をセット ----------------------------
	this.getRan = function(){
		//ランダムな値を取得
		var ran = Math.floor(Math.random()*length) + 1;
		return ran;
	};
	//--- div要素の表示・非表示を切替 ----------------------------
	this.show = function(){
		//ランダムな値をセット
		var ran = getRan();
		//ランダムな値がマイナスだった場合、もう一度値を取得する
		while (ran == temp){
			ran = getRan();
		};

		//idを削除
		$("div.piczone div.picLotation").removeAttr("id");
		//写真／名前／テキストを非表示
		$("div.piczone div.picLotation").hide();
		$("p.readtxtzone a").hide();

		//表示する要素にidを追加
		$("div.piczone div.picLotation:nth-child(" + ran + ")").attr("id", ran);
		//写真／名前／テキストを表示
		$("div.piczone div.picLotation:nth-child(" + ran + ")").fadeIn("slow");
		$("p.readtxtzone a:nth-child(" + ran + ")").fadeIn("slow");
	};

	//div要素を切替
	show();
	
	//指定時間で切替
	//pause = 1500;
	//setInterval(show,pause);
};



//=== 次の情報を表示 ===========================================================
this.nextImage = function(){

	//おすすめ情報の最大数を取得
	var maxNum = $("div.piczone div.picLotation").length;

	//id属性を持つ要素の、id値を取得
	var nowNum = $("div.piczone div[id]").attr("id");
	//数値に変換
	nowNum = parseInt(nowNum);

	//alert(maxNum);
	//alert(nowNum);

	//--- div要素の表示・非表示を切替 ----------------------------
	this.show = function(){

		//表示中の情報が、最後の場合
		if(nowNum == maxNum){
			//最初の値をセット
			var nextNum = 1;
		}else{
			//次の値をセット
			var nextNum = nowNum + 1;
		}
		//idを削除
		$("div.piczone div.picLotation").removeAttr("id");
		//写真／名前／テキストを非表示
		$("div.piczone div.picLotation").hide();
		$("p.readtxtzone a").hide();

		//表示する要素にidを追加
		$("div.piczone div.picLotation:nth-child(" + nextNum + ")").attr("id", nextNum);
		//写真／名前／テキストを表示
		$("div.piczone div.picLotation:nth-child(" + nextNum + ")").fadeIn("slow");
		$("p.readtxtzone a:nth-child(" + nextNum + ")").fadeIn("slow");

	};

	//div要素を切替
	show();
}



//DOMがロードされて操作・解析が可能になったタイミングで関数を実行
$(document).ready(function(){
	randomImage();
});

$(function(){
	//「次へ」がクリックされたとき、div要素を切替
	$("span#picNavi").click(function(){
		nextImage();
		//randomImage();
		return false;
	});
});
