jQuery(document).ready(function($) {
	
	$("a[rel^='prettyPhoto']").prettyPhoto();
	
	var init_cont_height = parseInt($('#content').height());
	if ( init_cont_height < 240 ) {
		$('#content').height(240);
	}
	
	$('#contact_phones').css({
		marginLeft: (793-parseInt($('#contact_phones').width()))+'px',
		marginTop: (260-parseInt($('#contact_phones').height()))+'px'
	})
	
	if ( $('#map_world').length == 0 ) {
		$('#logo_white_bg').fadeOut(100);
		$('#map_russia_radar, #flags div').fadeIn();
	} else {
		var radar_move_timer_id = null;
		
		function radar_move(){
			var cur_margin_left = parseInt($('#map_radar_line').css('marginLeft'));
			if ( cur_margin_left < 753 ) {
				$('#map_radar_line').animate({
					marginLeft: cur_margin_left+15
				}, 100, function(){
					$('#flags div:hidden').each(function(){
						var cur_flag_margin = parseInt($(this).css('marginLeft'));
						if ( cur_flag_margin < (cur_margin_left+40) ) {
							$(this).fadeIn(200);
						}
					});
					radar_move();
				});
			} else {
				$('#map_radar_line').fadeOut(100);
			}
		}
		
		function scale_russia(){
			$('#map_russia').fadeIn(200).animate({
				width: 561,
				height: 251,
				marginTop: 7,
				marginLeft: 234
			}, 500, function(){
				$('#map_russia').fadeOut(2000);
				$('#map_russia_radar').fadeIn(2000, function(){
					$('#map_radar_line').show(0, function(){
						radar_move();
					});
				});
			});
			$('#map_world').fadeOut(400, function(){$('#logo_white_bg').fadeOut(100);});
		}
		
		setTimeout(scale_russia, 2000);
	}
	
	$('#flags div').each(function(){
		var flag_id = $(this).index();
		var flag_margin_left = $(this).css('marginLeft');
		var flag_margin_top = $(this).css('marginTop');
		$('#flags_info div:eq('+flag_id+')').css({
			marginLeft: flag_margin_left,
			marginTop: flag_margin_top
		});
	});
	
	$('#flags div').hover(
		function(){
			$('#flags_info div:eq('+$(this).index()+')').fadeIn(100);
		},
		function(){}
	);
	
	$('#flags_info div').hover(
		function(){},
		function(){
			$(this).fadeOut(100);
		}
	);
	
	$('#menu_left .menu_lvl_1, #menu_left .menu_lvl_1_active, #menu_left div.submenu div').each(function(){
		$(this).children('a.submenu, a.submenu_active').parent().hover(
			function(){
				$(this).children('div.submenu').show();
			},
			function(){
				$(this).children('div.submenu').hide();
			}
		);
	});
	
	$('#user_message_form tr:odd').css("background-color", "#eee");
	
	$('#activate_params a').click(function(){
		$('#activate_params a.active').removeClass('active');
		$(this).addClass('active');
		var a_id = $(this).attr('id');
		if ( a_id == 'active_metall_params' ) {
			$(this).parent().find('input').attr('value', '1');
			$('#lumber_params').fadeOut();
			$('#metall_params').fadeIn();
		} else {
			$(this).parent().find('input').attr('value', '0');
			$('#metall_params').fadeOut();
			$('#lumber_params').fadeIn();
		}
		return false;
	});
	
	$('#activate_params a.active').trigger('click');
	
	$('.content_news_entity .news_content img').each(function(){
		if ( $(this).height() > $(this).parent().height() ) {
			$(this).parent().height($(this).height());
		}
	});
	
});
