/*//////////////////////////////////////////////////////////////////////////////

index.js
	
//////////////////////////////////////////////////////////////////////////////*/

$(function(){
	// IE7、IE8フラグ
	var isIE = $('html').hasClass("ie8") || $('html').hasClass("ie7") ? true : false;

	var agent = navigator.userAgent;
	var isiOS = agent.search(/iPhone/) != -1 || agent.search(/iPad/) != -1 || agent.search(/iPod/) != -1 ? true : false;
	
	/**
	 * フェードインする画像を真っ先に非表示
	 */
	if (!isIE) {
		$("#mainContents .imgFadeInit").fadeTo(0, 0);
	}
	
	/*--------------------------------------------------------------------------
		プラン一覧レイアウト
	--------------------------------------------------------------------------*/
	var planNum = $("#plans .planItem").length;
	
	function setColumn()
	{
		for (var i = 0; i < planNum; i++) {
			
			var targetColumn;
			
			switch(i % 3) {
				case 0:
					targetColumn = "colLeft";
				break;
				case 1:
					targetColumn = "colCenter";
				break;
				case 2:
					targetColumn = "colRight";
				break;
			}
			
			$("#plans").find("." + targetColumn).append($("#plans .planItem").eq(i));
			
		}
		$("#plans .colRight").append($("#plans .btn_showOtherPlan"));
	}
	
	/*--------------------------------------------------------------------------
		初期化
	--------------------------------------------------------------------------*/
	function init()
	{

		/**
		 * グローバルナビゲーションの固定
		 */
		$.tadaya("#globalNavigation").fixGlobalNavigationPos($("#imageSlideShow .body"));
		
		/**
		 * スライドショーの開始
		 */
		$.tadaya("#imageSlideShow").fadeSlideShow();
		
		if (!isiOS) {
			/**
			 * のとつづりボタンのマウスオーバー
			 */
			if ($('html').hasClass("ie8") || $('html').hasClass("ie7")){
				$("#information .btn_nototsuduri")
					.mouseover(function(){
						$(this).find(".rollOver").show();
					})
					.mouseout(function(){
						$(this).find(".rollOver").hide();
					});
			} else {
				$("#information .btn_nototsuduri")
					.mouseover(function(){
						$(this).find(".rollOver").stop().fadeTo(400, 1);
					})
					.mouseout(function(){
						$(this).find(".rollOver").stop().fadeTo(400, 0);
					});
			};
		};
		/**
		 * プラン一覧のレイアウト
		 */
		setColumn();
		
		$("#plans .planItem")
			.find(".rollOver")
				.each(function(){
					var _parent = $(this).next();
					$(this).find(".innerBlock")
						.width(_parent.width())
						.height(_parent.height());
				})
			.end()
			.find("a.photoAndTitle")
				.each(function(i, elem){
					if (!isiOS) {
						if ($('html').hasClass("ie8") || $('html').hasClass("ie7")){
							$(this)
								.mouseover(function(){
									$(this).find(".rollOver").show();
								})
								.mouseout(function(){
									$(this).find(".rollOver").hide();
								});
						} else {
							$(this)
								.mouseover(function(){
									$(this).find(".rollOver").stop().fadeTo(400, 1);
								})
								.mouseout(function(){
									$(this).find(".rollOver").stop().fadeTo(400, 0);
								});
						}
					};
				})
			.end()
			// roughRectangle適用
			.find(".roughRectangle").roughRectangle({scale:false});
			
		/**
		 * フェードイン表示
		 */
		$("#mainContents .imgFadeInit").imgFadeInit();
	}
	init();
});
