jQuery(document).ready(function(){

	commonLib_old. _init ();
	_action_graph. _init ();

//	_commonLib. gm_bgp_change ();
	_commonLib. view_sw_change ();		// - common library view switch controller

	jQuery("#debug_off_btn").click(function(){
		jQuery("#debug_wrap").hide();
	});

	jQuery("#action_graph_btn").click(function(){
//alert("test");
		_commonLib. _dialogs (jQuery("#_dialog_area"), "アクショングラフ", '<img src="'+_base_url+'action/php/graph.html" />', 550,510);

	});

});

var commonLib_old = {

	test_string : "test_string",

	_init : function () {
		commonLib_old. wait_msg_clear ();
//		commonLib_old. a_link_click ();
		commonLib_old. font_size_switch ();
		commonLib_old. css_remove ();
		commonLib_old. to_top_banner ();
		commonLib_old. border_off ();
		commonLib_old. border_on ();
	},

	border_off : function () {
		jQuery("#border_off_btn").click(function(){
			jQuery("#header").css("border","0px");
//			jQuery("#body_wrap").css("border","0px");
			jQuery(".contents").css("border","0px");
//			jQuery(".left_menu").css("border","0px");
//			jQuery(".blog_side_menu").css("border","0px");
			jQuery("#footer").css("border","0px");
		});
	},

	border_on : function () {
		jQuery("#border_on_btn").click(function(){
			jQuery("#header").css("border","1px solid blue");
//			jQuery("#body_wrap").css("border","1px solid blue");
			jQuery(".contents").css("border","1px solid blue");
//			jQuery(".left_menu").css("border","1px solid red");
//			jQuery(".blog_side_menu").css("border","1px solid red");
			jQuery("#footer").css("border","1px solid blue");
		});
	},

	to_top_banner : function () {
		jQuery("#site_banner").click(function(){
			location.href = _base_url;
		});
	},

	wait_msg_clear : function () {
		jQuery(".wait_msg").css("visbility","hidden");
		jQuery(".wait_msg").html("");
	},

	a_link_click : function () {
		jQuery("a").click(function(){
			jQuery(".wait_msg").css("visibility","visible");
			jQuery(".wait_msg").html("読み込み中");
		});
	},

	// css remove
	css_remove : function () {
		jQuery('#css-naked').click(function(){
			jQuery.each(jQuery.makeArray(document.styleSheets), function(){
				this.disabled=true;
			});
			jQuery('*').removeAttr('style');
		});
	},

	// fontsize switch
	font_size_switch : function () {
		var _c_body = jQuery(".contents_body");
		jQuery(".fnt_l").unbind("click");
		jQuery(".fnt_l").bind("click",function(){
			_c_body.find("p").each(function(){
				jQuery(this).css("font-size","16px").css("line-height","24px");
			});
			_c_body.find("li").each(function(){
				jQuery(this).css("font-size","16px").css("line-height","24px");
			});
			_c_body.find("h2").each(function(){
				jQuery(this).css("font-size","20px").css("line-height","26px").css("letter-spacing","2px");
			});
			_c_body.find("h3").each(function(){
				jQuery(this).css("font-size","18px").css("line-height","26px").css("letter-spacing","1px");
			});
			_c_body.find("h4").each(function(){
				jQuery(this).css("font-size","16px").css("line-height","24px").css("letter-spacing","1px");
			});
			jQuery("a").unbind("click");
		});
		jQuery(".fnt_m").unbind("click");
		jQuery(".fnt_m").bind("click",function(){
			_c_body.find("p").each(function(){
				jQuery(this).css("font-size","12px").css("line-height","18px");
			});
			_c_body.find("li").each(function(){
				jQuery(this).css("font-size","12px").css("line-height","18px");
			});
			_c_body.find("h2").each(function(){
				jQuery(this).css("font-size","16px").css("line-height","18px").css("letter-spacing","0px");
			});
			_c_body.find("h3").each(function(){
				jQuery(this).css("font-size","14px").css("line-height","16px").css("letter-spacing","0px");
			});
			_c_body.find("h4").each(function(){
				jQuery(this).css("font-size","12px").css("line-height","14px").css("letter-spacing","0px");
			});
			jQuery("a").unbind("click");
		});
	}

}

var _commonLib = {

	gm_bgp_change : function () {
		var gm_label_table = {
			"order"			: "order"
			,"statement"	: "stat"
			,"sales_report"	: "sales"
			,"goods"		: "goods"
			,"customer"		: "cust"
			,"system"		: "sys"
		};
		jQuery("#gm_"+gm_label_table[gm_params]).css("background","url("+_base_url+"image/_g_menu_btn_on.png)");
	},

	show : function (_obj, _sec, _slide) {
		if (_slide=="slide") {
			_obj. slideDown(_sec);
		} else {
			_obj. slideDown(_sec);
//			_obj. show("slide", _sec);
		}
	},

	hide : function (_obj, _sec, _slide) {
		if (_slide=="slide") {
			_obj. slideUp(_sec);
		} else {
			_obj. slideUp(_sec);
//			_obj. hide("slide", _sec);
		}
	},

	view_sw_change : function () {
		jQuery(".view_sw").click(function(){
			_target = jQuery("#" + jQuery(this).attr("target_id"));
			if (_target. css("display")!="none") {
				_commonLib. hide (_target, 200);
				jQuery(this).attr("title","開く");
			} else {
				_commonLib. show (_target, 200);
				jQuery(this).attr("title","閉じる");
			}
		});

		jQuery(".view_sw_group").click(function(){
			var _this_obj = jQuery(this);
			jQuery(".view_sw_group"). each(function(){
				var _all_target = jQuery("#"+jQuery(this).attr("target_id"));
				_commonLib. hide (_all_target, 500);
//				_all_target. slideUp (500);
			});
			_commonLib. show (jQuery("#"+_this_obj.attr("target_id")), 500);
		});

/*
		jQuery(".view_sw").mouseover(function(){
			if (jQuery(this).attr("target_id")!="debug_area") {
				jQuery(this).parent().css("border-left","8px solid #d11241");
			}
			jQuery(this).css("color","#d11241");
			jQuery(this).css("text-decoration","underline");
		});

		jQuery(".view_sw").mouseout(function(){
			if (jQuery(this).attr("target_id")!="debug_area") {
				jQuery(this).parent().css("border-left","8px solid #533");
			}
			jQuery(this).css("color","#533");
			jQuery(this).css("text-decoration","none");
		});
*/
	},

	list_bgc_mouse : function (_obj, _flag) {
		var color_str = {
			"over" : "#f8f8f8"
			,"out" : ""
		};
		_obj. css("background-color", color_str[_flag]);
	},

	detail_link_mouse : function (_obj, _attr, _target_class, _flag) {
		if (_obj. parent(). attr(_attr) != _target_class) {
			switch (_flag) {
				case "over":
					_obj. css("color", "#d11241");
					_obj. css("text-decoration", "underline");
					break;
				case "out":
					_obj. css("color", "#333");
					_obj. css("text-decoration", "none");
					break;
			}
		}
	},

	_dialogs : function (_obj, _title, _html, _width, _height) {
		_obj.dialog("close");
		_obj.remove();
		_obj.dialog({
			draggable: true,
//			draggable: false,
			resizable: false,
			autoOpen: false,
			closeOnEscape: false,
			width: _width,
			height: _height,
			modal: true,
//			show: 'drop',
//			show: 'slide',
			hide: 'fold',
			show: 'fold',
			title: _title,
			position: ['center','middle'],
			open: function(){
				_obj.html(_html);
			},
			buttons:{
//				'送信':function(){
					//『送信』ボタンを押下したときの処理
//					document.forms[0].submit();
//				},
//				Cancel:function(){
				'閉じる':function(){
					//『Cancel』ボタンを押下したときの処理
					_obj.dialog('close');
					_obj.dialog('destroy');
					_obj.html('');
					jQuery('.ui-effects-wrapper').remove();
				}
			}
			,beforeclose: function() {
			// - ダイアログを閉じる前処理
			}
		});
		_obj. dialog('open');
	},

	_dialogs_form : function (_obj, _title, _html, _width, _height, func) {
		_obj.dialog("close");
		_obj.remove();
		_obj.dialog({
			draggable: true,
//			draggable: false,
			resizable: false,
			autoOpen: false,
			closeOnEscape: false,
			width: _width,
			height: _height,
			modal: true,
//			show: 'drop',
//			show: 'slide',
			hide: 'fold',
			show: 'fold',
			title: _title,
			position: ['center','middle'],
			open: function(){
				_obj.html(_html);
			},
			buttons:{
				'送信':function(){
					//『送信』ボタンを押下したときの処理
					if (func) {
						func();
					}
					_obj.dialog('close');
//					document.forms[0].submit();
				},
//				Cancel:function(){
				'閉じる':function(){
					//『Cancel』ボタンを押下したときの処理
					_obj.dialog('close');
//					_obj.dialog('destroy');
				}
			}
			,beforeclose: function() {
			// - ダイアログを閉じる前処理
			}
		});
		_obj. dialog('open');
	},

	_ajax_html : function (_controller, _filename, _obj, _func) {
		jQuery.get(
			_base_url+'?a=controll&c=receive',
			{
				"ctrl"	: _controller,
				"file"	: _filename
			},
			function(html) {
				_obj. html(html);
				if (_func) {
					_func ();
				}
			},
			"html"
		);
	},

	_Ajax_tpl_receive : function (_template_name, _func) {
		jQuery.get(
			_base_url+'?a=controll&c=d_help',
			{
				"ctrl"	: 500,
				"file"	: _template_name
			},
			function(html) {
				if (_func) {
					_func (html);
				}
			},
			"html"
		);
	}

}

// -----
// アクショングラフ
// -----
var _action_graph = {

	_init : function () {
/*
		var _action_graph_area = jQuery("#action_graph_area");
		jQuery(".action_graph").click(function(){
// -
_action_graph. _Ajax_counter ("graph_01");
// -
			_action_graph_area.html("");
			_g_navi. _change_action_graph ();
			_action_graph_area.html(
				'<div id="_graph_01" style="display:none; width:400px; margin:125px auto;"><img src="./image/top_background03_400.jpg" width="400" height="200" border="1" /><div class="btn_tmd_close" id="_graph_01_close" style="margin:10px auto;" title="トップページへ"></div></div>'
			);
			jQuery("#_graph_01").fadeIn(500);
			jQuery("#_graph_01_close").click(function(){
				_action_graph_area.html("");
				_g_navi. _change_toppage ();
			});
		});
*/
	},

	_Ajax_counter : function (_ajact, _func) {
		jQuery.post(
			_base_url+'?a=controll&c=count',
			{
				"ctrl"	: 500,
				"file"	: 'test',
				"ajact" : (_ajact!="" ? _ajact : "")
			},
			function(json) {
				jQuery("#action_counter_str"). html(json["cnt"]);
				if (_func) {
					_func ();
				}
			},
			"json"
		);
	}

}
