(function($){
    $.extend({
        common : {
    		redirect : "",
    	
    		goSignin:"/member/goSignin.action",
    		
    		actionGoogle:"/member/sign_in_with.action?with=google",
    	
	        changeLanguage:function(){		
				var tflocale = $("#selectLanguage").val();
				this.setLocale(tflocale);
				
				var _host = location.host;
				var _pathname = location.pathname;
				var _search = location.search;
				
				if(_search){
					_search = (_search.indexOf('&t=')!=-1)?_search.substring(0,_search.indexOf('&t=')):_search;	
					_search = (_search.indexOf('?t=')!=-1)?_search.substring(0,_search.indexOf('?t=')):_search;	
				}
				if(_search){
					_search = _search+"&t="+new Date().getTime();
				}else{
					_search = "?t="+new Date().getTime();
				}	
				var selfURL = "http://"+_host+_pathname+_search;	
				document.location.href = selfURL;				
			},
			
			/**
			 * TFLocale 얻기. 없으면 셋팅하고 그 값 리턴.
			 */
			getLocale :function() {
				var tflocale = $("#selectLanguage").val();
				var locale =  $.cookie("TFLocale") || this.setLocale(tflocale);	
				return locale;
			},
			
			/**
			 * TFlocale 설정.
			 * 주어진 locale > 기존에 있던 TFLocale 유지 > browser locale.
			 */
			setLocale : function(locale) {
				var tflocale = locale || $.cookie("TFLocale");		
				$.cookie("TFLocale",tflocale,{path:'/',domain:'.thinkfree.com',expires: 10});
				return tflocale;
			},

			isSignIn : function() {
				if($.cookie("smb_session") != null && $.cookie("smb_session") != ""){
					return true;
				}else{
					return false;
				}				
			},			
			
			fileReSize :function(size) {
				var file_resize;
				  //console.log("Size: " , foo.details.size);
				  if(size < 1024){ 
					  file_resize = "1 KB"; 
				  }else if(size > 1024 && size < (1024*1024)){ 
					  file_resize = String(Math.abs(parseFloat(size/1024)).toFixed(1)) + "KB";
				  }else if(size > (1024*1024) && size < (1024*1024*1024)){
					  file_resize = String(Math.abs(parseFloat(size/(1024*1024))).toFixed(1)) + "MB";
				  }else{
					  file_resize = String(Math.abs(parseFloat(size/(1024*1024*1024))).toFixed(1)) + "GB";
				  } 
				  return file_resize;
			},

			fileReSizeMax :function(size) {
				var file_resize;
				file_resize = String(Math.abs(parseFloat(size/(1024*1024*1024))).toFixed(0)) + "GB";
				return file_resize;
			},			
			
			getStorageInfo : function(usedSize , maxSize){
				var percentage;	
				percentage = Math.abs(parseFloat((usedSize * 137)/maxSize)).toFixed(0);
				if( percentage < 5){ percentage = 5;}				
				return percentage
				
			},
			
			
			slide : function(id){	
				$("#mainVisual .keyImg li.selected").removeClass("selected");
				$("#slide_"+id).addClass("selected");				
				$("#mainVisual .nav a.selected").removeClass("selected");
				$("#slideBtn_"+id).addClass("selected");
			},
			
			openWindow : function (url,mode){
				var feature="";
				if(mode==1){
			   		feature="width=800,height=600,menubar=no,toolbar=no,directories=no, location=no, scrollbars=yes,resizable=yes, status=no";
			   	}else if(mode==2){
			   		feature="width=800,height=600,menubar=yes,toolbar=yes,directories=yes, location=yes, scrollbars=yes,resizable=yes, status=yes";
			   	}else if(mode==3){
			   		feature="width=1024,height=600,menubar=yes,toolbar=yes,directories=yes, location=yes, scrollbars=yes,resizable=yes, status=yes";
			   	}else if(mode==4){
			   	   	feature="width=1000,menubar=yes,toolbar=yes,directories=no, location=no, scrollbars=yes,resizable=yes, status=no";		
			   	}else{
			   		feature="width=800,height=600,menubar=no,toolbar=no,directories=no, location=no, scrollbars=yes,resizable=yes, status=no";
			   	}	
				window.open(url, '_blank', feature);
			},

    		goSignIn: function(){				
				var redirectURL = window.location;
				if(this.redirect == "skip"){
					document.location.href = this.goSignin;
				}else{
					document.location.href = this.goSignin + "?redirect="+ encodeURI(redirectURL);
				}
    		},			
			
    		signin_google: function(){				
				var redirectURL = window.location;
   				this.actionGoogle = this.actionGoogle + "&redirect="+encodeURI(redirectURL);
    			document.location.href = this.actionGoogle;
    		}
        }
    });
})(jQuery);
