jQuery(document).ready(function(){
	bx_lock = 0;
	var bx_int = 0;
	var map_show = 0;
	
	jQuery('#show_map_t, #show_map_b').click(function(){
		if(map_show == 0) {
			jQuery('#footer_map').slideDown('slow', function() {
				map_show = 1;
				var html = jQuery('#show_map_b').html();
				jQuery('#show_map_t').removeClass('text-padding');
				jQuery('#show_map_t').html(html.replace('show_map','hide_map'));
				jQuery('#show_map_b').html('<p>zwiń mapę strony</p>');
			});
		} else {
			jQuery('#footer_map').slideUp('slow', function(){
				map_show = 0;
				var html = jQuery('#show_map_t').html();
				jQuery('#show_map_t').addClass('text-padding');
				jQuery('#show_map_b').html(html.replace('hide_map','show_map'));
				jQuery('#show_map_t').html('<p>rozwiń mapę strony</p>');
			});
		}
	});
	
	jQuery('.single_art_intro .faq_more').click(function(){
		var more = jQuery(this);
		var self = jQuery(this).next('.faq_body');
		if(!self.hasClass('faq_opened')) {
			self.slideDown('slow', function(){
				self.addClass('faq_opened');
			});
			more.html("<b>ZWIŃ</b>");
		} else {
			self.slideUp('slow', function(){
				self.removeClass('faq_opened');
			});
			more.html("<b>WIĘCEJ</b>");
		}
	});
	
	jQuery('#case-menu div').click(function(){
		var self = jQuery(this);
		if(!self.hasClass('case_a') && bx_lock == 0) {
			bx_lock = 1;
			clearInterval(bx_int);
			var id = self.attr('id').substr(8);
			jQuery('.case_active').fadeOut('slow', function(){
				var act = jQuery('#case'+id);
				var pnt = jQuery('#case-menu .case_a');
				
				jQuery(this).removeClass('case_active');
				act.fadeIn('slow', function(){
					act.addClass('case_active');
				});
				self.addClass('case_a');
				pnt.removeClass('case_a');
				bx_lock = 0;
				bx_int = setInterval('slideBoxes()', 7000);
			});
		}
	});
	
	var bx_int = setInterval('slideBoxes()', 7000);
	
});

function slideBoxes() {
	if(bx_lock ==0) {
		bx_lock = 1;
		var self = jQuery('#case-study .case_active');
		var pnt = jQuery('#case-menu .case_a');
		if(self.next('.case-study-box').length > 0) {
			var next = self.next();
			var pnt_next = pnt.next();
		} else {
			var next = jQuery('#case-study .case-study-box:first');
			var pnt_next = jQuery('#case-menu div:first');
		}
		
		self.fadeOut('slow', function(){
			self.removeClass('case_active');
			pnt.removeClass('case_a');
			next.fadeIn('slow', function(){
				next.addClass('case_active');
			});
			pnt_next.addClass('case_a');
			bx_lock = 0;
		});
	}
}
