var SEARCH_DEFAULT = 'Поиск по сайту';
jQuery.noConflict;
jQuery(document).ready(function() {
	jQuery('#photos-hdr .slide').css({float: 'none', position: 'absolute'}).append('<span class="control play" />');
	jQuery('#photos-hdr .slide').not(':eq(1)').find('.control').hide();
	jQuery('#photos-hdr .slide:eq(1)')
		.prev().css({marginTop: '219px', borderWidth: '3px', left: 0, top: 0}).end()
		.css({borderWidth: '3px', left: '77px', top: '46px'})
		.nextAll('.slide').each(function(i) {
			jQuery(this).css({top: 0 - 71*i, borderWidth: '3px', left: 332 + 95*i});
		});
	jQuery('#photos-hdr .slide:eq(1)').append('<span class="caption">' + jQuery('#photos-hdr .slide:eq(1)').find('img').attr('alt') + '</span>');
	jQuery('#photos-hdr .slide').not(':eq(1)').find('img').attr('src', function() { return this.src.replace('slide-', 'preview/preview-'); });
	jQuery('#photos-hdr .slide').click(function() {
		if	(jQuery(this).prev().css('left') == '77px') {
			jQuery(this).find('img').attr('src', function() { return this.src.replace('preview/preview-', 'slide-'); });
			jQuery(this).prev().find('img').attr('src', function() { return this.src.replace('slide-', 'preview/preview-'); });
			jQuery(this).prev().animate({marginTop: '173px', borderWidth: '3px', left: '-=77px'}, {duration: 500, easing: 'jswing'}).find('img').animate({width: '89px', height: '65px'}, {duration: 500, easing: 'jswing'});
			jQuery(this).prev().prevAll().animate({left: '-=95px', opacity: '0', marginTop: '+=71px' }, {duration: 500, easing: 'jswing'});
			jQuery(this).animate({top: '46px', borderWidth: '3px', left: '-=255px'}, {duration: 500, easing: 'jswing'}).find('img').animate({width: '267px', height: '190px'}, {duration: 500, easing: 'jswing'});
			jQuery(this).next().animate({left: '-=95px', opacity: '1', top: '0px'}, {duration: 500, easing: 'jswing'}).show();
			jQuery(this).next().nextAll().animate({left: '-=95px', top:'-71px'}, {duration: 500, easing: 'jswing'}).hide();
			jQuery(this).append('<span class="caption">' + jQuery(this).find('img').attr('alt') + '</span>').prev().find('.caption').remove();
			jQuery(this).find('.caption').css({display: 'none'}).show();

		};
		if	(jQuery(this).next().css('left') == '77px') {
			jQuery(this).find('img').attr('src', function() { return this.src.replace('preview/preview-', 'slide-'); });
			jQuery(this).next().find('img').attr('src', function() { return this.src.replace('slide-', 'preview/preview-'); });
			jQuery(this).next().animate({marginTop: '0px', top: '0px', borderWidth: '3px', left: '+=255px'}, {duration: 500, easing: 'jswing'}).find('img').animate({width: '89px', height: '65px'}, {duration: 500, easing: 'jswing'});
			jQuery(this).next().nextAll().animate({left: '+=95px', opacity: '0', top: '-71px' }, {duration: 500, easing: 'jswing'});
			jQuery(this).animate({top: '46px', borderWidth: '3px', left: '+=77px', marginTop: '0px'}, {duration: 500, easing: 'jswing'}).find('img').animate({width: '267px', height: '190px'}, {duration: 500, easing: 'jswing'});
			jQuery(this).prev().animate({left: '+=95px', opacity: '1', marginTop: '-=71px'}, {duration: 500, easing: 'jswing'}).end();
			jQuery(this).prev().prevAll().animate({left: '+=95px', top:'-=71px'}, {duration: 500, easing: 'jswing'});
			jQuery(this).append('<span class="caption">' + jQuery(this).find('img').attr('alt') + '</span>').next().find('.caption').remove();
			jQuery(this).find('.caption').css({display: 'none'}).show();

		};
		return
	});
	jQuery('#photos-hdr .control').click(function() {
		if (jQuery(this).hasClass('play'))	{
			interval = setInterval(rightToLeft, 5000);
			jQuery('#photos-hdr .control').removeClass('play').addClass('pause');
		}
		else if (jQuery(this).hasClass('pause'))	{
			clearInterval(interval);
			jQuery('#photos-hdr .control').removeClass('pause').addClass('play');
		}
	});
	jQuery('#photos-hdr img').not(':eq(1)').each(function(i) {
		jQuery(this).css({width: '89px', height: '65px'});
	});
});

var clickableElement = 2;

function rightToLeft()	{
	if	(jQuery('#photos-hdr .slide:last').css('left') == '200px')
		clickableElement = 0;
	else if (jQuery('#photos-hdr .slide:first').css('left') == '0px')
		clickableElement = 2;

	jQuery('#photos-hdr .slide:visible:eq(' + clickableElement + ')').trigger('click');
}
 
