var Cast = function($me, hidden){ this._build($me, hidden); }

Cast.prototype = {

	_build:function($me, hidden){
		var me = this;

		me.$ = $me;
		me.$opa = $(".opa", me.$);

		me.$target = (me.$opa.size()>0)? me.$opa: me.$;

		me.isShow = true;
		if(hidden) {
			me.isShow = false;
			me.$target.fadeTo(0, 0);
			me.$.css("display", "none");
		}
	},

	show:function(duration, delay, callback){
		var me = this;

		if(me.isShow) return;
		me.isShow = true;

		if(!duration && duration!=0) duration = 0;
		if(!delay && delay!=0) delay = 0;

		if(me.delayID) clearTimeout(me.delayID);
		if(delay==0) me._show(duration, callback);
		else {
			me.delayID = setTimeout(function(){
				me._show(duration, callback);
			}, delay);
		}
	},
	_show:function(duration, callback){
		var me = this;
		me.$.css("display", "block")
		me.$target.stop().fadeTo(duration, 1);
		if(duration==0) me._showComp(callback);
		else {
			me.delayID = setTimeout(function(){
				me._showComp(callback);
			}, duration);
		}
	},
	_showComp:function(callback){
		var me = this;
		me.$target.stop().css("filter", "none");
		if(callback) callback();
	},

	hide:function(duration, delay, callback){
		var me = this;

		if(!me.isShow) return;
		me.isShow = false;

		if(!duration && duration!=0) duration = 0;
		if(!delay && delay!=0) delay = 0;

		if(me.delayID) clearTimeout(me.delayID);
		if(delay==0) me._hide(duration, callback);
		else {
			me.delayID = setTimeout(function(){
				me._hide(duration, callback);
			}, delay);
		}
	},
	_hide:function(duration, callback){
		var me = this;

		me.$target.stop().fadeTo(duration, 0);
		if(duration==0) me._hideComp(callback);
		else {
			me.delayID = setTimeout(function(){
				me._hideComp(callback);
			}, duration);
		}
	},
	_hideComp:function(callback){
		var me = this;
		me.$.css("display", "none");
		if(callback) callback();
	}

}




/*
フェードな画像のボタン
 */

var ImgBtn = function($btn, hasAc){ this._build($btn, hasAc); }
ImgBtn.prototype = {

	_build:function($btn, hasAc){
		var me = this;

		if($btn.size()==0) return;

		me.hasAc = hasAc;

		me.$ = $btn;
		me.$img = $("img", me.$);

		if(me.$img.size()==0) return;

		me.$.data("enhance", me);
		
		var imgSrc = me.$img.attr("src");
		me.imgSrcOv = imgSrc.substr(0, imgSrc.length-4) + "_ov" + imgSrc.substr(imgSrc.length-4);
		me.imgSrcAc = imgSrc.substr(0, imgSrc.length-4) + "_ac" + imgSrc.substr(imgSrc.length-4);

		me.$.css({
			"display":"block",
			"background-color": "transparent",
			"background-image": "url(" + me.imgSrcOv + ")",
			"background-repeat": "no-repeat",
			"background-position": "left top"
		})
		me.$img.fadeTo(0, 1);

		var w = parseInt( me.$img.attr("width"), 10 );
		var h = parseInt( me.$img.attr("height"), 10 );
		if(w) me.$.css("width", w);
		if(h) me.$.css("height", h);


		me.mouseoverHdl = function(){
			if(me.isSelect) return;
			me.$img.stop().fadeTo(300, 0);
		}
		me.mouseoutHdl = function(){
			if(me.isSelect) return;
			me.$img.stop().fadeTo(300, 1);
		}
		me.clickHdl = function(){
			if(me.isSelect) return false;
			me.clickFunc.apply(me);
			return false;
		}
		
		me.$.bind("mouseover", me.mouseoverHdl);
		me.$.bind("mouseout", me.mouseoutHdl);

		
		//prevent click
		me.$.bind("click", function(){
			if(me.isSelect) return false;
		})
	},
	destory:function(){
		var me = this;
		
		me.$.unbind("mouseover", me.mouseoverHdl);
		me.$.unbind("mouseout", me.mouseoutHdl);
		if(me.clickFunc) {
			me.$.unbind("click", me.clickHdl);
			me.clickFunc = null;
		}
		me.$ = null;
	},

	setClickFunc:function(func){
		var me = this;
		me.clickFunc = func;
		me.$.bind("click", me.clickHdl);
	},

	selection:function(isSelect){
		var me = this;
		if(me.isSelect == isSelect) return;
		me.isSelect = isSelect;
		if(me.isSelect) {
			me.$img.stop().fadeTo(100, 0);
			if(me.hasAc) me.$.css({ "background": "url(" + me.imgSrcAc + ")" });
		} else {
			me.$img.stop().fadeTo(100, 1);
			if(me.hasAc) me.$.css({ "background": "url(" + me.imgSrcOv + ")" });
		}
	}
}

/*
ToggleBtn
 */

var ToggleBtn = function($btn){ this._build($btn); }
ToggleBtn.prototype = {

	_build:function($btn){
		var me = this;

		if($btn.size()==0) return;

		me.$ = $btn;

		if(me.$.size()==0) return;

		me.$.data("enhance", me);

		//prevent click
		me.$.bind("click", function(){
			if(me.isSelect) return false;
		})
	},

	selection:function(isSelect){
		var me = this;
		if(me.isSelect == isSelect) return;
		me.isSelect = isSelect;
		if(me.isSelect) {
			me.$.addClass("off");
		} else {
			me.$.removeClass("off");
		}
	}
}



/* オーバーで画像を切り替えるタイプのボタン */

var ImgReplaceBtn = function($btn){ this._build($btn); }
ImgReplaceBtn.prototype = {

	_build:function($btn){
		var me = this;

		if($btn.size()==0) return;


		me.$ = $btn;
		me.$img = $("img", me.$);

		var imgSrc = me.$img.attr("src");
		me.imgSrcDf = imgSrc;
		me.imgSrcOv = imgSrc.substr(0, imgSrc.length-4) + "-ov" + imgSrc.substr(imgSrc.length-4);


		me.mouseoverHdl = function(){
			if(me.isSelect) return;
			me.$img.attr("src", me.imgSrcOv)
		}
		me.mouseoutHdl = function(){
			if(me.isSelect) return;
			me.$img.attr("src", me.imgSrcDf)
		}

		me.$.bind("mouseover", me.mouseoverHdl);
		me.$.bind("mouseout", me.mouseoutHdl);
	},
	destory:function(){
		var me = this;

		me.$.unbind("mouseover", me.mouseoverHdl);
		me.$.unbind("mouseout", me.mouseoutHdl);
		if(me.clickFunc) {
			me.$.unbind("click", me.clickFunc);
			me.clickFunc = null;
		}
		me.$ = null;
	},

	setClickFunc:function(func){
		var me = this;
		me.clickFunc = func;
		me.$.bind("click", me.clickFunc);
	}
}



/* フォントカラーが変わるボタン */

var ColorBtn = function($btn, dfClr, ovClr){ this._build($btn, dfClr, ovClr); }
ColorBtn.prototype = {

	_build:function($btn, dfClr, ovClr){
		var me = this;

		if($btn.size()==0) return;


		me.$ = $btn;
		me.dfClr = dfClr;
		me.ovClr = ovClr;


		me.mouseoverHdl = function(){
			if(me.isSelect) return;
			me.$.stop().animate({
				"color": me.ovClr
			}, 100, "easeOutQuad");
		}
		me.mouseoutHdl = function(){
			if(me.isSelect) return;
			me.$.stop().animate({
				"color": me.dfClr
			}, 600, "easeInOutQuad");
		}

		me.$.bind("mouseover", me.mouseoverHdl);
		me.$.bind("mouseout", me.mouseoutHdl);
	},
	destory:function(){
		var me = this;

		me.$.unbind("mouseover", me.mouseoverHdl);
		me.$.unbind("mouseout", me.mouseoutHdl);
		if(me.clickFunc) {
			me.$.unbind("click", me.clickFunc);
			me.clickFunc = null;
		}
		me.$ = null;
	},

	setClickFunc:function(func){
		var me = this;
		me.clickFunc = func;
		me.$.bind("click", me.clickFunc);
	}
}


/*
アルファなボタン
 */

var AlphaBtn = function($btn, defDisp, alp){ this._build($btn, defDisp, alp); }
AlphaBtn.prototype = {

	_build:function($btn, defDisp, alp){
		var me = this;

		me.$ = $btn;
		me.defDisp = defDisp || "block";
		me.alp = alp || 0.3;

		me.$.data("enhance", me);

		me.$target = $("img", me.$);
		if(me.$target.size() == 0) me.$target = me.$;

		me.$.css({
			"zoom": 1
		})
		me.$target.css({
			"zoom": 1
		})

		me.mouseoverHdl = function(){
			if(!me.isShow) return;
			if(me.isSelect) return;
			me.$target.stop().fadeTo(200, me.alp);
		}
		me.mouseoutHdl = function(){
			if(!me.isShow) return;
			if(me.isSelect) return;
			me.$target.stop().fadeTo(200, 1);
		}

		me.$.bind("mouseover", me.mouseoverHdl);
		me.$.bind("mouseout", me.mouseoutHdl);

		me.isShow = true;
	},
	destroy:function(){
		var me = this;

		me.$target.stop();
		me.$.unbind("mouseover", me.mouseoverHdl);
		me.$.unbind("mouseout", me.mouseoutHdl);
		if(me.clickFunc) {
			me.$.unbind("click", me.clickFunc);
			me.clickFunc = null;
		}
		me.$target = null;
		me.$ = null;
	},

	setClickFunc:function(func){
		var me = this;
		me.clickFunc = func;
		me.$.bind("click", me.clickFunc);
	},

	show:function(delay, isDirect){
		var me = this;
		if(!delay) delay = 0;

		if(me.isShow) return;
		me.isShow = true;

		var ta = (me.isSelect)? me.alp: 1;

		if(isDirect) clearTimeout(me.switchID);
		if(isDirect) me.$target.stop().css("display", me.defDisp).fadeTo(0, ta);
		else {
			me.switchID = setTimeout(function(){
				me.$target.stop().css("display", me.defDisp).fadeTo(150, ta);
			}, delay)
		}
	},

	hide:function(delay, isDirect){
		var me = this;
		if(!delay) delay = 0;

		if(!me.isShow) return;
		me.isShow = false;

		if(me.switchID) clearTimeout(me.switchID);
		if(isDirect) me.$target.stop().fadeTo(0, 0).css("display", "none");
		else {
			me.switchID = setTimeout(function(){
				me.$target.stop().fadeTo(150, 0);
				me.switchID = setTimeout(function(){
					me.$target.stop().css("display", "none");
				}, 150)
			}, delay)
		}
	},

	selection:function(isSelect){
		var me = this;
		if(me.isSelect == isSelect) return;
		if(isSelect) {
			me.mouseoverHdl();
			me.isSelect = true;
		} else {
			me.isSelect = false;
			me.mouseoutHdl();
		}
	}
}

/*
シンプルなovボタン
 */

var OvBtn = function($btn){ this._build($btn); }
OvBtn.prototype = {

	_build:function($btn){
		var me = this;

		me.$ = $btn;
	},
	destroy:function(){
		var me = this;

		if(me.clickFunc) {
			me.$.unbind("click", me.clickFunc);
			me.clickFunc = null;
		}
		me.$ = null;
	},

	setClickFunc:function(func){
		var me = this;
		me.clickFunc = func;
		me.$.bind("click", me.clickFunc);
	},

	selection:function(isSelect){
		var me = this;
		if(me.isSelect == isSelect) return;
		if(isSelect) {
			me.$.addClass("ov");
			me.isSelect = true;
		} else {
			me.isSelect = false;
			me.$.removeClass("ov");
		}
	}
}


/*
クリックで出てくるフローティング選択肢
 */

var Choice = function($choice, $container){ this._build($choice, $container); }

Choice.prototype = {

	_build:function($choice, $container){
		var me = this;

		me.$ = $choice;
		me.$container = $container;
		me.$btns = $("a", me.$container);

		me.$.css("display", "none");
		me.$.remove();
		me.$container.append(me.$);

		me.containerClickHdl = function(e){
			if($.contains(me.$[0], e.target)) {
				var href=$(e.target).attr("href");
				if(!href) return;
			}
			me.hide();
		}

		//コールバック
		me.onHide = function(){}
	},
	destory:function(){
		var me = this;
		me.onHide = null;
		me.hide(true);
		me.$container = null;
		me.$ = null;
	},

	show:function($targetBtn){
		var me = this;

		if(me.hideID) clearTimeout(me.hideID);
		var x = 0;
		var y = 0;
		if($targetBtn) {
			var x = $targetBtn.offset().left + $targetBtn.width()*0.5 - me.$.width()*0.5 + 0.5 | 0;
			var y = $targetBtn.offset().top + $targetBtn.height() + 2;
		}
		me.$.css({
			"display":"block",
			"left": x+"px",
			"top": y+"px"
		});
		me.$container.bind("mousedown", me.containerClickHdl);
	},
	hide:function(isDirect){
		var me = this;
		me.onHide();
		if(isDirect) me.doHide();
		else {
			me.hideID = setTimeout(function(){
				me.doHide();
			}, 300)
		}
	},
	doHide:function() {
		var me = this;
		me.$.css("display", "none");
		me.$container.unbind("mousedown", me.containerClickHdl);
	}
}



/*
テキスト内容に応じて高さを自動調整するテキストエリア
※ie6かどうか渡すのを忘れずに！
 */

var AutoTextarea = function($textarea){ this._build($textarea); }

AutoTextarea.prototype = {

	_build:function($textarea){
		var me = this;

		me.$ = $textarea;
		me.raw = me.$.get()[0];

		//ブラウザ判別
		me.isIE6 = false;
		var ua = navigator.userAgent;
		if(ua.indexOf("MSIE 6")>=0) me.isIE6 = true;
		if(ua.indexOf("MSIE")>=0) me.isIE = true;
		if(ua.indexOf("iPad")>=0) me.iPad = true;

		me.defH = me.$.height();
		me.$.css("overflow", "hidden")

		me.checkVal = function(){
			me.$.css({
				"height": me.defH+"px",
				"overflow": (me.isIE? "auto": "hidden")//ieではautoでないとscrollHeightがちゃんととれない！
			})
			var sh = Math.max( me.raw.scrollHeight, me.defH );
			me.$.css({
				"height": sh+"px",
				"overflow": "hidden"
			});
		}
		me.focusHdl = function(e){
			if(me.isIE6) {
				if(me.autoID) clearInterval(me.autoID);
				me.autoID = setInterval(me.checkVal, 10)
			} else {
				if(!me.iPad) me.$.bind("keydown", me.checkVal);
				me.$.bind("keyup", me.checkVal);
			}
			me.onFocus();
		}
		me.blurHdl = function(e){
			if(me.isIE6) {
				if(me.autoID) clearInterval(me.autoID);
			} else {
				if(!me.iPad) me.$.unbind("keydown", me.checkVal);
				me.$.unbind("keyup", me.checkVal);
			}
			me.onBlur();
		}

		//コールバック
		me.onFocus = function(){};
		me.onBlur = function(){};

		me.$.bind("focus", me.focusHdl);
		me.$.bind("blur", me.blurHdl);
	},

	destroy:function(){
		var me = this;
		me.$.unbind("focus", me.focusHdl);
		me.$.unbind("blur", me.blurHdl);
		me.$.unbind("keydown", me.checkVal);
		me.$.unbind("keyup", me.checkVal);
		if(me.autoID) clearInterval(me.autoID);
		me.onFocus = null;
		me.onBlur = null;
		me.raw = null;
		me.$ = null;
	},

	setVal:function(val){
		var me = this;
		if(!val) val = "";
		me.$.val( val );
		setTimeout(me.checkVal, 0);
	},

	getVal:function(){
		var me = this;
		return me.$.val();
	}
}




/* フォーカスすると背景色が変わるテキストフィールド、エリア */

var EnhancedText = function($text, dfClr, slClr){ this._build($text, dfClr, slClr); }
EnhancedText.prototype = {

	_build:function($text, dfClr, slClr){
		var me = this;

		me.$ = $text;
		
		me.defVal = me.$.attr("df");
		if(!me.defVal) me.defVal = "";

		me.defVal = me.defVal.split("<br />").join("\n")

		me.isEmpty = true;
		me.$.addClass("empty");
		me.setVal( me.$.val() );

		me.focusHdl = function(e){
			if(me.$.val()==me.defVal) {
				me.$.val("");
				me.$.removeClass("empty");
			}
			me.$.stop().animate({
				"background-color": slClr
			}, 500, "easeOutQuad")
		}
		me.blurHdl = function(e){
			if(me.$.val()=="") {
				me.$.val(me.defVal);
				me.$.addClass("empty");
			}
			me.$.stop().animate({
				"background-color": dfClr
			}, 500, "easeOutQuad")
		}

		me.$.bind("focus", me.focusHdl);
		me.$.bind("blur", me.blurHdl);
	},

	setVal:function(val){
		var me = this;
		me.$.val(val);
		if(val=="") {
			me.$.val(me.defVal);
			me.$.addClass("empty");
		}
		else me.$.removeClass("empty");
	},
	getVal:function(){
		var me = this;
		var val = me.$.val()
		return (val==me.defVal? "": val);
	}
}


/*
チェックボックス
wrapper > a > spanて構造
wrapper > a.ac > spanて構造
 */

var ACheckBox = function($checkbox, name, isDefaultCheck){ this._build($checkbox, name, isDefaultCheck); }

ACheckBox.prototype = {

	_build:function($checkbox, name, isDefaultCheck){
		var me = this;

		//cast
		me.$ = $checkbox;
		me.$a = $($("a", $checkbox).get()[0]);
		me.$span = $("span", me.$a);
		me.$input = $("input", me.$a);

		me.$.data("enhance", me);

		if(me.$input.attr("checked")=="checked") isDefaultCheck = true;

		//
		me.name = name;

		//selection
		me.isSelect = false;
		me.isDefaultCheck = (isDefaultCheck)? true: false;
		me.selection( me.isDefaultCheck )

		//click
		me.clickHdl = function(e){
			me.selection( !me.isSelect )
			return false;
		}
		me.$a.bind("click", me.clickHdl);
	},

	destroy:function(){
		var me = this;
		me.$a.unbind("click", me.clickHdl);
		me.$input = null;
		me.$span = null;
		me.$a = null;
		me.$ = null;
		me.chengeFunc = null;
	},

	/* 選択状態が変わったときのコールバック */
	addChangeFunc:function(func){
		var me = this;
		me.chengeFunc = func;
	},


	/* チェックの切り替え
	 */
	selection:function(isSelect, noEvent){
		var me = this;
		if(me.isSelect == isSelect) return;
		me.isSelect = isSelect;
		if(me.isSelect) {
			me.$a.addClass("ac");
			me.$input.attr("checked", true);
		}
		else {
			me.$a.removeClass("ac");
			me.$input.attr("checked", false);
		}

		if(!noEvent && me.chengeFunc) me.chengeFunc.apply(this);
	},


	/* デフォルトにもどす
	 */
	goDefault:function(){
		var me = this;
		me.selection(me.isDefaultCheck, true)
	}
}




/*
画像のロード完了を待って、指定した長辺サイズにリサイズして下揃え
span > img

※30pxより小さい画像の場合は注意！

@option {
	longer
	longerW
	longerH
	baseLong
	sideFit
	vCenter
	transTime
	showDelay
	widthFrame
	frameClr
	trim
	wrapperDisplay
}
 */

var PicLoader = function($pic, path, option){ this._build($pic, path, option); }
PicLoader.prototype = {

	_build:function($pic, path, option){
		var me = this;

		if(!option) option = {};
		me.path = path;
		me.longer = option.longer || 100;
		me.longerW = option.longerW || me.longer;
		me.longerH = option.longerH || me.longer;
		me.baseLong = option.baseLong;
		me.sideFit = option.sideFit;
		me.vCenter = option.vCenter;
		me.transTime = option.transTime || 300;
		me.showDelay = option.showDelay || 0;
		me.withFrame = option.withFrame;
		me.frameClr = option.frameClr || "#fff";
		me.trim = option.trim;
		me.noAnime = option.noAnime;
		me.autoLoad = option.autoLoad;
		me.wrapperDisplay = option.wrapperDisplay || "relative";

		me.$ = $pic;
		me.$img = $("img", me.$);	

		if(!me.path) {
			me.path = me.$img.attr("src");
//			me.path = me.$img.attr("src") + "?_=" + (Math.random()*100000|0);
//			me.$img.attr("src", "");
		}

		
		//ブラウザ判別
		me.isIE = false;
		var ua = navigator.userAgent;
		if(ua.indexOf("MSIE")>=0) me.isIE = true;


		me.$.css({
			"position": me.wrapperDisplay,
			"display": "block",
			"width": me.longerW+"px",
			"height": me.longerH+"px"
		})
		me.$img.css({
			"display":"none"
		})

		//
		me.loadCompHdl = function(){
			if(me.finished) return;
			var sizeObj = Util.getImageSize( me.$img.get()[0] );
//			if((sizeObj.width==1 && sizeObj.height==1) || (me.$img.width()==1 && me.$img.height()==1)) {
			if(sizeObj.width==1 && sizeObj.height==1) {
				setTimeout(function(){
					me.loadCompHdl()
				}, 1000)
				return;
			}
			me.finished = true;
			me.$img.unbind("imgLoad", me.loadCompHdl);
			me.$img.unbind("load", me.loadCompHdl);
			setTimeout(function(){

				me.isLoading = false;
				me.isLoaded = true;

				me.$img.css({
					"display":"inline",
					"position": "absolute"
				});
				if(me.withFrame){
					me.$img.css({
						"border":"10px solid "+me.frameClr
					});
				}
				
				me._resize();	

				me.$img.fadeTo(0,0);

				if(me.callback) {
					me.callback();
					me.callback = null;
				}

				if(me.isShow) {
					me.isShow = false;
					me.show();
				}
			},100)
		}

		if(me.autoLoad) {
			me.load();
		}
	},

	_resize:function(time){
		var me = this;
		if(!me.isLoaded) return;
		if(!me.sizeObj) {
			me.sizeObj = Util.getImageSize( me.$img.get()[0] );
			me.iw = me.sizeObj.width;
			me.ih = me.sizeObj.height;
		}
		var scale;
		if(me.baseLong) {
			if(me.trim) scale = Math.max(me.longerW/me.baseLong, me.longerH/me.baseLong);
			else scale = Math.min(me.longerW/me.baseLong, me.longerH/me.baseLong);
		}
		else {
			if(me.trim) scale = Math.max(me.longerW/me.iw, me.longerH/me.ih);
			else scale = Math.min(me.longerW/me.iw, me.longerH/me.ih);
		}
		me.w = (me.iw*scale+0.5|0);
		me.h = (me.ih*scale+0.5|0);
		me.x = me.longerW-me.w+0.5>>1;
		me.y = me.longerH-me.h+0.5|0;
		if(me.sideFit) me.x = 0;
		if(me.vCenter) me.y = me.longerH-me.h+0.5>>1;
		if(me.withFrame) {
			me.x -= 10;
			me.y -= 10;
		}
		if(time) {
			me.$img.stop().animate({
				"width": me.w+"px",
				"height": me.h+"px",
				"left": me.x+"px",
				"top": me.y+"px"
			}, time, "easeInOutQuart");
		} else {
			me.$img.css({
				"width": me.w+"px",
				"height": me.h+"px",
				"left": me.x+"px",
				"top": me.y+"px"
			});
		}
		me.$.css({
			"width": me.longerW+"px",
			"height": me.longerH+"px"
		})
		if(me.sideFit) {
			me.$.css({
				"width": me.w+"px"
			})
		}
	},

	setLong:function(longer){
		var me = this;
		me.longer = longer;
		me.longerW = me.longerH = me.longer;
		me._resize();
	},

	setLongs:function(longerW, longerH){
		var me = this;
		me.longerW = longerW;
		me.longerH = longerH;
		me._resize();
	},

	animateTo:function(longerW, longerH, time){
		var me = this;
		me.longerW = longerW;
		me.longerH = longerH;
		me._resize(time);
	},

	load:function(callback){
		var me = this;
		if(me.isLoading || me.isLoaded) {
			if(callback) callback();
			return;
		}
		me.isLoading = true;
		me.isShow = true;
		me.$img.attr("src", "data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
		me.$img.attr("src", me.path)
		me.$img.bind("imgLoad", me.loadCompHdl);
		me.$img.bind("load", me.loadCompHdl);
		if(me.isIE && me.$img.width()>28) me.loadCompHdl();
		me.callback = callback;
	},

	show:function(isDirect){
		var me = this;
		if(me.isShow) return;
		me.isShow = true;

		if(me.isLoading) return;
		if(!me.isLoaded) return;

		var ta = (me.isSelect)? 0.3: 1;

		if(me.showDelayID) clearTimeout(me.showDelayID);
		me.showDelayID = setTimeout(function(){
			me.$img.css("display", "inline").stop().fadeTo(((isDirect||me.noAnime)? 0: me.transTime), ta, function(){
				$(this).css('filter', 'none');
			});
		}, me.showDelay)
	},

	hide:function(isDirect){
		var me = this;
		if(!me.isShow) return;
		me.isShow = false;

		if(me.showDelayID) clearTimeout(me.showDelayID);
		me.$img.stop().fadeTo((isDirect? 0: me.transTime), 0, function(){
			$(this).css("display", "none")
		});
	},

	selection:function(isSelect){
		var me = this;
		if(me.isSelect == isSelect) return;
		if(isSelect) {
			me.mouseover();
			me.isSelect = true;
		} else {  
			me.isSelect = false;
			me.mouseout();
		}
	},

	mouseover:function(){
		var me = this;
		if(me.isSelect) return;
		if(me.isLoading) return;
		if(!me.isLoaded) return;
		if(!me.isShow) return;
		me.$img.stop().fadeTo(200, 0.3, function(){
		});
	},

	mouseout:function(){
		var me = this;
		if(me.isSelect) return;
		if(me.isLoading) return;
		if(!me.isLoaded) return;
		if(!me.isShow) return;
		me.$img.stop().fadeTo(300, 1, function(){
			$(this).css('filter', 'none');
		});
	},

	destroy:function(){
		var me = this;
		me.$img.unbind("load", me.loadCompHdl)
		me.$img.unbind("imgLoad", me.loadCompHdl)
		if(me.showDelayID) clearTimeout(me.showDelayID);
		me.callback = null;
		me.$ = null;
		me.$img = null;
	}
}
var PicLoaderChain = function(picLoaderArr){ this._build(picLoaderArr); }
PicLoaderChain.prototype = {

	_build:function(picLoaderArr){
		var me = this;

		//コールバック
		me.onLoadEach = function(){}
		me.onLoadComp = function(){}

		me.picLoaderArr = picLoaderArr;
	},

	start:function(delayStep){
		var me = this;
		if(!delayStep) delayStep = 0;
		me.delayStep = delayStep;

		me._loop();
	},

	_loop:function(){
		var me = this;
		if(me.picLoaderArr.length == 0) {
			me.onLoadComp();
			return;
		}
		var pic = me.picLoaderArr.shift();
		pic.load(function(){
			setTimeout(function(){
				me.onLoadEach();
				me._loop();
			}, me.delayStep)
		})
	}
}




/* チップヘルプを表示するためのボタン */
var TipBtn = function($btn, ifrName){ this._build($btn, ifrName); }
TipBtn.prototype = {

	_build:function($btn, ifrName){

		var me = this;

		//casts
		me.$ = $btn;
		me.ifrName = ifrName;

		me.$tipConte = $(".tipConte", me.$);
		if(me.$tipConte.size()==0) me.$tipConte = $("span", me.$);
		me.str = me.$tipConte.remove().html();
		me.$tipConte.html("")

		me.$
		.mouseover(function(e){
			if(parent && parent._ctrl) {
				parent._ctrl.showTipHelp(me.$, me.str, me.ifrName);
			}
		})
		.mouseout(function(e){
			if(parent && parent._ctrl) {
				parent._ctrl.hideTipHelp();
			}
		})
		
		//クリックを無効に
		if(me.$.attr("href")=="#"){
			me.$
			.css("cursor", "default")
			.click(function(){
				return false;
			})
		}

	}
}


/* チップヘルプ */
var TipHelp = function(){ this._build(); }
TipHelp.prototype = {

	_build:function(){
		var me = this;

		//casts
		me.$ = $("#tipHelp");
		me.$inner = $(".inner", me.$);

		me.$.fadeTo(0,0).css("display", "none");

		me.$.mouseleave(function(){
			me.hide();
		})
	},

	show:function($btn, str, $iframe){
		var me = this;

		me.$inner.html(str);
		setTimeout(function(){
			var gx = $btn.offset().left + $btn.width()*0.5;
			var gy = $btn.offset().top;
			if($iframe) {
				gx += $iframe.offset().left;
				gy += $iframe.offset().top;
			}
			var tx = gx - me.$.width()*0.5 + 0.5|0;
			var ty = gy - me.$.height() + 0.5|0;
			var time = (_ctrl.ie)? 0: 200;
			me.$.stop().css({
				"left": tx+"px",
				"top": ty+"px",
				"display": "block"
			}).fadeTo(time, 1, function(){
				me.$.css("filter", "none");
			});
		}, 0);

	},

	hide:function(){
		var me = this;
		setTimeout(function(){
			var time = (_ctrl.ie)? 0: 100;
			me.$.stop().fadeTo(time, 0, function(){
				me.$.css({
					"display": "none"
				});
			});
		}, 0);
	}
}

/* ソーシャルボタンたちをポップアップに */
var SocialIcons = function($socials){ this._build($socials); }
SocialIcons.prototype = {

	_build:function($socials){
		var me = this;

		//casts
		me.$ = $socials;

		if(!me.$ || me.$.size()==0) return;

		//twitter
		$(".twitter a", me.$).click(function(){
			window.open( $(this).attr("href"), "pop", 'width=720, height=250, menubar=no, toolbar=no, scrollbars=yes' )
			return false;
		})
		$(".facebook a", me.$).click(function(){
			window.open( $(this).attr("href"), "pop", 'width=720, height=450, menubar=no, toolbar=no, scrollbars=yes' )
			return false;
		})

	}
}
