var isIE = false;
var t_id, t1_id = 0;
function show_h(){

function sortNumber(a, b)
{
return a - b;
}

	var m_ul = [];
	var ul_0;
	m_ul[0] = jQuery('#CityList ul:first').height();
	m_ul[1] = jQuery('#CityList ul li.selected ul').height();
	m_ul[2] = jQuery('#CityList ul li.selected ul li.selected ul').height();
	var ul_0 = m_ul[0];

	//console.log(ul_0);
	//console.log(m_ul[0], m_ul[1], m_ul[2]);

	m_ul.sort(sortNumber);
	
	var bottom_height = 5;
	if ( isIE ){ bottom_height = 12; }
	if ( m_ul[2] > ul_0 ){ 
		bottom_height = 10; 
		if ( isIE ){
			bottom_height = 20;
		}
	}



	var measurer = jQuery('#measurer').height();
//	console.log(m_ul[2]);
//	console.log(bottom_height);
//	console.log(bottom_height);
//	console.log('=================');
	var n_height = Math.round ( m_ul[2] / measurer );
	jQuery('#Regions .background').css({ 'height': n_height + bottom_height + 'em' });
};

jQuery.noConflict();
jQuery('document').ready(function(){

	if ( jQuery.browser.msie ) isIE = true;
	setTimeout('show_h();',50);

	jQuery('#CityList').mouseup(function(){
		clearTimeout(t_id);
		t_id = setTimeout('show_h();',10);
	});


	jQuery('.region-selector').mouseup(function(){
		clearTimeout(t1_id)
		t1_id = setTimeout('show_h();',10);
	});

	

	if ( jQuery.browser.msie ){	
		
		// высота меню меняется при изменении размера шрифт, -1 в ие
		if ( jQuery('#measurer').height() < 16 ){
			jQuery('#Regions #background').addClass('ie');
		}
		jQuery('#measurer').resize(function(){
			var nMeasurerHeight = jQuery('#measurer').height();
			//alert(nMeasurerHeight);
			// высота меню меняется при изменении размера шрифт, -1 в ие 6
			if ( nMeasurerHeight < 16 ){
				jQuery('#Regions #background').addClass('ie');
			}else{
				jQuery('#Regions #background').removeClass('ie');
			}
		});
		
	
		// все превдохрефы
		jQuery('span.pseudo-href').mouseover(function(){
			jQuery(this).css({
				'color': '#FC1921',
				'border-color': '#FC1921'
			});
		});
		jQuery('span.pseudo-href').mouseout(function(){
			jQuery(this).attr('style','');
		});
		
		// меню первого уровня
		jQuery('#CityList li span.okrug-name').mouseover(function(){
			jQuery(this).addClass('main-menu-hover');
			/*jQuery(this).css({
				'color': '#FC1921',
				'border-color': '#FC1921'
			});*/
		});
		jQuery('#CityList li span.okrug-name').mouseout(function(){
			jQuery(this).removeClass('main-menu-hover');
			//jQuery(this).attr('style','');
		});
		
		// меню второго уровня
		jQuery('#CityList li li span').mouseover(function(){
			if ( !jQuery(this).parent().parent().hasClass('selected') ){
				jQuery(this).addClass('main-menu-hover');
				/*jQuery(this).css({
					'color': '#FC1921',
					'border-color': '#FC1921'
				});*/
			}
		});
		jQuery('#CityList li li span').mouseout(function(){
			jQuery(this).removeClass('main-menu-hover');
			//jQuery(this).attr('style','');
		});
		jQuery('#CityList li li span').click(function(){
			jQuery(this).removeClass('main-menu-hover');
			//jQuery(this).attr('style','');
		});
	}
});