/**<?php
 * tsumiki2.0
 *
 * PHP versions 5.2.0 upper
 *
 * Copyright 2009-2011, MAGREX 
 *
 * @copyright		Copyright 2009-2011, MAGREX
 * @link			http://www.magrex.co.jp/
 * @version			2.0.0.9
 * @lastmodified	2011-10-07
 *
*/

var contents_callback = {
	root_path: function(){
		return jQuery('#root_path').html() || '';
	}
};

//ブラウザ言語(現状日本語以外は全て英語)
var contents_browser_lang = (function(){
	var lang = "";
	var langs = {"ja":""};
	
	var temp = (navigator.browserLanguage || navigator.language || navigator.userLanguage).substr(0,2);
	if(temp in langs){
		lang = temp;
	}
	if(lang === ""){
		lang = "en";
	}
	return lang;
})();

//多言語対応
var contents_langs = {
	"ja":[	
			"を選択をして下さい",
			"のチェックをして下さい",
			"を入力して下さい",
			"を正しく入力して下さい",
			"が（確認用）と一致しません。正しく入力して下さい。",
			"成功しました",
			"データが見つかりません"
		],
	"en":[
			"Please select it",
			"Please check it",
			"Please input it",
			"Please input it correctly.",
			"(for confirmation)It doesn't agree.  Please input it correctly. ",
			"It succeeded. ",
			"Data is not found. "
	]
};

var flip_arr;
var ticker_timers = [];
var reset_Content = function(){

//ticker
	var length = ticker_timers.length;
	for(var i=0; i<length; i++){
		clearInterval(ticker_timers[i]);
	}
	ticker_timers = [];

	$(".me-ticker").each(function(){
		$(this).removeAttr("loop");
	});

//form
	$(".formObject").each(function(){
		//クリック処理
		$(":button", jQuery(this)).unbind("click").click(function(button){
		});
	});
};

(function($){
$(function(){

	var state = {};
	(function(state){
		state.ua = navigator.userAgent;
		state.spn = state.ua.match(/(?:Android|iPhone|IEMobile)/i);
		state.preview = $("#base_url").length;
	})(state);

	var init = function(){

		forSmartphone.init();

		if(!state.spn){

			if(!state.preview){
				accessCounter();
			}

			image_popup();
			newsticker();
			changeFontsize();
			uiSpriteButton.init();
			uiScroll.init();
			uiImageflip.init();
			uiAccordion.init();
			uiTab.init();
			LCO.init();
			globalmenu.init();
			asSiteSearch.init();

		}

	};


/*	URLからの自動処理
 *
 */
	var url_checker = (function(){
		var check = true;
		if( $("#base_url").size() ){
			if($("#isload").html() !== ""){
				check = false;
			}
		}
		if(check){
			var temps = location.search.split("&");
			var i=0,j, length = temps.length, length, s, temp, mode, datas = {};
			if(length > 0){
				for(; i<length; ++i){
					temp = temps[i].split("=");
					length1 = temp.length;
					if(length1 >= 2){
						if(temp[0] === "?mode"){
							mode = temp[1];
						}else{
							if(length1 === 2){
								datas[ temp[0] ] = temp[1];
							}else{
								s = "";
								for(j=1; j<length1; ++j){
									s += temp[j];
									if(j !== (length1-1)){
										s += "=";
									}
								}
								datas[ temp[0] ] = s;
							}
						}
					}
				}

				if( $("#base_url").size() ){
					$("#isload").html("true");
				}
				if(mode === "topic"){
					var contents_id = ("contents_id" in datas) ? datas["contents_id"] : "";
					var data_id     = ("data_id" in datas)     ? datas["data_id"]     : "";
					var condition   = ("condition" in datas)   ? datas["condition"]   : "";
					topicView( contents_id, data_id, condition);
				}
			}
		}
	})();


	// ディレクトリの取得
	// 開発と公開の分岐をする
	var sitedir = (function(){
		if( $("#base_url").size() ){
			return ($("#base_url").html())?$("#base_url").html()+"/":"/tsumiki2/";
		}else{
			var path = $("#root_path").html();
			return path;
		}
	})();

	// !change font-size
	var changeFontsize = function(){
		$("#fontsS, #fontsM, #fontsL, #fontsXL").click(function(){
			$("body").removeClass("fontsS fontsM fontsL fontsXL")
				.addClass($(this).attr("id"));
		});
	};

	// !image_popup
	var image_popup = function(){
		var css = sitedir +"library/fancybox/jquery.fancybox-1.3.0.css";
		var script = sitedir +"library/fancybox/jquery.fancybox-1.3.0.pack.js";
		if($(".image_popup").length){
			
			if(!$("link[href="+ css +"]").length){
				$("head").append("<link href=\""+ css +"\" type=\"text/css\" rel=\"stylesheet\">");
			}
			
			if($.fancybox){
				$(".image_popup").fancybox({"titlePosition"  : "over"});
			} else {
			    $.getScript(script, function(){
					$(".image_popup").fancybox({"titlePosition"  : "over"});
				});
			}
		}
	};


	// !newsticker
	var newsticker = function(){
		if($(".me-ticker").size()){
			//time
			var speed = 3000;
			var pause = 8000;
			
			$(".me-ticker").each(function(i,data){
				//ul,liのset
				$(this).attr("loop", 0);
				var tag = $(this);
				var w = tag.width();
				var h = $("li:first",tag).height();
				tag.css({"margin":"10px","overflow":"hidden"}).width(w-20).height(h);
				$("li",tag).css({"position":"absolute","left":w+"px","opacity":0}).width(w-20);
				
				//start
				$("li:eq(0)",tag).animate({"left": "10px","opacity":1}, speed);
				
				//loop
				ticker_timers[i] = setInterval(function(){
					$("li:eq("+ $(tag).attr("loop") +")",tag).animate({"opacity":0}, "slow",function(){
						$("li:eq("+ $(tag).attr("loop") +")",tag).css({"position":"absolute","left":w+"px","opacity":0});
	
						var i = parseInt($(tag).attr("loop")) + 1;
						if(i >= $("li",tag).length){
							i=0;
						}
						$(tag).attr("loop", i);
						$("li:eq("+ i +")",tag).animate({"left": "10px","opacity":1}, speed);
					});
				},pause);
			});
		}
	};

	// access counter
	var createHttpRequest = function(){
		// Win ie用
		if( window.ActiveXObject ){
			try {
				// MSXML2以降用
				return new ActiveXObject( "Msxml2.XMLHTTP" );
			} catch (e) {
				try {
					// 旧MSXML用
					return new ActiveXObject( "Microsoft.XMLHTTP" );
				} catch (e2) {
					return null;
				}
			}
		}
		else if( window.XMLHttpRequest ){
			// Win ie以外のXMLHttpRequestオブジェクト実装ブラウザ用
			return new XMLHttpRequest();
		}
		else{
			return null;
		}
	};
	
	
	var accessCounter = function()
	{
		var i, j, num, c_flag;
		// cookieの設定準備
		var name = "counter";			// クッキーの名前
		var date = document.cookie;		// 以前の値を保存。
		var d = new Date();
		var e = new Date();
		e.setTime( d.getTime() + (1000*60*60*3) );
	
		// リセット動作
		var c = 0;

		// 日時の判定
		c_flag = true;
		if( date ){
			var cs = date.split( "; " );
			for( i = 0; i < cs.length; i++ ){
				// NAMEの値が『counter』であるクッキーを見つける。
				if( cs[i] == "NAME=" + name ){
					c_flag = false;		// 数値は変えずに、カウンタのクラスだけ書き換えたいから。
					break;	// 目的のクッキー以外は見る必要が無いので抜ける。
				}
			}
	
			// 他にクッキーがあるけど、目的のクッキーが無い場合
			if( i == cs.length ){
				document.cookie = "NAME=" + name + ";expires=" + e.toGMTString() + ";";
			}
		}
		else{
			// 目的のクッキーが無い場合
			document.cookie = "NAME=" + name + ";expires=" + e.toGMTString() + ";";
		}
	
	
		// カウンタ書き換え用関数
		function chgCounter()
		{
			var httpoj2 = createHttpRequest();
			if( !httpoj2 ){
				return;
			}
	
			// ファイルの存在確認。どうやら『静的ファイルにPOSTが使えない』って話があるらしい。
			var date = new Date();		// IEでキャッシュから読み込ませないようにするため。
			var d_url = sitedir + "data/count.dat?time=" + date.getTime();
			httpoj2.open( "GET", d_url, false );		// false（同期）にしないと、ファイルの存在確認ができない。
			httpoj2.send( null );
			if( httpoj2.status != 200 ){
				return;
			}
	
			// readyState値は4で受信完了
			if( httpoj2.readyState == 4 ){
				var a_num = $(".accesscounter").length;			// カウンタの個数
				var cl_name = "ac_";	// 接頭文字（変わると面倒なので）
				var count;		// カウンタの数字
				var num;		// １番下の桁の数値
				var n;			// 右から何番目を処理しているか（始まりの値は１）
				var len;		// アクセスカウンタの桁数
				var tmp;
	
				for( var a = 0; a < a_num; a++ ){
					count = parseInt( httpoj2.responseText );
					n = 0;
					len = $(".accesscounter:eq("+a+") li").length;		// a番目のアクセスカウンタが持ってる<li>の個数を取得。
					$(".accesscounter:eq("+a+") li").attr( "class", "" );
					// 置いてあるカウンタの桁数だけ処理するので、実際の数値があふれてても無視できる。
					for( var i = 0; i < len; i++ ){
						// 常に１番下の桁の数値を取って、１０で割り続ける。
						num = count % 10;
						count = parseInt( count / 10 );
						// クラスの書き換え。
						n++;
						tmp = cl_name + num;
						$(".accesscounter:eq("+a+") li").eq(len-n).addClass(tmp);
					}
				}
			}
		}
	
		// counter.phpを呼んで、count.datを書き換える
		if( c_flag || (c == 1) ){
			// PHP呼び出し準備
			var httpoj = createHttpRequest();
			if( !httpoj ){
				return;
			}
	
			// ファイルの存在確認。どうやら『静的ファイルにPOSTが使えない』って話があるらしいけど、IEだとここはPOSTじゃなきゃ動かない。
			var p_url = sitedir + "php/accesscounter/counter.php";
			if( (i = navigator.userAgent.indexOf("MSIE")) >= 0 ){
				// IEの場合。
				httpoj.open( "POST", p_url, false );		// false（同期）にしないと、ファイルの存在確認ができない。
			}
			else{
				// それ以外。
				httpoj.open( "GET", p_url, false );			// false（同期）にしないと、ファイルの存在確認ができない。
			}
			httpoj.send( null );
			if( httpoj.status != 200 ){
				return;
			}
		}
	
		// カウンタ書き換え
		chgCounter();
	
		// 無駄なspanタグを消す
		num = $(".accesscounter").length;
		for( i = 0; i < num; i++ ){
			var p = $(".accesscounter").parent();
			$("span", p).remove();
		}
	};



/* フォームユニット処理
 *
 */	
	var formObject = function(){
		$(".formObject").each(function(i,object){
			//ID付与
			var $object = $(this);
			$("[name=id]", $object).attr("value", "jquery");
	
			var alert_mess = $("[name=alert_mess]", $object).attr("value");
			var sendFlg = false;
	
			//クリック処理
			$(":button", $object).unbind("click").click(function(button){
				if(!sendFlg){
					var error_mess = "", before = "", pd = "", str="", type="", $name;
					//値のチェック
					$("[name^='text']", $object).each(function(){
						if(before != this.name){
							before = this.name;
							$name = $(this);
							//データチェック & 
							type = $name.attr("type");
							if(type === "radio"){//radio
								value="";
								$(":radio", $name.parent()).each(function(){
									if(this.checked){
										value = this.value;
										return false;
									}
								});
								if((value === "") && chkRequired($name)){
									error_mess = $.trim($name.parent().prev().text()) + contents_langs[contents_browser_lang][0];
									return false;
								}else{
									pd += "&" + this.name + "=" + encodeURIComponent(value);
								}
							}else if( type === "checkbox"){//check
								value=0;
								$(":checkbox", $name.parent()).each(function(){
									if(this.checked){
										pd += "&" + this.name + "[" + value + "]=" + encodeURIComponent($(this).attr("value"));
										value++;
									}
								});
								if((value === 0) && chkRequired($name)){
									error_mess = $.trim( $name.parent().prev().text()) + contents_langs[contents_browser_lang][1];
									return false;
								}
							}else if(this.tagName.toLowerCase() === "select"){//select
								value = $("option:selected", $name).attr("value");
								if((value === "") && chkRequired($name)){
									error_mess = $.trim($name.parent().prev().text()) + contents_langs[contents_browser_lang][0];
									return false;
								}else{
									pd += "&" + this.name + "=" + encodeURIComponent(value);
								}	
							}else if( (type === "text") || (this.tagName.toLowerCase() === "textarea")){
								if(($name.attr("value") === "") && chkRequired($name)){
									error_mess = $.trim($name.parent().prev().text()) + contents_langs[contents_browser_lang][2];
									return false;
								}else{
									if($name.attr("mail") === "1"){
										if(!$name.attr("value").match( /^[A-Za-z0-9._-]+[\w-]+[\w-]+@[\w\.-]+\.\w{2,}$/) ) {
											error_mess = $.trim($name.parent().prev().text()) + contents_langs[contents_browser_lang][3];
											return false;
										}
										str = this.name.split("_");
										if(str.length === 2){
											if($("[name=" + str[0]  + "_1]", $object).attr("value") != $name.attr("value")){
												error_mess = $.trim($name.parent().prev().text()) + contents_langs[contents_browser_lang][4];
												return false;
											}
										}
									}
									pd += "&" + this.name + "=" + encodeURIComponent($name.attr("value"));
								}
							}
						}
					});
					if(error_mess === ""){
						if(confirm(alert_mess)){
							sendFlg = true;
	
							var root_path = "", program_path="";
							var data_path = $object.parent().attr("medata");
							if($("#base_url").html() != null){
								//ルートパスを得る
								root_path = $("#base_url").html() + "/";
								program_path = root_path;
							}else{
								root_path = "";
								program_path = $("#root_path").html();
								data_path = $("#my_dir").html() + data_path;
							}
	
							pd += "&id=" + $("[name=id]", $object).attr("value");
							pd += "&data_path=" + data_path;
							pd += "&root_path=" +  root_path;
							//送信
							$.ajax({
								url: program_path + "php/form.php",
								type: "post",
								data: pd,
								cache: false, 
								scriptCharset: "utf-8",
								dataType: "json",
								success: function(data, dataType){
									if(sendFlg){
										sendFlg = false;
										if(data.res === "true"){
											if(data.redirect != ""){
												if($("#base_url").html() != null){
													//URlで問い合わせ
													postdata = {"data[url]": data.redirect};
													$.post(sitedir + "/site_pages/getdatabyurl/current",postdata,function(data){
														if(data){
															location.href = sitedir + "/site_pages/preview/" + data.SitePage.id;
														}else{
															alert(contents_langs[contents_browser_lang][5]);
														}
													},"json");
												}else{
													location.href = data.redirect;
												}
											}else{
												alert(contents_langs[contents_browser_lang][5]);
											}
										}else{
											alert(data.mess);
										}
									}
								},
								error: function(XMLHttpRequest,textStatus){
									sendFlg = false;
									alert(textStatus);
								}
							});
						}
					}else{
						alert(error_mess);
					}
				}
			});

			function chkRequired($t){
				var t = $('<div>').append($t.clone()).html();
				return t.indexOf('required') > 0 ? !(t.match(/required=\"?0/i) !== null) : false;
			}

		});
	}();


/* sprite button
*/
	var uiSpriteButton = {
		init: function(){
			$.each($('.button_sprite'), function(){
				var $btn = $(this);
				var $wrap = $btn.parents('p');
				var left = parseInt($btn.css('left'));
				var width = $wrap.width();
				$btn.unbind('hover').hover(
					function(){
						$btn.css('left', (left - width) + 'px');
					},
					function(){
						$btn.css('left', left + 'px');
					}
				);
			});
		}
	};


/* トピックユニット処理
 *
 */
	var topic2Object = function(){
		$(".topic2Object").each(function(i,object){
			var $object = $(this);
			var sendFlg = false;
			//クリック処理
			$(":button", $object).unbind("click").click(function(button){
				if(!sendFlg){
					var contents_id = $(this).attr("contents_id"), pd="";
					sendFlg = true;

					var root_path = "", program_path="", preview="";
					var data_path = $object.parent().attr("medata");
					if($("#base_url").html() != null){
						//ルートパスを得る
						root_path = $("#base_url").html() + "/";
						program_path = root_path;
						preview = "true";
					}else{
						preview = "false";
						root_path = "";
						program_path = $("#root_path").html();
						data_path = $("#my_dir").html() + data_path;
					}

					if(preview === "true"){
						me_indicator.on();	
					}
		
					pd += "&preview=" + preview;
					pd += "&contents_id=" + contents_id;
					pd += "&template_path=" + data_path;
					pd += "&root_path=" +  root_path;
					pd += "&condition=" +  $(this).attr("condition");
		
					$.ajax({
						url: program_path + "php/topic.php",
						type: "post",
						data: pd,
						cache: false, 
						scriptCharset: "utf-8",
						dataType: "json",
						success: function(data, dataType){
							if(sendFlg){
								sendFlg = false;
								if(data.res === "true"){
									var $o;
									$(".data_container", $object).html( data.view );
									if(data.before_display === "block"){
										$o = $("button[name='before']", $object);
										$o.show();
										$o.attr("condition", data.before_condition);
										$o.attr("contents_id", contents_id);
									}else{
										$("button[name='before']", $object).hide();
									}
									if(data.next_display === "block"){
										$o = $("button[name='next']", $object);
										$o.show();
										$o.attr("condition", data.next_condition);
										$o.attr("contents_id", contents_id);
									}else{
										$("button[name='next']", $object).hide();
									}

									if(preview === "true"){
										me_indicator.off();	
									}

									location.href="#contents_"+contents_id;

								}else{
									if(preview === "true"){
										me_indicator.off();	
									}
									alert(data.mess);
								}
							}
						},
						error: function(XMLHttpRequest,textStatus){
							if(preview === "true"){
								me_indicator.off();	
							}
							sendFlg = false;
							alert(textStatus);
						}
					});
				}
			});
		});
	}();



/* トピックの描画処理
 *
 */
	function topicView(param1, param2, param3){
		var contents_id=param1, data_id=param2, condition=param3, pd="";
		var $target = $(".topic2Object[contents_id='"+contents_id+"']");
		if($target !== void 0){	
			var root_path = "", program_path="", preview="";
			var data_path = $target.parent().attr("medata");
			if($("#base_url").html() != null){
				//ルートパスを得る
				root_path = $("#base_url").html() + "/";
				program_path = root_path;
				preview = "true";
			}else{
				preview = "false";
				root_path = "";
				program_path = $("#root_path").html();
				data_path = $("#my_dir").html() + data_path;
			}

			if(preview === "true"){
				me_indicator.on();	
			}
		
			pd += "&preview=" + preview;
			pd += "&contents_id=" + contents_id;
			pd += "&data_id=" + data_id;
			pd += "&template_path=" + data_path;
			pd += "&root_path=" +  root_path;
			pd += "&condition=" +  condition;
		
			$.ajax({
				url: program_path + "php/topic.php",
				type: "post",
				data: pd,
				cache: false, 
				scriptCharset: "utf-8",
				dataType: "json",
				success: function(data, dataType){
					if(data.res == "true"){
						var $o;
						$(".data_container", $target).html( data.view );
						if(data.before_display === "block"){
							$o = $("button[name='before']", $target);
							$o.show();
							$o.attr("condition", data.before_condition);
							$o.attr("contents_id", contents_id);
						}else{
							$("button[name='before']", $target).hide();
						}
						if(data.next_display === "block"){
							$o = $("button[name='next']", $target); 
							$o.show();
							$o.attr("condition", data.next_condition);
							$o.attr("contents_id", contents_id);
						}else{
							$("button[name='next']", $target).hide();
						}
						if(preview === "true"){
							me_indicator.off();	
						}
						location.href="#contents_"+contents_id;
					}else{
						if(preview === "true"){
							me_indicator.off();	
						}
						alert(data.mess);
					}
				},
				error: function(XMLHttpRequest,textStatus){
					if(preview === "true"){
						me_indicator.off();	
					}
					alert(textStatus);
				}
			});
		}else{
			alert(contents_langs[contents_browser_lang][6]);
		}
	}



/* smartphone 限定動作
 * 
 */

	var forSmartphone = {
		init: function(){
			var ua = (navigator.userAgent.indexOf("iPhone")>=0 || navigator.userAgent.indexOf("iPod")>=0) ? true : false;
			if( ua ){
				this.treeMenu();
			}
		},
		treeMenu: function(){
			$("#menu .contents > ul > .havechild > ul").hide();
			$("#menu .contents > ul > .havechild > ul > .havechild > ul").hide();
			TM_init($("#menu .contents > ul"));
			function TM_init(elem, sp, so){
				if (!sp) sp = 400;
				if (!so) so = false;
				$(">li:has(ul)", elem).each(function() {
					var myTree = this;
					$(">:first-child", myTree).click(function(e){
						var target = this;
						$(">li:has(ul)", elem).each(function(){
							if ($(">:first-child", this).get()[0] == target){
								$(">ul:first", this).slideToggle(sp);
							}else if (so == true){
								$(">ul:first", this).slideUp(sp);
							}
						});
					});
					TM_init($(">ul:first", myTree), sp, so);
				});
			}
		}
	};



/* ページ内スクロール処理
 * 
 */
	var uiScroll = {
		init: function(){
			$(".ui_pagescroll").click( function(){
				var nums = String($(this).attr('class')).split(' ');
				var speed = 0;
				for( var i = 0; i < nums.length; i++ ){
					if( String(nums[i]).indexOf( 'ui_pagescroll_spd-' ) != -1 ){
						speed = String(nums[i]).split('-')[1];
						break;
					}
				}

				var anc = $(this).attr('href');
				var targetOffset = 0;
				if( anc != '#' ){		// ページトップに行ってくれないので。
					targetOffset = $(anc).offset().top;
				}
				$('html,body').animate( {scrollTop: targetOffset}, parseInt(speed) );

				return false;
			});
		}
	};


/* スライド切り替え処理
 * 
 */
	var uiImageflip = {};
	(function(uiImageflip){
		flip_arr = {};//pre version
		uiImageflip.init = function(){
			var $tgts = $('.imageflip');
			var btnHovOpacity = 1;
			var btnOnOpacity = 0.8;
			var btnNormalOpacity = 0.3;
			var len = $tgts.length;
			var i;
			for (i=0;i<len;i++){
				var tgt = $($tgts[i]);
				var vercheck_ind = tgt.attr('class').search('ver2');
				if(vercheck_ind != -1){
					//ver2
					eachSet(tgt);
				}else{
					//pre version
					tgt.each(function(){
						var $this = $(this);
						var n = $this.parents('.contents').eq(0).attr('id');
						if( !flip_arr[n] ){
							flip_arr[n] = new Object;
						}
						flip_arr[n].timer = $this.attr('slidetimer') * 1000;
						flip_arr[n].waittime = $this.attr('waittime') * 1000;
						flip_arr[n].slidetype = $this.attr('slidetype');
						flip_arr[n].flip_t = setTimeout(function(){ slidenext(n, -1); }, flip_arr[n].timer);
					});
					// ボタン部の処理
					tgt.find(".imageflipbutton-item").unbind("click").click(function(){
						var $this  = $(this);
						if( $this.hasClass('selected') ){
							return;// 今選択中なら動かさない。
						}
						var n = $this.parents('.contents').eq(0).attr('id');
						var num = this.className.match( /imageflipbtn_(\d+)/ );
						clearTimeout( flip_arr[n].flip_t );
						slidenext( n, parseInt(num[1]) );		// 割り込みたいので待たない。
					});
					//
				}
			}
			function eachSet(tgt) {
				var tgtBody = tgt.find('.imageflipbody');
				var btnGroup = tgt.find('.imageflipbutton');
				var objArr = [];
				var len = tgtBody.find('.imageflipbody-item').length;
				if(len <= 1){
					return;
				}
				for (var i=0;i<len;i++){
					var t = tgtBody.find('.imageflipbody-item').eq(i);
					if(i > 0) {
						t.css({'display':'none'});
					}
					t.hover(
						function(){
							imgHov();
						},
						function(){
							imgOut();
						}
					);
					objArr.push(t);
				}
				var in_slide_key = 'no';
				var ind = tgt.attr('class').search('imgflp_');
				var str = tgt.attr('class').substr(ind);//imgflp_type001_500_rl_5000
				var tdlrArr = str.split('_');//["imgflp", "type001", "500", "rl","5000"] 0:no use, 1:slidetype, 2:duration milli seconds, 3:orientation-right to left, 4:wait time milli seconds
				var slideArr = {
					type: tdlrArr[1],
					duration: parseInt(tdlrArr[2]),
					orient: tdlrArr[3],
					from: 'timer'
				};
				var W = tgtBody.width();
				var H = tgtBody.height();
				var waitTime = parseInt(tdlrArr[4]);
				var orient_normal = slideArr.orient;
				var orient_opposite = slideArr.orient;
				if(orient_normal == 'rl') {
					orient_opposite = 'lr';
				}
				if(orient_normal == 'tb') {
					orient_opposite = 'bt';
				}
				evtTim = false;
				var evtBtn_lr;
				var evtBtn_group;
				var evtBtn_hov;
				var nownextArr = [0,1];//[1,5] now=1,next=5
				var bridge_afterNowArr = [];
				var eEase = 'easeOutQuart';
				//imageflipbutton
				var btnArr = {
					group:[],
					lr:[]
				};
				for (var i=0;i<len;i++){
					var btng = btnGroup.find('.imageflipbutton-item').eq(i);
					if(i == 0) {
						btng.css({'opacity':btnOnOpacity});
					}
					function btng_Hov(){
						var myInd = btnGroup.find('.imageflipbutton-item').index(this);
						btngHov(myInd);
					}
					function btng_Out(){
						var myInd = btnGroup.find('.imageflipbutton-item').index(this);
						btngOut(myInd);
					}
					function btng_Click() {
						var myInd = btnGroup.find('.imageflipbutton-item').index(this);
						btngClick(myInd);
					}
					btng.unbind();
					btng.bind('mouseenter',btng_Hov);
					btng.bind('mouseleave',btng_Out);
					btng.bind('click',btng_Click);
					btnArr.group.push(btng);
				}
				function btnLR_Hov(arg) {
						var myInd = arg.data.num;
						btnLRHov(myInd);
				}
				function btnLR_Out(arg) {
						var myInd = arg.data.num;
						btnLROut(myInd);
				}
				function btnLR_Click(arg){
					var myInd = arg.data.num;
					btnLRClick(myInd);
				}
				for (var i = 0;i < 2; i++){
					if(i == 0){
						var obj = tgt.find('.imageflip-lrbtn').find('.lbtn');
					}else if(i == 1){
						var obj = tgt.find('.imageflip-lrbtn').find('.rbtn');
					}
					obj.unbind();
					obj.bind('mouseenter',{num:i},btnLR_Hov);
					obj.bind('mouseleave',{num:i},btnLR_Out);
					obj.bind('click',{num:i},btnLR_Click);
					btnArr.lr.push(obj);
				}
				startTimer();
				function slideImg(arr) {
					btnStop();
					stopTimer();
					nownextArr = nownextChecker(arr);
					var slide_orient = orientChecker(nownextArr);
					if(slideArr.from == 'btn_group'){
						switch(slide_orient){
							case 'normal':
								slideArr.orient = orient_normal;
								break;
							case 'opposite':
								slideArr.orient = orient_opposite;
								break;
							default:
								slideArr.orient = orient_normal;
								break;
						}
					}else if(slideArr.from == 'btn_lr_r'){
						slideArr.orient = orient_normal;
					}else if(slideArr.from == 'btn_lr_l'){
						slideArr.orient = orient_opposite;
					}else if(slideArr.from == 'timer'){
						slideArr.orient = orient_normal;
					}
					var objNow = tgt.find('.imageflipbody-item').eq(nownextArr[0]).stop().queue([]);
					var objNext = tgt.find('.imageflipbody-item').eq(nownextArr[1]).stop().queue([]);
					var eTypeNow;
					var eTypeNext;
					var nowW = objNow.width();
					var nowH = objNow.height();
					var nextW = objNext.width();
					var nextH = objNext.height();
					bridge_afterNowArr = [objNow,nowW,nowH,arr.type];
					changeBtnG(nownextArr);
					switch(arr.type){
						case 'slide':
							switch(arr.orient){
								case 'rl'://R to L
									objNow.css({
									});
									objNext.css({
										'display': 'block',
										'left': W + 'px'
									});
									eTypeNow = {left : - nowW + 'px'};
									eTypeNext = {left : (W - nextW) / 2 + 'px'};
									break;
								case 'lr'://L to R
									objNow.css({
									});
									objNext.css({
										'display': 'block',
										'left': -nextW + 'px'
									});
									eTypeNow = {left : W + 'px'};
									eTypeNext = {left : (W - nextW) / 2 + 'px'};
									break;
								case 'tb'://Top to Bottom
									objNow.css({
									});
									objNext.css({
										'display': 'block',
										'top': -nextH + 'px'
									});
									eTypeNow = {top : H + 'px'};
									eTypeNext = {top : (H - nextH) / 2 + 'px'};
									break;
								case 'bt'://Bottom to Top
									objNow.css({
									});
									objNext.css({
										'display': 'block',
										'top': H + 'px'
									});
									eTypeNow = {top : -H + 'px'};
									eTypeNext = {top : (H - nextH) / 2 + 'px'};
									break;
							}
							break;
						case 'away':
							switch(arr.orient){
								case 'rl'://R to L
									objNow.css({
										'z-index':1
									});
									objNext.css({
										'z-index':0,
										'display': 'block',
										'top': (H - nextH) / 2 + 'px',
										'left': (W - nextW) / 2 + 'px'
									});
									eTypeNow = {left : - nowW + 'px'};
									eTypeNext = {display: 'block'};
									break;
								case 'lr'://L to R
									objNow.css({
										'z-index':1
									});
									objNext.css({
										'z-index':0,
										'display': 'block',
										'top': (H - nextH) / 2 + 'px',
										'left': (W - nextW) / 2 + 'px'
									});
									eTypeNow = {left : W + 'px'};
									eTypeNext = {display: 'block'};
									break;
								case 'tb'://Top to Bottom
									objNow.css({
										'z-index':1
									});
									objNext.css({
										'z-index':0,
										'display': 'block',
										'top': (H - nextH) / 2 + 'px',
										'left': (W - nextW) / 2 + 'px'
									});
									eTypeNow = {top : H + 'px'};
									eTypeNext = {display: 'block'};
									break;
								case 'bt'://Bottom to Top
									objNow.css({
										'z-index':1
									});
									objNext.css({
										'z-index':0,
										'display': 'block',
										'top': (H - nextH) / 2 + 'px',
										'left': (W - nextW) / 2 + 'px'
									});
									eTypeNow = {top : -nowH + 'px'};
									eTypeNext = {display: 'block'};
									break;
							}
							break;
						case 'zoomout':
							switch(arr.orient){
								default:
									objNow.css({
										'z-index':1
									});
									objNext.css({
										'z-index':0,
										'display': 'block',
										'opacity': 1
									});
									eTypeNow = {width: 0 + 'px', height: 0 + 'px', opacity: 0};
									eTypeNext = {display: 'block'};
									break;
							}
							break;
						case 'zoomin':
							switch(arr.orient){
								default:
									objNow.css({
										'z-index':0
									});
									objNext.css({
										'z-index':1,
										'display': 'block',
										'top': (H - nextH) / 2 + 'px',
										'left': (W - nextW) / 2 + 'px',
										'width': 0 + 'px',
										'height': 0 + 'px',
										'opacity': 0
									});
									eTypeNow = {display: 'block'};
									eTypeNext = {width: nextW + 'px', height: nextH + 'px', opacity: 1};
									break;
							}
							break;
						case 'fade':
							switch(arr.orient){
								default:
									objNow.css({
										'z-index':1
									});
									objNext.css({
										'z-index':0,
										'display': 'block',
										'opacity': 1
									});
									eTypeNow = {opacity: 0};
									eTypeNext = {opacity: 1};
									break;
							}
							break;
						case 'over':
							switch(arr.orient){
								case 'rl'://R to L
									objNow.css({
										'z-index':0
									});
									objNext.css({
										'z-index':1,
										'display': 'block',
										'top': (H - nextH) / 2 + 'px',
										'left': W + 'px'
									});
									eTypeNow = {display: 'block'};
									eTypeNext = {left: (W - nextW) / 2 + 'px'};
									break;
								case 'lr'://L to R
									objNow.css({
										'z-index':0
									});
									objNext.css({
										'z-index':1,
										'display': 'block',
										'top': (H - nextH) / 2 + 'px',
										'left': -nextW + 'px'
									});
									eTypeNow = {display: 'block'};
									eTypeNext = {left: (W - nextW) / 2 + 'px'};
									break;
								case 'tb'://Top to Bottom
									objNow.css({
										'z-index':0
									});
									objNext.css({
										'z-index':1,
										'display': 'block',
										'top': -H + 'px',
										'left': (W - nextW) / 2 + 'px'
									});
									eTypeNow = {display: 'block'};
									eTypeNext = {top: (H - nextH) / 2 + 'px'};
									break;
								case 'bt'://Bottom to Top
									objNow.css({
										'z-index':0
									});
									objNext.css({
										'z-index':1,
										'display': 'block',
										'top': nextH + 'px',
										'left': (W - nextW) / 2 + 'px'
									});
									eTypeNow = {display: 'block'};
									eTypeNext = {top: (H - nextH) / 2 + 'px'};
									break;
							}
							break;
					}
					objNow.animate(eTypeNow, arr.duration, eEase, callback_slideImgNow);
					objNext.animate(eTypeNext, arr.duration, eEase, callback_slideImgNext);
				}
				function callback_slideImgNow() {
					var obj = bridge_afterNowArr[0];
					var w = bridge_afterNowArr[1];
					var h = bridge_afterNowArr[2];
					var type = bridge_afterNowArr[3];
					switch(type){
						case 'zoomout':
						obj.css({
							'width': w + 'px',
							'height': h + 'px',
							'display': 'block'
						});
						break;
						case 'zoomin':
							obj.css({
								'display': 'none'
							});
							break;
						case 'over':
							obj.css({
								'display': 'none'
							});
							break;
						default:
							break;
					}
				}
				function callback_slideImgNext() {
					nownextArr[0] = nownextArr[1];
					btnStart();
					if(slideArr.from == 'timer' && (typeof me_guard == 'undefined' || (typeof me_guard != 'undefined' && me_guard.property.status.mode != 'edit'))){
						startTimer();
					}
				}
				function nownextChecker(arr) {
					var now = nownextArr[0];
					var next;
					var return_arr = [];
					switch(arr.from){
						case 'timer':
							next = now + 1;
							if(next >= len){
								next = 0;
							}
							return_arr = [now,next];
							break;
						case 'btn_lr_l':
							return_arr = nownextArr;
							break;
						case 'btn_lr_r':
							return_arr = nownextArr;
							break;
						case 'btn_group':
							return_arr = nownextArr;
							break;
					}
					return return_arr;
				}
				function orientChecker(arr){
					var now = arr[0];
					var next = arr[1];
					var key = now - next;
					if(key < 0){
						return 'normal';
					}else if(key > 0){
						return 'opposite';
					}
				}
				function stopTimer() {
					clearInterval(evtTim);
				}
				function startTimer(){
					if(typeof me_guard != 'undefined' && me_guard.property.status.mode == 'edit'){
						timKiller();
						return;
					}
					if(in_slide_key == 'yes'){
						return;
					}
					timKiller();
					evtTim = setTimeout(function(){slideImg(slideArr);},waitTime);
				}
				function timKiller(){
					clearTimeout(evtTim);
				}
				function changeBtnG(nnArr){
					btnArr.group[nnArr[0]].css({'opacity':btnNormalOpacity});
					btnArr.group[nnArr[1]].css({'opacity':btnOnOpacity});
				}
				function btngHov(ind){
					var tgt = btnArr.group[ind];
					tgt.css({
						'opacity': btnHovOpacity
					});
					if(in_slide_key == 'yes'){
						return;
					}
					stopTimer();
				}
				function btngOut(ind){
					var tgt = btnArr.group[ind];
					if(in_slide_key == 'yes'){
					}else {
						tgt.css({
							'opacity': btnNormalOpacity
						});
						var tgt2 = btnArr.group[nownextArr[0]];
						tgt2.css({
							'opacity': btnOnOpacity
						});
					}
					slideArr.from = 'timer';
					startTimer();
				}
				function btngClick(ind){
					if(in_slide_key == 'yes'){
						return;
					}
					if(ind == nownextArr[0]){
						return;
					}
					slideArr.from = 'btn_group';
					nownextArr[1] = ind;
					slideImg(slideArr);
				}
				function btnLRHov(ind){
					var tgt = btnArr.lr[ind];
					tgt.find('.backg').css({
						'opacity': btnHovOpacity
					});
					if(in_slide_key == 'yes'){
						return;
					}
					stopTimer();
				}
				function btnLROut(ind){
					var tgt = btnArr.lr[ind];
					tgt.find('.backg').css({
						'opacity': btnNormalOpacity
					});
					slideArr.from = 'timer';
					startTimer();
				}
				function btnLRClick(ind){
					if(in_slide_key == 'yes'){
						return;
					}
					var now = nownextArr[0];
					var next;
					var len = objArr.length;
					switch(ind){
						case 0:
							next = now -1;
							if(next < 0){
								next = len -1;
							}
							nownextArr[1] = next;
							slideArr.from = 'btn_lr_l';
							break;
						case 1:
							next = now + 1;
							if(next >= len){
								next = 0;
							}
							nownextArr[1] = next;
							slideArr.from = 'btn_lr_r';
							break;
					}
					slideImg(slideArr);
				}
				function imgHov(){
					if(in_slide_key == 'yes'){
						return false;
					}
					stopTimer();
				}
				function imgOut(){
					slideArr.from = 'timer';
					startTimer();
				}
				function btnStop(){
					in_slide_key = 'yes';
				}
				function btnStart(){
					in_slide_key = 'no';
				}
			}

			//pre version
			function slidenext( contnts_id, index ){
				var id = '#' + contnts_id + ' .imageflip';
				var that = $(id).eq(0);
				var $now_slide = $(id).eq(0);
				var $preimage, $nextimage;
				var wait_flag = false;
				var pre_index;

				// これから消えるヤツと次に出すヤツを取得。
				if( index >= 0 ){		// 指定された場合
					wait_flag = true;
					clearTimeout( flip_arr[contnts_id].flip_t );
					$('.imageflipbody-item', that).each( function( i ){
						var $this = $(this);
						if( $this.hasClass('current') ){
							$this.removeClass('current');
							$preimage = $this;
							pre_index = i;
							return;
						}
					});
					$nextimage = $('.imageflipbody-item', that).eq(index);
				}
				else{				// 通常ループ
					$('.imageflipbody-item', that).each( function( i ){
						var $this = $(this);
						if( $this.hasClass('current') ){
							$this.removeClass('current');
							$preimage = $this;
							$nextimage = $this.next();
							index = i + 1;
							pre_index = i;
							if( $nextimage.length == 0 ){
								$nextimage = $('.imageflipbody-item:first', $now_slide);
								index = 0;
							}
							return;
						}
					});
				}

				// ボタン部にクラスを付ける。
				var $buttons = $( '.imageflipbutton-item', that );
				if( (index >= 0) && $buttons ){
					$buttons.each(function(){
						$(this).removeClass('selected');
					});
					$buttons.eq(index).addClass('selected');
				}

				// 動き。表示させないものは『display:none』に。
				if( $preimage && $nextimage && flip_arr[contnts_id] ){
					$nextimage.css('display','block').addClass('current');
					$preimage.css('display','block');

					switch( flip_arr[contnts_id].slidetype )
					{
					case 'left_to_right':			// 右から左に
						var move_val = parseInt( $('.imageflipbody', that).css('width') );		// 動く量
			 			$nextimage.css( 'z-index', 10 ).css( 'margin-left', move_val );		// まず右に飛ばす
			 			$preimage.css( 'z-index', 2 );
						$nextimage.animate(
							{marginLeft: 0}, "slow",		// 徐々に動かす
							function(){
								$nextimage.css( 'z-index', 2 );
								$preimage.css( 'z-index', 1 ).css('display','none');
							}
						);
						break;

					case 'top_to_bottom':			// 上から下に
						var move_val = parseInt( $('.imageflipbody', that).css('height') );		// 動く量
						$nextimage.css( 'z-index', 10 ).css( 'margin-top', -move_val );		// まず上に飛ばす
			 			$preimage.css( 'z-index', 2 );
						$nextimage.animate(
							{marginTop: 0}, "slow",		// 徐々に動かす
							function(){
								$nextimage.css( 'z-index', 2 );
								$preimage.css( 'z-index', 1 ).css('display','none');
							}
						);
						break;

					case 'fade':			// フェード
						$nextimage.css( 'opacity', 0 ).css( 'z-index', 2 );
			 			$preimage.css( 'z-index', 10 );
						$preimage.animate(
							{opacity: 0}, "slow",		// 徐々に消す
							function(){
					 			$nextimage.css( 'z-index', 10 );
					 			$preimage.css( 'z-index', 2 );
								$nextimage.animate(
									{opacity: 1}, "slow",		// 徐々に出す
									function(){
										$nextimage.css( 'z-index', 2 );
										$preimage.css( 'z-index', 1 ).css( 'opacity', 1 ).css('display','none');
									}
								);
							}
						);
						break;

					case 'zoom_in':			// ズームイン（DIVのズーム）
						var x = parseInt($('.imageflipbody', that).css('width')) / 2;
						var y = parseInt($('.imageflipbody', that).css('height')) / 2;
			 			$preimage.css( 'z-index', 2 );
						$nextimage.css( 'z-index', 10 ).css( 'width', "0%" ).css( 'height', "0%" ).css( 'margin-left', x ).css( 'margin-top', y );
						$nextimage.animate(
							{width: "100%", height: "100%", marginLeft:0, marginTop:0}, "slow",		// 徐々に動かす
							function(){
								$nextimage.css( 'z-index', 2 );
								$preimage.css( 'z-index', 1 ).css('display','none');
							}
						);
						break;

					case 'zoom_out':			// ズームアウト（DIVのズーム）
						var x = parseInt($('.imageflipbody', that).css('width')) / 2;
						var y = parseInt($('.imageflipbody', that).css('height')) / 2;
			 			$nextimage.css( 'z-index', 2 );
			 			$preimage.css( 'z-index', 10 );
						$preimage.animate(
							{width: "0%", height: "0%", marginLeft:x, marginTop:y}, "slow",		// 徐々に動かす
							function(){
								$nextimage.css( 'z-index', 2 );
								$preimage.css( 'z-index', 1 ).css('display','none').css( 'width', "100%" ).css( 'height', "100%" ).css( 'margin-left', 0 ).css( 'margin-top', 0 );
							}
						);
						break;

					case 'pre_go_right':			// 今のを左に
						var move_val = parseInt( $('.imageflipbody', that).css('width') );
			 			$nextimage.css( 'z-index', 2 );
			 			$preimage.css( 'z-index', 10 );
						$preimage.animate(
							{marginLeft: -move_val}, "slow",		// 徐々に動かす
							function(){
								$preimage.css( 'z-index', 1 ).css('display','none').css( 'margin-left', 0 );
							}
						);
						break;

					case 'pre_go_bottom':			// 今のを下に
						var move_val = parseInt( $('.imageflipbody', that).css('height') );
			 			$nextimage.css( 'z-index', 2 );
			 			$preimage.css( 'z-index', 10 );
						$preimage.animate(
							{marginTop: move_val}, "slow",		// 徐々に動かす
							function(){
								$preimage.css( 'z-index', 1 ).css('display','none').css( 'margin-top', 0 );
							}
						);
						break;

					case 'joint_lr':			// 繋げて左右に
						// 塊の作成と設置
						var $m_div = $( document.createElement("div") );
						var div_h = parseInt( $('.imageflipbody',that).css('height') );
						var div_num;
						if( wait_flag ){
							div_num = Math.abs( index - pre_index );
						}
						else{
							div_num = 1;
						}
						var div_w = parseInt( $('.imageflipbody',that).css('width') ) * (div_num+1);
						var move_val = parseInt( $('.imageflipbody',that).css('width') ) * div_num;

						// 先に、開始画像と終了画像の順番を決めて設置
						if( wait_flag && ((pre_index - index) > 0) ){
							$m_div.append( $nextimage.clone().css('float','left').css('position','relative') ).append( $preimage.clone().css('float','left').css('position','relative') ).css('margin-left',-move_val);
						}
						else{
							move_val = move_val * (-1);
							$m_div.append( $preimage.clone().css('float','left').css('position','relative') ).append( $nextimage.clone().css('float','left').css('position','relative') );
						}

						// さらに間に画像がある場合
						if( div_num > 1 ){
							var s_i = Math.min( index, pre_index );
							for( var i = 0; i < div_num; i++ ){
								// 常に最後の１つ前に挿入
								$(".imageflipbody-item:last",$m_div).before( $('.imageflipbody-item', that).eq(s_i+i+1).clone().css('display','block').css('float','left').css('position','relative') );
							}
						}

						// 塊を置く
						$m_div.css('z-index',10).css('width',div_w).css('height',div_h).css('float','left').css('overflow','hidden').css('position','relative');
						$('.imageflipbody', that).eq(0).append( $m_div );

						// 動かす
						move_val = "+=" + move_val + "px";
						$m_div.animate(
							{marginLeft: move_val}, "slow",
							function(){
								$m_div.remove();
								$nextimage.css( 'z-index', 2 );
								$preimage.css( 'z-index', 1 ).css('display','none');		// 他のdivは出していないので消すのはこれだけ。
							}
						);
						break;

					case 'joint_ud':			// 繋げて上下に
						// 塊の作成と設置
						var $m_div = $( document.createElement("div") );
						var div_w = parseInt( $('.imageflipbody',that).css('width') );
						var div_num;
						if( wait_flag ){
							div_num = Math.abs( index - pre_index );
						}
						else{
							div_num = 1;
						}
						var div_h = parseInt( $('.imageflipbody',that).css('height') ) * (div_num+1);
						var move_val = parseInt( $('.imageflipbody',that).css('height') ) * div_num;

						// 先に、開始画像と終了画像の順番を決めて設置
						if( wait_flag && ((pre_index - index) > 0) ){
							$m_div.append( $nextimage.clone().css('position','relative') ).append( $preimage.clone().css('position','relative') ).css('margin-top',-move_val);
						}
						else{
							move_val = move_val * (-1);
							$m_div.append( $preimage.clone().css('position','relative') ).append( $nextimage.clone().css('position','relative') );
						}

						// さらに間に画像がある場合
						if( div_num > 1 ){
							var s_i = Math.min( index, pre_index );
							for( var i = 0; i < div_num; i++ ){
								// 常に最後の１つ前に挿入
								$(".imageflipbody-item:last",$m_div).before( $('.imageflipbody-item', that).eq(s_i+i+1).clone().css('display','block').css('position','relative') );
							}
						}

						// 塊を置く
						$m_div.css('z-index',10).css('width',div_w).css('height',div_h).css('overflow','hidden').css('position','relative');
						$('.imageflipbody', that).eq(0).append( $m_div );

						// 動かす
						move_val = "+=" + move_val + "px";
						$m_div.animate(
							{marginTop: move_val}, "slow",
							function(){
								$m_div.remove();
								$nextimage.css( 'z-index', 2 );
								$preimage.css( 'z-index', 1 ).css('display','none');		// 他のdivは出していないので消すのはこれだけ。
							}
						);
						break;

					default:
						break;
					}

					// 次の時間まで待つ。
					if( wait_flag ){
						flip_arr[contnts_id].flip_t = setTimeout(function(){ slidenext(contnts_id, -1); }, flip_arr[contnts_id].waittime);
					}
					else{
						flip_arr[contnts_id].flip_t = setTimeout(function(){ slidenext(contnts_id, -1); }, flip_arr[contnts_id].timer);
					}
				}
			}
		};
	})(uiImageflip);

/* アコーディオン
 * 
 */
	var uiAccordion = {
		init: function(){
			$('.accordiontitle').unbind('click').click( function(){
				var speed = 0;
				if( this.className.match(/ui_accordion-spd-(\d+)/) ){
					speed = parseInt(this.className.match(/ui_accordion-spd-(\d+)/)[1]) || 0;
				}

				var $b = $(this).parents(".accordionbox:first").find(".accordionbody:first");
				if( $b.css('display') == 'none' ){
					$b.slideDown(speed);
				}else{
					$b.slideUp(speed);
				}
			});
		}
	};


/* タブ
 * 
 */
	var uiTab = {
		init: function(){
			$('.tabthumb-item').unbind('click').click( function(){
				var $this = $(this);
				if( this.className.indexOf('tabthumb-selected') < 0 ){
					var $tabbox = $this.parents('.tabbox').eq(0);
					var $indeces = $('.tabthumb-item', $tabbox);
					if( $indeces.length < 2 ) return false;
					var $bodies = $('.tabbody-item', $tabbox);
					var $last = $('.tabthumb-selected', $tabbox).removeClass('tabthumb-selected');
					var last = $last.prevAll().length;
					$('.tabthumb-selected', $tabbox).removeClass('tabthumb-selected');
					var num = $this.prevAll().length;
					$indeces.eq(num).addClass('tabthumb-selected');
					var anim = $tabbox.attr('class').match(/ui_tabbox-anim-([a-z]+)/)[1] || 'none';
					switch( anim ){
						case 'fade':
							$bodies.hide();
							$bodies.eq(num).fadeIn(500);
							break;
						case 'slide':
							$bodies.eq(last).slideUp(300, function(){
								$bodies.eq(num).slideDown(300);
							});
							break;
						default:
							$bodies.hide();
							$bodies.eq(num).show();
							break;
					}
				}
				return true;
			});
		}
	};


/* LCO
*/

	var LCO = {
		init: function(){
			try{
				var rules = lcorules;
			}catch(e){
				return false;
			}
			var edit = $('#base_url').length;
			if(edit){
				$('head').prepend('<style type="text/css">\n.contents.ui_lco-hide-contents{display:none}\n.me-editNow .contents.ui_lco-hide-contents{display:block}\n<\/style>\n');
			}
			var state = [true, false, false, false, false, false, false, false, false, false];
			var words = (function(ref){
				var query = null;
			    if(ref.match(/^http:\/\/(www)?\.?google.*/i)){
					if (ref.match(/&q=/)){
						query = ref.replace(/^.*&q=([^&]+)&?.*$/i, '$1');
					}
			    } 
				else if (ref.match(/^http:\/\/search\.yahoo.*/i)) {
					if (ref.match(/p=/)){
						query = ref.replace(/^.*p=([^&]+)&?.*$/i, '$1');
					}
			    }
				else if(ref.match(/^http:\/\/(www)?\.?bing.*/i)){
					if (ref.match(/q=/)){
						query = ref.replace(/^.*q=([^&]+)&?.*$/i, '$1');
					}
			    } 
				else if(ref.match(/^http:\/\/search\.goo.*/i)){
					if (ref.match(/MT=/)){
						query = ref.replace(/^.*MT=([^&]+)&?.*$/i, '$1');
					}
			    } 
				else if(ref.match(/^http:\/\/websearch\.rakuten.*/i)){
					if (ref.match(/qt=/)){
					    query = ref.replace(/^.*qt=([^&]+)&?.*$/i, '$1');
					}
			    } 
				else if(ref.match(/^http:\/\/cgi\.search\.biglobe.*/i)){
					if (ref.match(/q=/)){
					    query = ref.replace(/^.*q=([^&]+)&?.*$/i, '$1');
					}
			    } 
				else if(ref.match(/^http:\/\/(www)?\.?excite.*/i)){
					if (ref.match(/search=/)){
						query = ref.replace(/^.*search=([^&]+)&?.*$/i, '$1');
					}
			    } 
				else if(ref.match(/^http:\/\/livedoor-search.*/i)){
					if (ref.match(/q=/)){
						query = ref.replace(/^.*q=([^&]+)&?.*$/i, '$1');
					}
			    } 
				else if(ref.match(/^http:\/\/search\.nifty.*/i)){
					if (ref.match(/q=/)){
					    query = ref.replace(/^.*q=([^&]+)&?.*$/i, '$1');
					}
			    } 
				else if(ref.match(/^http:\/\/search\.fresheye.*/i)){
					if (ref.match(/kw=/)){
					    query = ref.replace(/^.*kw=([^&]+)&?.*$/i, '$1');
					}
			    } 
				else if (ref.match(/^http:\/\/search\.lycos.*/i)) {
					if (ref.match(/query=/)){
					    query = ref.replace(/^.*query=([^&]+)&?.*$/i, '$1');
					}
			    } 
				else if (ref.match(/^http:\/\/(www)?\.?ask.*/i)) {
					if (ref.match(/q=/)){
					    query = ref.replace(/^.*q=([^&]+)&?.*$/i, '$1');
					}
			    } 
			    if (query) {
					query = decodeURIComponent(query);
					query = query.replace(/[\'\"]/g, '');
				}
				return query;
			})(document.referrer);
			if(words){
				for(var i = 1, p; i < 10; i++){
					if(rules[i][0]){
						p = new RegExp(rules[i][0].join('|'));
						if(words.match(p)){
							state[0] = false;
							state[i] = true;
							break;
						}
					}
				}
			}
			for(var i = 0; i < 10; i++){
				if(!state[i] && rules[i][1]){
					for(var n = 0, len = rules[i][1].length; n < len; n++){
						if(!edit){
							$('#contents_' + rules[i][1][n]).hide();
						}else{
							$('#contents_' + rules[i][1][n]).addClass('ui_lco-hide-contents');
						}
					}
				}
			}
			return true;
		}
	};

/*グローバルメニュー*/
	var globalmenu = {
		init: function(){
			var $tgts = $('.globalmenu');
			var len = $tgts.length;
			var i;
			for (i=0;i<len;i++){
				var tgt = $($tgts[i]);
				eachSet(tgt);
			}
			function eachSet(tgt){
				//animation parameter
				var clsstr1 = tgt.attr('class').toString();
				if(clsstr1.match(/animation\w\D*/) == null){
					return;
				}
				var clsstr2 = clsstr1.match(/animation\w\D*/).toString();
				var a_str = clsstr2.substr(clsstr2.search(/animation_/) + ('animation_').length);
				var eTypeS;
				var eTypeH;
				switch(a_str){
					case 'peel':
						eTypeS = {height : "show" };
						eTypeH = {height : "hide" };
						break;
					default://fade
						eTypeS = {opacity : "show" };
						eTypeH = {opacity : "hide" };
						break;
				}
				var eSeconds = 200;
				var eEase = "linear";
				//opacity
				var $target = tgt.find('.depth0');
				//var $target = $(".depth0");
				if($target.length <= 0) {
					return;
				}
				if($target !== void 0){
					var opacity_str = $target.attr('class').toString();
					var temp = opacity_str.match(/\s*opacity\d*/);
					if(temp){
						var o_str1 = opacity_str.match(/\s*opacity\d*/).toString();
						var o_str2 = o_str1.substr(o_str1.search(/opacity/) + ('opacity').length);
						var o_num = parseInt(o_str2) / 100;
						var $all_li_a = $target.find('li').find('a');
						$all_li_a.hover(
							function(){
								$(this).css('opacity', o_num);
							},
							function(){
								$(this).css('opacity', 1);
							}
						);
						//timer parameter
						var tim_arr = {};
						var delaySeconds = 300;
						//the body
						var $depth0li = $target.find('li');
						//var $depth0li = $('.depth0 > li');
						$depth0li.mouseenter(function(){
							var $ul = $(this).find('.depth1');
							$(this).parent().css({'z-index':10});
							$ul.css({'z-index':1});
							var myInd = $(this).parent().children().index(this);
							if(tim_arr[myInd]){
								clearTimeout( tim_arr[myInd]);
								delete tim_arr[myInd];
							}
							$ul.animate(eTypeS, eSeconds, eEase, callback_show);
						});
						function callback_show() {
						}
						function hide_delay(obj) {
							obj.animate(eTypeH, eSeconds, eEase, callback_hide());
							function callback_hide() {
								obj.css({'z-index':''});
								obj.parent().parent().css({'z-index':''});
							}
						}
						$depth0li.mouseleave(function(){
							var $ul = $(this).find('.depth1');
							bridgeObj = $ul;
							var myInd = $(this).parent().children().index(this);
							tim_arr[myInd] = setTimeout(function(){hide_delay($ul);},delaySeconds);
						});
					}
				}
			}
		}
	};


/* asSiteSearch
*/

	var asSiteSearch = {
		init: function(){
			$('.asSiteSearch-content').each(function(e){
				var site = $('.asSiteSearch-site', this).val();
				var info = $('.asSiteSearch-info', this).html();
				var alert_text = $('.asSiteSearch-alert', this).html();
				var $input = $('.asSiteSearch-input', this);
				var $submit = $('.asSiteSearch-button', this);

				var setInfo = {
					enable: function(){
						$input.val(info).addClass('asSiteSearch-blank').css('color', '#ccc');
					},
					disable: function(){
						$input.val('').removeClass('asSiteSearch-blank').css('color', '#333');
					}
				};

				function chkEnough(){
					var v = $input.val(), chk = true;
					if(v == '' || v == info){
						alert(alert_text);
						setInfo.enable();
						chk = false;
					}
					return chk;
				}

				$input.unbind().focus(function(){
					if(this.className.indexOf('asSiteSearch-blank') > 0){
						setInfo.disable();
					}
				}).blur(function(){
					if(this.value === ''){
						setInfo.enable();
					}
				});

				$submit.unbind().click(function(){
					if(!chkEnough()){
						return false;
					}
				});

				setInfo.enable();
			});
		}
	};



	init();

});
})(jQuery);
/* eof
?>*/
