var timeo=8000; // czas pomiędzy przejściami
var block;
function pokazBaner(nr) {
	if (!block){
		block=true;
		$(".mainNew1Cont:visible").fadeOut("slow",function(){
		$(".mainNew1Cont:eq("+nr+")").fadeIn("slow",function(){block=false;})});
		var lnk=$(".mainNew1Cont:eq("+nr+")").attr("rel");
		$("#mainNewLink").attr("href",lnk);
	}
}

function przesunLewo() {
	tw=$("#baner-lista span.podswietl").attr("rel");
	cnt=$("#baner-lista span").length;
	if (cnt>0){
		$("#baner-lista span.podswietl").removeClass("podswietl");
		tw--;
		if (tw<0)
			tw=cnt-1;
		$("#baner-lista span:eq("+tw+")").addClass("podswietl");
		pokazBaner(tw);
	}
}

function przesunPrawo() {
	tw=$("#baner-lista span.podswietl").attr("rel");
	cnt=$("#baner-lista span").length;
	if (cnt>0){
		$("#baner-lista span.podswietl").removeClass("podswietl");
		tw++;
		if (tw>cnt-1)
			tw=0;
		$("#baner-lista span:eq("+tw+")").addClass("podswietl");
		pokazBaner(tw);
	}
}

function pokazGlowne(nr) {
	$(".glowna-lista-tr:visible").fadeOut("slow");
	$(".glowna-lista-tr:eq("+nr+")").fadeIn("slow");
}

function przesunDol() {
	tw=$("#glowna-lista table tr.wyswietl").attr("rel");
	cnt=$("#glowna-lista table tr").length;
	if (cnt>0){
		$("#glowna-lista table tr.wyswietl").removeClass("wyswietl");
		tw++;
		if (tw>cnt-1)
			tw=0;
		$("#glowna-lista table tr:eq("+tw+")").addClass("wyswietl");
		pokazGlowne(tw);
	}
}

$().ready(function() {
  
	/* banner na stronie glownej */
	t='<span id="baner-wybierajka"><span id="baner-lewo"></span><span id="baner-lista">';

	for (i=0;i<$(".mainNew1Cont").length;i++)	{
		t+='<span id="baner-guzik-'+i+'" rel="'+i+'">'+(i+1)+'</span>';	
	}
	t+='</span><span id="baner-prawo"></span></span>'

	$("#banneryMain").append(t);	
	$("#baner-guzik-0").addClass("podswietl");

	$("#banneryMain").hoverIntent(function(){

		window.clearInterval(timeee);
	},function(){

		timeee = window.setInterval('przesunPrawo()', timeo);
	});
	
	
	$("#baner-lista span").click(function(){

		tw=$(this).attr("rel");
		$("#baner-lista span.podswietl").removeClass("podswietl");
		$(this).addClass("podswietl");
		pokazBaner(tw);		
	//window.clearInterval(timeee);
	 //	timeee = window.setInterval('przesunPrawo()', 5000);
	});
	
	$("#baner-lewo").click(przesunLewo);
	$("#baner-prawo").click(przesunPrawo);	

	/* automatyczne przesuwanie banneru co okreslony czas */
	timeee = window.setInterval('przesunPrawo()', timeo);
 

	$('.mainNew1Cont').css({"visibility":"visible"});
	$('.mainNew1Cont:eq(0)').show();
	$('.mainNew1Cont:gt(0)').hide();
	$("#banneryMain").append('<a href="" id="mainNewLink"></a>');
	var lnk=$(".mainNew1Cont:eq(0)").attr("rel");
	$("#mainNewLink").attr("href",lnk);

});

