document.observe('dom:loaded', function() {
	Mbox.init('mbox_container');
	Ajax.Process.init();
	//$$('body *').invoke('pngfix');
	//$$('.form textarea').invoke('autogrow');
	$$('.wg_MBox', '.wg_menu_item').each(function(el) {
		el.observe('mouseover', function(e) {
			el.addClassName('wg_Hover');
		}).observe('mouseout', function(e) {
			el.removeClassName('wg_Hover');
		});
	});		
	
	$$('#wg_icons img').each(function(el) {
		el.observe('mouseover', function(e) {
			imageHoverOn(el);
		}).observe('mouseout', function(e) {
			imageHoverOff(el);
		});
	});
	
	preloadImages(
		'/img/wg_MBoxTLBgHover.gif',
		/*'/img/sprtXR1.gif',
		'/img/sprtNR1.gif',
		'/img/sprtNR2.gif',
		'/img/sprtNR3.gif',*/
		'#'
	);
	
	$$('a[rel=popup]').each(function(el) {
		Event.observe(el, 'click', function(e) {
			Event.stop(e);
			var el = Event.findElement(e, 'a'),
				options = {
					width: 900,
					height: 600,
					features: 'resizable,scrollbars'
				};
				
			if (el.readAttribute('popup-style')) {
				var parts = {};
				el.readAttribute('popup-style').split(";").each(function(val) {
					if (!val.length) { return; }
					var pair = val.split(":", 2);
					if (!pair[0].length || !pair[1].length) { return; }
					parts[pair[0]] = pair[1]; 
				});
				Object.extend(options, parts);
			}
			var href = el.href;
			if (!href.include('nopopup=')) {
				href += (href.include('?') ? '&' : '?') + 'nopopup=0';
			}
			
			return popup(href, options)
		});
	});
	
	/*var topOffset = $('wg_main').cumulativeOffset()['top'],
	    bodyHeight = $('wg_main').getHeight();
	$('wg_LThing').setStyle({
		_top: topOffset+bodyHeight+400+'px'
	});*/
	
	// init highslide
	initHighslide();

	/* динамика в дереве, в левом столбце */
	$$('.item_tree li>a, .item_tree li>span').each(function(element) {
		if (element.up('li').down('ul')) {
			element.addClassName('clickable dashed');
	    	element.observe('click', function(event) {
	    		element.up('li').down('ul').toggle();
	    		Event.stop(event);
	    	});
			 
			if (element.up('li').hasClassName('level_1') && !element.up('li').hasClassName('opened')) {
				if (!element.up('li').down('.selected')) {
					element.up('li').down('ul').hide();
				}
			}
			
		}
	});

}, false);
