var hash=window.location.hash.replace('#','');
if (hash.length>0) window.location=hash;

$(function(){
	
	var is_error = ($('#error').length>0) ? true : false;
	var last_window_height = $(window).height();
	var ustawTloTimer=null;
	
	if ($(window).height()<750) {		//przesuwamy dolne tło tak, zeby zawsze była widoczna tablica
		$('#site_wrapper').css('background-position', '50% 0');
	}
	$(window).resize(function() {
		clearTimeout(ustawTloTimer);
		ustawTloTimer = setTimeout(function(){
			if (last_window_height != $(window).height()){
				last_window_height = $(window).height();
				if ($(window).height()<750) {		//przesuwamy dolne tło tak, zeby zawsze była widoczna tablica
					$('#site_wrapper').css('opacity', 0.8).animate({backgroundPosition: '50% 0', opacity: '1'}, 600);
				} else {
					$('#site_wrapper').animate({backgroundPosition: '50% 100%'}, 600);
				}
			}
		}, 250);
	});

	
	$('a#change_loc').click(function(){
		$('#header_adds').slideToggle();
	});
	
	$('#menu a.ajax').click(function(){
		var href = $(this).attr('href');
		$(this).addClass('active').siblings('a').removeClass('active');
			$('#header_adds').slideUp();
			$('#body_wrapper').hide().after('<div class="loading"></div>');
			$.getJSON(href, function(data){
				$('#body_wrapper').html(data.body).slideDown(500);
				document.title=data.title;
				if ($('#news_cs').length>0) {
					$('#news_cs').ContentSlider(); 				
				}
				$('#body_wrapper').slideDown(500)
				$('#body_wrapper').next('.loading').remove();
			});
		window.location.hash=href;
		$(this).blur();
		return false;
	});

	//contentslider na głównej
    $('#news_cs').ContentSlider(); 
	
});
