/**
 * @name main.js
 * @fileOverview
 * @version 1.0
 * @description
 * <p>(c) FOURDIGIT Inc. Licensed <a href="http://ja.wikipedia.org/wiki/GNU_General_Public_License">GNU General Public License</a>.</p>
 */
//他ライブラリと共存する場合、下の一行削除($無効化)
//jQuery.noConflict();
(function($){
	var typeselet = function () {
		switch (jQuery("body .page").attr("id")) {
			case "roomplan":
				var imgData = {
					"def":   "img-bright_ov.gif",
					"Atype": "img-axis_ov.gif",
					"Btype": "img-bright_ov.gif",
					"Ctype": "img-cleam_ov.gif",
					"Dtype": "img-delight_ov.gif",
					"Etype": "img-df.gif",
					"Ftype": "img-fine_ov.gif",
					"Gtype": "img-grace_ov.gif",
					"Htype": "img-harmonic_ov.gif"
				}
				//typeの定義
				$(".ahoverArea .btn,#ground .child img").each(function(){
					var classArr = $(this).attr("class").split(" ");
					this._type = classArr[classArr.length-1];
				})
				//groundImageを変更する
				$(".ahoverArea .btn,#ground .child img").hover(
					function(){$("#groundImg").attr("src","imgs/behavior/"+imgData[this._type]);},
					function(){$("#groundImg").attr("src","imgs/behavior/"+imgData["def"]);}
				);
				$(".typeBtn")
					.each(function(){
						$(this)
							.attr("type",$(this).attr("href"))
							.attr("href","#stopper");
					})
					.click(function(){
						var _a_type   = $(this).attr("type");
						$(this).find("img").mouseover();
						imgData["def"] = $("#groundImg").attr("src").split("imgs/behavior")[1];
						$(".innerArea").hide();
						$(_a_type).show();
						$(".typeBtn img").each(function(){
							$(this)
								.attr("src",$(this).attr("dsrc"))
								.bind('mouseout',$.easyOver.mouseoutHandler)
							.end();
							if(_a_type == "#"+this._type+"Area") {
								$(this)
									.attr("src",$(this).attr("hsrc"))
									.unbind('mouseout',$.easyOver.mouseoutHandler)
								.end();
							}
						})
					})
				.end();
				//対応するボタンを相互に変更する
				$(".ahoverArea .btn").hover(
					function(){
						this.flag = "over";
						//mouseover
						if($("#ground ."+this._type)[0].flag != "over") {
							$("#ground ."+this._type).mouseover();
						}
					},function(){
						this.flag = "out";
						//mouseout
						if($("#ground ."+this._type)[0].flag != "out") {
							$("#ground ."+this._type).mouseout();
						}
					}
				);
				$("#ground .child img").hover(
					function(){
						this.flag = "over";
						if($(".ahoverArea ."+this._type)[0].flag != "over") {
							$(".ahoverArea ."+this._type).mouseover();
						}
					},function(){
						this.flag = "out";
						//mouseout
						if($(".ahoverArea ."+this._type)[0].flag != "out") {
							$(".ahoverArea ."+this._type).mouseout();
						}
					}
				);
				$("#AtypeBtn").click();
			break;
			case "pageID":
				//eachPageFunction
			break;
		}
	}
	var config = function () {
	//bodyのクラスにブラウザ情報を追加
		$.addClassUA();
	//easyOverのターゲット設定
		$("img.ahover, .ahoverArea img").easyOver();
	//IE5,6にてPNG有効化 (pngfixの読み込みが必要)
		$("img[src$=png],p.png").enablePNG();
	//Flash
		//$("object, embed").enableFlash();
	//ポップアップリンクに置換
		$(".commonPop").easyPop();
	//他ドメインリンク時にpageTracker有効化
		//$("a,area").blankLogToGoogle();
		typeselet();
		
	//アンカーリンクをスムージング
		$("a[href^=#]").smoothScroll();
	//対象の要素をスクロールに追従するようにする
		//$("#fixBox").fixPosition("stopperID","normal");
	}
	//onload
	$(function() {
		config();
		if($.browser.msie && $.browser.version == 6) {
			if($("body.inPage")[0]) {$("#gHeaderWrapper").exFixed();}
			/* snav */
			$(".hasSnav").each(function(){
				$(this).find(".snavbt").hide();
				$(this).mouseover(function(){
					$(this).find(".snavbt").show();
				});
				$(this).find(".snavbt").mouseout(function(){
					$(this).hide();
				});
			});	
		}
		$(".tabView").each(function(){
			var btns = $(this).find(".changeImg img");
			var btnsD = $(this).find(".changeDiv img");
			var targetArea = this;
			$(this)
				.find(".changeImg").click(function(){
					var target = $(this).attr("rel");
					var src = $(this).attr("href");
					btns.each(function(){
						$(this).attr("src",$(this).attr("dsrc"));
						$(this).easyOver();
					});
					$(this).find("img").each(function(){
						$(this)
							.attr("src",$(this).attr("hsrc"))
							.removeEasyOver();
					});
					$("#"+target).attr("src",src);
					return false;
				})	
			.end()
				.find(".changeImg:first").click()
			.end()
				.find(".changeDiv").click(function(){
					var target = $(this).attr("rel");
					btnsD.each(function(){
						$(this).attr("src",$(this).attr("dsrc"));
						$(this).easyOver();
					});
					$(this).find("img").each(function(){
						$(this)
							.attr("src",$(this).attr("hsrc"))
							.removeEasyOver();
					});
					
					$(targetArea).find(".divGrp1").hide();
					$("#"+target).show();
					return false;
				})
			.end()
				.find(".changeDiv:first").click()
			.end();			
		})
	});
})(jQuery);

function hideAndSeek (objId, objsclass) {
	$("div."+objsclass).css("display","none");
	$("div#"+objId).css("display","block");
	//$("div#"+objId).fadeIn();
}

(function($j){
	$j.positionFixed = function(el){
		$j(el).each(function(){
			new fixed(this)
		})
		return el;					
	}
	$j.fn.positionFixed = function(){
		return $j.positionFixed(this)
	}
	var fixed = $j.positionFixed.impl = function(el){
		this.target = $j(el).css('position','fixed')
		if(!this.ie6)return;
		this.bindEvent();
	}
	$j.extend(fixed.prototype,{
		ie6 : $.browser.msie && $.browser.version < 7.0,
		bindEvent : function(){
			var target=this.target;
			target
			.css('position','absolute')
			.basePos = {
				top: parseInt(target.css('top')) || 0,
				right: parseInt(target.css('right')) || 0
			}
			target.parents().each(function(){
				var o = $j(this);
				if (o.css('position') == 'relative') 
					o.after(target)
			})
			$j(window).scroll(this.scrollEvent());
		},
		scrollEvent : function(){
			var target=this.target;
			return function(){
				target.css({
					top: $j(document).scrollTop() + target.basePos.top,
					right: $j(document).scrollLeft() + target.basePos.right
				})
			}
		}
	})
})(jQuery)

$(function(){
	if($("#floatingBnr")[0]){
		$("#floatingBnr").positionFixed();
		$("#draggable").draggable();
	}
})
function hideBnr () {
	$("#floatingBnr").fadeOut();
}