function initToTopButton()
{
	$(".toTop a").click(function()
	{
		$('html,body').animate({scrollTop:0});
	})
}

function __initSlideBooking()
{
	$(".contact ul").click(function()
	{
		$("#bookingForm").slideToggle("slow");
	});
}

function initSlideBooking()
{
	var posTop = $("#siteFooter").offset().top;
	$(".contact ul").click(function(){
	  $("#bookingFormWrapper").animate(
	    { height: "toggle"/* , opacity: "toggle" */ },
	    {
	    	step: function(s)
	    	{
	    		$("html").css({
	    			backgroundPosition: "0px "+(posTop+s)+"px"
	    		})
	    	}
	    }
	  );
	});
}

function initUnderBG()
{
	var posTop = $("#siteFooter").offset().top;
	//alert(posTop)
	$("html").css({
		backgroundPosition: "0px "+posTop+"px",
		backgroundImage: "url(../assets/images/common/bg_footer.gif)",
		backgroundRepeat: "repeat-x",
		backgroundColor: "transparent"
	});
}



/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * アコーディオン要素を開く際、ボタンの三角矢印を上下に反転させる
 * ＃引数triは三角矢印(▲)要素 
 * ex.) #sec1 a.more > .triangle
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
function clickAccordionBtn(tri)
{
	var triStr = tri.text();
	if(triStr == "▼") tri.text("▲");
	else tri.text("▼");
}





/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * SpecialOffersのコピーリスト取得〜構築〜表示
 * ＃ニュースと異なり、最新１件のみ表示（11.08.01）
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

var _soCopyItems	= [];	//配列で保持

/*
 * SpecialOffersのコピー リスト(JSON)の取得
 */
function getSpecialOffersCopyJson(param)
{
	$.ajax(
	{
		type : 'GET',
		//url : './json/message.json',
		//url : 'http://localhost:8888/nishigaki/nikiclub_wp/specialofferscopyjson',
		//url : '../nikiclub_wp/specialofferscopyjson',
		url : 'http://www.nikiclub.jp/program/specialofferscopyjson',
		data :
		{
			per_page	: 1,
			page		: 1
		},
		dataType	: 'jsonp',
		jsonp		: 'jsoncallback', // Flickrの場合はjsoncallback
		//error: function(er){ alert("load error");},
		success	: _onGetSpecialOffersCopyHandler // 通信が成功した場合の処理
	 });
}
	function _onGetSpecialOffersCopyHandler(data)
	{
		if(data.stat=="ok")
		{
			_soCopyItems= data.special_copy.items;
			setupSpecialOffersCopyBlock();		// ニュースのHTML構築のセットアップ
		}
	}
	
/*
 * [ニュースのHTML構築用セットアップ]
 */
var _soCopyBlock;

function setupSpecialOffersCopyBlock()
{
	_soCopyBlock = $("#specialOffers div.maincopy");

	var description = decodeURIComponent(_soCopyItems[0].description);
	description = description.replace("+/>", " />");
	//alert(description)
	var spCopyElement = description;
	_soCopyBlock.html(spCopyElement);
	_soCopyBlock.css("opacity", 0);
	_soCopyBlock.animate({opacity: 1},{duration:500});
}






function initSpecialOffers(type)
{
	var xmlPath = "";
	var kind = "special";
	
	if(type == "sp_top")		xmlPath = "xml.php";
	else if(type == "sp")	xmlPath = "../xml.php";
	else if(type == "")		xmlPath = "../xml.php";
	else
	{
		xmlPath = "../xml.php?type=" + type;
		kind = "seasonal";
	}
	
	$.ajax({
		type: "GET",
		url: xmlPath,
		dataType: "xml",
		success: function(xml) { parseXml(xml,kind); },
		error: function(er){ /* alert("load error"); */}
	});
};



function tagDelete(str)
{
  delete01 = new RegExp(/\n/g);
  delete02 = str.replace(delete01, "");
  delete03 = new RegExp(/>(.*?)</g);
  delete04 = delete02.replace(delete03, ">\n$1\n<");
  rgexp = new RegExp(/<("[^"]*"|'[^']*'|[^'">])*>/g);
  
  return delete04.replace(rgexp, "");
}

var itemLen = 0;
function parseXml(xml,kind)
{
	var ajust = (kind == "special")? 3 : 0;
	itemLen = $(xml).find("PlanList").length - ajust;
	//itemLen = $(xml).find("PlanList").length - 0;
	
	var cnt = 0;
	if(itemLen <= 0)
	{
		$("div#specialOffers").css("display","none");
	}
	else
	{
		$(xml).find("PlanList").each(function()
		{
			var planName	= $(this).find("PlanName").text(); 
			var planDetail	= $(this).find("PlanDetail").text(); 
			var imgPath		= $(this).find("PlanPicturePath1").text();
			var linkPath	= $(this).find("PlanReservePath").text();
			if(!imgPath || imgPath=="" || imgPath.length<30) 
			{
				imgPath = "http://nikiclub.jp/assets/images/common/noimage290.gif";

			}else{
				imgPath = imgPath.split('-175x175.jpg').join('.jpg');
			}
	
			var htmlElement="";
			htmlElement	=	(cnt==0)? '<li class="first">' : '<li>';
			htmlElement	+=	'<a href="'+linkPath+'"><div class="itemImgContainer">';
			htmlElement	+=	'<div class="itemImg"><img src="' + imgPath + '" /></div>';
			htmlElement	+=	'<div class="whiteMask alphafilter"></div>';
			htmlElement	+= '</div></a>'
			htmlElement	+=	'<h4><a href="'+linkPath+'">' + planName + '</a></h4>';
			//htmlElement	+=	'<p class="detail"><a href="'+linkPath+'">' + tagDelete(planDetail).substr(0,80) + '</a></p>';
			htmlElement	+=	'<p class="detail"><a href="'+linkPath+'">' + planDetail + '</a></p>';
			htmlElement	+=	'<p class="link"><a href="'+linkPath+'">詳細はこちら</a></p>';
			htmlElement	+=	'</li>';
			
			$("div#specialOffers .itemContainer ul").append(htmlElement);
			
			if(++cnt >= itemLen)
			{
				setupImage();
				return false;
			}
		});
	}
}

// 画像の加工。リサイズ→中央揃え
function setupImage()
{
	var size = 250;
	var cnt = 0;
	
	$("div#specialOffers ul img").each(function()
	{
		var img = $(this);
		img.css("opacity", 0);
		img.load(function()
		{
			var w = img.width();
			var h = img.height();
			
			var rate = w/h;
			if(w > h)
			{
				h=size;
				w=Math.round(size*rate);
			}
			else
			{
				w =size;
				h =Math.round(size*rate);		
			}
			
			var cssProp =
			{
				width: w,
				height: h,
				left: 145-w/2,
				top: 75-h/2
			}
			img.css(cssProp);
			
			img.animate({opacity:1}, 800);
			
			if(++cnt >= itemLen)
			{
				$("div#specialOffers div.itemContainer").listSlider(
				{
					container: "#specialOffers",
					displayNum: 3,
					numType: "circle",
					continuous: false
					//auto: true,
					//numeric: true,
					//nextId: "slider1next",
					//prevId: "slider1prev"
				});
			}
		})
	})
}





