$(document).ready(function(){

	if ($.browser.msie && $.browser.version == 6) {
		DD_belatedPNG.fix('.header, #flashParts, .title img, .tabs li, .footerInside, .jdpicker_w .nav, .jdpicker_w, .wrapper, .priceTitle, .mapDetails, .mapDetails img, .galleryBlock, .newsBlock');
	}else{
		
		var _speed = 400,
			_timer = null;
		
		$('#parts area').mouseover(function(){
			clearTimeout(_timer);
			var currentClass = $(this).attr('class');
			if(!$('.bgImage img:visible').is('.' + currentClass) && !$('body').is('.inside')){
				$('.bgImage img:visible').fadeOut(_speed);
				$('.bgImage img.' + currentClass).fadeIn(_speed);
				$('body').attr('clas', currentClass);
			}
		});
		
		$('#parts').mouseout(function () {
			
			_timer = setTimeout(function () {
				$('.bgImage img:visible').fadeOut(_speed);
				$('.bgImage img:first').fadeIn(_speed);	
			}, 500)
			
		})
	}
	
	$('.jcarousel-skin-index').jcarousel({scroll: 1, start: 6});
	
	$('.jcarousel-skin-gallery').jcarousel({scroll: 1, vertical: true});
	
	
	
	{	// Календарь
		
		var getDateArchive = function () {
			
			var _findCurrDay = document.location.toString().match(/\&d=(\d*)/),
				_findCurrMonth = document.location.toString().match(/\&m=(\d*)/),
				_findCurrYear = document.location.toString().match(/\&y=(\d*)/),
				date = new Date();
				
			if (_findCurrYear) {
				var month = _findCurrMonth[1],
					year = _findCurrYear[1],
					day = _findCurrDay? _findCurrDay[1] : date.getDate();
			}
			else {
				var month = date.getMonth() + 1,
					year = date.getFullYear(),
					day = date.getDate();
					
				month = month < 10 ? '0' + month.toString() : month;
			}
			
			return {
				d: day.toString(),
				m: month.toString(),
				y: year.toString()
			}
		}
		
		if ($('#calendar').length) {
		
			
			var _currMonth = 0,
				_currYear = 0;
			
			$('#calendar').val(getDateArchive().y + '/' + getDateArchive().m + '/' + getDateArchive().d);
			
			$('#calendar').jdPicker({
				short_day_names : ["Вс", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"],
				month_names: ["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"],
				getSeletableArray: function(date) {
					
					_currMonth = date.getMonth() + 1;
					_currYear = date.getFullYear();
					
					var arrayDays = [];
					$.ajax({
						async: false,
						url: _link_archive,
						dataType: 'json',
						data: {ajax: 1, action: 'calendar', m: date.getMonth() + 1, y:date.getFullYear()},
						success: function(json){  
		                  arrayDays = json;
		               }  
					});
					
					return arrayDays;
					
				},
				callbackComplete : function () {
					$('.selectable_day').click(function () {
						
						var _date = $(this).attr('date'),
							_temp = _date.split('/');
						
						document.location = _link_archive + '?action=viewday&d=' + _temp[2] + '&m=' + _temp[1] + '&y=' + _temp[0];
						
					})
					
					_text = getDateArchive().y + '/' + getDateArchive().m + '/' + getDateArchive().d;
					
					$('.date_selector .selected').removeClass('selected');
					$('.date_selector td').each(function () {
						if ($(this).attr('date') == _text) {
							$(this).addClass('selected');
						}
					})
		
				}
			});
			
			
			$('.allEvents').click(function() {

				document.location = _link_archive + '?action=viewmonth&m=' + _currMonth + '&y=' + _currYear;
				
				return false;
				
			})
			
			
		}
			
	}
	
	
	{	// вставка flash в схеме отображения залов

		if ($('.mapDetails').length) {
			
			var _playerVersion = $.flash.version,
				_majorVersion = _playerVersion.major; 
		
			if (_majorVersion >= 9){

				$('#flash_map').click(function () {
					$(this).fadeOut();
					return false;
				});
				
				
				$('.mapDetails').click(function () {
					
					var _data = $(this).prev();
					
					var _href = $('.map_link', _data).html().replace('&amp;', '&');
					
					$('#flash_map .flash').flash({
						swf: _root + 'public/flash/'+ ($('.map_type', _data).html() == 2 ? 'map_big' : 'map_small') +'.swf',
						width: $('.map_type', _data).html() == 2 ? 1002 : 676,
						height: $('.map_type', _data).html() == 2 ? 1025 : 565,
						wmode: 'normal',
						allowScriptAccess: 'always',
						flashvars: {
							XMLURL: _href
						}
					});
					$('<span class="flashClose" title="Закрыть"></span>').appendTo($('#flash_map .flash'));

					

					
					var _top = $(this).position().top,
						_heightFlash = $('.map_type', _data).html() == 2 ? 1025 : 565,
						_topFlash = $('body').height() < parseInt(_top + _heightFlash)
										? $('body').height() - _heightFlash - 200
										: _top - 300;
										
					
					$('#flash_map .flash')
						.removeClass('type_1')
						.removeClass('type_2')
						.addClass('type_' + $('.map_type', _data).html())
						.css('top', _topFlash);
					
					$('#flash_map').fadeIn();
					
					return false;
					
				});
				
			}

		}

	}

	
	
	
	/*
	
	$('#calendar').jdPicker({
		short_day_names : ["Вс", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"],
		month_names: ["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"]
	});
	
	*/
	
	$('.calendarTitle').click(function(){
		if($('.calendarBlock').is(':visible')){
			$('.calendarBlock').hide();
			$(this).removeClass('calendarTitleActive');
			$(this).html('Развернуть календарь');
		}else{
			$('.calendarBlock').show();
			$(this).addClass('calendarTitleActive');
			$(this).html('Спрятать календарь');
		}
	})
	
	
	var _playerVersion = $.flash.version,
		_majorVersion = _playerVersion.major; 

	if ($('#imageTopFlash').length) {
		if (_majorVersion >= 9){
			$('#imageTopFlash').show();
			$('#imageTopFlash').flash({
				swf: _root + 'public/flash/topimage.swf',
				width: 710,
				height: 165,
				wmode: 'transparent',
				allowScriptAccess: 'always',
				flashvars: {
					imageURL: _img
				}
			});
		} else {
			$('#imageTopNoFlash').show();
		}
	}
	
	if ($('#flashParts').length) {
		if (_majorVersion >= 9){
			$('#flashParts #plash_placeholder').flash({
				swf: _root + 'public/flash/menu.swf',
				width: 637,
				height: 270,
				wmode: 'transparent',
				allowScriptAccess: 'always',
				flashvars: {
					link0: _link0,
					link1: _link1,
					link2: _link2,
					link3: _link3
				}
			});
		} else {
			$('#flashParts .noflash').show();
		}
	}
	
});

function showBg(num){
	
	if (num !=999) {
		$($('#parts area').get(num)).mouseover();
	}
	else {
		$($('#parts area').get(0)).mouseout();
	}
	
	//alert('showBg '+num);
}

function zindexHeaderAdv(num){
	$('.headerAdv').css('z-index',num );
}
