$(document).ready(function(){

	var _playerVersion = $.flash.version,
	_majorVersion = _playerVersion.major;

	{	// Вставка флеша на титульной странице
	
		if ($('#flashIndex').length) {
			
			if (_majorVersion >= 10){
				$('#flashIndex').html('');
				$('#flashIndex').flash({
					swf: _root + 'public/flash/index_4_7.swf',
					width: 100+'%',
					height: 100+'%',
					// wmode: 'transparent',
					bgcolor: '#1C1C1C',
					name: 'flashIndex',
					id: 'flashIndex',
					flashvars: {
						xmlMenuLeftURL: _root + 'catalog/?xml=1',
						xmlMenuBottomURL: _root + 'btmxml/',
						xmlMenuLangURL: _root + 'public/flash/menulang.xml',
						xmlBannersURL: _root + 'bannerxml/',
						copyright: _copyright
					}
				});
				//swffit.fit("flashIndex",1000,850);
			} else {
				$('#flashIndex').hide();
				$('#noflashIndex').show();
			}
			
		}
		
		if ($('#flashMenuLeft').length) {
			
			var _currentItemName = $('#menuLeft li.current a').html();
			if (!_currentItemName) {
				_currentItemName = 'noCurrentItem';
			}
		
			_currentItemNameMod = _currentItemName.replace(/&amp;/i, "|")

			if (_majorVersion >= 9){
				$('#flashMenuLeft').html('');
				$('#flashMenuLeft').flash({
					swf: _root + 'public/flash/menu_3_4.swf',
					width: 100+'%',
					height: 600,
					wmode: 'transparent',
					flashvars: {
						xmlMenuLeftURL: _root + 'catalog/?xml=1&asdfasdf',
						currentItemName: _currentItemNameMod,
						rootLink: _root
					}
				});
			} else {
				$('#noflashMenuLeft').show();
			}
			
		}
		
	}

	
	{	// Вставка флеша в подвал
	
		if ($('#flashFooter').length) {
			
			if (_majorVersion >= 9){
				$('#flashFooter').html('');
				$('#flashFooter').flash({
					swf: _root + 'public/flash/footer_3.swf',
					width: 100+'%',
					height: 68,
					wmode: 'transparent',
					flashvars: {
						color: _color
					}
				});
			} else {
				$('#noflashFooter').show();
			}
			
		}
		
	}
	
	{	// Вставка флеша в шапку
	
		if ($('#flashTop').length) {
			
			if (_majorVersion >= 9){
				$('#flashTop').html('');
				$('#flashTop').flash({
					swf: _root + 'public/flash/top_3.swf',
					width: 100+'%',
					height: 840,
					wmode: 'transparent',
					flashvars: {
						color: _color,
						imageURL: _imageURL,
						visual: _visual
					}
				});
			} else {
				$('#noflashTop').show();
			}
			
		}
		
	}
	
	if ( $(".containers  img").length ) {
		$(".containers  img").tooltip({ 
			track: true,
			delay: 0,
			showURL: false,
			top: -40,
			left: -55, 		
			fade: 250
		});
	}
	
	if ( $(".tastes img").length ) {
		$(".tastes img").tooltip({  
			track: true,
			delay: 0,
			top: -40,
			left: -55, 
			showURL: false,
			fade: 250
		});
	}

	$('.catalog a.item').hover(function () {
	
		var itemName = $(this).attr('rel');
		var bottleFlashName = itemName+'_flash';
		thisMovie(bottleFlashName).itemOver();
	
	}, function () {
		
		var itemName = $(this).attr('rel');
		var bottleFlashName = itemName+'_flash';
		thisMovie(bottleFlashName).itemOut();
	
	});
	
	$(window).resize(reSize);
	reSize();

	reLink( $("#popup") );	

	$(".catalog a").click(function () {

		$("#overlay").height(1);

		$.ajax({
			type: "GET",
			url: this.href + "&ajax=1",
			success: function(msg){

				$('html, body').animate({scrollTop:100}, 'slow', 'linear', function(){  
					$("#popup").show();
					$("#overlay").show();
					$("#popup").html(msg);
					$("#overlay").height($(document).height()/* + 100*/);
					reLink( $("#popup") );
				} );
			}
		});
		return false;

	});

});


var thisMovie = function(movieName) {
	if (true == $.browser.msie) {
		return window[movieName]
	} else {
		return document[movieName]
	}
};

var reSize = function() {
	$("#main").css( 'min-height', 0);
	var docHeight = $(document).height();
	$("#main").css( 'min-height',  docHeight );
};

var reLink = function( block ) {

	$("a[id!='close']", block).click(function () {
		$.ajax({
			type: "GET",
			url: this.href + "&ajax=1",
			success: function(msg){
				$("#overlay").show();
				$("#popup").html(msg);
				$("#overlay").height(1);
				$("#overlay").height($(document).height()/* + 100*/);
				reLink( $("#popup") );
				reSize();
			}
		});
		return false;		
		
	});

	$('#close', block).click(function () {
		$("#overlay").hide();
		$('#popup').hide();
		reSize();
		return false;
		
	});

};

