/**
 * JavaScript Lib Created with jQuery
 *
 *
 * @author Bartosz Grzybowski melkorm@gmail.com
 * @version 1.0 Development
 */
var Lib = {

	/**
	 * Method checks if element is undefined or not
	 *
	 * @param el mixed
	 * 
	 * @return bool
	 */
	isUndefined: function(el)
	{
		if(el == undefined)
		{
			return true;
		}
		return false;
	},

	/**
	 * Method checks if provided element exists in a DOM Object.
	 * 
	 * @param name string | jQuery Object
	 * @return bool | jQuery Object
	 */
	elExists: function(name)
	{
		if(name instanceof jQuery) {
			return name;
		}
		name = $(name);
			if(!name.length) {
				alert('taki element nie istnieje!');
				return false;
			} else {
				return name;
			}
	},

	/**
	 * Array of actions actually executing
	 */
	requestBlock : [],
	
	/**
	 * Method sends an Ajax request with data provided from HTML Form Object
	 * 
	 * @param form HTML Form Object
	 * @param loadingDiv elementid | jQuery Object existing element for response
	 * @param callback string name of a function for callback
	 * 
	 * @return bool | string
	 */
	requestForm: function(form, callback, loadingDiv)
    {
		if(!(form = Lib.elExists(form))) return false;

        if (!Lib.isUndefined(Lib.requestBlock[form.attr('name')])) {
			alert('Ta funkcja jest właśnie wykonywana!');
            return false;
        }
		
        jQuery.ajax({
			type: Lib.isUndefined(form.attr('method')) ? 'GET' : form.attr('method'),
            url: Lib.isUndefined(form.attr('action')) ? '/' : form.attr('action'),
            data: form.serialize(),
            beforeSend  : function()
			{
                Lib.requestBlock[form.attr('name')] = true;
				
				if(loadingDiv) {
					$(loadingDiv).show().html('<img src="/public/images/ajax-loader.gif" />');
				}
            },
            success: function(text)
			{
                delete(Lib.requestBlock[form.attr('name')]);
				if(callback) {
					try {
						eval(callback+'(text)');
					} catch (e) {
						alert('Podana funckja nie istnieje!'+e.toString());
					}
				}
				if(loadingDiv) {
					$(loadingDiv).hide();
				}
            },
			error: function()
			{
				delete(Lib.requestBlock[form.attr('name')]);
				if(loadingDiv) {
					$(loadingDiv).hide();
				}
			} 
        });
        return false;
    }
}

	function LGLightbox(action,controller) {
	
		if (action == "on") {
		
			$('#LGLightbox').css("height",$(document).height()); 
		
			$('#LGLightbox').fadeIn("slow");
			$('#LGLightboxClose').fadeIn("slow");

			$('#FRAME').attr("src","/public/panoramy/"+controller+"/"+controller+".html");
			
			$('#FRAME').fadeIn("slow");
			
//			var pan = new SWFObject("/public/panoramy/"+controller+"/"+controller+".swf", controller, "685", "485", "9.0.28", "#ffffff");
//			pan.addParam("quality", "high");
//			pan.addParam("salign", "lt");
//			pan.addParam("allowScriptAccess", "always");
//			pan.addParam("allowFullScreen", "true");
//			pan.write("FlashContent");			
			
		}
		else {
			$('#LGLightbox').fadeOut("slow");
			$('#LGLightboxClose').fadeOut("slow");
			$('#FRAME').fadeOut("slow");
		}
	}
	
	function ClickIT(id) {
	
		$('#'+id).click();
	
	}
	
		function Slide(id) {
	
		if ($('#'+id).is(":hidden")) {
			$('#'+id).slideDown();
		  } else {
			$('#'+id).slideUp();
		  }
		  
	  }
