function styleFirstWord() {
  var el,pel,str,str2,idx,j,k,m,r=/^\s+$/;
  var paras = $$('h1, h2.big');
  for(var i=0;i<paras.length;i++) {
    if(!paras[i].hasChildNodes()) continue;
    if(paras[i].normalize) paras[i].normalize();
    pel = paras[i].childNodes[0];
    j=0;
    m=(pel.nodeType != 3)?1:(pel.nodeValue.match(r)?1:0);
    while(m) {
      if(!pel.hasChildNodes()) {
        if(pel.nextSibling) pel = pel.nextSibling;
      } else if(pel.nodeType == 1) {
        pel = pel.childNodes[0];
      }
      j++;
      m=(pel.nodeType!=3)?1:(pel.nodeValue===null)?1:pel.nodeValue.match(r)?1:0;
      m=(j<16)?m:0;
    }
    str = pel.data;
    if(!str.length) continue;
    k=0;
    while(str.charAt(k).match(/\s/)) { k++; }
    idx = str.replace(/^\s+/,'').indexOf(' ');
    if(idx==-1) idx=0;
    if(idx > 0) {
      idx+=k;
      pel.data = str.substring(idx,str.length);
      str = str.substring(0,idx);
    } else {
      pel.data = '';
    }
    el = document.createElement('span');
    pel.parentNode.insertBefore(el,pel);
    el.className='fwx';
    str2 = document.createTextNode(str);
    el.appendChild(str2);
    if(pel.data == '') pel.parentNode.removeChild(pel);
  }
}
/* o_O
var tempFunc;
if(typeof window.onload == "function") { tempFunc = window.onload; }
window.onload = function() {
  if(typeof tempFunc == "function") tempFunc();
  styleFirstWord();
}
*/
Shadowbox.init({
	language: 'ru',
	adapter: 'mootools',
	skipSetup: true,
	players:  ['img', 'html', 'iframe']
});
window.addEvent('domready', function() {
	styleFirstWord();


	// включаем shadowbox
  var Shadowbox_options = {
    resizeDuration: 0.2,
    fadeDuration: 0.2,
    viewportPadding: 10,
    handleOversize: 'drag',
    overlayOpacity: 0.5,
    viewportPadding: 5,
    autoDimensions: true,
		animate: false
  };

  $('m32').getFirst().addEvent('click', function(e) {
  	e.stop();

  	if ($('YMapsID')) $('YMapsID').setStyle('visibility', 'hidden');

  	Shadowbox.open({
      content: this.href,
      player: "iframe",
      title: this.get('html'),
      height: 800,
      width: 600,
      options: {
      	onClose: function() {
      		if ($('YMapsID')) $('YMapsID').setStyle('visibility', '');
     	 }
   	 }
    });

  });

  $$('#dbody h2.shownext').each(function(item) {
  	item.addEvent('click', function() {
  		if (this.closd) {
  			this.closd = false;
	  		this.getNext().setStyle('display', '');
	  		//this.removeClass('href');
  		} else {
  			this.closd = true;
	  		this.getNext().setStyle('display', 'none');
	  		this.addClass('href');
  		}
  	});
  	item.fireEvent('click');

  });

	list = $$(document.links);
  list = list.filter(function(item){
  	//if (item.hasClass('no')) return false;
    return item.href.test(/\.(jpe?g|png|gif)$/)
  });
  if (list && list.length) {
		Shadowbox.setup(list, Shadowbox_options);
  }

  new SmoothScroll({
  	onStart: function() {
  		if (this.oldanchor) {
  			this.oldanchor.removeClass('anchored');
  		}
  		this.oldanchor = $(this.anchor).addClass('anchored');
  		try {
  			var testh2 = $(this.anchor).getParent().getParent().getParent().getPrevious();
  			if (testh2.hasClass('shownext') && testh2.closd) {
  				testh2.fireEvent('click', {'stop': function(){} });
  				this.cancel();
  				this.toElement(this.anchor);
  			}
  		} catch(ex) {}

  	}
  });

  if (m = location.toString().match(/#(pr_.*)$/)) {
  	$(m[1]).fireEvent('click', {'stop': function(){} });
  }



});