	$('a.fa-dialog').live('click', function(){
		var metadata = $(this).metadata();
		if ( !$(metadata.block).length ) faShowNotify('не найден контейнер');
		metadata.title = $(this).attr('title')
		metadata.width = typeof(metadata.width) != 'undefined' ? metadata.width : '400px'; //defaults
		var faDialog = $('<div id="fa-dialog" style="margin:0px; padding:0px;"></div>').appendTo('body');//create dialog
		faAjaxRequest($(this).attr('href'), metadata.data, $(metadata.block), function(getResponse) {
			if (getResponse.status == 'error') faShowError(faDialog, getResponse.response);
			else faDialog.append(getResponse.response);
			faDialog.dialog({
				autoOpen: true, closeOnEscape: false, modal: true, position: 'center', width: metadata.width, title: metadata.title,
				buttons: {
					"отмена": function() {
						faDialog.dialog("destroy");
						faDialog.remove();
					},
					"подтвердить": function() { 
						faHideHighlight(faDialog);
						faHideError(faDialog);
						var serialized = $('form', faDialog).serializeArray();
						$.each(serialized, function(i, field){ metadata.data[field.name] = field.value; });
						faAjaxRequest( $('form', faDialog).attr('action'), metadata.data, $('.ui-dialog'), function (getResponse){
							if (getResponse.status == 'error') {
								faShowError(faDialog, getResponse.response);
							} else {
								faShowNotify( getResponse.response );//faShowHighlight(faDialog, getResponse.response);
								faDialog.dialog("close");
							};
						});
					}
				},
				beforeclose: function() {
					//metadata.width = typeof(metadata.width) != 'undefined' ? metadata.width : '400px'; //defaults
					if (!metadata.reload) {
						faDialog.dialog("destroy");
						faDialog.remove();
					} else {
						faAjaxRequest( metadata.url, metadata.data, $(metadata.reload), function (getResponse){
							if (getResponse.status == 'error') {
								faShowError(faDialog, getResponse.response);
							} else {
								$(metadata.reload).html(getResponse.response);
								faDialog.dialog("destroy");
								faDialog.remove();
							};
						});
					};
					return false;
				}
			});
		});
		return false;
	});
	
	function faAjaxRequest(ajaxUrl, ajaxData, blockContainer, responseData){
		$.ajax({
			context:this, type:'post', dataType:'html',
			url:ajaxUrl, data:ajaxData, 
			beforeSend:function(XMLHttpRequest) { faContainerBlock(blockContainer); },
			complete:function(XMLHttpRequest, textStatus){ faContainerUnblock(blockContainer); },
			error:function(XMLHttpRequest, textStatus, errorThrown){ responseData({response:XMLHttpRequest.responseText, status:textStatus}); },
			success:function(data, textStatus, XMLHttpRequest){ responseData({response:XMLHttpRequest.responseText, status:textStatus}); }
		});
	};
	
	function faContainerBlock(container) {
		container.block({
			fadeIn:0, centerY:1,
			message:'<img src="/images/ajax-container-block.gif"></img>',
			css:{ border: 'none', backgroundColor: 'transparent' },//css: { margin: 'auto', cursor: null },
			overlayCSS:{ backgroundColor: '#2E8AE5', opacity: .3 }
		});
	};
	function faContainerUnblock(container) {
		container.unblock();
	};
	
	
	function faShowNotify(message){
		//$.growlUI('Growl Notification', 'Have a nice day!');
		$.blockUI({
            message: message, fadeIn: 300, fadeOut: 300, timeout: 7000, showOverlay: false, centerY: false, 
            css: {width: '240px', top: '6px', left: '', right: '6px', border: 'none', padding: '5px', backgroundColor: '#2E8AE5', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: .9, color: '#fff'}
        }); 
	};
	
	//message handling
	function faShowError(container, data) {
 		//var overwrite = typeof(overwrite) != 'undefined' ? overwrite : true;//default for overwrite
		if ( !$('.ui-state-error', container).length ) $(container).append('<div class="ui-state-error"></div>');//if not exist create
		$('.ui-state-error', container).append('<div>'+data+'</div>');
	};
	function faHideError(container) { $('.ui-state-error', container).remove(); };
	
	function faShowHighlight(container, data, overwrite) {
		if ( !$('.ui-state-highlight', container).length ) $(container).append('<div class="ui-state-highlight"></div>');//if not exist create
		highlight = $('.ui-state-highlight', container).append('<div>'+data+'</div>');
	};
	function faHideHighlight(container) { $('.ui-state-highlight', container).remove(); };
	
	
	//image hover menu
	$('.fa-hover').live('mouseover', function (){
		$(this).children('.fa-hover-content').show();
	});
	$('.fa-hover').live('mouseout', function (){
		$(this).children('.fa-hover-content').hide();
	});
	
	
$(document).ready(function() {	
});
