	//Глобальное переопределение параметров по умолчанию
	$.blockUI.defaults.css.cursor = 'default';
	$.blockUI.defaults.css.border = '0';


	var newWindow = '<div class="tcmf_block" id="{%objectCount%}"><img class="tcmf_block_close" src="/images/close.gif" /><div class="tcmf_block_header">{%title%}</div><div class="tcmf_block_content" style="overflow:auto; height: 300px">{%content%}</div></div>';
	var newBlock = '<div id="{%objectCount%}"></div>';
	var objectCount = 2323;

	jQuery.fn.tcmfWindowClose = function()
	{
		this.parent(".tcmf_block").slideUp("slow", function() { $(this).remove(); });
		return this;
	};

	jQuery.fn.tcmfWindowSlide = function()
	{
		this.tcmfWindowClick();
		this.siblings('.tcmf_block_content').slideToggle("slow");
		return this;
	};

	jQuery.fn.tcmfWindowClick = function()
	{
		jQuery.fn.tcmfWindowClick.zindex += 1;
		$(this).css('zIndex', jQuery.fn.tcmfWindowClick.zindex);
		return this;
	};

	jQuery.fn.tcmfSetBlockControls = function()
	{
		return this.each(
			function()
			{
				$(this).bind("mousedown", function() { $(this).tcmfWindowClick() });
				$(this).find('.tcmf_block_close').bind("click", function() { $(this).tcmfWindowClose() });
				$(this).find('.tcmf_block_header').bind("dblclick", function() { $(this).tcmfWindowSlide() });

			}
		);
	}

	jQuery.fn.tcmfSetWindowControls = function()
	{
		return this.each(
			function()
			{
				$(this).bind("mousedown", function() { $(this).tcmfWindowClick() });
				$(this).find('.tcmf_block_close').bind("click", function() { $(this).tcmfWindowClose() });
				$(this).find('.tcmf_block_header').bind("dblclick", function() { $(this).tcmfWindowSlide() });
				$(this).css('position', 'absolute');
				$(this).Draggable({ handle: '.tcmf_block_header', zIndex: ++ jQuery.fn.tcmfWindowClick.zindex, onStart: $(this).tcmfWindowClick });
			}
		);
	}

	jQuery.tcmfCreateWindow = function(title, content)
	{
   		windowObjectCount = objectCount++;

		var windowObj = document.createElement('div');
		windowObj.innerHTML = newWindow;
		windowObj.innerHTML = windowObj.innerHTML.replace(/{%title%}/g, title);
		windowObj.innerHTML = windowObj.innerHTML.replace(/{%content%}/g, content);
		windowObj.innerHTML = windowObj.innerHTML.replace(/{%objectCount%}/g, windowObjectCount);
		windowObj = windowObj.childNodes[0];

		document.getElementById('windows').appendChild(windowObj);

		windowObj.setAttribute('window', 1);
		windowObj.style.position = 'absolute';

		$(windowObj).tcmfSetWindowControls();
        $(windowObj).center();
		return windowObjectCount;
	}


	jQuery.fn.tcmfWindowClick.zindex = 1000;


function calb()
{
	alert('uploadcomplate');
}


//params[] - type, position, objectCount, oncomplete, iframe, file, loader
	jQuery.fn.Request = function(options)
	{
		var defaults = {
    		url: '',
    		loader: 'global',
    		oncomplete: false,
    		data: '',
    		form: null
  		};

  		var opts = $.extend(defaults, options);
        opts['objectCount'] = null;

		if (this.attr('block') == 1 || this.attr('window') == 1)
        	opts['objectCount'] = this.attr('id');
		else
        {
        	// Если хотим апдейтить не блок, а какой то другой элемент
			alert('Данное действие невозможно, ждите следующей версии библиотеки.');
		}

		if  (opts['form'] != null)
		{

			uploadCounter = jQuery(opts['form']).find('.tcmf_uploader_button_upload').length;
			jQuery(opts['form']).find('.tcmf_uploader_button_upload').each(
				function()
				{
					jQuery.uploader.upload($(this).attr('index'));
				});
		}

		return jQuery._Request(opts);
	}

	jQuery.Request = function(options)
	{
		var defaults = {
    		loader: 'global',
    		oncomplete: false,
    		data: '',
    		windowWidth: '500px',
    		windowHeight: null,
    		windowTop: null,
    		windowLeft: null
  		};

  		var opts = $.extend(defaults, options);
        objectCount = null;

		opts['objectCount'] = $.tcmfCreateBlock();

		return jQuery._Request(opts);
	}

	jQuery._Request = function(opts)
	{
		if (opts['windowTop'])
			opts['data'] += '&windowTop=' + opts['windowTop'];
		if (opts['windowLeft'])
			opts['data'] += '&windowLeft=' + opts['windowLeft'];

		opts['data'] += '&objectCount=' + opts['objectCount'] + '&datarequest=1';

		if (opts['oncomplete'])
			opts['data'] += '&oncomplete=' + opts['oncomplete'];

		$.ajax({
 	      	type: "POST",
 			url: opts['url'],
 			data: opts['data'],
 			success: $.RequestComplete
 		});

		if (opts['loader'] == 'global')
		{
			$.blockUI({message: '<img src=\'/images/ajax-loader.gif\' />', css: { border: '0px', background: 'none' } });
		}
		else if (opts['loader'] == 'block')
		{
			$('#' + opts['objectCount']).block({message: '<img src=\'/images/ajax-loader.gif\' />', css: { border: '0px', background: 'none' } });
		}

		return false;
	}

	jQuery.RequestComplete = function(responce)
	{
		var jsonObj = new Array();
		try
		{
			jsonObj = eval('(' + responce + ')');
        }
        catch(ex)
        {
        	jsonObj = new Array();
        	jsonObj['error'] = 1;
        	jsonObj['message'] = responce;
        }

		try
		{
			$.unblockUI();
			if (jsonObj['error'] == 1)
			{
				jsonObj['objectCount'] = $.tcmfCreateWindow('Сообщение системы', jsonObj['message']);
			}
			else
			{
				var block = '#' + jsonObj['objectCount'];
				var isWindow = ($(block).attr('window') == 1) ? true : false;
                var opts = new Array();

				if (isWindow)
				{
					opts = {
    					top: $(block).css('top'),
    					left: $(block).css('left')
  					};
				}

				$(block).replaceWith(jsonObj['content']);

                if (isWindow)
                {
                	$(block).attr('window', '1');
                	$(block).tcmfSetWindowControls();

       				$(block).center();

                }
                else
                {
                	$(block).tcmfSetBlockControls();
                }

				if (jsonObj['scripts'] !== undefined)
					eval(jsonObj['scripts']);
			}
		}
		catch (ex) { }

		if (jsonObj['oncomplete'] !== undefined)
		{
			eval(jsonObj['oncomplete'] + "\(jsonObj\);");
		}
	}

	document.getElementsByBlockName = function(blockName)
	{
		var nodes = document.getElementsByTagName('div');
		var elements = new Array();
		for (var i = 0, child; child = nodes[i]; i++)
		{
			if (child.getAttribute('blockName') && child.getAttribute('blockName') == blockName)
			{
				elements.push(Element.extend(child));
			}
		}
		return elements;
	}




	jQuery.tcmfCreateBlock = function()
	{
		windowObjectCount = objectCount++;
		var windowObj = document.createElement('div');
		windowObj.innerHTML = newBlock;
		windowObj.innerHTML = windowObj.innerHTML.replace(/{%objectCount%}/g, windowObjectCount);
		windowObj = windowObj.childNodes[0];

		document.getElementById('windows').appendChild(windowObj);

		windowObj.setAttribute('window', 1);
		windowObj.style.zIndex = ++ jQuery.fn.tcmfWindowClick.zindex;

        return windowObjectCount;
	}


	FilterInt = function(inputElement)
	{
		inputElement.value = inputElement.value.replace(/[^\d]+/, '');
	}

	FilterStringLat = function(inputElement)
	{
		inputElement.value = inputElement.value.toLowerCase();
		inputElement.value = inputElement.value.replace(/[^a-z0-9_\-\.\@]+/, '');
	}


	jQuery.fn.center = function()
	{
		var w = $(window);
		this.css("position","absolute");
		this.css("top",(w.height()-this.height())/2+w.scrollTop() + "px");
		this.css("left",(w.width()-this.width())/2+w.scrollLeft() + "px");
		return this;
	}

	jQuery.preloadImages = function()
	{
		for (var i = 0; i < arguments.length; i++)
			jQuery("<img>").attr("src", arguments[i]);
	}



