$(document).ready(function()
{
	// ТИЗЕР
	// <<<


	var currB = '#teaser .currentBlock';
	var teasB = '#teaser .teaserBlock';
	var clickB = '#teaser .clickBlock';
	var imageActivePosition = {top:-90,left:-140,'z-index':10};
	var imageDisPosition = {top:240,left:-300,'z-index':15};
	$('#teaser .teaserBlock:last .linkNext').hide();
	$('#teaser .teaserBlock:first .linkPrev').hide();

	$('#teaser .teaserBlock .imageBlock').css(imageDisPosition);
	$('#teaser .currentBlock .imageBlock').css(imageActivePosition);

	$('#teaser .dImage').click(function(){
		$(this).parents('.clickBlock').each(function()
		{
			teaserGo(this);
		});
	});

	$(document).bind('keydown', 'ctrl+left', function(){
		$(currB).prev('.clickBlock').each(function(){
			teaserLeft();
		});
	});

	$(document).bind('keydown', 'ctrl+right', function(){
		$(currB).next('.clickBlock').each(function(){
			teaserRight();
		});
	});

	$('#teaser .linkPrev').click(function(){
		$(currB).prev('.clickBlock').each(function(){
			teaserLeft();
		});
	});

	$('#teaser .linkNext').click(function(){
		$(currB).next('.clickBlock').each(function(){
			teaserRight();
		});
	});

	var teaserGo = function (img)
	{
		var prev = $(img).prev('.currentBlock');
		var next = $(img).next('.currentBlock');
		$(next).each(function(){
			teaserLeft();
		});
		$(prev).each(function(){
			teaserRight();
		});
	};

	if ( !$.browser.msie )
	{
		$(teasB).css({opacity:0,'z-index':3});
		$(currB).css({opacity:1,'z-index':4});
		$(currB).next().addClass('clickBlock');
		$(clickB).css({opacity:1,'z-index':5});
		$('#teaser .clickBlock .dImage').css({'cursor':'pointer'});
		$('#teaser .clickBlock .dImage').css({width:220,height:220,opacity:1,'z-index':5});
		$('#teaser .clickBlock .currImage').css({width:220,height:220,opacity:0,'z-index':4});
		$('#teaser .currentBlock .dImage').css({width:700,height:700,opacity:0,'z-index':4});
		$('#teaser .currentBlock .currImage').css({width:700,height:700,opacity:1,'z-index':5});

		var teaserRight = function()
		{
			$('#teaser .clickBlock .dImage').dequeue().css({'z-index':10}).animate({opacity:0});
			$('#teaser .clickBlock .currImage').dequeue().css({'z-index':5}).animate({opacity:0});
			$('#teaser .clickBlock').dequeue().css({'z-index':5});

			$('#teaser .currentBlock + .clickBlock .dImage').dequeue().css({'z-index':5}).animate({opacity:0,width:700,height:700});
			$('#teaser .currentBlock + .clickBlock .currImage').dequeue().css({'z-index':10}).animate({opacity:1,width:700,height:700});
			$('#teaser .currentBlock + .clickBlock .imageBlock').dequeue().stop().animate(imageActivePosition);

			$('#teaser .currentBlock .dImage').dequeue().stop().css({'z-index':10}).animate({opacity:1,width:220,height:220});
			$('#teaser .currentBlock .currImage').dequeue().stop().css({'z-index':5}).animate({opacity:0,width:220,height:220});
			$('#teaser .currentBlock .imageBlock').dequeue().stop().animate({top:240,left:460});

			$(currB).each(function()
			{
				$(teasB).removeClass('clickBlock').css({'z-index':5,'cursor':'default'});
				$('.clickBlock .dImage').css({'cursor':'default'});
				$(this).removeClass('currentBlock').addClass('clickBlock').css({'z-index':10});
				$(this).next().addClass('currentBlock').removeClass('clickBlock').css({'z-index':5});
				$('.clickBlock .dImage').css({'cursor':'pointer'});
				$(currB).prev().addClass('clickBlock');
				var next = $('.currentBlock').next();
				next.css({opacity:1,'z-index':11}).addClass('clickBlock');
				next.children('.imageBlock').children('.dImage').css({width:220,height:220,opacity:0}).animate({opacity:1});
				next.children('.imageBlock').children('.currImage').css({width:220,height:220,opacity:0});
			});
		};

		var teaserLeft = function()
		{
			$('#teaser .clickBlock .dImage').dequeue().css({'z-index':5}).animate({opacity:0,width:700,height:700});
			$('#teaser .clickBlock .currImage').dequeue().css({'z-index':10}).animate({opacity:1,width:700,height:700});
			$('#teaser .clickBlock .imageBlock').dequeue().stop().animate(imageActivePosition);

			$('#teaser .currentBlock + .clickBlock .dImage').dequeue().stop().css({'z-index':10}).animate({opacity:0});
			$('#teaser .currentBlock + .clickBlock .currImage').dequeue().stop().css({'z-index':5}).animate({opacity:0});
			$('#teaser .currentBlock + .clickBlock .imageBlock').dequeue().stop().animate({left:-300,top:240});

			$('#teaser .currentBlock .dImage').dequeue().stop().css({'z-index':10}).animate({opacity:1,width:220,height:220});
			$('#teaser .currentBlock .currImage').dequeue().stop().css({'z-index':5}).animate({opacity:0,width:220,height:220});
			$('#teaser .currentBlock .imageBlock').dequeue().stop().animate({top:240,left:-300});

			$(currB).each(function()
			{
				$(teasB).removeClass('clickBlock').css({'z-index':5,'cursor':'default'});
				$('.clickBlock .dImage').css({'cursor':'default'});
				$(this).removeClass('currentBlock').addClass('clickBlock').css({'z-index':10});
				$(this).prev().addClass('currentBlock').removeClass('clickBlock').css({'z-index':5});
				$('.clickBlock .dImage').css({'cursor':'pointer'});
				$(currB).next().addClass('clickBlock');
				var next = $('.currentBlock').prev();
				next.css({opacity:1,'z-index':9}).addClass('clickBlock');
				next.children('.imageBlock').children('.dImage').css({width:220,height:220,opacity:0}).animate({opacity:1});
				next.children('.imageBlock').children('.currImage').css({width:220,height:220,opacity:0});
			});
		};

	}
	else
	{
			if ( $.browser.version.substr(0,1) <= 8 )
			{
				$(teasB).css({'visibility':'hidden','z-index':3});
				$(currB).css({'visibility':'visible','z-index':4});
				$(currB).next().addClass('clickBlock');
				$(clickB).css({'visibility':'visible','z-index':5});
				$('#teaser .clickBlock .dImage').css({'cursor':'pointer'});
				$('#teaser .clickBlock .dImage').css({width:220,height:220,'visibility':'visible','z-index':5});
				$('#teaser .clickBlock .currImage').css({width:220,height:220,'visibility':'hidden','z-index':4});
				$('#teaser .currentBlock .dImage').css({width:700,height:700,'visibility':'hidden','z-index':4});
				$('#teaser .currentBlock .currImage').css({width:700,height:700,'visibility':'visible','z-index':5});

				var teaserRight = function()
				{
					$('#teaser .clickBlock .dImage').dequeue().css({'z-index':10,'visibility':'hidden'});
					$('#teaser .clickBlock .currImage').dequeue().css({'z-index':5,'visibility':'hidden'});
					$('#teaser .clickBlock').dequeue().css({'z-index':5});

					$('#teaser .currentBlock + .clickBlock .dImage').dequeue().css({'z-index':5,'visibility':'hidden'}).animate({width:700,height:700});
					$('#teaser .currentBlock + .clickBlock .currImage').dequeue().css({'z-index':10,'visibility':'visible'}).animate({width:700,height:700});
					$('#teaser .currentBlock + .clickBlock .imageBlock').dequeue().stop().animate(imageActivePosition);

					$('#teaser .currentBlock .dImage').dequeue().stop().css({'z-index':10,'visibility':'visible'}).animate({width:220,height:220});
					$('#teaser .currentBlock .currImage').dequeue().stop().css({'z-index':5,'visibility':'hidden'}).animate({width:220,height:220});
					$('#teaser .currentBlock .imageBlock').dequeue().stop().animate({top:240,left:460});

					$(currB).each(function()
					{
						$(teasB).removeClass('clickBlock').css({'z-index':5,'cursor':'default'});
						$('.clickBlock .dImage').css({'cursor':'default'});
						$(this).removeClass('currentBlock').addClass('clickBlock').css({'z-index':10});
						$(this).next().addClass('currentBlock').removeClass('clickBlock').css({'z-index':5});
						$('.clickBlock .dImage').css({'cursor':'pointer'});
						$(currB).prev().addClass('clickBlock');
						var next = $('.currentBlock').next();
						next.css({'visibility':'visible','z-index':11}).addClass('clickBlock');
						next.children('.imageBlock').children('.dImage').css({width:220,height:220,'visibility':'visible'});
						next.children('.imageBlock').children('.currImage').css({width:220,height:220,'visibility':'hidden'});
					});
				};

				var teaserLeft = function()
				{
					$('#teaser .clickBlock .dImage').dequeue().css({'z-index':5,'visibility':'hidden'}).animate({width:700,height:700});
					$('#teaser .clickBlock .currImage').dequeue().css({'z-index':10,'visibility':'visible'}).animate({width:700,height:700});
					$('#teaser .clickBlock .imageBlock').dequeue().stop().animate(imageActivePosition);

					$('#teaser .currentBlock + .clickBlock .dImage').dequeue().stop().css({'z-index':10,'visibility':'hidden'});
					$('#teaser .currentBlock + .clickBlock .currImage').dequeue().stop().css({'z-index':5,'visibility':'hidden'});
					$('#teaser .currentBlock + .clickBlock .imageBlock').dequeue().stop().animate({left:-300,top:240});

					$('#teaser .currentBlock .dImage').dequeue().stop().css({'z-index':10,'visibility':'visible'}).animate({width:220,height:220});
					$('#teaser .currentBlock .currImage').dequeue().stop().css({'z-index':5,'visibility':'hidden'}).animate({width:220,height:220});
					$('#teaser .currentBlock .imageBlock').dequeue().stop().animate({top:240,left:-300});

					$(currB).each(function()
					{
						$(teasB).removeClass('clickBlock').css({'z-index':5,'cursor':'default'});
						$('.clickBlock .dImage').css({'cursor':'default'});
						$(this).removeClass('currentBlock').addClass('clickBlock').css({'z-index':10});
						$(this).prev().addClass('currentBlock').removeClass('clickBlock').css({'z-index':5});
						$('.clickBlock .dImage').css({'cursor':'pointer'});
						$(currB).next().addClass('clickBlock');
						var next = $('.currentBlock').prev();
						next.css({'visibility':'visible','z-index':9}).addClass('clickBlock');
						next.children('.imageBlock').children('.dImage').css({width:220,height:220,'visibility':'visible'});
						next.children('.imageBlock').children('.currImage').css({width:220,height:220,'visibility':'hidden'});
					});
				};
			}
	}

	// >>>
	// ТИЗЕР

	// min-width для body в ie6
	if ( $.browser.msie && $.browser.version.substr(0,1) <= 6 )
	{

		var widthSet = function()
		{
			var minWidth = $('body').css('min-width');
			minWidth = minWidth.substring(minWidth.length-2,0);
			if ($(window).width() > minWidth)
			{
				$('body').css({'width':$(window).width()});
			}
			if ($(window).width() <= minWidth)
			{
				$('body').css({'width':minWidth});
			}
		};
		$(window).resize(function()
		{
			widthSet();
		});
		widthSet();
	}

});
