// JavaScript Document
/* ScrollFollow */
$( document ).ready( function (){
	$( '#floatMenu' ).scrollFollow();
});

/* Accordion */
$( document ).ready( function (){
$( '#menu .parent dd' ).hide();
$( '#menu .parent dd.selected' ).show();
	$( '#menu .parent dt' ).click(function (){
		$(this).next('#menu .parent dd.open').slideToggle('normal');
	});
});

/* pngFix */
$(document).ready(function(){
	$(document).pngFix();
});

/* scrollable */
$(document).ready(function() {
	$("div.scrollable").scrollable({
		vertical:true,
		size:3,
		next: 'div.itemnext',
		prev: 'div.itemprev'
	});
	$("div.channelScrollable").scrollable({
		vertical:true,
		size:3,
		next: 'div.itemnext',
		prev: 'div.itemprev'
	});
});

/* Smooth Scroll */
$(document).ready(function(){
//	$(".footAnchor a").click(function() {
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
			&& location.hostname == this.hostname) {
			var $target = $(this.hash);
            $target = $target.length && $target
            || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
	            var targetOffset = $target.offset().top;
				$('html,body')
				.animate({scrollTop: targetOffset}, 'slow');
				return false;
            }
		}
	});
});

/* bpref = tab body prefix, hpref = tab header prefix */
function seltab(bpref, hpref, id_max, selected) {
  if (! document.getElementById) return;
  for (i = 0; i <= id_max; i++) {
    if (! document.getElementById(bpref + i)) continue;
    if (i == selected) {
      document.getElementById(bpref + i).style.display = "block";
      document.getElementById(bpref + i).style.visibility = "visible";
//      document.getElementById(bpref + i).style.position = "";
      document.getElementById(hpref + i).className = hpref + i + "_on";
    } else {
      document.getElementById(bpref + i).style.display = "none";
      document.getElementById(bpref + i).style.visibility = "hidden";
//      document.getElementById(bpref + i).style.position = "absolute";
      document.getElementById(hpref + i).className = hpref + i;
    }
  }
}

/* itemFrame Mouse ON/OFF */
function mouseOver(obj){
	obj.style.backgroundImage = 'url(/imgJP/common/bg_itemframe_btm.gif)';
//	obj.style.backgroundImage = 'url(/imgJP/common/bg_itemframe_btm.gif)';
	obj.style.backgroundRepeat = 'no-repeat';
	obj.style.backgroundPosition = 'left bottom';
	obj.parentNode.style.backgroundImage = 'url(/imgJP/common/bg_itemframe.gif)';
//	obj.parentNode.style.backgroundImage = 'url(/imgJP/common/bg_itemframe.gif)';
	obj.parentNode.style.backgroundRepeat = 'no-repeat';
	obj.parentNode.style.backgroundPosition = '9px 0px';
}
function mouseOut(obj){
	obj.style.backgroundImage='';
	obj.parentNode.style.backgroundImage='';
}

//必要となるGlobal変数の定義
// 間違いのないように全文字列を小文字に変換
var agt = navigator.userAgent.toLowerCase();
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_gecko = (agt.indexOf('gecko') != -1);
var is_opera = (agt.indexOf("opera") != -1);

//要素のスタイル属性を取得する関数
var getElementStyle = function (targetElm,IEStyleProp,CSSStyleProp) {
var elem = targetElm;
	if (elem.currentStyle) {
		return elem.currentStyle[IEStyleProp];
	} else if (window.getComputedStyle) {
		var compStyle = window.getComputedStyle(elem,"");
		return compStyle.getPropertyValue(CSSStyleProp);
	}
}//---End Function

var getPosition = function (that) {
	var targetEle = that;	//thatは位置を取得したい要素Object
	var pos = new function(){ this.x = 0; this.y = 0; }
	while( targetEle ){
		pos.x += targetEle.offsetLeft;
		pos.y += targetEle.offsetTop;
		targetEle = targetEle.offsetParent;
		//IEの補正：上記計算で無視されてしまう各親要素のborder幅を加算
		if ((targetEle) && (is_ie)) {
			pos.x += (parseInt(getElementStyle(targetEle,"borderLeftWidth","border-left-width")) || 0);
			pos.y += (parseInt(getElementStyle(targetEle,"borderTopWidth","border-top-width")) || 0);
		}
	}
		//geckoの補正：カウントしないbody部border幅をマイナスしてしまうので２倍して加算
	if (is_gecko) {
			//以下の部分でbody部を取得し、borderの減算を補正する。
		var bd = document.getElementsByTagName("BODY")[0];		//body部を取得
		pos.x += 2*(parseInt(getElementStyle(bd,"borderLeftWidth","border-left-width")) || 0);
		pos.y += 2*(parseInt(getElementStyle(bd,"borderTopWidth","border-top-width")) || 0);
	}
	return pos;
}//---End Function

function OpenColVari(itemId,tooltipId,event) {
	//toolTip背景画像のディレクトリを指定
	var ImgPath = "/imgJP/common/";
	//var ImgPath = "http://www.boxio.jp/work/tokyo_life/test/html/imgJP/common/";
	//他にポップアップが開いていない場合
	if (!Open && !Loading){
		var itemlistWrap = document.getElementById('itemlistWrap');
		if(tooltipId) {
			var StyleTop,StyleLeft
			
			var pos=getPosition(itemId);
			var pos2=getPosition(itemlistWrap);
			if(pos.x - pos2.x < 384) {
				StyleTop=pos.y - 170;
				StyleLeft=pos.x + 20;
				tooltipId.getElementsByTagName('div')[0].style.padding = "0 0 0 15px";
				tooltipId.getElementsByTagName('div')[1].style.padding = "0 0 0 21px";
				tooltipId.getElementsByTagName('div')[1].style.background = "url(" + ImgPath + "tooltip_middleRg.gif) no-repeat 0 0";
				tooltipId.getElementsByTagName('div')[2].style.padding = "0 0 0 15px";
			} else {
				StyleTop=pos.y - 170;
				StyleLeft=pos.x - 407;
				tooltipId.getElementsByTagName('div')[0].style.padding = "0 15px 0 0";
				tooltipId.getElementsByTagName('div')[1].style.padding = "0 15px 0 6px";
				tooltipId.getElementsByTagName('div')[1].style.background = "url(" + ImgPath + "tooltip_middleLf.gif) no-repeat 0 0";
				tooltipId.getElementsByTagName('div')[2].style.padding = "0 15px 0 0";
			}

			if((document.getElementById) && (!document.all)){
				tooltipId.style.top=StyleTop  + 'px';
				tooltipId.style.left=StyleLeft+ 'px';
				tooltipId.style.visibility='visible';
			} else if(document.all){
				tooltipId.style.pixelTop=StyleTop;
				tooltipId.style.pixelLeft=StyleLeft;
				tooltipId.style.visibility='visible';
			}
			
			Open = true;
		}
	}
	OpenerTool = itemId;
}

function CloseColVari(tooltipId,event) {
	
	// マウスが出て行った先を取得
	var r = event.relatedTarget || event.toElement;

	// マウスが出て行った先がアイコンの外ならツールチップを閉じる
	if( !Contains(r,OpenerTool)){
		if(Open && !Loading) {
			with(tooltipId.style){
				visibility = 'hidden';
			}
		}
		Open = false;
	}
	
function Contains (node, parentNode) {
	// node が parentNode の子孫かどうかを探索
	while (node && node != parentNode) node = node.parentNode;
	return Boolean (node);
}	

}

/* 指定サイズでウィンドウを開き、センターに表示 */
// gf_OpenNewWindow(URL,NAME,SIZE)
// SIZEは、"width=800:height=600"のように入力
function openNewWindow(pURL,pName,pSize){
	var wWidth,wHeight;
	var wSize,wFeatures;
	var wLeft,wTop,PositionX,PositionY;
	
	wWidth = window.screen.availWidth/2;
	wHeight = window.screen.availHeight/2;
	wSize = pSize.split(":");
	wLeft = wSize[0].split("=");
	wTop = wSize[1].split("=");
	PositionX = wWidth-wLeft[1]/2;
	PositionY = wHeight-wTop[1]/2;
	
	wFeatures = wSize+",left="+PositionX+",top="+PositionY;
	wWindow = window.open(pURL,pName,wFeatures+",scrollbars=yes,status=no,resizable=yes");
	
	wWindow.focus();
}

/* inputの背景色を変更 */
function chnBg(objInp) {
	objInp.style.backgroundColor = '#ffffe5';
}
function defBg(objInp) {
	objInp.style.backgroundColor = '#ffffff';
}

/* bgiframe */
$(document).ready(function(){
        if (typeof document.documentElement.style.maxHeight != "undefined") { //IE7以上、Firefox, Opera, Chrome等
        } else { //IE6
            $("div#menu_guide").bgiframe(); //jquery.bgiframe.min.jsを選択エリアに適用
            $("div#menu_sitemap").bgiframe(); //jquery.bgiframe.min.jsを選択エリアに適用
        }
});