	  	// настройки по умолчанию
		var options = {
			time:7000,
			changetime:500,
			pause:'pause'
		};
		var container,timer=null,nVis=0,images=[],nopause=false;
		var start = function(el){
			if(!el) return;
			container=el;
			jQuery(el).append('<div class="load"></div>');
			jQuery(el).children('img').each(function(i,el){
				if(!i) {
					//jQuery(el).css({'opacity':0,'display':'none','z-index':0});
					if(jQuery(container).find('div.text>p').eq(i).text()!='') {
						jQuery(container).find('div.text>p').eq(i).css({'opacity':1,'display':'block'});
					}
					else jQuery(container).find('div.text>p').eq(i).css({'opacity':0,'display':'none'});
				}
				else {
					//jQuery(el).css({'opacity':0,'display':'none','z-index':-1});
					jQuery(container).find('div.text>p').eq(i).css({'opacity':0,'display':'none'});
				}
				images.push(el.src);
				$(el).remove();
			});
			show(nVis);
			if(images.length<2) {return false;}
			if(!nopause) {
				jQuery(el).append('<div class="'+options.pause+'" style="position:absolute;z-index:10;bottom:5px;right:5px;height:20px;width:30px;padding:0 0 0 11px;font:11px/18px Arial;color:#fff;cursor:pointer;">pause</div>')
				jQuery('div.'+options.pause,el).click(function(){pause();});
			}
		};
		var show = function(n){
			var l=(n-1)<0?(images.length-1):n-1;

			if(!$(container).children('img[rel='+n+']').length) {
				$(container).prepend('<img alt="" rel="'+n+'" style="visibility:hidden;" src="'+images[n]+'" onload="if($(this).width()) show('+n+');" onclick="imageClick(this);">');
				var newimg=$(container).children('img[rel='+n+']');
				newimg.css({'opacity':0,'z-index':0});
				$('div.load',container).show(0);
				return false;
			}

			$(container).find('div.load').hide(0);
			$(container).children('img[rel='+n+']').css({'visibility':'visible','display':'block','z-index':1}).animate(
					{'opacity':1},
					{
						duration:options.changetime
					}
				);
			if(images.length<2) return false;
			$(container).children('img[rel='+l+']').animate({'opacity':0},{
						duration:options.changetime,
						complete:function(){
							$(container).children('img[rel='+l+']').css({'opacity':0,'display':'none','z-index':-1});
						}
					});
			var half=options.changetime/2;
			jQuery(container).find('div.text>p').eq(l).animate(
				{'opacity':0},
				{
					duration:half,
					complete:function(){
						jQuery(this).css('display','none');
						if(jQuery(container).find('div.text>p').eq(n).text()!='') jQuery(container).find('div.text>p').eq(n).css({'opacity':0,'display':'block'}).animate({'opacity':1},half);
					}
				}
			);

			nVis=(n+2>images.length)?0:n+1;
			timer=setTimeout(function(){show(nVis);},options.time);

		};
		var pause = function(){
			if(timer) {
				clearInterval(timer);
				timer=null;
				jQuery('div.'+options.pause,container).text('play').addClass('play');
			}
			else {
				timer=setTimeout(function(){show(nVis);},options.time);
				jQuery('div.'+options.pause,container).text('pause').removeClass('play');
			}
		};


$(document).ready(function() {
	start($('#slideshow').get(0));
});

function viewPicture(el){
	if($(el).width()) {
		var newWidth,newHeight,k=1;
		var size,s=1;

		while(s) {
			size = ($(el).width()<=0.91*$(document).width()?0:1)+''+($(el).height()<=0.91*$(window).height()?0:1);
			switch(size){
				case '00':
					newWidth = $(el).width();
					newHeight = $(el).height();
					s=0;
					break;
				case '01':
					newHeight = 0.9*$(window).height();
					k=newHeight/$(el).height();
					newWidth = $(el).width()*k;
					s=0;
					break;
				case '10':
					newWidth = 0.9*$(window).width();
					k=newWidth/$(el).width();
					newHeight = $(el).height()*k;
					s=0;
					break;
				case '11':
					k=$(el).width()/$(el).height();
					if(k>1) {
						newWidth = 0.9*$(window).width();
						k=newWidth/$(el).width();
						newHeight = $(el).height()*k;
					}
					else {
						newHeight = 0.9*$(window).height();
						k=newHeight/$(el).height();
						newWidth = $(el).width()*k;
					}
					break;
			} // switch
			$(el).width(newWidth).height(newHeight);
		}
		$(el).width(newWidth).height(newHeight);
		$('#simplemodal-container').animate({left:($(document).width()-newWidth)/2,top:($(window).height()-newHeight)/2,width:newWidth,height:newHeight}, 500, function(){jQuery('#modalWindow>img').animate({opacity:1},500);});
	}
}

function imageClick(el) {
	if(nopause) return;
	jQuery('#modalWindow').html('<img alt="" style="visibility:hidden;" src="'+el.src.replace('middle_','')+'" onload="viewPicture(this);">');
	jQuery('#modalWindow>img').css({
		'opacity':0,
		'visibility':'visible',
		'position':'absolute'
	});
	jQuery('#modalWindow').modal({
		overlayClose:true,
		containerCss: {
			width:700,
			height:400,
			'background':'#fff url(/images/load.gif) center center no-repeat'
		},
		containerId:'simplemodal-container'
	});
}
