
/*	
	パッケージオブジェクトを拡張
	継承機能を追加
*/
(
	function($package) {
		
		
		/**
		 * defineClass
		 * クラス作成処理
		 * @param c コンストラクタ
		 * @param m メソッド
		 * @return クラス
		 */
		$package.defineClass = function(c, m) {
			if (m != null) {
				c.prototype = m;
			} else {
				function f(){};
				c.prototype = new f();
			}
			c.prototype.constructor = c;
			return c;
		};
		
		$package.extend = function(s, c)
		{
			function f(){};
			f.prototype = s.prototype;
			c.prototype = new f();
			c.prototype.__super__ = s.prototype;    // __super__のところを superclass とかにしてもOK!!
			c.prototype.__super__.constructor = s;  // 上に同じく。但し、 super は予約語。
			c.prototype.constructor = c;
			return c;
		};
		
	}
	
)($Package);



/*	
	ユーティリティベースクラスsuperUtilを引数のオブジェクトに定義
*/
(
	function($package) {
	
		//クラスを定義
		$package.superUtil = function() {//コンストラクタ
			
			
			/* function to fix the -10000 pixel limit of jquery.animate */
			$.fx.prototype.cur = function(){
				if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
					return this.elem[ this.prop ];
				}
				var r = parseFloat( jQuery.css( this.elem, this.prop ) );
				return typeof r == 'undefined' ? 0 : r;
			}

			//配列にシャッフル機能を追加
			Array.prototype.shuffle = function() {
				var i = this.length;
				while(i){
					var j = Math.floor(Math.random()*i);
					var t = this[--i];
					this[i] = this[j];
					this[j] = t;
				}
				return this;
			}
			
			//配列にユニーク機能を追加
			Array.prototype.unique = function() {
				var storage = {};
				var uniqueArray = [];
				var i,value,l;
				for ( i=0, l = this.length; i<l; i++) {
					value = this[i];
					if (!(value in storage)) {
						storage[value] = true;
						uniqueArray.push(value);
					}
				}
				return uniqueArray;

			}


			//ストリングクラスに追加
			/*---------------------------------------
			　全部置換
			--------------------------------------- */
			String.prototype.replaceAll = function(find, newstr, targetstr) {
				
				if(String(targetstr).indexOf(find) == -1) return targetstr;
				var tmp = targetstr.split(find);
				var str = tmp.join(newstr);
				return str;
			}
			
			
			//jQueryを拡張
			$.extend({
				//ダンプ
				dump : function(data) {
					var str = "";
					for(var item in data) {
						str += item+"："+data[item]+"\n";
					}
					alert(str);
				}
			});
		};
		
		$package.superUtil.prototype = {
			
						
			/*---------------------------------------
				HTMLにテキストを出力する場合のフィルタ
			--------------------------------------- */
			textToHTML : function(str) {
				str = str.replace(/[\r\n|\r|\n]/gi, '<br>');
				
				//str = this.replaceAll('&lt;', '<', str);
				//str = this.replaceAll('&gt;', '>', str);
				
				return str;
			},
			
			/*---------------------------------------
				HTMLからテキストを取得する場合のフィルタ
			--------------------------------------- */
			textFromHTML : function(str) {
				str = str.replace(/<br>/gi, '\n');
				return str;
			},
	

			/*---------------------------------------
				alphaUP
			--------------------------------------- */
			alphaUP: function(targetnode, callBack, delay) {
			
				targetnode.css("opacity", "0");
				if(delay > 0) {
					
					setTimeout(upFunc, delay);
				} else {
					upFunc();
				}
				
				function upFunc() {
					targetnode.show().animate({opacity:1}, {duration: "slow", complete: function(){
						if(callBack) callBack();
					}});;
				}
			},
			
			/*---------------------------------------
				delKaigyoBR
			--------------------------------------- */
			delKaigyoBR: function(str){
				var str = this.delKaigyo(str);
				str = this.delBR(str);
				return str;
			},
			
			/*---------------------------------------
				delKaigyo
			--------------------------------------- */
			delKaigyo: function(str){
				var str = str.split("\n").join("");
				return str;
			},
			
			/*---------------------------------------
				delBR
			--------------------------------------- */
			delBR: function(str){
				var str = str.split("<br>").join("");
				str = str.split("<br />").join("");
				return str;
			},
		
			/*---------------------------------------
				getUnixTime
			--------------------------------------- */
			getUnixTime : function() {
				return ~~(new Date/1000);
			},
		 
			/*---------------------------------------
				getYobi_JP
			--------------------------------------- */
			getYobi_JP : function(num) {
				var yobiNameList = ["日", "月", "火", "水", "木", "金", "土"];
				return yobiNameList[num];
			},
		
			/*---------------------------------------
				basename
			--------------------------------------- */
			basename: function(url){
				var tmp = url.split("/");
				var name = tmp[tmp.length-1];
				return name;
			},
			
			/*---------------------------------------
				dirname
				//なんかうごかない
			--------------------------------------- */
			dirname: function(url){
				
				var name = url.replace(/(.+)\/.+/, "\1");
				return name;
			},
			
			/*---------------------------------------
				dump
			--------------------------------------- */
			dump: function(data){
				var str = "";
				for(var item in data) {
					str += item+"："+data[item]+"\n";
				}
				alert(str);
			},
		
			/*---------------------------------------
				今日のストリングを取得
			--------------------------------------- */
			getTodayStr: function(splitstr){
				if(!splitstr) splitstr = "";
				var d = new Date();
				var datestr = d.getFullYear()+splitstr+this.keta(d.getMonth()+1, 2)+splitstr+this.keta(d.getDate(),2);
				return datestr;
			},
			
			/*---------------------------------------
				日付のストリングから日付のナンバーを取得
			--------------------------------------- */
			getDateNumFromDateStr: function(str){
				
				return this.replaceAll("/", "", str);
			},
			
			/*---------------------------------------
				日付のストリング　ドットタイプ
			--------------------------------------- */
			getDateStr_typeDot: function(str){
				
				var str = this.replaceAll("/", ".", str);
				str = this.replaceAll("_", ".", str);
				return str
			},
		
			/*---------------------------------------
				strToHTML
			--------------------------------------- */
			strToHTML: function(str) {
				
				var txt = str.split("\n").join("<br />");
				
				//txt = txt.split("&amp;lt;").join("<");
				//txt = txt.split("&amp;gt;").join(">");
		
		
				return txt;
			},
			/*---------------------------------------
				strFromHTML
			--------------------------------------- */
			strFromHTML: function(str) {
				
				var txt = "";
				if(str.indexOf("<br />") != -1) {
					txt = str.split("<br />").join("\n");
		
				} else if(str.indexOf("<br>") != -1) {
					txt = str.split("<br>").join("\n");
		
				} else {
					txt = str;
				}
				
				//txt = txt.split("<").join("&amp;lt;");
				//txt = txt.split(">").join("&amp;gt;");
				
				return txt;
			},
		
			/*---------------------------------------
				ソート
			--------------------------------------- */
			asort: function(ary, key){
		
				ary.sort(function (b1, b2) {
					return b1[key] > b2[key] ? 1 : -1;
				});
		
				return ary;
			},
			/*---------------------------------------
				桁をそろえる
			--------------------------------------- */
			keta: function(num, ketanum) {
				
				var n = String(num);
				while(n.length < ketanum){
					n = "0"+n;
				}
				return n;
			},
			
			/*---------------------------------------
				トリム
			--------------------------------------- */
			trim: function(str) {
				
				var newstr = str.replace(/(^\s+)|(\s+$)/g, "");
				return newstr;
			},
			

						
			/*---------------------------------------
			　ブラウザを取得（IE以外はノーマル）
			--------------------------------------- */
			getBlowser : function(){
				var str = "";
				if (typeof document.documentElement.style.msInterpolationMode != "undefined") {
					// IE 7 or newer
					if (navigator.userAgent.indexOf("MSIE 8")!=-1 && navigator.userAgent.indexOf("Trident/4.0")!=-1){
						str = "IE8";
					} else if (navigator.userAgent.indexOf("MSIE 7")!=-1 && navigator.userAgent.indexOf("Trident/4.0")!=-1){
						str = "IE8gokan";
						
					} else if (navigator.userAgent.indexOf("MSIE 7")!=-1){
						str = "IE7";
					}
				} else if (navigator.userAgent.indexOf("MSIE")!=-1 ){
					str = "oldIE";
				} else {
					str = "normal";
				}
				return str;
			},
			
			/*---------------------------------------
			　デイトピッカ
			--------------------------------------- */
			setDatePicker : function(node) {
				
				//カレンダー
				$(".datepicker").datepicker({
					inline: true,
					showOn: 'button',
					buttonImage: 'images/calendar.gif',
					buttonImageOnly: true,
					dateFormat: "yy/mm/dd"
		
				});
				
				$("#ui-datepicker-div").css("z-index", 100);
				$("img.ui-datepicker-trigger").css("margin-left", 5);
				
			},
			
			/*---------------------------------------
			　IEかな
			--------------------------------------- */
			IsIE : function() {
				IE='\v'=='v';
				return IE;
			},
			
			/*---------------------------------------
			　ゲッコーかな
			--------------------------------------- */
			IsGecko : function(){
				if(navigator){
					if(navigator.userAgent){
						if(navigator.userAgent.indexOf("Gecko/") != -1){
							return true;
						}
					}
				}
				return false;
			},
			
			/*---------------------------------------
			　リロード
			--------------------------------------- */
			reload : function() {
				location.reload();
			},
		
		
			
			/*---------------------------------------
			　アイフォンかな
			--------------------------------------- */
			isIPhone : function(){
				
				var flg = false;
				if (navigator.userAgent.indexOf('iPhone') != -1){
					flg = true;
				}
				
				return flg;
				
			},
				
			/*---------------------------------------
			　クエリーをオブジェクトとして取得
			--------------------------------------- */
			getQueryObj : function(){
			
				var obj = {};
				var query = document.URL.split("?")[1];
				if(!query) return obj;
				
				if(query.indexOf("&") == -1) {
					var tmp = query.split("=");
					obj[tmp[0]] = tmp[1];
				} else {
				
					var ary = query.split("&");
					
					for(var i=0; i < ary.length; i++){
						var tmp = ary[i].split("=");
						var key = tmp[0];
						var value = tmp[1];
						obj[key] = value;
					}
							
				}
				return obj;
			},
			
			/*---------------------------------------
			　全部置換
			--------------------------------------- */
			replaceAll : function(find, newstr, targetstr){
				
				if(String(targetstr).indexOf(find) == -1) return targetstr;
				var tmp = targetstr.split(find);
				var str = tmp.join(newstr);
				return str;
			},
			
			
			/*---------------------------------------
			　アクセス解析を非表示
			--------------------------------------- */
			hideAdTimer : null,
			hideKaiseki : function(){
				var me = this;
				me.hideAdTimer = setInterval(function() {		
					
					var node = $('#ninja_p3_ad').parent();
					var d = node.html();
					if(d){
						clearInterval(me.hideAdTimer);
						node.hide();
					}
				}, 100);
			
			},
			
			
			/*---------------------------------------
				通知開始
			--------------------------------------- */
			startInform : function(str){
				
				$("#compeleteInform").stop().remove();
				$("body").append("<div id='compeleteInform'>"+str+"</div>");
				$("#compeleteInform").css("top", "-30px").css("opacity", 0).animate({ opacity:1 , top:"0px"}, {duration: "slow", easing: "easeOutCubic", complete:function(){
					$("#compeleteInform").animate({ opacity:1 }, {duration: 1000, easing: "swing", complete:function(){
						
					}});
				}});
			},
			
			
			/*---------------------------------------
				通知完了
			--------------------------------------- */
			finishInform : function(callback){
				
				$("#compeleteInform").animate({ top:"-30px" }, {duration: "fast", easing: "easeInCubic", complete:function(){
					$("#compeleteInform").remove();
					if(callback) callback();
				}});
			},



			/*---------------------------------------
				完了通知
			--------------------------------------- */
			onComplete : function(str, callback){
				
				$("#compeleteInform").stop().remove();
				$("body").append("<div id='compeleteInform'>"+str+"</div>");
				$("#compeleteInform").css("top", "-30px").css("opacity", 0).animate({ opacity:1 , top:"0px"}, {duration: "slow", easing: "easeOutCubic", complete:function(){
					$("#compeleteInform").animate({ opacity:1 }, {duration: 1000, easing: "swing", complete:function(){
						$("#compeleteInform").animate({ top:"-30px" }, {duration: "fast", easing: "easeInCubic", complete:function(){
							$("#compeleteInform").remove();
							if(callback) callback();
						}});
					}});
				}});
			},
		
			
			/*---------------------------------------
			　IEアラート
			--------------------------------------- */
			IEalert : function() {
				
				var node = "";
				node += "<div style='display: none;' id='inform'>";
					node += "<p>インターネットエクスプローラでは閲覧できません。<br>…あれ、見えるのかな？<br>見えない場合は、<a href='http://getfirefox.jp/'>FireFox</a>等のクールなブラウザでご覧ください。</p>";
					node += "<p class='firefox' style='text-align: center; width: 100%; height: 90px;'>";
					node += "<a href='http://getfirefox.jp/'><img src='http://getfirefox.jp/b/120x90_2_white' alt='Mozilla Firefox ブラウザ無料ダウンロード' title='Mozilla Firefox ブラウザ無料ダウンロード' border='0'></a>";
					node += "</p>";
				node += "</div>";
			
				$("#maincontainer").prepend(node);
			},
			
			
			/*---------------------------------------
				カバーかけよう
			--------------------------------------- */
			cover : function(flg) {
				var me = this;
				if(flg){
					$("body").append("<div id='dialogBG'></div>");//BGをひくよ
					$("#dialogBG").css("opacity", 0.3);
					
					$(window).bind("resize", me.resizeCover);
					me.resizeCover();
					
				
				}else {
					$("#dialogBG").remove();
					$(window).unbind("resize");
				}
			},
			
			/*---------------------------------------
			　カバー
			--------------------------------------- */
			resizeCover : function() {
				var w = $(window).width();
				var h = $(document).height();
				$("#dialogBG").css("width", w);
				$("#dialogBG").css("height", h);
			}
			
			
		}//superUtil

		
		
	}
)($Package);

	


