$(document).ready(function(){

	

	if($('#gallery').length){
		 var galleries = $('.ad-gallery').adGallery();
		$('#switch-effect').change(
		  function() {
			galleries[0].settings.effect = $(this).val();
			return false;
		  }
		);
		$('#toggle-slideshow').click(
		  function() {
			galleries[0].slideshow.toggle();
			return false;
		  }
		);
		$('#toggle-description').click(
		  function() {
			if(!galleries[0].settings.description_wrapper) {
			  galleries[0].settings.description_wrapper = $('#descriptions');
			} else {
			  galleries[0].settings.description_wrapper = false;
			}
			return false;
		  }
		);
	}
	if($('.schedule').length){
		$('.shedule-content').slideUp(0);
		$('.schedule li').first().find('.schedule-header').addClass('current');
		$('.schedule li').first().find('.shedule-content').slideDown(100);
		$('.open-all a').html('Расскрыть все дни');
		
		$('.open-all a').click(function(){
			if($(this).html()=='Расскрыть все дни'){
				$('.schedule li').find('.shedule-content').slideDown(200);
				$('.schedule li').find('.schedule-header').addClass('current');
				$(this).html('Скрыть все дни');
			}else{
				$('.schedule li').find('.shedule-content').slideUp(200);
				$('.schedule li').find('.schedule-header').removeClass('current');
				$(this).html('Расскрыть все дни');
			}
		});
		
		$('.schedule-header h2 a').click(function(){
			$(this).parent().parent().toggleClass('current');
			$(this).parent().parent().next().slideToggle(200);
		});
	}

	$('.text-page img[align="left"]').addClass('img-left');
	$('.text-page img[align="right"]').addClass('img-right');
	$('blockquote').append('<span class="l-q">«</span><span class="r-q">»</span>');
	
	$('.text-page tr:nth-child(odd)').addClass('table-row-gray');
	$('.schedule tr:nth-child(odd)').addClass('table-row-gray');
	
	$('.events-list li:nth-child(2n)').after('<div style="clear:both"></div>');
	if($('.video-tabs').length){
		$('.vtab-2').hide();
		$('.video-tabs .tabs li:first-child').addClass('current');
		$('.video-tabs .tabs li').click(function(){
			$('.vtabs').hide();
			$('.video-tabs .tabs li').removeClass('current');
			$(this).addClass('current');
			var current = $('.video-tabs .tabs li').index(this)+1;
			$('.vtab-'+current).show();
		});
	}
	
	
});
$(window).load(function() {
        $('#slider').nivoSlider({
			effect:'boxRain',
			slices:15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed:500, // Slide transition speed
        pauseTime:4000, // How long each slide will show
        startSlide:0, // Set starting Slide (0 index)
        directionNav:false, // Next & Prev navigation
        directionNavHide:false, // Only show on hover
        controlNav:true, // 1,2,3... navigation
        controlNavThumbs:false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, // Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', // Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
        keyboardNav:true, // Use left & right arrows
        pauseOnHover:true, // Stop animation while hovering
        manualAdvance:false, // Force manual transitions
        captionOpacity:"", // Universal caption opacity
        prevText: 'Prev', // Prev directionNav text
        nextText: 'Next', // Next directionNav text
        beforeChange: function(){
		$('.nivo-caption').attr('style', '');
			//$('.nivo-caption').fadeOut(500);
		}, // Triggers before a slide transition
        afterChange: function(){
			//$('.nivo-caption').fadeIn(300);
			$('.nivo-caption').attr('style', '');
			
		}, // Triggers after a slide transition
        slideshowEnd: function(){}, // Triggers after all slides have been shown
        lastSlide: function(){}, // Triggers when last slide is shown
        afterLoad: function(){
			$('.nivo-caption').attr('style', '');
		} // Triggers when slider has loaded
		});
		$('.nivo-caption').attr('style', '');
    });
