$(document).ready(function() {
	$("img").error(function() {
		$(this).hide();
	});

		$("textarea[limit]").livequery(function() {
			$(this).limit( { "leftChars" : "Осталось"
			});
		});
		$("input[limit]").livequery(function() {
			$(this).limit( { "show" : false
			});
		});

		$('div.popup').livequery(function() {
			$(this).center();
			$(this).fadeIn();
		});

		$('a.feedback,a.contacts').click(function() {
			$.post("/xajax/xajax.php", { func : "feedback",
			cmd : 'form',
			responseType : 'html'
			}, function(data) {
				$("div.popup").remove();
				$('body').append(data);
			});
			return false;
		});


		if (lightbx) {
			$('a.lb').lightBox( {
			// overlayBgColor : '#FFF',
				overlayOpacity : 0.8,
				imageLoading : '/engine/images/loading.gif',
				imageBtnClose : '/engine/images/close.gif',
				imageBtnPrev : '/engine/images/prev.gif',
				imageBtnNext : '/engine/images/next.gif',
				containerResizeSpeed : 350,
				txtImage : 'фото',
				txtOf : 'из'
			});
		}
		$('a#home').click(function() {
			if (document.all)
				window.external.AddFavorite(location.href, document.title);
			else if (window.sidebar)
				window.sidebar.addPanel(document.title, location.href, "");
			return false;
		});

		$('input.date').livequery(function() {
			$(this).attachDatepicker();
		});


		$('a.pay_ajax').click(function() {
			var ob = $(this);

			$.get(ob.attr('href'), function(data) {
				switch (data) {
					case '1':
						if (ob.html() == 'оплачен') {
							ob.html('оплатить');
							ob.parent().parent().attr('bgcolor','#b7ffc4');
						} else {
							ob.html('оплачен');
							ob.parent().parent().attr('bgcolor','#fac1bf');
							if ($('div.mcontainer'))
								$('div.mcontainer').remove();
						}
					break;
					default:
						// alert(data);
				break;
			}
		}	);
			return false;
		});
		
		
		
		$('a.publish_ajax').click(function() {
			var ob = $(this);

			$.get(ob.attr('href'), function(data) {
				switch (data) {
					case '1':
						if (ob.html() == 'скрыть') {
							ob.html('отобразить');
						} else {
							ob.html('скрыть');
							if ($('div.mcontainer'))
								$('div.mcontainer').remove();
						}
					break;
					default:
						// alert(data);
				break;
			}
		}	);
			return false;
		});

		$('a.delete, a.delete_ajax').live('click', function() {
			var href = $(this).attr('href');
			var title = $(this).attr('title');
			if (title == '')
				title = 'Удаление';
			jConfirm('Вы уверены, что хотите удалить?', title, function(r) {
				if (r)
					window.location = href;
			});
			return false;
		});

	$('a.note_img').live('click', function() {
			var href = $(this).attr('href');
			jPrompt('',$('a[href="'+href+'"] input').attr('value'), 'Введите описание файла', function(r) {
				if (r) {
					$('a[href="' + href + '"] input').attr('value', r);
					if (r != '') $('a[href="' + href + '"].note_img img').attr('src', '/img/note.png');
					
				} else {
					$('a[href="' + href + '"].note_img img').attr('src', '/img/note_none.png');
				$('a[href="' + href + '"] input').attr('value', '');	
				}
			});
			return false;
		});
	

		$('.fotka').mouseover(function() {
			$(this).addClass('fotka_hover').removeClass('fotka');
		});
		$('.fotka').mouseout(function() {
			$(this).addClass('fotka').removeClass('fotka_hover');
		});

		$('a.reload_captcha').live('click', function() {
			$(this).prev('img.captcha').attr('src', $(this).prev('img.captcha').attr('src') + '?reload');
			return false;

		});

		if ($.mask) {
			$('input:text').setMask();
		}

	});


function deleteFile(file, table, field, multi, id_parent) {

	$.post("/xajax/xajax.php", { func : "deleteFile",
	file : file,
	table : table,
	field : field,
	multi : multi,
	id_parent : id_parent
	});
}