$(document).ready(function() {  //растяжение крошек
  $('p#breadcrumbs').css('width',(document.body.clientWidth+15)+"px");
  $('p#breadcrumbs').css('margin-left',"-"+((document.body.clientWidth-840)/2)+"px");
  $(window).resize(function() {
    $('p#breadcrumbs').css('width',(document.body.clientWidth+15)+"px");
    $('p#breadcrumbs').css('margin-left',"-"+((document.body.clientWidth-840)/2)+"px");
  });
  $("#"+$('ul#main_menu').find('li.active > a').attr('rel')).show();
  $('#main_menu li').mouseover(function(){  	$('#main_menu li').removeClass('active');
  	$(this).addClass('active');  	$('.submenu').hide();
  	var curr_menu_str = $(this).find('a').attr('rel');
  	if (curr_menu_str) {
  	  $('#'+curr_menu_str).show();
  	}  }).mouseout(function(){  	$('.submenu').hide();  	$("#"+$('ul#main_menu').find('li.active > a').attr('rel')).show();  });
  // ajax-хэндлеры
  $('body').ajaxStart(function() {
    $(this).append('<div id="wrapper_full" class="wrapper_full_layer" onclick="ajax_hide();"></div><div id="wrapper_bar" class="wrapper_bar_layer"></div>');
    var wrapper_bar_top = $(document).scrollTop() + 0.5*$(window).height() - 0.5*$('div#wrapper_bar').height();
    $('div#wrapper_bar').css({top: wrapper_bar_top+'px', left: '50%', marginLeft: -0.5*$('div#wrapper_bar').width()+'px'});
  });
  $('body').ajaxStop(function() {

  });
  $('body').ajaxComplete(function() {
    ajax_hide();
  });
  $('body').ajaxError(function(event, request, settings) {
    var message = 'При обращении к странице <a href="'+settings.url+'">'+settings.url+'</a> возникла ошибка.';
    message += '<span style="font-size: 1em;"><br /><a href="javascript:void(0);" style="outline: none; text-decoration: none; border-bottom: 1px dashed #0057B9;" onmouseover="this.style.borderBottom = \'0\';" onmouseout="this.style.borderBottom = \'1px dashed #0057B9\';" onclick="if (document.getElementById(\'backend_flash_exception\').style.display == \'none\') { document.getElementById(\'backend_flash_exception\').style.display = \'block\'; } else { document.getElementById(\'backend_flash_exception\').style.display = \'none\'; }">подробные сведения</a></span>';
    message += '<div id="backend_flash_exception" style="display: none">';
    message += request.responseText;
    message += '</div>';
    flash_error(message);
  });

  // baloon
  if (window.attachEvent) {
    window.attachEvent("onload", function() { create_baloon(); });
  } else if (window.addEventListener) {
    window.addEventListener("DOMContentLoaded", function() { create_baloon(); }, false);
  } else {
    document.addEventListener("DOMContentLoaded", function() { create_baloon(); }, false);
  }

  // "обёртки"
  $('#content div.notice').wrapInner('<div class="notice_content"></div>');
  $('#content div.notice').prepend('<div class="notice_caption">Внимание!</div>');
  $('#content div.notice').wrap('<div class="notice_wrapper"></div>');

  // оформление <pre>
  $('#content pre').wrap('<div class="pre_wrapper"></div>');

  // оформление .doc_method
  $('#content .doc_method').wrap('<div class="doc_method_wrapper"></div>');

  // подключение prettyprint для <pre>
  $('#content pre').addClass('prettyprint');
  prettyPrint();

  //popup-бокс просмотра галереи
  $(document).pngFix();
	$(function() {
	  $.nyroModalSettings({
	    processHandler: function(settings) {
	      var from = settings.from;
	      if (from && from.href && $(from).hasClass('video_view') == true) {
	        $.nyroModalSettings({
	          type: 'swf',
//	          forceType: 'swf',
	          height: 350,
	          width: 600,
//	          bgcolor: "#111111",
	          url: "/media/FlvPlayer.swf",
	          swf: {				flashvars: 'flvpFolderLocation=/media/gallery/&flvpWidth=610&flvpHeight=360&flvpInitVolume=50&flvpTurnOnCorners=true&flvpVideoSource='+from.href,
				bgcolor: "#000",
				menu: true,
				allowfullscreen: true	          }
	        });
	      }
	    }
	  });
	});
});
