$(document).ready(function()
{
  /* Открытие подменю хлебных крошек */
  $('#breadcrumbs div.wrap').live('mouseover', function(event)
  {
    if(event.target.tagName == 'DIV')
    {
      if($(this).next('div.submenu').children('div.item').length)
      {
        var parentWidth = $(this).parent('div.sec').width();
        var menuWidth = $(this).next('div.submenu').width();

        if(parentWidth > menuWidth) $(this).next('div.submenu').css('width', parentWidth + 'px')

        $(this).next('div.submenu').show();
      }
    }
  });


  /* Закрытие подменю хлебных крошек */
  $('#breadcrumbs div.submenu').live('mouseleave', function()
  {
    $(this).hide();
  });
  
  /* Закрытие подменю хлебных крошек */
  $('#breadcrumbs').mouseleave(function()
  {
    $(this).children('.sec').chilren('submenu').hide();
  });


  /* Костылюшечка для хлебных крошек */
  var height = 0;

  $('#breadcrumbs div.sec div.wrap a').each(function(index, el)
  {
      if($(el).height() > height) height = $(el).height();
  });

  $('#breadcrumbs div.sec div.wrap a').css('height', height + 'px');



  /* Открытие попапа */
  $('a.open-popup').live('click', function()
  {
    var WinID = $(this).attr('name');
    var TopPos = $('body').height() / 2 - $('#'+ WinID).height() / 2;
    var LeftPos = $('body').width() / 2 - $('#'+ WinID).width() / 2;

    $('#'+ WinID).css('position', 'absolute');
    $('#'+ WinID).css('z-index', '10000');
    $('#'+ WinID).css('top', parseInt(TopPos) +'px');
    $('#'+ WinID).css('left', parseInt(LeftPos) +'px');


    $('#fog').css('opacity', '0.6');
    $('#fog').css('background', '#fff');
    $('#fog').css('height', $(document).height());

    $('#fog').show();
    $('#'+ WinID).fadeIn();

    return false;
  });


  /* Закрытие попапа */
  $('div.popup div.close').live('click', function()
  {
    $('#fog').hide();
    $(this).parent('div.popup').fadeOut();

    return false;
  });


  /* Закрытие попапа по клику вне попапа */
  $('#fog').live('click', function()
  {
	if ($(".tempClass").length > 0) {
		$('.hide-big').hide();
		$('.hidebox_min_absolute').hide();
		$("#fog").animate({opacity: "0"},0);
		$("#fog").hide();
		$(".tempClass").removeClass('tempClass');
	} else if ($(".office_map_box").length > 0) {
		office_active = false;
		$(".office_map_box").each(function() {
			if ($(this).css('display') == 'block') {
				office_active = true;
			}
		});
		if (office_active) {
			$('.hide-box').hide();
			$("#fog").animate({opacity: "0"},0);
			$("#fog").hide();
		}
	}  else if ($("div#loading_new").css('display') != 'block') {
		$('#fog').hide();
		$('div.popup').fadeOut();
	}
  });




  /* Welcome to your code! */



});


