
var SqueezeBox = new function(){
	
	this.onClose = null;
	
	this.initialize = function(){};
	this.assign = function(){};
	
	
	/**
	 * open fancybox, set onclose function
	 */
	this.open = function(onCloseFunction){
				
		this.onClose = onCloseFunction;
		var url = "index.php?option=com_unitegallery&view=mediaselect";
		
		var options = {};
		options.handler = "iframe";
		options.size = {x:900,y:550};
		
		var objFancybox = jQuery("#fancybox_trigger");
		objFancybox.attr("href",url);
				
		jQuery("#fancybox_trigger").trigger("click");
	};
	
	
	/**
	 * close fancybox
	 */
	this.close = function(){
				
		jQuery("#fancybox-close").trigger("click");
	};	
};


/**
 * 
 * on inset image, taken from iframe
 */
function jInsertFieldValue(urlImage){
	
	if(typeof SqueezeBox.onClose == "function")
		SqueezeBox.onClose(urlImage);
	
	SqueezeBox.close();
}


/**
 * provider admin class
 */
function UniteProviderAdminUG(){
	
	var t = this;
	
	/**
	 * open "add image" dialog
	 */
	this.openAddImageDialog = function(title, onInsert, isMultiple){
		
		SqueezeBox.open(function(urlImage){
			onInsert(urlImage);
		});
		
	};
	
	
	/**
	 * get shortcode
	 */
	this.getPHPCode = function(alias, catid){
		
		var addhtml = "";
		if(catid)
			addhtml = ", "+catid;
		
		var code = "";
		
		var br = "\n";
		
		code += "<!-- put this code to HEAD part -->"+br+br;
		code += "<?php " + br;
		code += "	require_once('"+g_pathFront+"');" + br;
		code += "	putUniteGalleryHeader(\""+alias+"\");"+br;
		code += "?>"+br;
		code += "<!-- put this code to BODY part -->"+br+br;
		code += "<?php putUniteGallery(\""+alias+"\""+addhtml+"); ?>"+br;
		
		return(code);
	};
       
	
	/**
	 * empty return, no shortcode needed
	 */
	this.getShortcode = function(gallery, cat){
		
		var code = t.getPHPCode(gallery, cat);
		
		return(code);
	}
	
	
	var g_handle = null;
	
	/**
	 * on global init hook
	 */
	this.onGlobalInit = function(){
				
		var inputPhpCode = jQuery("#phpcode");
		if(inputPhpCode.length == 0)
			return(true);

		//init events
		inputPhpCode.focus(function(){
			inputPhpCode.stop().animate({height:"200px"},"slow");
			if(g_handle)
				clearTimeout(g_handle);
			g_handle = null;
		});
		
		inputPhpCode.blur(function(){

			if(g_handle)
				clearTimeout(g_handle);
			
			g_handle = setTimeout(function(){
				inputPhpCode.stop().animate({height:"80px"},"slow");
			},3000); 
			
		});
		
		
		//update php code
		var alias = jQuery("#alias").val();
		
		var code = t.getPHPCode(alias);
		inputPhpCode.val(code);
		
		return(true);
	}
	
}

