a1=0,b1=0,c1=0,tlo1=0,a2=0,b2=0,c2=0,tlo2=0;
opoznienie = 1000;
koniec = 0;

$(document).ready(function(){

	// cycle + next_prev
	if($('#tabs .tabsgroup').get(0) != undefined){
		$('#tabs .tabsgroup').cycle({fx: 'fade',
			                     speed: 400,
		        	             timeout: 7500,
			        	     prev: '#tabs .tableft',
					     next: '#tabs .tabright',
					     after: function(currSlideElement, nextSlideElement, options, forwardFlag){
						clearTimeout(tlo1);
						clearTimeout(tlo2);
						clearTimeout(a1);
						clearTimeout(a2);
						clearTimeout(b1);
						clearTimeout(b2);
						clearTimeout(c1);
						clearTimeout(c2);

						tlo1 = setTimeout("$('.tabanimate').fadeIn(2000)", opoznienie);
						a1 = setTimeout("$('.baner1').fadeIn(2000)", opoznienie + 1000);
						b1 = setTimeout("$('.baner2').fadeIn(2000)", opoznienie + 1500);
						c1 = setTimeout("$('.baner3').fadeIn(2000)", opoznienie + 2000);

						tlo2 = setTimeout("$('.tabanimate').fadeOut(2000);", 2000-opoznienie + 4500);
						a2 = setTimeout("$('.baner1').fadeOut(2000);", 2000-opoznienie + 4500);
						b2 = setTimeout("$('.baner2').fadeOut(2000);", 2000-opoznienie + 4500);
						c2 = setTimeout("$('.baner3').fadeOut(2000);", 2000-opoznienie + 4500);
					     },
					     before: function(currSlideElement, nextSlideElement, options, forwardFlag){
						if(koniec){
							opoznienie = 1000;
							koniec = 0;
						}

						$('.tabanimate').stop(true,true).hide();
						$('.baner1').stop(true,true).hide();
						$('.baner2').stop(true,true).hide();
						$('.baner3').stop(true,true).hide();

						indeks = $('#tabs .tabsgroup .tab').index($(nextSlideElement));
						wszystkie = $('#tabs .tabsgroup .tab').length - 1;
						pokazod = indeks - 2 < 0 ? 0 : indeks - 2;
						pokazdo = pokazod + 2;
						
						for(i=0; i<=wszystkie; i++){
							if(i>=pokazod  &&  i<=pokazdo){
								$('#tabbutton_' + i).removeClass('tabbuttonhid');
							}
							else{
								$('#tabbutton_' + i).addClass('tabbuttonhid');
							}
						}
					     },
					     pager: '#tabsbuttons .tabsbuttonspager',
					     pause: 1,
					     pauseOnPagerHover:	1,
					     fastOnEvent: 1,
					     pagerEvent: 'mouseover',
		                             pagerAnchorBuilder: function(index, slide) { 
						if(index >=3) tabbuttonhid = " tabbuttonhid"; else tabbuttonhid = "";
						return '<a href="' + $('#tablinkhid'+index).text() + '" class="tabbutton' + tabbuttonhid + '" id="tabbutton_' + index + '"><div class="tabsmainarrow"></div>' + $('#tabtitlehid'+index).text() + '</a>'; 
					     } 
		});

		$('#tabsbuttons .tabbutton').click(function(){
			window.location.href = $(this).attr('href');
		});

		

		$('#tabsbuttons .tabbutton').hover(function(){
			opoznienie = 0;
			koniec = 0;
		},function(){
			koniec = 1;
		});

	}
	
});


