////////////////////////////////////////////////////////////////////////////////
//
//	lib.js	[utf-8]
//
////////////////////////////////////////////////////////////////////////////////
(function(){



//
//	スクロール用
//
var moveObject = function(){
	var y = document.body.scrollTop || document.documentElement.scrollTop;
	var target = Math.max(Math.floor(y - (y / 8)));
	scrollTo(0, target);
	if(target > 0){
		setTimeout(moveObject,10);
	}
};



//
//	IE用objectタグ関係
//
var removeData = function(obj){
	var data = obj.getAttribute("data");
	if(data){
		obj.removeAttribute("data");
	}
};



//
//	リンクの点線を消す
//
var disableLinkOutline = function() {
	$(document.links).each(function(){
		$(this).focus(function(){
			this.blur();
		});
	});
};


////////////////////////////////////////////////////////////////////////////////////////////////////
//
//	DOM読み込み完了後に実行
//
////////////////////////////////////////////////////////////////////////////////////////////////////
$(function(){



//
//	このページの先頭へボタン動作
//
$(".anchorTop a").click(function(){
	moveObject();
	return false;
});
$("#anchorTop a").click(function(){
	moveObject();
	return false;
});



//
//	IE用objectタグ関係
//
if(document.all && !window.opera){
	$("object").each(function(){
		removeData(this);
		this.outerHTML = this.outerHTML;
	});
}



//
//	リンクの点線を消す
//
window.setTimeout(disableLinkOutline, 1000);



//
//	ポップアップリンク用
//
var win = null;
$(".popup").click(function(){
	var url = new URL(this.href);
	var winName = "win";
	if(this.href){
		if(url.search.hasParameters()){
			win = window.open(url.get(), winName, url.search.join(","));
		}else{
			win = window.open(url.get());
		}
		win.focus();
	}
	return false;
});

//
//	サイト内検索用
//
var preload = new Image();
preload.src = "../images/common/site_search_bg_focused.gif";
var fQuery = $("#fQuery");
var buttonSearch = $("#buttonSearch");
fQuery.focus(function(){
	if(this.value=="サイト内検索"){
		this.value="";
	}
	$(this.parentNode).addClass("focused");
});
fQuery.blur(function(){
	if(this.value.match(/^(\s+)?$/)){
		this.value="サイト内検索";
	}
	$(this.parentNode).removeClass("focused");
});
buttonSearch .click(function(){
	if(fQuery.val()=="サイト内検索"){
		fQuery.val("");
	}
});


//
//	googleSearch
//
var searchForm = $("#f1");
buttonSearch.click(function(){
	return gotoResults();
});
searchForm.submit(function(){
	return gotoResults();
});

function gotoResults(){
	var q = fQuery.val();
	if(q){
		q = q + "+site:www.lovela-bandai.com";
		var win = window.open("http://www.google.co.jp/search?oe=utf8&ie=utf8&hl=ja&q=" + encodeURIComponent(q));
		win.focus();
	}
	return false;
}




//
//	ローカルナビロールオーバー用
//
$(".list li a").each(function(){
	$(this).hover(
		function(){
			$(this.parentNode).addClass("hover");
		},
		function(){
			$(this.parentNode).removeClass("hover");
		}
	)
});



//
//	カテゴリーナビ折りたたみ
//
var list = document.getElementById("categoryList");
if(list){
	var jUlUl = $("#categoryList ul ul");
	jUlUl.each(function(){
		this.style.display = "none";
	});
	
	$("#categoryList ul li a").each(function(){
		$(this).click(function(evt){
			var spd = "fast";
			var jUl = $("ul", this.parentNode);
			var ul = jUl.get(0);
			if(ul){
				if(ul.style.display == "block"){
					jUl.slideUp(spd);
				}else{
					jUlUl.each(function(){
						if(this.style.display=="block"){
							$(this).slideUp(spd);
						}
					});
					jUl.slideDown(spd);
				}
				return false;
			}
		});
	});
}


//
//	印刷ボタン用
//
$("#buttonPrint").click(function(){
	window.print();
	return false;
});



//
//	ウィンドウを閉じるボタン用
//
$("#buttonClose").click(function(){
	window.close();
	return false;
});



//
//	p#siteDescription in IE6
//
/*
if(document.all && !window.opera && !window.XMLHttpRequest){
	var sd = document.getElementById("siteDescription");
	if(sd){
		(new OnFontSizeChange()).addListener("change", function(){
			sd.style.removeAttribute("width");
			if(sd.clientWidth>400){
				sd.style.setAttribute("width", "400px");
			}
		});
	}
}
*/


//
//	footer用
//
window.setTimeout(function(){
	setFooter("footer");
}, 500);



//
//	pageNav
//
var pageNav = document.getElementById("pageNav");
if(pageNav){
	if(!pageNav.innerHTML.match(/\w/)){
		pageNav.style.display = "none";
	}
}



//
//	テキスト回り込み対策
//
var bodyId= document.body.getAttribute("id");
var bodyClassName = document.body.className;
var isShop = ( bodyId=="shop" || bodyId=="recommend" || bodyId=="news" || bodyClassName.match(/\bshop\b/) || bodyClassName.match(/\brecommend\b/) || bodyClassName.match(/\bnews\b/) );
var isPickup = ( bodyId=="francfranc" || bodyId=="tsutaya" || bodyId=="kinokuniya" || bodyId=="loft" || bodyId=="mujirushi" );

if(isShop){
	//$(window).load(function(){
		fixTextFloat();
	//});
}
if(isPickup){
	//$(window).load(function(){
		fixTextFloat();
	//});
}



});
////////////////////////////////////////// END DOM READY ///////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////////////////////////////
//
//	テキスト回り込み対策用　関数＆クラス
//
function fixTextFloat(){
	//まずはpタグを収集
	var ps = $("div.section p").get();
	if(!ps.length){
		return;
	}
	
	//float:leftのimgタグを子に持つpタグのリスト
	var imgs = [];
	for(var i=0, len=ps.length; i<len; i++){
		// 1)→<p class="photo left"><img /></p>
		if(ps[i].className.match(/\bphoto\b/) && ps[i].className.match(/\bleft\b/)){
			if(ps[i].getElementsByTagName("img").item(0)){//中身が無い場合もある
				imgs.push(new FloatedImage(ps[i]));
			}
		}else{
			var img = ps[i].getElementsByTagName("img").item(0);
			var span = ps[i].getElementsByTagName("span").item(0);
			// 2)→<p>[<span>]<img class="mt-image-left" />[</span>]</p>
			if(img && img.className.match(/\bmt\-image\-left\b/)){
				imgs.push(new FloatedImage(ps[i]));
			}
			// 3)→<p><span class="mt-image-left"><img /></span></p>
			/*
			}else if(span && span.className.match(/\bmt\-image\-left\b/)){
				imgs.push(new FloatedImage(ps[i]));
			}
			*/
		}
	}
	
	var len = imgs.length;
	for(var j=0; j<len; j++){
		imgs[j].collectSiblings([""], ["h3", ".entryDate", ".entryCategory"]);
		imgs[j].setPaddingLeft();
	}
}


//
//	FloatedImage クラス（float:left/rightのimgタグを子に持つ要素を扱う）
//
//	対応マークアップ<hoge>は引数のobj
//		1) <hoge><img /></hoge>
//		2) <hoge><span><img /></span></hoge>
//		3) <hoge></hoge>（中身がない場合も）
//
function FloatedImage(obj){
	//対象要素
	this.obj = obj;
	$(this.obj).addClass(FloatedImage.CLASS_NAME);
	this.obj.style.clear = "both";
	
	//中のspan
	this.innerSpan = obj.getElementsByTagName("span").item(0);
	
	//中の画像
	this.innerImage = obj.getElementsByTagName("img").item(0);
	if(this.innerImage){//画像がない場合もある
		this.innerImageWidth = parseInt(this.innerImage.getAttribute("width"));//width属性があるか
		if(!this.innerImageWidth){//width属性がない場合画像を読み込んでその幅を取得するため遅延処理が必要
			this.delay = true;
		}
	}
	this.innerImageObj = new Image();
	this.innerImageObj.src = this.innerImage.getAttribute("src");
	
	//paddingを指定する必要のある要素のリスト
	this.siblings = [];
}

//目印として付けるクラス名
FloatedImage.CLASS_NAME = "_LOVELA_FLOATED_IMAGE_";

//Imageのロードを待つため[ms]
FloatedImage.DELAY_MS = 1000;

//任意要素の横方向のマージン、パディング、ボーダー幅の和を算出
FloatedImage.calcPadding = function(obj){
	if(!obj)return 0;
	
	var marginLeft = 0;
	var marginRight = 0;
	var paddingLeft = 0;
	var paddingRight = 0;
	var borderLeft = 0;
	var borderRight = 0;
	if(document.defaultView){
		marginLeft = parseInt( document.defaultView.getComputedStyle(obj, null).getPropertyValue("margin-left") );
		marginRight = parseInt( document.defaultView.getComputedStyle(obj, null).getPropertyValue("margin-right") );
		paddingLeft = parseInt( document.defaultView.getComputedStyle(obj, null).getPropertyValue("padding-left") );
		paddingRight = parseInt( document.defaultView.getComputedStyle(obj, null).getPropertyValue("padding-right") );
		borderLeft = parseInt( document.defaultView.getComputedStyle(obj, null).getPropertyValue("border-left-width") );
		borderRight = parseInt( document.defaultView.getComputedStyle(obj, null).getPropertyValue("border-right-width") );
	}else{
		marginLeft = parseInt( obj.currentStyle.getAttribute("marginLeft") );
		marginRight = parseInt( obj.currentStyle.getAttribute("marginRight") );
		paddingLeft = parseInt( obj.currentStyle.getAttribute("paddingLeft") );
		paddingRight = parseInt( obj.currentStyle.getAttribute("paddingRight") );
		var bl = parseInt( obj.currentStyle.getAttribute("borderLeftWidth") );
		borderLeft = (isNaN(bl)) ? 0 : bl;
		var br = parseInt( obj.currentStyle.getAttribute("borderRightWidth") );
		borderRight = (isNaN(br)) ? 0 : br;
	}
	return marginLeft + marginRight + paddingLeft + paddingRight + borderLeft + borderRight;
}

//pに指定すべきpaddingLeftを算出
FloatedImage.prototype.calcTotalPadding = function(){
	//メモ：innerImage.clientWidth はNNで取得できない。
	var padding = this.getImageWidth() + FloatedImage.calcPadding(this.innerImage) + FloatedImage.calcPadding(this.innerSpan) + FloatedImage.calcPadding(this.obj);
	return padding;
};

//imgの幅を取得（width属性が指定されていない場合にoffsetWidth/clientWidthでは幅が取得できない）
FloatedImage.prototype.getImageWidth = function(){
	//width属性がある場合はそちらを優先
	if(!this.delay){
		return this.innerImageWidth;
	}else if(this.innerImageObj.complete){//width属性がない場合は画像ファイル本来の幅を取得し返す
		width = this.innerImageObj.width;
		return width;
	}else{
		return 0;
	}
};

//
//	["p", ".hoge", "#hogehoge", .....]をid,class,タグ名に分け、さらに正規表現に変換し返す
//
FloatedImage.parseOptions = function(options){
	var ids = [];
	var classNames = [];
	var tagNames = [];
	var exps = {};
	exps.ids = null;
	exps.classNames = null;
	expstagNames = null;
	
	//optionsが配列かどうかチェック
	if(!options || options.constructor!=ids.constructor){
		return exps;
	}
	
	//正規表現に変換
	for(var i=0, len=options.length; i<len; i++){
		if( options[i].match(/^(#|\.)?([a-zA-Z0-9_\-\$]+)/) ){
			if(RegExp.$1=="#"){//id名のとき
				ids.push(RegExp.$2);
			}else if(RegExp.$1=="\."){//クラス名のとき
				classNames.push(RegExp.$2);
			}else if(RegExp.$2){//タグ名のとき（小文字で統一）
				tagNames.push((RegExp.$2).toLowerCase());
			}
		}
	}
	
	ids = ids.join("|");
	classNames = classNames.join("|");
	tagNames = tagNames.join("|");
	
	exps.ids = 			ids ?			( new RegExp(ids) ) : null;
	exps.classNames =	classNames ?	( new RegExp("\\b"+classNames+"\\b") ) : null;
	exps.tagNames =		tagNames ?		( new RegExp(tagNames) ) : null;
	
	return exps;
};

//
//	引数 : 
//		1)exps : FloatedImage.parseOptionsによって生成された正規表現リスト
//		2)obj : 対象要素
//		3)defaultValue : expsに合致しない場合の戻り値
//
FloatedImage.matchOptions = function(exps, obj, defaultValue){
	if( obj.id && exps.ids!==null && obj.id.match(exps.ids) ){
		return true;
	}else if( obj.className && exps.classNames!==null && obj.className.match(exps.classNames) ){
		return true;
	}else if( obj.tagName && exps.tagNames!==null && obj.tagName.toLowerCase().match(exps.tagNames) ){
		return true;
	}else{
		return defaultValue;
	}
};

//
//	(paddingを指定すべき)兄弟要素を収集
//
//	引数 : 
//		1)optionsAllow : 収集する要素の条件 例）["p", ".hoge", "#hogehoge", .....]
//		2)optionsIgnore : 収集しない要素の条件 例）["p", ".hoge", "#hogehoge", .....]
//		※["div#hogehoge"]のような指定は未対応
//		※ワイルドカード未対応
//		※収集しない条件が優先される
//
FloatedImage.prototype.collectSiblings = function(optionsAllow, optionsIgnore){
	//廻りこませたくない要素を収集
	var a = this.obj;
	while(true){
		a = a.nextSibling;
		//nextSibling が null もしくは FloatedImageクラスのインスタンスの場合はそこで収集ストップ
		var exp = new RegExp("\\b" + FloatedImage.CLASS_NAME + "\\b");
		if( !a || (a.className && a.className.match(exp)) ){
			break;
		}
		
		//収集するタグ、クラス、idのリスト（正規表現）を作成
		var expsAllow = FloatedImage.parseOptions(optionsAllow);
		
		//無視するタグ、クラス、idのリスト（正規表現）を作成
		var expsIgnore = FloatedImage.parseOptions(optionsIgnore);
		
		if(a.tagName){
			if(FloatedImage.matchOptions(expsIgnore, a, false)){
				continue;
			}else if(FloatedImage.matchOptions(expsAllow, a, true)){
				this.siblings.push(a);
			}
		}
	}
};


//
//	画像の読み込みを待つためFloatedImage.DELAY_MS後に実行
//
FloatedImage.prototype.setPaddingLeft = function(){
	var delay = this.delay ? FloatedImage.DELAY_MS : 0;
	var self = this;
	var func = function(){
		var paddingLeft = self.calcTotalPadding() + "px";
		var len = self.siblings.length;
		for(var i=0; i<len; i++){
			self.siblings[i].style.paddingLeft = paddingLeft;
		}
	}
	window.setTimeout(func, delay);
};

//
//	画像の読み込みを待つためFloatedImage.DELAY_MS後に実行
//
FloatedImage.prototype.setPaddingRight = function(){
	var delay = this.delay ? FloatedImage.DELAY_MS : 0;
	var self = this;
	var func = function(){
		var paddingRight = FloatedImage.calcTotalPadding(self.obj) + "px";
		var len = self.siblings.length;
		for(var i=0; i<len; i++){
			self.siblings[i].style.paddingRight= paddingRight;
		}
	}
	window.setTimeout(func, delay);
};








//bxxxx.onfontsizechange.js.1.0.2+bxxxx.footer.js.1.0.2.MIN
OnFontSizeChange = function(){
	this.idName = "_ONFONTSIZECHANGE_WRAPPER_";
	this.funcList = {};
	this.funcList.change = [];
	this.funcList.smaller = [];
	this.funcList.larger = [];
	this.init();
	this.isReady = true;
	var interval = 100;
	var oldSize = this.getCurSize();
	var oldComputedSize = this.getCurComputedSize();
	var self = this;
	this.timer = setInterval(function(){
		if(self.isReady){
			var curSize = self.getCurSize();
			var curComputedSize = self.getCurComputedSize();
			if(oldSize != curSize){
				self.callFunc("change");
				if(oldSize > curSize){
					self.callFunc("smaller");
				}else if(oldSize < curSize){
					self.callFunc("larger");
				}
			}else if(oldComputedSize != curComputedSize){
				self.callFunc("change");
				if(oldComputedSize > curComputedSize){
					self.callFunc("smaller");
				}else if(oldComputedSize < curComputedSize){
					self.callFunc("larger");
				}
			}
			oldSize = curSize;
			oldComputedSize = curComputedSize;
		}
	}, interval);	
};
OnFontSizeChange.prototype.init = function(){
	var _dummyElement = document.getElementById(this.idName);
	if(_dummyElement){
		this.dummyElement = _dummyElement;
	}else{
		this.dummyElement = document.createElement("span");
		this.dummyElement.style.display = "block";
		this.dummyElement.style.visibility = "hidden";
		this.dummyElement.style.position = "absolute";
		this.dummyElement.style.zIndex = "-9999";
		this.dummyElement.style.left = "-9999px";
		this.dummyElement.style.top = "-9999px";
		this.dummyElement.style.margin = "0px";
		this.dummyElement.style.padding = "0px";
		this.dummyElement.style.minWidth = "1px";
		this.dummyElement.style.minHeight = "1px";
		if(document.all && !window.opera && !window.XMLHttpRequest){
			this.dummyElement.style.height = "1px";
		}
		this.dummyElement.style.lineHeight = "1em";
		this.dummyElement.style.overflow = "visible";
		this.dummyElement.style.fontSize = "1000%";
		this.dummyElement.style.textIndent = "0em";
		this.dummyElement.innerHTML = "B";
		this.dummyElement.setAttribute("id", this.idName);
		var body = document.getElementsByTagName("body").item(0);
		body.appendChild(this.dummyElement);
	}
};
OnFontSizeChange.prototype.addListener = function(eventName, func){
	if(eventName == "change" || eventName == "smaller" || eventName == "larger"){
		if(typeof func != "function"){
			return;
		}else{
			this.funcList[eventName].push(func);
		}
	}
};
OnFontSizeChange.prototype.callFunc = function(eventName){
	this.isReady = false;
	for(var i=0; i<this.funcList[eventName].length; i++){
		if(typeof this.funcList[eventName][i] == "function"){
			(this.funcList[eventName][i])();
		}
	}
	this.isReady = true;
};
OnFontSizeChange.prototype.getCurSize = function(){
	return this.dummyElement.clientHeight;
};
OnFontSizeChange.prototype.getCurComputedSize = function(){
	if(document.defaultView){
		return document.defaultView.getComputedStyle(this.dummyElement, null).getPropertyValue("font-size");
	}else{
		return 0;
	}
};
OnFontSizeChange.prototype.removeListener = function(eventName){
	if(eventName == "change" || eventName == "smaller" || eventName == "larger"){
		this.funcList[eventName] = null;
	}
};



//////////////////////////////////////////////////////////////////////
var _DEBUG_ = false;
var spacer = document.createElement("span");
spacer.setAttribute("id", "_FOOTER_SPACER_");
spacer.style.display = "block";
spacer.style.visibility = "hidden";
spacer.style.position = "static";
spacer.style.lineHeight = "0";//ie6用
spacer.style.width = "1px";
spacer.style.height = "0px";
spacer.style.margin = "0";
spacer.style.padding = "0";
spacer.style.border = "none";
spacer.style.fontSize = "0";//ie6用
var checkFloat = false;
var floatedElements =[];

var insertSpacer = function(obj){
	
	//blades.resize.js の _acorn.prototype.getLastElementNodeから拝借。
	//spacerを挿入できそうなタグを探す。
	//一つ上の
	var getPrev = function(node){
		if(node){
			if(node.nodeType == 1){//ElementNodeのとき
				//if(_DEBUG_)alert(node.tagName);
				if(_DEBUG_)if(_DEBUG_)alert("ノード" + node.tagName);
				
				//タグ名にかかわらず、絶対配置の要素は無視する。
				var position = "";
				try{
					position = document.defaultView.getComputedStyle(node, null).getPropertyValue("position");
				}catch(e){
					position = node.currentStyle.getAttribute("position");
				}
				if(position == "absolute" || position == "fixed"){//さらにひとつ前のノードをチェック
					return arguments.callee(node.previousSibling);
				}		
				
				//絶対配置でなければタグ名をチェック
				switch(node.tagName.toLowerCase()){
					//以下がスペーサー挿入可能とみなすタグ
					//これらを見つけるまでDOMツリーをさかのぼる
					case "acronym":
					case "abbr":
					case "a":
					case "sub":
					case "sup":
					case "strike":
					case "i":
					case "em":
					case "strong":
					case "span":
					case "th":
					case "td":
					case "dt":
					case "dd":
					case "li":
					case "p":
					case "div":
						if(_DEBUG_)alert("挿入できそうです");
						
						
						var cssFloat = "";
						try{
							//float = document.defaultView.getComputedStyle(node, null).getPropertyValue("float");
							cssFloat = document.defaultView.getComputedStyle(node, null).cssFloat;
						}catch(e){
							//float = node.currentStyle.getAttribute("styleFloat");
							cssFloat = node.currentStyle.styleFloat;
						}
						if(_DEBUG_)alert("float: " + cssFloat);
						
						//floatされた要素を見つけた場合float要素の収集に入る。
						if(cssFloat == "left" || cssFloat == "right"){
							if(!checkFloat){
								if(_DEBUG_)alert("float収集に入ります");
								checkFloat = true;//
								floatesdElements = null;
								floatesdElements = [];
							}
							floatedElements.push(node);
							return arguments.callee(node.previousSibling);
						}else{
							//float要素収集中にfloatでない要素に出会った場合収集をやめ収集した要素の中から、一番下にあるものを返す。
							if(checkFloat){
								checkFloat = false;
								//底辺の位置を計算
								if(_DEBUG_)alert("float要素の中から一番下の要素を探します");
								for(var i=0, maxBottom=0, _bottom=0, result=null, len=floatedElements.length; i<len; i++){
									_bottom = floatedElements[i].offsetTop + floatedElements[i].clientHeight;//内包要素のmargin-bottomをあとで考慮しないといけない
									if(_bottom > maxBottom){
										result = floatedElements[i];
										maxBottom = _bottom;
									}
								}
								return result;
							}
						}
						return node;
						
					//以下のノードは無視しその上のノードを試す
					case "hr":
					case "br":
						return arguments.callee(node.previousSibling);
						
					//以下のノードならその子ノードを試す
					case "ul":
					case "ol":
					case "dl":
					case "table":
					case "thead":
					case "tbody":
					case "tfoot":
					case "tr":
						return arguments.callee(node.lastChild);
						
					default:
						if(_DEBUG_)alert("諦めます");
						return null;
				}
			}else if(node.nodeType == 3){//TextNodeのとき
				if(_DEBUG_)alert("textnode");
				if(node.nodeValue && node.nodeValue.match(/[^\s\t\n]/)){//TextNodeで改行・タブ・スペース以外の時
					//if(_DEBUG_)alert(node.nodeValue);
					//テキストの
					if(_DEBUG_)alert("テキスト");
					return null;
				}else{
					if(_DEBUG_)alert("改行");
					//改行・タブ・スペースのときはさらにその前の要素を調べる
					return arguments.callee(node.previousSibling);
				}
			}else{
				if(_DEBUG_)alert("それ以外" + node.nodeType);
				return arguments.callee(node.previousSibling);
			}
			
		}else if(checkFloat){//float要素収集中にfloatでない要素に出会った場合収集をやめ収集した要素の中から、一番下にあるものを返す。
			checkFloat = false;
			//底辺の位置を計算
			if(_DEBUG_)alert("float要素の中から一番下の要素を探します");
			for(var i=0, maxBottom=0, _bottom=0, result=null, len=floatedElements.length; i<len; i++){
				_bottom = floatedElements[i].offsetTop + floatedElements[i].clientHeight;//内包要素のmargin-bottomをあとで考慮しないといけない
				if(_bottom > maxBottom){
					result = floatedElements[i];
					maxBottom = _bottom;
				}
			}
			return result;
		}
		if(_DEBUG_)alert("null");
		return null;
	};
	(function(obj){
		/*
		var prev = obj.previousSibling;
		var target;
		switch(prev.tagName.toLowerCase()){
			//直前の要素がtd/thの場合はtrから探す
			case "td":
			case "th":
				target = getPrev(prev.parentNode);//ホワイトスペースが考慮されていない
				break;
			default:
				target = getPrev(prev);
		}
		*/
		var target = getPrev(obj.previousSibling);
		if(target){
			target.appendChild(spacer);
		}else{//前のノードで適当なものが見つからない場合は前のノードを拡張するのではなく、その直前にスペーサーを挿入する
			//ただし、parentNodeがtr,ul,ol,dl,thead,tbody,tfoot,table,trの場合は・・・・・親ノードの直前のノードからまたさかのぼってチェックする。
			switch(obj.parentNode.tagName.toLowerCase()){
				case "ul":
				case "ol":
				case "dl":
				case "table":
				case "thead":
				case "tbody":
				case "tfoot":
				case "tr":
					if(_DEBUG_)alert("親ノードにspanを挿入できません");
					arguments.callee(obj.parentNode);
					break;
				default:
					obj.parentNode.insertBefore(spacer, obj);
			}
		}
	})(obj);
}

function setHeight(height){
	var d = 0;
	if(height){
		d = height;
	}else{
		d=calcHeight();
	}
	if(d>=0){
		spacer.style.height = d + "px";
	}
}

function calcHeight(){
	var html = document.getElementsByTagName("html").item(0);
	var bodyClientHeight = document.body.clientHeight || document.documentElement.clientHeight;
	
	//var wh = window.innerHeight;//fx,opera,chrome,safari,netscapeはOK![ie6 & ie7はundefined]
	//var wh = blades.DOM("html").get(0).clientHeight;//fx,ie8,safari,chromeはOK! [ダメ:operaはwindowではなく中身の高さを返す, ie6,netscapeは0]
	//var wh = document.body.clientHeight;//ie6,opera,netscapeはwindow内の高さを返す。[fx,ie7,chrome,safariはちゃんと中の高さを返す]
	//if(_DEBUG_)alert(wh);
	
	//window高さを取得
	var wh = window.innerHeight;
	if(document.all && !window.opera){//ie
		if(window.XMLHttpRequest){//ie7
			wh = html.clientHeight;//落ちる(これは原因ではなかった）
			//alert(document.documentElement.clientHeight);//ウィンドウの高さを返す
			//alert(document.body.clientHeight);//中身の高さを返す
			//wh = document.documentElement.clientHeight;
			//wh = 800;//これも落ちる(これは原因ではなかった）
		}else{//ie 6
			wh = bodyClientHeight;
		}
	}
	//if(_DEBUG_)alert(wh);
	
	//body高さを取得
	var dh = bodyClientHeight;
	if(window.opera){//opera
		dh = html.clientHeight;
	}
	if(
		(window.innerHeight == bodyClientHeight && !window.opera) || (document.all && !window.opera && !window.XMLHttpRequest)//netscape & ie6
		){
		/***** ie6 *****
		if(_DEBUG_)alert("ie6");
		dh = html.scrollHeight;//ウィンドウの高さを返す。
		dh = html.offsetHeight;//ウィンドウの高さを返す。
		dh = document.getElementsByTagName("body")[0].offsetHeight;
		*/
		
		/*----- 最終手段 -----*/
		var scale = document.createElement("span");
		scale.style.display = "block";
		scale.style.visibility = "hidden";
		scale.style.position = "static";
		scale.style.lineHeight = "0";//ie6用
		scale.style.width = "100%";
		scale.style.height = "0";
		scale.style.margin = "0";
		scale.style.padding = "0";
		scale.style.border = "none";
		scale.style.fontSize = "0";//ie6用
		document.getElementsByTagName("body")[0].appendChild(scale);
		dh = scale.offsetTop;
		document.getElementsByTagName("body")[0].removeChild(scale);
		//if(_DEBUG_)alert(dh);
	}
	return parseInt(spacer.clientHeight + wh - dh);
}

var setFooter = function(idName){
	var obj = document.getElementById(idName);
	if(obj){
		insertSpacer(obj);
		(function(){
			var d = calcHeight();
			if(d>=0){
				setHeight(d);
			}
			//setTimeout(arguments.callee, 10);
		})();
		(new OnFontSizeChange()).addListener("change", function(){
			setHeight();
		});
		if(!(document.all && !window.opera && window.XMLHttpRequest)){//ie7以外
			$(window).resize(function(){
				setHeight();//ieはresize時にイベントが2回発生する（たぶんスクロールバーの関係で）サイズが2度変化する
			});
		}
	}	
};



///////////////////////////////////////////////////////////////////////////////////////////////
//	bxxxx.resize.js.1.0.1.MIN requires OnFontSizeChange
var _acorn = function(_obj){
	this.obj = _obj;
	this.isIE = (document.all && !window.opera);
	this.isIE6 = (this.isIE && !window.XMLHttpRequest);
	this.defaultHeight = this.obj.style.height;
};
_acorn.prototype.getClientHeight = function(){
	var lastChildMarginBottom = 0;
	var a = this.getLastElementNode();
	if(a){
		if(document.defaultView){
			lastChildMarginBottom = document.defaultView.getComputedStyle(a, null).getPropertyValue("margin-bottom");
		}else if(a.currentStyle){
			lastChildMarginBottom = a.currentStyle.getAttribute("marginBottom");
		}
	}
	
	return this.obj.offsetHeight + parseInt(lastChildMarginBottom);
};
_acorn.prototype.getLastElementNode = function(){
	var result = (function(node){
		if(node){
			if(node.nodeType == 1){
				return node;
			}else if(node.nodeType == 3){
				if(node.nodeValue && node.nodeValue.match(/[^\s\t\n]/)){
					return null;
				}	
			}
			return arguments.callee(node.previousSibling);
		}
		return null;
	})(this.obj.lastChild);
	return result;
};
_acorn.prototype.resetHeight = function(){
	if(this.defaultHeight){
		this.obj.style.height = this.defaultHeight;
	}else{
		if(this.isIE){
			this.obj.style.removeAttribute("height");
		}else{
			this.obj.style.removeProperty("height");
		}
	}
};
_acorn.prototype.setHeight = function(strHeight){
	var _height = 0;
	if(this.isIE6){
		_height = strHeight;
	}else{
		var paddings = this.getPaddings();
		_height = (parseInt(strHeight) - paddings);
		if(_height<0){
			_height = 0;
		}
	}
	this.obj.style.height = _height + "px";
};
_acorn.prototype.getPaddings = function(){
	var paddings = 0, paddingTop = 0, paddingBottom = 0;
	if(this.isIE){
		paddingTop = this.obj.currentStyle.getAttribute("paddingTop");
		paddingBottom = this.obj.currentStyle.getAttribute("paddingBottom");
	}else{
		paddingTop = document.defaultView.getComputedStyle(this.obj, null).getPropertyValue("padding-top");
		paddingBottom = document.defaultView.getComputedStyle(this.obj, null).getPropertyValue("padding-bottom");
	}
	paddings = parseInt(paddingTop.replace("px", "")) + parseInt(paddingBottom.replace("px", ""));
	return paddings;
};
var Acorn = function(obj){
	return new _acorn(obj);
};
var toAcorns = function(objs){
	var acorns = new Array();
	for(var i=0; i<objs.length; i++){
		acorns.push(Acorn(objs[i]));
	}
	return acorns;
};
resize = function(objs){
	var acorns = toAcorns(objs);
	var func = function(){
		for(var i=0; i<acorns.length; i++){
			acorns[i].resetHeight();
		}
		var getMaxHeight = function(){
			var _max = 0;
			var _height = 0;
			for(var i=0; i<acorns.length; i++){
				_height = acorns[i].getClientHeight();
				if(_max<_height){
					_max = _height;
				}
			}
			return _max;
		}
		var max = getMaxHeight();
		for(var j=0; j<acorns.length; j++){
			acorns[j].setHeight(max);
		}
	}
	func();
	
	(new OnFontSizeChange()).addListener("change", func);
};
resize2 = function(objs){
	for(var i=0; i<objs.length; i+=2){
		var pair = new Array();
		if(objs[i+1]){
			pair.push(objs[i]);
			pair.push(objs[i+1]);
			resize(pair);
		}
		pair = null;
	}
};
resize3 = function(objs){
	for(var i=0; i<objs.length; i+=3){
		var pair = new Array();
		if(objs[i+1]){
			pair.push(objs[i]);
			pair.push(objs[i+1]);
			
			if(objs[i+2]){
				pair.push(objs[i+2]);
			}
			resize(pair);
		}
		pair = null;
	}
};
resize4 = function(objs){
	for(var i=0; i<objs.length; i+=4){
		var pair = new Array();
		if(objs[i+1]){
			pair.push(objs[i]);
			pair.push(objs[i+1]);
			
			if(objs[i+2]){
				pair.push(objs[i+2]);
			}
			if(objs[i+3]){
				pair.push(objs[i+3]);
			}
			resize(pair);
		}
		pair = null;
	}
};

////////////////////////////////////////////////
//
//	URL CLASS from bxxxx.js.ver.1.0.6
//
var URL = function(url){
	var _DEBUG_ = false;
	var search=null, hash=null;
	
	//check if the url is global
	var a = url.match(/^([a-zA-Z]+):\/\/([^\/][\w.]+)(\/([\s\S]+)?)/);
	this.isGlobal = !!(a);//if the url is global or not
	var remainder;
	if(this.isGlobal){
		this.protocol = a[1];
		this.domain = a[2];
		remainder = a[4];//this can be undefined
		if(_DEBUG_){
			alert("protocol: " + this.protocol);
			alert("domain: " + this.domain);
		}
	}else{
		remainder = url;
	}
	if(_DEBUG_){
		alert("isGlobal: " + this.isGlobal);
	}
	
	//if there is path or fileName....etc.
	if(remainder){
		
		//at first, remove parameters and hash	
		this.path = remainder.split("\?")[0].split("#")[0];//strings without search&hash parameters
		if(_DEBUG_){
			alert("path: " + this.path);
		}
		
		//alert(remainder);
		//check if the url has file name
		var b = this.path.match(/(([\s_\S]+\/)?)([^\/]+)$/);
		var possibleFileName;
		if(b){
			this.directories = b[1].split("/");
			possibleFileName = b[3];
		}else{
			this.directories = this.path.split("/");
		}
		
		//check if it IS fileName
		if(possibleFileName && possibleFileName.indexOf(".") > -1){
			this.fileName = possibleFileName;
		}else{//tured out to be directory
			this.directories.push(possibleFileName);
		}
		
		//clean up　連続したスラッシュ、"."を取り除く
		var _directories = [];
		for(var i=0, len=this.directories.length; i<len; i++){
			if(this.directories[i] && this.directories[i]!="."){
				_directories.push(this.directories[i]);
			}
		}
		this.directories = _directories;
		
		if(_DEBUG_){
			alert("directories: " + this.directories);
			alert("fileName: " + this.fileName);
		}
		
		//create this.location
		if(this.isGlobal){
			this.location = this.protocol + "://" + this.domain + "/" + this.directories.join("/");
		}else{
			this.location = this.directories.join("/");
		}
		if(this.directories.length>0){
			this.location += "/";
		}
		
		
		//find file extention
		if(this.fileName){
			this.fileType = this.fileName.match(/.(\w+)$/)[1];//file extention
		}
		if(_DEBUG_){
			alert("fileType: " + this.fileType);
		}
		
		//find search and hash parameters
		
		if(url.indexOf("\?") > -1){
			//alert("search exists");
			search = url.split("\?")[1].replace(/#\S*/,"");
			search = this._getParameters(search);
		}
		if(url.indexOf("#") > -1){
			hash = url.split("#")[1].replace(/\?\S*/, "");
			hash = this._getParameters(hash);
		}
	}
		this.search = new Parameters(search);
		this.hash = new Parameters(hash);
	this.get = function(){
		return url;
	}
};

/*----- INTERNAL USE ONLY -----*/
URL.prototype._getParameters = function(str){
	var pairs = [];
	var parameters = {};
	if(str){
		if(str.indexOf("&") > -1){
			pairs = str.split("&");
		}else{
			pairs[0] = str;
		}
		for(var i=0, len=pairs.length, key, val; i<len; i++){
			if(pairs[i].indexOf("=")>-1){
				key = pairs[i].split("=")[0];
				val = pairs[i].split("=")[1];
				if(val){
					parameters[key] = val;
				}
			}
		}
	}else{
		parameter = null;
	}
	return parameters;
};

//
//	Parametersクラス
//
var Parameters = function(params){
	this.params = params;
};

Parameters.prototype.set = function(key, val){
	;
};

Parameters.prototype.get = function(key){
	if(this.params && key){
		if(this.params[key]){
			return this.params[key];
		}else{
			return null;
		}
	}else{
		return this.params;
	}
};

Parameters.prototype.has = function(key){
	if(this.params.hasOwnProperty(key)){
		return true;
	}else{
		return false;
	}
};
	
Parameters.prototype.hasParameters = function(){
	if(this.params){
		return true;
	}else{
		return false;
	}
};

Parameters.prototype.join = function(prefix){
	var a = [];
	for(var p in this.params){
		a.push(p + "=" + this.params[p]);
	}
	var results = a.join(prefix);
	return results;
};





})();

//
//	ポップアップリンク（外部呼出し用）
//
var win1 = null;
var width1 = null;
var height1 = null;

function popupWindow(_url,_size_x,_size_y){
	var url = _url;
	
	//Winウィンドウが無い場合
	if(win1==null||win1.closed==true){
		width1 = _size_x;
		height1 = _size_y;
		win1 = window.open(url,"Win1","location='0',status=0,menubar=0,scrollbars=1,resizable=0,width="+width1+",height="+height1+"\"");
	}
	//Winウィンドウが在る場合
	else{
		//新規ウィンドウのwidth とheight が同じ場合はlocationだけ変更
		if(!width1 && !height1 && !(_size_x&&_size_y)){
			win1.location = url;
		}else if((width1 == _size_x)&&(height1 == _size_y)){
			win1.location = url;
		}
		//そうでない場合はWinウィンドウを閉じて、Winウィンドウが無い場合と同じ処理
		else{
			win1.close();
			width1 = _size_x;
			height1 = _size_y;
			win1 = window.open(url,"Win1","location='0',status=0,menubar=0,scrollbars=1,resizable=0,width="+width1+",height="+height1+"\"");
		}
	}
	
	win1.focus();
	return false;
}

