function scrollNews(idnews)
{
	var nextn = idnews.next();
	
    if(nextn.next().next().length == 0)
	{
		$('#NewsBox').stop().scrollTo("#NewsBoxItem1", 1500, { easing:'easeInOutCubic' } );
		nextn = $("#NewsBoxItem1");
	}
	else
		$('#NewsBox').stop().scrollTo(nextn, 1000, { easing:'easeInOutCubic' } );

	setTimeout(function() 
		{
		    scrollNews(nextn);
		}, 5000
	);
}

function resize()
{
	$("#MainContainer").css('height', 'auto');
	var wh = $(window).height();
	var cc = $("#ContentContainer").height();
	var fc = $("#FooterContainer").height();	

	if(wh > cc + fc)
	{
		$("#MainContainer").css('height', wh - 415 + 'px');
	}
}

$(document).ready(function()
{

	$(".newwindow").click(function()
	{
		window.open(this.href, '_blank'); 
		return false;
	});

	if ($('#Winiety').length > 0) // Strona główna
	{
		$('#Winiety').cycle();
	
		var countnews = $("#NewsBoxSlider > a").size();
		$("#NewsBoxSlider").css("width", countnews * 265);
		$('a.NewsBoxItem').scrollTo(0);	
		$('#NewsBox').scrollTo("#NewsBoxItem1", 1000, { easing:'easeInOutCubic' });
		setTimeout(function() 
			{
			    scrollNews($("#NewsBoxItem1"));
			}, 7000
		);

		$("#NewsBoxSlider a.NewsBoxItem div.divimg").each(function(index) {
			var imgh = $(this).height();
			var ah = $(this).children("span").height();

			$(this).children("span").css("top", imgh - ah - 14);
		  });

		
	} else
	{
		resize();
		$(window).bind("resize", resize);

		$("a.gallery").lightBox({
			txtImage: 'Obraz',
			txtOf: 'z',
			imageBlank: './img/lightbox-blank.gif',
			imageLoading: './img/lightbox-ico-loading.gif',
			imageBtnClose: './img/lightbox-btn-close.gif',
			imageBtnPrev: './img/lightbox-btn-prev.gif',
			imageBtnNext: './img/lightbox-btn-next.gif'
		});
		
		$(".SubMenuBox h3 a").click(function(e) 
		{
			if(this.className.indexOf("clicked") != -1) 
			{
		   		$(this).parent().parent().children("ul").slideUp(200, resize);
				$(this).removeClass("clicked");
			}
			else 
			{
				$(this).parent().parent().parent().children("div").children("h3").children("a").removeClass("clicked");
				$(this).addClass("clicked");
				$(this).parent().parent().parent().children("div").children("ul").slideUp(200);
				$(this).parent().parent().children("ul").slideDown(200, resize);
			}
			return false;
		});
		
		$("img.obrazek").click(function(e){
			var imageID = $(this);
			$.ajax({
				type: "GET",
				url: "otk.php",
				success: function(msg){
					var img_src = imageID.attr('src');
					var timestamp = new Date().getTime();
					imageID.attr('src',img_src+'?'+timestamp);
		        }
		   });
		});
	}
});
