$(document).ready(function() {

	
	$('.region-item').bind({ mouseover : function() {
		if ($(this).find('ul>li').length > 4) {
			$(this).find('ul').attr('style', 'z-index: 9999; position: absolute; height: auto; background-color:#eee; border: solid 1px #aaa');
			$(this).find('ul li:last').css('padding-bottom', '10px');
		}
	},
	mouseout : function() {
		if ($(this).find('ul>li').length > 4) {
			$(this).find('ul').removeAttr('style');
			$(this).find('ul li:last').css('padding-bottom', '0px');
		}
	}
	});



	$('.tab_region li a').click(function() {
		$('.tab_region li a, .tab_region li').removeClass('active');
		$(this).addClass('active');
		$(this).parents('li').addClass('active');
		$('div.region div.region_top .region_bot').removeClass('hide');
		$('div.region div.region_top .region_bot[alt!="' + $(this).attr('id') + '"]').addClass('hide');
		return false;
	});

	
	$('#showCount').click(function(){
		$('#codeCount').slideToggle();
		return false;
	});
	


	$('div.popup').livequery(function() {
		$(this).center();
		$(this).fadeIn();
	});

	
	$('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('Вы уверены, что хотите удалить?','', function(r) {
			if (r)
				window.location = href;
		});
		return false;
	});
		
	$('a.reload_captcha').live('click', function() {
		$('img.captcha').attr('src', $('img.captcha').attr('src') + '?reload');
		return false;
	});

	if ($.mask) {
		$('input:text').setMask();
	}

	$('a.popupOpenBtn, a.popupCloseBtn').click(function() {
		$(this).prev().slideToggle('slow');
		$(this).toggleClass('popupCloseBtn popupOpenBtn');
	});




		
});
