Shadowbox.init({
	language: 'ru',
	adapter: 'mootools',
	skipSetup: true,
	players:  ['img']
});
window.addEvent('domready', function() {

	// включаем shadowbox
  var Shadowbox_options = {
    resizeDuration: 0.1,
    fadeDuration: 0.1,
    marginDuration: 0.03,
    viewportPadding: 10,
    handleOversize: 'resize',
    overlayOpacity: 0.5,
    viewportPadding: 5,
    autoDimensions: true
  };

	list = $$(document.links);
  list = list.filter(function(item){
  	//if (item.hasClass('no')) return false;
    return item.href.test(/\.(jpe?g|png|gif|swf)$/)
  });
  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');
  	}
  });

  slideThis($$('#teaser .img'), 3000, {duration: 600});

  // menu
  $$('#sidebar .l1 > a').each(function(item) {
		var ul = item.getNext();
		if (!ul) return;
		var	ulh = ul.getSize().y;

		ul.set('tween', {duration: 300, transition: 'sine:out'});
		if (!item.hasClass('subactive')) {
			ul.setStyle('height', 0);
			var closed = true;
		} else {
			var closed = false;
		}

		item.addEvent('click', function(e) {
			e.stop();
			if (closed) {
				ul.tween('height', ulh);
				closed = false;
				item.addClass('subactive');
			} else {
				ul.tween('height', 0);
				closed = true;
				item.removeClass('subactive');
			}
		});


  });


});


function slideThis(collection, interval, params) {

	try {
		var total = collection.length;
		if (!total) return false;
	} catch(e) {}

	if (!interval) interval = 1500;
	if (!params) params = {}

	collection.currentNode = 0;

	collection.each(function(item) {
		item.setStyle('opacity', 0);
		item.set('morph', params);
	});

	var change = function() {
		if (collection.inactive) return true;


		collection[collection.currentNode].morph({
			'opacity': 0
			//, marginLeft: [0, -4]
		});
		collection.currentNode++;
		if (collection.currentNode == total) collection.currentNode = 0;

	if (collection[collection.currentNode].getStyle('visibility') == 'hidden')
			collection[collection.currentNode].setStyle('opacity', 0);

		collection[collection.currentNode].morph({
			'opacity': 1
			//, marginLeft: [4, 0]
		});

	}

	change.periodical(interval);
	collection[collection.currentNode].setStyles({
		opacity: 1,
		visibility: 'visible'
	});

}
