(function($)
{
	$.extend(
	{
		uniPaper : 
		{
		//-----------------------------------------------------------------------------------------
		   getViewURL : function(url){
				url = url.split("&amp;").join("&");
				jQuery.ajax({
		            url: url,
		            dataType:"jsonp",		            
		            success: function(objResponse){
					    
		                return objResponse.response.result;
		            }
		            
		        });
		        return "";
		   },  
		
           request : function(url, target, popup){
                url = url.split("&amp;").join("&");

                if(popup == null){
					popup = false;
				}
                jQuery.ajax({
                    url: url,
                    dataType:"jsonp",
                    
                    complete : function(){
	                	if(popup == true){
							jQuery.popup.hResize();
						 }
                    },

                    error : function(XMLHttpRequest){
                    	if (XMLHttpRequest.status === 404)
                    		alert("404");
                    	jQuery.uniPaper.makeErrorBox("lang_enzymeError9999999");
                    },

                    success: function(objResponse){

                        if (typeof objResponse.response.code !== "undefined") {
    						var Contents = objResponse.response.description;
    						Contents = Contents.replace(/([^>]?)\n/g, '$1'+ '<br />' +'\n');
							jQuery.uniPaper.makeErrorBox(Contents);
                        }else{
                            var Contents = objResponse.response.result;                           
                            jQuery(target).html(Contents);
                            jQuery(target).css('background','none');
                        }
                    }
                    
                });
            },
            
			// ViewerRequestURL---------------------------
			VIWER_LICENSE_ADPACKAGE : 'adpackage',
			VIWER_LICENSE_COMMERCIAL : 'commercial',
			VIWER_LICENSE_FREE : 'free',
			VIWER_REPO_S1 : 's1',
			VIWER_REPO_DEFAULT : 'default',
			VIWER_METHOD_VIEW : 'view',
			VIWER_METHOD_EMBED : 'embed',
			
			getViewerURL : function(/*HTML DOM Object*/divTag, /*String*/fileUrl){
				
				var id = $(divTag).attr("id");
				var repoType = $(divTag).attr("repoType");
				var licenseType = $(divTag).attr("licenseType");
				var viewerMethod = $(divTag).attr("method");
				var width = $(divTag).attr("width");
				var height = $(divTag).attr("height");
				
				if(!fileUrl) return false; 
				if(!licenseType){
					licenseType = this.VIWER_LICENSE_ADPACKAGE;
				}
				if(!repoType){
					repoType = this.VIWER_REPO_DEFAULT;
				}		
				
				var content = null;		
				if(viewerMethod==='view'){
					content =  {method:'VIEWERURLDEMO', repoType:repoType,licenseType:licenseType,fileUrl:fileUrl,viewerMethod:viewerMethod,width:width,height:height};		
				}else if(viewerMethod==='embed'){
					content =  {method:'VIEWERURLDEMO', repoType:repoType,licenseType:licenseType,fileUrl:fileUrl,viewerMethod:viewerMethod,width:width,height:height};
				}
			 			
				var result = jQuery.ajax({
                    url: "/member/internal",
                    data: content,
                    dataType:"json",

                    error : function(data){
						//jQuery.uniPaper.makeErrorBox("lang_enzymeError9999999");
                    },

                    success: function(data){
                    	var enzymeUrl = data.url;
                    	jQuery.uniPaper.request(enzymeUrl, "#"+id, false);
                    	jQuery("#"+id).attr("style","");
                    }
				});
				
                    
			},
			
			loadingProgress : function(jqueryObj){
				var locale = jQuery.common.getLocale();
				var unipaperBackgroundImgURL = "/static/images/common/" + locale + "/loading.gif";
				var cssText = {'background':'url(' + unipaperBackgroundImgURL + ') no-repeat 50% 50%','height':'110px'};

				jQuery(jqueryObj).css(cssText);
			},

            makeErrorBox :  function(errorMessage){
//                jQuery("#doc_view_box").css("background-color", "#FFF");
//                jQuery("#doc_view_box").css("background-image", "none");
//                jQuery("#enzyme_status").css("top", "150px");
                jQuery("#enzyme_status").css("color", "#333");
                jQuery("#enzyme_status").css("display", "none");
                jQuery("#enzyme_status").html(errorMessage);
                jQuery(".enzymeErrorStyle1").css("font-size" ,"1.8em");
                jQuery(".enzymeErrorStyle1").css("font-weight" ,"bold");
                jQuery(".enzymeErrorA").css("color", "#333");
                jQuery("#enzyme_status").css("display", "none");
                jQuery("#enzyme_status").css("margin-top", "-20px");
                jQuery("#enzyme_status").fadeIn("slow");
                
            },
            
			_version : '1.1'
        //-----------------------------------------------------------------------------------------
		}
	});
})(jQuery);

