$(document).ready(function(){

	//link
	//var links = location.href.slice(7);
	//var links = $('.search ul li:last').attr('href');
	//var link = document.location.hash.replace(/http://palace.by/,'');
	//$('.search ul li:last').attr('href','/en'+links+'')
	

	$('.preview li a').click(function(e){
		var src = $(this).attr('href');
		$('#big_img_toj').attr('src',src);
		$('#big_img_toj').load(function(){
			$('#big_img_toj').animate({'opacity':'1'},200);
		});
		src = '';
		e.preventDefault();
	});
	
	//$('.menu2 div').css('opacity','0.8');
	$('.menu2 div img,.menu2 div a').hide();
	$('.menu2 div').hover(function(){
		$(this).children('img').slideDown(100);
		$(this).children('a').delay(100).slideDown(100);
		$(this).children('span').children('a').delay(100).slideDown(100);
		$(this).children('span').delay(100).slideDown(100);
	},function(){
		$(this).children('img').delay(100).slideUp(100);
		$(this).children('a').slideUp(100);
		$(this).children('span').slideUp(100);
	});
	
	//AFISHA 3D
	// берем все необходимые нам картинки
	var $img = $('.afisha_3d table td a.img img');
	// ждем загрузки картинки браузером
	$img.load(function(){
		// удаляем атрибуты width и height
		$(this).removeAttr("width")
			   .removeAttr("height")
			   .css({ width: "", height: "" });
	 
		// получаем заветные цифры
		var width  = $(this).width();
		var height = $(this).height();
		$(this).css({
			'margin-top':-(height/2)+'px',
			'margin-left':-(width/2)+'px'
		});
	});
	 
	// для тех браузеров, которые подгрузку с кеша не считают загрузкой, пишем следующий код
	//var src  = $img.attr('src');
              //$img.attr('src', '');
              //$img.attr('src', src);
	//alert(src);		  
	$('.afisha_3d table td p.img img').each(function(){
		$(this).css({
			'margin-top':-($(this).height()/2)+'px',
			'margin-left':-($(this).width()/2)+'px'
		});
	});
	
	var ar = $('.afisha_3d table td p.img img');
	for(i=0;i<ar.length;i++){
		$(ar[i]).css({
			'margin-top':-($(ar[i]).height()/2)+'px',
			'margin-left':-($(ar[i]).width()/2)+'px'
		});
	}
	
	$('ul.menu li:last a').css('background','none');
	
	$('.foto_block ul,.foto_block_item ul').each(function(i){
		$(this).children('li:last').css('margin-right','0');
	});
	$('.bord p:last').css('border','0');
	
	$('.head ul.menu li').mouseover(function(){
		$(this).children('ul').show();
	}).mouseout(function(){
		$(this).children('ul').hide();
	});
	/*
	$('.afisha_index .onePart').mouseover(function(){
		$(this).children('a.img').hide();
		$(this).children('p.text').show();
	}).mouseout(function(){
		$(this).children('a.img').show();
		$(this).children('p.text').hide();
	});
	*/
	//$('.jscroller2_left').width
	var indexLi = $('.jscroller2_left .onePart');
	var indexLiLeft = $('.jscroller2_left_endless .onePart');
	var widthIndex = 0;
	var widthIndexL = 0;
	for(var i=0;i<indexLi.length; i++){
		var widthIndex = widthIndex + $(indexLi[i]).width();
	}
	for(var i=0;i<indexLiLeft.length; i++){
		var widthIndexL = widthIndexL + $(indexLiLeft[i]).width();
	}
	$('.jscroller2_left').css('width',widthIndex+'px');
	$('.jscroller2_left_endless').css('width',widthIndexL+'px');
	
	$('.foto_block ul li').mouseover(function(){
		$(this).addClass('active');
		$(this).parent('ul').parent('div').children('div.tit').text($(this).children('a').children('img').attr('alt'));
	}).mouseout(function(){
		var sp = ''
		$(this).removeClass('active');
		$(this).parent('ul').parent('div').children('div.tit').text(sp);
	});
	
	$('.foto_block_item ul li').mouseover(function(){
		$(this).addClass('active');
		$(this).parent('ul').parent('div').children('div.tit').text($(this).children('a').attr('title'));
	}).mouseout(function(){
		var sp = ''
		$(this).removeClass('active');
		$(this).parent('ul').parent('div').children('div.tit').text(sp);
	});
	$('ul.news_list li:last').css('border-bottom','0');
	
	// SITEMAP
	
	$('.site_map ul li a').hover(function(){
		$(this).parent().children('p').show();	
	},function(){
		$(this).parent().children('p').hide();	
	});
	
	if($.browser.msie && $.browser.version < 8){
		$('.button1 span.c input').css({'padding':'3px 0px 0 0px'});
	}
	
	///////////////////////////////////////////////////
	
	$('#slct_date').change(function(){
		//alert($(this).val());
	});
	

	$('.afisha_index').each(function(){
		var maxZ = Math.max.apply(null,$.map($('.onePart p.date'), function(e,n){
				//return $(e).css('height')||1;
			}) 
		);
		//alert(maxZ);
		$('.onePart p.date').height(maxZ);
	});
	
	$('.catalog_list li').each(function(){
		var descH = $(this).children('div.desc').height();
		var titH = $(this).children('div.tit').height();
		var imgH = $(this).children('div.img').height();
		var maxZ = Math.max.apply(null,$.map($(this).children('div'), function(e,n){
                return $(e).css('height')||1 ;
           })
		);
		//alert(maxZ+'|'+titH+'|'+imgH+'|'+descH);
		$(this).children('div.img').css('padding-top',(maxZ-imgH)/2+'px');
		$(this).children('div.desc').css('padding-top',(maxZ-descH)/2+'px');
		$(this).children('div.tit').css('padding-top',(maxZ-titH)/2+'px');
	});
	
	$('.afisha_3d table td div span').each(function(){
		//alert($(this).html());
		$(this).text().replace(/ по/,' по');
	});
 
});
	

$(window).resize(function(){
	
});
