function substring_els (els, tosubstr, lim) {
	if (!lim) {
		lim = 180;
	}
	Publis.lim = lim;
	if (els.contains(':')) {
		var splited = els.split(":");
		splited.each(function(el){
			var text_path = $(el).getElements(tosubstr);
			text = text_path.get('text');
			var substr = (""+text+"").substring(0, Publis.lim);
			text_path.getParent().grab(new Element('span', {'text': substr}));
			text_path.destroy();
		});
	} else {
		var text_path = $(els).getElements(tosubstr);
		text = text_path.get('text');
		var substr = (""+text+"").substring(0, Publis.lim);
		text_path.getParent().grab(new Element('span', {'text': substr}));
		text_path.destroy();
	}
}

window.addEvent('domready',function() {

	if ($('content-box--home-bottom--')) {
		var Boxes = $('content-box--home-bottom--').getElements('.perex');
		Boxes.each(function(el){
			if (el.getElements('h3').length > 0) {
				var hd = el.getElements('h3').get('text');
				var wrapper = el.getParent().getParent().getParent();
				wrapper.getElements('h2').set('text', hd);
				el.getElements('h3').destroy();
			}
		});
	}
		  
	/* create container */

	if ($('slideshow_images')) {
		
		var getImages = $('slideshow_images').getElements('img');
		$('slideshow_images').getParent().grab(new Element('div', {'id': 'slideshow-container'}));
		getImages.each(	function(el) {
			$('slideshow-container').adopt(el);
		});
		
		var images_cnt = $('slideshow-container').getElements('img');
		
		var allLinks = $('slideshow_links').getElements('a');
		images_cnt.each( function(el, j) {
			new Element('a', {'class': 'img', 'id': 'slideshow_image_'+(j+1), 'href': allLinks[j].get('href'), 'styles': {
				'position': 'absolute'
			}}).wraps(el);	
			el.set('alt', allLinks[j].get('alt'));	
		});    
		
		$('slideshow-container').grab(new Element('div', {'class': 'clear'}), 'bottom');
		
		$('slideshow_images').destroy();
		$('slideshow_links').destroy();
		
		/* settings */
		
		var showDuration = 3000;
		var container = $('slideshow-container');
		var images = container.getElements('a.img');
		var currentIndex = 0;
		var interval;
		
		/* slideshow navigation */
		
			$('slideshow-container').getParent().grab(new Element('div', {'id': 'slideshow-navigation', 'styles': {
				'position': 'relative',
				'z-index': '120'
			}}));
		
			$('slideshow-navigation').adopt(new Element('ul'));
			images.each( function(el, j) {
				$('slideshow-navigation').getElement('ul').grab(new Element('li', {'id': 'slideshow_navigation-li-'+(j+1)}));
				$('slideshow_navigation-li-'+(j+1)).grab(new Element('span', {'styles': {
					'cursor': 'pointer'
				}, 'events': {
					'click': function() {
						$('slideshow-navigation').getElements('li').removeClass('active');
						$('slideshow_navigation-li-'+(j+1)).addClass('active');
						images.setStyles({
							'visibility': 'hidden',
							'opacity': '0'
						});
						$('slideshow_image_'+(j+1)).setStyles({
							'visibility': 'visible',
							'opacity': '1'						
						});
						currentIndex = j;
					}
				}}));
				if (j == 0) {
					$('slideshow_navigation-li-1').addClass('active');	
				}
			});
		
		/* opacity and fade */
		images.each(function(img,i){ 
			if(i > 0) {
				img.set('opacity',0);
			}
		});
		/* worker */
		var show = function() {
			$('slideshow_navigation-li-1').addClass('active');	
			images[currentIndex].fade('out');
			images[currentIndex = currentIndex < images.length - 1 ? currentIndex+1 : 0].fade('in');
				if (currentIndex == 0) {
					$('slideshow_navigation-li-'+(images.length)).removeClass('active');	
				} else if (currentIndex == (images.length)-1) {
					$('slideshow_navigation-li-1').removeClass('active');		
				}
				$('slideshow_navigation-li-'+(currentIndex)).removeClass('active');
				$('slideshow_navigation-li-'+(currentIndex+1)).addClass('active');	
		};
		/* start once the page is finished loading */
		window.addEvent('load',function(){
			interval = show.periodical(showDuration);
		});
	
	}
	
});
