function closeProfilebox(){
	window.close();
}

(function(){
	$(function(){
		$('a[href*=#]').click(function(){
			var _link = $(this).attr('href');
			var _targetH;

			if(_link == '#'){
				_targetH = 0;
			}else{
				return;
			}

			$('html,body').animate({'scrollTop':_targetH},400,'easeInOutCubic');
			return false;
		});
	});
})();

//赤文字のフォームにフォーカスしたらclassはずす（途中）
(function(){
	$(function(){
		 $('form input') .focus(function(){
				 $(this).toggleClass('.tippedCheck');
				 });
		 });
})();


//// pulldown ///////////////////////////////////////////////////////////////////////////

;(function($) {
	$.Pulldown = function(params){
		var p = params || {}
		this.$element = $(p.target);
  	this.$button = this.$element.find(p.button);
		this.$list = this.$element.find(p.list);
		this.defaultHeight = p.height || this.$list.height();

		this.speed = p.speed || 400;
		this.outTime = p.outTime || 0; //0だとすぐに隠れる。"none"を指定すると自動で隠さない.
		this.hideOver = p.hideOver == undefined ? true : p.hideOver;
		this.easing = p.easing || "liner";
		this.isShow = false;
		this.isOver = false;

		//表示するモード. clickとoverのどちらか
		this.mode = p.mode || 'over'

		var self = this;

		this._initList();
		this._initButton();
		this.hide(false);

		this.$element.css('overflow', 'visible');


		// hideOverがfalseの場合はオーバーでなにもしない。
		if( this.hideOver ){
			this.$element.hover(function(){
				self.isOver = true;
			},
			function(){
				self.isOver = false;

				//none の場合は自動で隠す処理をしない
				if(this.outTime == 'none'){
					return
				}
				setTimeout(function(){
					if(self.isOver == false){
						self.hide(true);
					}
				},p.outTime)

			})
		}
	}
	$.Pulldown.prototype = {

		show : function(animation){
			var flug = animation;

			if(flug == 'undefined'){
				flug = true;
			}

			this.$list.css({ display : 'block'})
				if(flug){
					this.$list.stop(true).animate({ height : this.defaultHeight }, this.speed, "swing");

				} else {
					this.$list.height(this.defaultHeight);
				}

				this.$element.addClass('active');
				this.isShow = true;
				this.$element.trigger('pulldown-show', [this.$element]);
			},
		hide : function(animation){
			var flug = animation,
					self = this;



			if(flug == 'undefined'){
				flug = true;
			}

			if(flug){
				this.$list.stop(true).animate({ height : 0 }, this.speed, null, function(){
					self.$element.removeClass("active");
					self.$list.css({ display : 'none' });
				});
			} else {
				this.$list.height(0);
				this.$element.removeClass('active');
			}

			  this.isShow = false;
				this.$element.trigger('pulldown-hide')
		},
		toggle : function(animation){


			if(this.isShow){
			  this.hide(animation);
			} else {
			  this.show(animation);
			}


		},
		_initButton : function(){
			var self = this;

			//開始するタイミング
			if(this.mode == "click") {
				this.$button.click(function(){
					self.toggle(true);
				})
			} else if( this.mode == "over"){
				this.$button.hover(function(){
					if( !self.isOver ){
						self.toggle(true);
					}
				},
				function(){});
			}
		},
		_initList : function(){
			this.$list.css({ overflow: 'hidden' })
		}
	}
})(jQuery);


//// 実行部分 /////

$(function(){
	var pulldownList = [];
	$('.parentNav.parent3.pulldown').each(function(){
		//セレクタ指定はtargetからのセレクタ
		//$(this).find()と同じ
		pulldownList.push(new $.Pulldown({
			mode : 'over',
			target : this,
			button : 'a.button',
			list : '.childNav',
			speed : 200,
			easing : 'liner',
			outTime : 150,
			height: 34
		}));

		// 他のpulldownが表示されたら隠れる。
		$(this).bind('pulldown-show', function(e, $elem){
			var i = 0,
					len = pulldownList.length;
			for(; i < len; i++){
				var pd = pulldownList[i];

					if(pd.$element != $elem){
						pd.hide(true);
					}
				}
			})
		})
});

/**
 * テキストエリア自動伸張
 *
 * 改行されるとテキストエリアを伸ばす。
 * 行がなくなると縮める。
 *
 * date		2011-08-30
 */
(function($) {

	$(function() {
		$("textarea.elastic").elasticHeight();
	});

	$.fn.elasticHeight = function() {
		var lineDefault = 2;

		this.each(function() {
			var self = $(this),
				clone = self.clone(),
				lineHeight = 18;  // parseInt(self.css("lineHeight"), 10);

			// clone
			clone.insertAfter(self).css({ position: "absolute", top: -1 , left: "-9999px" , overflow: "auto" }).height(0);

			_elastic = function() {
				// for IE
				self.scrollTop(0);
				// data copy & scroll
				clone.val(self.val()).scrollTop($(document).height());

				self.stop(true).animate({
					height: Math.max(clone.scrollTop(), lineHeight * lineDefault)
				}, {
					duration: 200
				});

			};

			self.bind("keydown keyup mousedown mouseup change", _elastic).change();
		});
		return this;
	};

})(jQuery);


/**
 * 現在日付をyyyyMMddHHmmssSSSで返す
 * @returns
 */
function getNowDatetime() {
	var d = new Date();

	var mm = d.getMonth()+1;
	var dd = d.getDate();
	if (mm < 10) { mm = "0" + mm; }
	if (dd < 10) { dd = "0" + dd; }
	return ""+d.getFullYear()+mm+dd+d.getHours()+d.getMinutes()+d.getSeconds()+d.getMilliseconds();
}

/**
 * 絶対urlを返す
 * @param url
 * @returns {String}
 */
function getFullUrl(url) {
	var paths = this.location.pathname.split("/");
	return this.location.protocol + "//" + this.location.host + "/" + paths[1] + "/" + url;
}


/**
 * プロフィールボックス表示
 * DOM生成版
 *
 * プロフィールリストから該当するプロフィールを呼び出し表示。
 * 閉じるボタンで非表示。
 *
 * @since	2011-08-30
 * @date	2011-10-06
 */
function showProfilebox2(url, event) {

	var profile = {
		// 背景
		shade: $("<div>", { "class": "profileShade" }),
		// ボックス
		box: $("<div>", { "class": "profileBox" }),
		// 初期化
		init: function() {
			profile.createShade();
		},
		// 背景作成
		createShade: function() {
			// IE6対策
			if ($.browser.msie && $.browser.version < 7) {
				profile.shade.height($(document).height());
			}
			profile.shade.click(profile.close).appendTo("body");
		},
		// ボックス作成
		createBox: function() {
			var fullurl = getFullUrl(url + "/dummyvalue:" + getNowDatetime());

			$.ajaxSetup({
		        beforeSend: function(xhr){
		            xhr.overrideMimeType("text/html;charset=Shift_JIS");
		            //xhr.overrideMimeType("text/html;charset=Windows-31J");
		            //xhr.overrideMimeType("text/html;charset=UTF-8");
		        }
		    });

			var lines;
			while (lines == undefined) {
				lines = $.ajax({
					  url: fullurl,
					  async: false
					 }).responseText;
			}

//			var obj = document.createElement('div');
//			obj.innerHTML = lines;
//			var target = obj.lastChild.innerHTML;

			profile.box.html(lines);
			profile.box.css({
				position: "absolute",
				top: 0,
				left: 0,
				zIndex: 30
			}).appendTo("body");
			$(".close", profile.box[0]).click(profile.close);
		},
		// 閉じる処理
		close: function(event) {
			profile.shade.stop(true).fadeOut();
			profile.box.remove();
			event.preventDefault();
		}
	}

	// 初期化
	profile.init();

	// ボックスを生成
	profile.createBox();

	profile.shade.show();

	var target;
	if($.browser.msie) {
		target = event.srcElement;
    } else {
    	target = event.target;
    }


	profile.shade.fadeTo(200, 0.5);
	profile.box.css({
		top: $(window).scrollTop() + 30,
		left: "50%",
		marginLeft: profile.box.height() / -2
	}).show();

	return false;
}


/**
 * プロフィールボックス表示
 * iframe版
 *
 * プロフィールリストから該当するプロフィールを呼び出し表示。
 * 閉じるボタンで非表示。
 * @param url
 */
/*
var g_profile = null;
function showProfilebox(url) {

	if (!g_profile) {
		g_profile = {
				// 背景
				shade: $("<div>", { "class": "profileShade" }),
				// ボックス
				box: $("<iframe>", { id: "area-profileBox", frameborder: 0, scrolling: "no" }),
				// 初期化
				init: function() {
					g_profile.createShade();
					g_profile.createBox();
				},
				// 背景作成
				createShade: function() {
					// IE6対策
					if ($.browser.msie && $.browser.version < 7) {
						g_profile.shade.height($(document).height());
					}
					g_profile.shade.click(g_profile.close).appendTo("body");
				},
				// ボックス作成
				createBox: function() {
					// iframe内にページが読み込まれた後の処理を設定
					g_profile.box.load(function() {
						if (!this.src) {
							return false;
						}
						var dataBox = $("#area-profileBox").contents().find(".profileBox");

						g_profile.shade.show();
						g_profile.box.show().css({
							display: "block",	// show()のコールバックで"display: inline"になるため
							top: $(window).scrollTop() + 20,
							left: "50%",
							marginLeft: dataBox.width() / -2
						});
						$(this).width(dataBox.width())
							.height(dataBox.height());
						// 閉じるボタン
						$(".close", g_profile.box.contents()).click(g_profile.close);
					}).appendTo("body");
				},
				// 閉じる処理
				close: function(event) {
					g_profile.shade.stop(true).fadeOut();
					g_profile.box.contents().empty().end().hide();
					event && event.preventDefault();
				}
			}

			// 初期化
			g_profile.init();
	}
    // シェードは呼び出しのたびに再作成
	g_profile.createShade();

   // 指定されたURLのページをiframe内に読み込む
	var fullurl = getFullUrl(url + "/dummyvalue:" + getNowDatetime());
	g_profile.box.attr("src", fullurl);

	return false;
}
*/

/* プロフィール ポップアップ */
function showProfilebox(url) {
     var fullurl = getFullUrl(url);
	 window.open(fullurl, "", "width=530,height=650,resizable=yes,scrollbars=yes");
	 return false;
}



/* table内のテキスト折り返し */
//(function($) {
//
//	$(function(){
//			var $targetElement = 'td p.txtComment';
//			if($.browser.msie) {
//					$($targetElement).css('word-break', 'break-all');
//			} else {
//					$($targetElement).each(function(){
//						    //if(navigator.userAgent.indexOf('Firefox/2') != -1) {
//							//		$(this).html($(this).text().split('').join('<wbr />'));
//							//} else {
//						            var testarray = $(this).text().split('');
//						            var test = testarray.join(String.fromCharCode(8203));
//						            var testarray2 = test.split('\n');
//						            var test2 = testarray2.join("<br />");
//						            $(this).html(test2);
//									//$(this).html($(this).text().split('').join(String.fromCharCode(8203)));
//							//}
//					});
//			}
//	});
//})(jQuery);

/* table内のテキスト折り返し */
(function($) {

	$(function(){
			var $targetElement = 'dl dd.txtReComment';
			if($.browser.msie) {
					$($targetElement).css('word-break', 'break-all');
			} else {
					$($targetElement).each(function(){
						    //if(navigator.userAgent.indexOf('Firefox/2') != -1) {
							//		$(this).html($(this).text().split('').join('<wbr />'));
							//} else {
						            var testarray = $(this).text().split('');
						            var test = testarray.join(String.fromCharCode(8203));
						            var testarray2 = test.split('\n');
						            var test2 = testarray2.join("<br />");
						            $(this).html(test2);
									//$(this).html($(this).text().split('').join(String.fromCharCode(8203)));
							//}
					});
			}
	});
})(jQuery);

/* table内のテキスト折り返し top用 */
(function($) {

	$(function(){
		$('.mod_bbsAreaInner p.ttl a, .mod_bbsAreaInner p.txt a').addClass('wrapTxt');
	});

	$(function(){
		var $targetElement = ('td p.txtComment , a.wrapTxt');
		if($.browser.msie) {
				$($targetElement).css({
						'word-break': 'break-all',
						'word-wrap': 'break-word'
						});
		} else {
				$($targetElement).each(function(){
					var testarray = $(this).text().split('');
		            var test = testarray.join(String.fromCharCode(8203));
		            var testarray2 = test.split('\n');
		            var test2 = testarray2.join("<br />");
		            $(this).html(test2);
					//$(this).html($(this).text().split('').join(String.fromCharCode(8203)));
				});
		}
	});
})(jQuery);

/* table内のテキスト折り返し(<a>版) */
(function($) {

	$(function(){
			var $targetElement = 'td p.txtCommentForLink';
			if($.browser.msie) {
					$($targetElement).css('word-break', 'break-all');
			} else {
					$($targetElement).each(function(){
						            var testarray = $(this).text().split('');
						            var test = testarray.join(String.fromCharCode(8203));
						            var testarray2 = test.split('\n');
						            var test2 = testarray2.join("<br />");

						            var aChild = this.firstElementChild;
						            aChild.innerHTML = test2;

						            $(this).html(aChild);
					});
			}
	});
})(jQuery);



/* テキストエリアの文字数カウント */
(function($){
	$(function () {
			 $("textarea.txtCount").keyup(function(){
						var counter = $(this).val().length;
					$("p.countUp span").text(counter);
					if(counter == 0){
							$("p.countUp span").text("0");
					}
					if(counter >= 2000){
							$("p.countUp span").css({"color":"#e25f58","font-weight":"bold"});
					} else{$("p.countUp span").css("color","#44423a");}
			});
	});
})(jQuery);

//画像ロールオーバー
(function($) {
		$(function(){
							 //class名.rolloverをもつ画像にマウスオーバーで_onを付与
				 $("img.rollover").mouseover(function(){
							$(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
							//マウスオーバーで与えた_onをマウスアウトで取り除く
							}).mouseout(function(){
								$(this).attr("src",$(this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2"));
							});
				 });
})(jQuery);

