jQuery(document).ready(function() {
$('div.menu-footer-container ul li:last').addClass('last');

/*$('li.har_li a').addClass('lic_href');
$('li.har_li ul li a').removeClass('lic_href');
$('li.har_li a.lic_href span.lic_wrap').eq(0).html(1);
$('li.har_li a.lic_href span.lic_wrap').eq(1).html(2);
$('li.har_li a.lic_href span.lic_wrap').eq(2).html(3);
$('li.har_li a.lic_href span.lic_wrap').eq(3).html(4);
$('li.har_li a.lic_href span.lic_wrap').eq(4).html(5);
$('li.har_li a.lic_href span.lic_wrap').eq(5).html(6);
$('li.har_li a.lic_href span.lic_wrap').eq(6).html(7);
$('li.har_li a.lic_href span.lic_wrap').eq(7).html(8);
$('li.har_li a.lic_href span.lic_wrap').eq(8).html(9);*/

$('li.cf-box-group input').addClass('styled');
$('input.cf-box-b').addClass('styled');

$('#opaco').height($(document).height()).fadeTo('slow', 0.7).click(function(){
	$(this).addClass('hidden');
	$('#popup_forma').addClass('hidden');
});

$('.current').live('click', function(){
	$('#popup_forma').removeClass('hidden');
	$('#opaco').removeClass('hidden');
});

$('.popup_close span').live('click', function(){
	$('#opaco').addClass('hidden');
	$('#popup_forma').addClass('hidden');
});

$('table').attr({cellpadding: 0, cellspacing: 0, border:0});
$('div.content table:nth-child(1n+1)').addClass('content_table');
$('div.post_content table:nth-child(1n+1)').addClass('content_table');
$('table.content_table tr:nth-child(1)').addClass('td_top');
$('table.content_table tr:nth-child(even)').addClass('td_bg'); 

// select all desired input fields and attach tooltips to them
$( "#cformsform input[type='text'], #cforms2form input[type='text']").tooltip({
	fixed: true,
	// place tooltip on the right edge
	position: "top left",
// a little tweaking of the position
	offset: [-8, 0],
	// use the built-in fadeIn/fadeOut effect
	effect: "toggle",
	// custom opacity setting
	opacity: 0.7,
	onShow: function() {
		var thisWidth = this.getTip().width();
		var thisLeft = this.getTip().offset().left*1 + thisWidth*1 + 10;
		this.getTip().css('left', thisLeft+'px');
	}
});

// VERTICALLY ALIGN FUNCTION
$.fn.vAlign = function() {
	return this.each(function(i){
			var ah = $(this).height();
					var ph = $(this).parent().height();
		var mh = (ph - ah) / 2;
	$(this).css('margin-top', mh);
	});
};


$(window).load(function() {
	$("li.har_li a.lic_href span.lic_txt").vAlign();
	$('li.har_li a.lic_href span.lic_wrap').vAlign();
});

$('p.cf-sb input').hover(function(){
$(this).addClass('button_hover');},
function(){
$(this).removeClass('button_hover'); 
});

$('.current').hover(function(){
	$(this).addClass('zakaz_hover');},
	function(){
		$(this).removeClass('zakaz_hover');
	});


	$('span.who_cat a').each(function() {
		thisText = $(this).text();
		$(this).replaceWith(thisText);
	});
	
		$('.lic_href a').each(function() {
		thisText = $(this).text();
		$(this).replaceWith(thisText);
	});

	
	if ($('body').hasClass('page-id-73')) {
		$('#menu-licvidation > li > ul').not(':first').hide();
		$('#menu-licvidation > li:first').addClass('current-menu-parent');
		$('#menu-licvidation > li:first > ul > li:first').addClass('current-menu-item');
		var firstHref = $('#menu-licvidation > li:first > ul > li:first > a').attr('href');
		
		$('#menu-licvidation > li > ul > li > a').filter(':first').each(function() {
			var thisHref = $(this).attr('href');
			$('#ajax_container').append('<div rel="'+thisHref+'"><img src="/wp-content/themes/twentyten/images/ajax-loader.gif" alt="" /> Идет загрузка, подождите, пожалуйста...</div>');
			$('#ajax_container > div[rel="'+thisHref+'"]').load(
				thisHref+' #lic_content',
				function() {
					$('#menu-licvidation > li > ul > li > a').not(':first').each(function() {
						var thisHref = $(this).attr('href');
						$('#ajax_container').append('<div rel="'+thisHref+'"><img src="/wp-content/themes/twentyten/images/ajax-loader.gif" alt="" /> Идет загрузка, подождите, пожалуйста...</div>');
						//$('#ajax_container > div[rel="'+thisHref+'"]').load(thisHref+' #lic_content');
						if (thisHref != firstHref) {
							$('#ajax_container > div[rel="'+thisHref+'"]').hide();
						}
					});
				}
			);
			if (thisHref != firstHref) {
				$('#ajax_container > div[rel="'+thisHref+'"]').hide();
			}
		});
		
		$('#menu-licvidation > li > a').live('click', function() {
			if ($(this).parent('li').hasClass('current-menu-parent')) {
				$(this).next('ul').slideUp();
				$(this).parent('li').removeClass('current-menu-parent')
			} else {
				$('#menu-licvidation > li > ul:visible').slideUp();
				$(this).next('ul').slideDown();
				
				// clear visible div and selected links
				var visibleHref = $('#ajax_container > div:visible').attr('rel');
				$('#ajax_container > div:visible').hide();
				$('#menu-licvidation > li > ul > li > a[href="'+visibleHref+'"]').parent('li').removeClass('current-menu-item');
				$('#menu-licvidation > li > ul > li > a[href="'+visibleHref+'"]').parent('li').parent('ul').parent('li').removeClass('current-menu-parent');
				
				// show first div and select links
				var thisHref = $(this).next('ul').children('li').children('a').attr('href');
				$('#ajax_container > div[rel="'+thisHref+'"]').show();
				if (!$('#ajax_container > div[rel="'+thisHref+'"]').hasClass('container-loaded')) {
					$('#ajax_container > div[rel="'+thisHref+'"]').load(
						thisHref+' #lic_content',
						function() {
							$('#ajax_container > div[rel="'+thisHref+'"]').addClass('container-loaded');
						}
					);
				}
				$(this).next('ul').children('li').filter(':first').addClass('current-menu-item');
				$(this).parent('li').addClass('current-menu-parent');
			}
			return false
		});
		$('#menu-licvidation > li > ul > li > a').live('click', function() {
			var thisHref = $(this).attr('href');
			if (!$('#ajax_container > div[rel="'+thisHref+'"]').is(':visible')) {
				// clear visible div and selected links
				var visibleHref = $('#ajax_container > div:visible').attr('rel');
				$('#ajax_container > div:visible').hide();
				$('#menu-licvidation > li > ul > li > a[href="'+visibleHref+'"]').parent('li').removeClass('current-menu-item');
				$('#menu-licvidation > li > ul > li > a[href="'+visibleHref+'"]').parent('li').parent('ul').parent('li').removeClass('current-menu-parent');
				
				// show current div and select links
				$('#ajax_container > div[rel="'+thisHref+'"]').show();
				if (!$('#ajax_container > div[rel="'+thisHref+'"]').hasClass('container-loaded')) {
					$('#ajax_container > div[rel="'+thisHref+'"]').load(
						thisHref+' #lic_content',
						function() {
							$('#ajax_container > div[rel="'+thisHref+'"]').addClass('container-loaded');
						}
					);
				}
				$(this).parent('li').addClass('current-menu-item');
				$(this).parent('li').parent('ul').parent('li').addClass('current-menu-parent');
			}
			return false;
		});
	}

});
