

//IEだとエラーが出るので回避
if(!console) {
	var console = {
		
		log : function(str){
			//alert(str);
		},
		
		dir : function(obj){
			//alert(str);
		}
	}
}



/*	
	ユーティリティを拡張
*/
(
	function($package) {
	
		
		$package.myUtil = $package.extend($package.superUtil, function(){//コンストラクタ
			
			this.__super__.constructor();
			
			var me = this;
			/*----------------------------------------------------------------------------
				jQueryを拡張しよう
			---------------------------------------------------------------------------- */
			$.extend({
				
				/*――――――――――――――――――――――――――――――――――
					
				―――――――――――――――――――――――――――――――――― */
				dump: function(obj) {
					me.dump(obj);
				},
				
				/*――――――――――――――――――――――――――――――――――
					
				―――――――――――――――――――――――――――――――――― */
				isDebug : false,
				isIE : false,
				verIE : null,
				isiPad : false,
				vendor : null,
				isIPhone : false
				
			});
			
			//デバッグかどうかのフラグを更新
			var q = me.getQueryObj();
			if(q.debug == "true"){
				$.isDebug = true;
			}
			
			//IEかどうかのフラグを更新
			var b = this.getBlowser();
			$.verIE = b;
			if(b.indexOf("IE") != -1) {
				$.isIE = true;
			}
			$.isiPad = navigator.userAgent.match(/iPad/i);
			$.vendor = (/webkit/i).test(navigator.appVersion) ? 'webkit' :(/firefox/i).test(navigator.userAgent) ? 'Moz' :'opera' in window ? 'O' : '';
			
			/*---------------------------------------
			　アイフォンかな
			--------------------------------------- */
			if (navigator.userAgent.indexOf('iPhone') != -1){
				$.isIPhone = true;
			}


			$.fn.extend({
				
				/*――――――――――――――――――――――――――――――――――
					cssのwidthをナンバーとして取得
				―――――――――――――――――――――――――――――――――― */
				widthNum : function(){
					
					return parseInt($(this).css("width").replace("px", ""),10);
				},
				
				/*――――――――――――――――――――――――――――――――――
					cssのwidthをナンバーとして取得
				―――――――――――――――――――――――――――――――――― */
				heightNum : function(){
					return parseInt($(this).css("height").replace("px", ""),10);
				},
				
				/*――――――――――――――――――――――――――――――――――
					translate3dでセットした値を数値としてとりだす
				―――――――――――――――――――――――――――――――――― */
				getTRS3DVal : function(){
					
					
					var str = $(this).get(0).style.webkitTransform;
					
					str = str.replace(/^.*translate3d\((.+?)\)/, "$1");
					var tmp = str.split(",");
					var ary = [];
					for(var i=0; i < tmp.length; i++) {
						var val = tmp[i];
						val = val.replace("px", "");//pxを削除
						val = val.replace(/(^\s+)|(\s+$)/g, "");//trim
						ary.push(val);
					}
					var obj = {};
					obj.x = parseInt(ary[0],10);
					obj.y = parseInt(ary[1],10);
					obj.z = parseInt(ary[2],10);
					
					return obj;
				},	
				
				/*――――――――――――――――――――――――――――――――――
					translate3dをセット
				―――――――――――――――――――――――――――――――――― */
				setTRS3DVal : function(x,y,z){
					
					if(!x) x = 0;
					if(!y) y = 0;
					if(!z) z = 0;
					
					var str = $(this).get(0).style.webkitTransform;
					
					$(this).get(0).style.webkitTransform = 'translate3d(' + x + 'px, ' + y + 'px,'+z+'px)';
				},
				
				/*――――――――――――――――――――――――――――――――――
					座標変更メソッド（webkitはtranslate3dを使用）
				―――――――――――――――――――――――――――――――――― */
				setMyPos : function(x,y){
					
					if($.vendor == "webkit"){
						this.setTRS3DVal(x,y,0);
					} else {
						if(x != undefined && x != null && y != undefined && y != null){
							$(this).css("left", x).css("top", y);
						} else if(x != undefined && x != null){
							$(this).css("left", x);
						} else if(y != undefined && y != null){
							$(this).css("top", y);
						}
					}
					
				},
				
				/*――――――――――――――――――――――――――――――――――
					座標取得メソッド（webkitはtranslate3dを使用）
				―――――――――――――――――――――――――――――――――― */
				getMyPos : function(){
					
					var obj = {};
					if($.vendor == "webkit"){
						obj = this.getTRS3DVal();
					} else {
						obj.x = parseInt($(this).css("left").replace("px", ""),10);
						obj.y = parseInt($(this).css("top").replace("px", ""),10);
					}
					
					return obj;
				}
			});

		});
		
		$P = $package.myUtil.prototype;
		
		/*---------------------------------------
			長さ1のオブジェクトを配列として初期化
		--------------------------------------- */
		$P.aryCheck = function(ary){
			if(!ary.length && ary) ary = [ary];
			return ary;
		}
		
		/*---------------------------------------
			長さ1のオブジェクトを配列として初期化
		--------------------------------------- */
		$P.aryCheck = function(ary){
			if(!ary.length && ary) ary = [ary];
			return ary;
		}
		
		/*---------------------------------------
			タイトル用の日付フォーマットを返却
		--------------------------------------- */
		$P.getTitleDate = function(date){
			
			var y = date.slice(0,4);
			var m = date.slice(4,6);
			var d = date.slice(6,8);
			
			return y+"."+m+"."+d;
		
		}
		
		/*---------------------------------------
			HTMLにテキストを出力する場合のフィルタ
		--------------------------------------- */
		$P.textToHTML = function(str){
			
			
			//str = str.replace(/(http:[0-9A-Za-z_\.\-/~?=]+)/gi, "<a href='$1' target='_blank'>$1</a>");
			str = str.replace(/[\r\n|\r|\n]/gi, '<br>');
			return str;
			
		}
		
		/*---------------------------------------
			HTMLからテキストを取得する場合のフィルタ
		--------------------------------------- */
		$P.textFromHTML = function(str) {
			//str = str.replace(/<a .*?>/gi, '');
			//str = str.replace("</a>", '');
			str = str.replace(/<br>/gi, '\n');
			return str;
		}
		
		/*---------------------------------------
			getNow
		--------------------------------------- */
		$P.getNow =  function(){
			var todaystr = this.getTodayStr();
			var d = new Date();
			var datestr = todaystr.slice(0,4)+"_"+todaystr.slice(4)+"_"+this.keta(d.getHours(), 2)+this.keta(d.getMinutes(),2);
			return datestr;
		}
		
		/*---------------------------------------
			画像のサイズを取得
		--------------------------------------- */
		$P.getImg_true_size = function(image){
		    var w = image.width ,
		        h = image.height ;
		 
		    if ( typeof image.naturalWidth !== 'undefined' ) {  // for Firefox, Safari, Chrome
		        w = image.naturalWidth;
		        h = image.naturalHeight;
		 
		    } else if ( typeof image.runtimeStyle !== 'undefined' ) {    // for IE
		        var run = image.runtimeStyle;
		        var mem = { w: run.width, h: run.height };  // keep runtimeStyle
		        run.width  = "auto";
		        run.height = "auto";
		        w = image.width;
		        h = image.height;
		        run.width  = mem.w;
		        run.height = mem.h;
		 
		    } else {         // for Opera
		        var mem = { w: image.width, h: image.height };  // keep original style
		        image.removeAttribute("width");
		        image.removeAttribute("height");
		        w = image.width;
		        h = image.height;
		        image.width  = mem.w;
		        image.height = mem.h;
		    }
		 
		    return {width:w, height:h};
		}
	}
	
)($Package);


