
/**
*	画像をランダムで表示した後
*	hide_msecミリ秒後に#index-wrapの内容を表示します。
*	jQuery 及び jquery.cookie.js(※)をインクルードしください
*/

var hidewrap={
	wrap_id:"#index-wrap"
	,bg_id:"#bgwrap"
	,showIndex:0
	,imgpaths:['/images/bg8.jpg','/images/bg3.jpg','/images/bg4.jpg','/images/bg5.jpg','/images/bg7.jpg']
	//,bg_ids:["#wrap2","#wrap1","#wrap4","#wrap3"]
	,hide_msec:2000
	,siid:0
};


//#index-wrapを表示ます
hidewrap.show = function (){
	$(hidewrap.wrap_id).css({ visibility : 'visible' });
}
//#index-wrapを隠します
hidewrap.hide = function (){
	$(hidewrap.wrap_id).css({ visibility : 'hidden' });
}

hidewrap.init = function (){
	/*var zi=0;
	var ziIncl=10;
	
	var bgids =array_shuffle(hidewrap.bg_ids);
	for (var i=0; i<bgids.length; i++){
		zi+=ziIncl;
		$(bgids[i]).css({zIndex : zi });
	}
	*/
	
	
	
	hidewrap.showIndex = $.cookie('hidewrap_showIndex');//読み出し
	
	
	//alert("old hidewrap.showIndex : " + hidewrap.showIndex);
	
	// 0-9までの乱数生成
	var randNum = Math.floor(Math.random()*7);
	var oldCookieNum = Number(hidewrap.showIndex);
	
	if(randNum >= 0 && randNum <= 2){
		hidewrap.showIndex = 0;
	}else if(randNum == 3){
		hidewrap.showIndex = 1;
	}else if(randNum == 4){
		hidewrap.showIndex = 2;
	}else if(randNum == 5){
		hidewrap.showIndex = 3;
	}else if(randNum == 6){
		hidewrap.showIndex = 4;
	}
	
	// 以前見た画像とランダムで決められた画像が同一の場合
	// 0 or 1の画像をセット
	if(hidewrap.showIndex == oldCookieNum){
	
	if(oldCookieNum > 2){
		hidewrap.showIndex = 0;
	}else{
		hidewrap.showIndex = 0;
	}
	
	}
	
	
	
	
	
	//alert("new hidewrap.showIndex : " + hidewrap.showIndex);
	
	
	/*
	if(hidewrap.showIndex=="" || hidewrap.showIndex==undefined){
		hidewrap.showIndex = 0;
	}else{
		hidewrap.showIndex = Number(hidewrap.showIndex);
		
		if(hidewrap.showIndex < hidewrap.imgpaths.length-1)
		hidewrap.showIndex ++;
		else hidewrap.showIndex =  0;
	}
	*/
	
	$.cookie('hidewrap_showIndex', hidewrap.showIndex ,{ expires: 7 });//cookie書き込み{保存期間}
	
	//var imgpath = hidewrap.imgpaths[Math.floor(Math.random() * hidewrap.imgpaths.length)];
	var imgpath = hidewrap.imgpaths[hidewrap.showIndex];
	
	/*debug*///alert("hidewrap.showIndex : "+hidewrap.showIndex);
	
	$(hidewrap.bg_id).css('backgroundImage','url('+imgpath+')');
	$(hidewrap.bg_id).hide();
	$(hidewrap.bg_id).fadeIn(700);
	
	hidewrap.siid = setTimeout(hidewrap.timeout,hidewrap.hide_msec);
}
hidewrap.timeout = function (){
	clearTimeout(hidewrap.siid);
	hidewrap.show();
}


/*
function array_shuffle(list) {
  var i = list.length;

  while (--i) {
    var j = Math.floor(Math.random() * (i + 1));
    if (i == j) continue;
    var k = list[i];
    list[i] = list[j];
    list[j] = k;
  }

  return list;
}*/