var car2Stopped = false;
var car2CurrentIndex = 1;
var car2Delay = 4000;
$(document).ready(function(){
	
	$('a, object').focus(function(){
		$(this).blur();
	});
	
	$('li.menuitem').hover(function() {
		var submenu = $(this).children('ul.submenu');
		if(submenu) {
			$(this).children('a:first').addClass('active');
			$(submenu).stop(true,true).slideDown(100);
		}
	},
	function() {
		var submenu = $(this).children('ul.submenu');
		if(submenu) {
			$(submenu).stop(true,true).slideUp(100);
			$(this).children('a:first').removeClass('active');
		}
	});
	
	$('#komunikaty').hover(function(){
		car2Stopped = true;
	},
	function(){
		car2Stopped = false;
	});
	
	$('#komunikaty_number a.nr').click(function(e){
		e.preventDefault();
		car2CurrentIndex = $(this).attr('rel');
		if(!$(this).hasClass('active'))
		{
			$('#komunikaty_number a').removeClass('active');
			var itemid = $(this).attr('rel');
			$(this).addClass('active');
			$('.komunikaty_content').stop(true, true).hide();
			$('#komunikaty_content'+itemid).stop(true, true).fadeIn();
		}
	});
		
	car2Step = function(index){
		if(!car2Stopped)
		{
			if(car2CurrentIndex<3){
				car2CurrentIndex++;
			} else {
				car2CurrentIndex = 1;
			}
			$('#komunikaty_link'+car2CurrentIndex).trigger('click');
		}
		setTimeout(car2Step, car2Delay, car2CurrentIndex);
	};
	setTimeout(car2Step, car2Delay, car2CurrentIndex);
	
	$('.tablink').click(function(e){
		e.preventDefault();
		$('.tablink').parent('li').removeClass('selected');
		$(this).parent('li').addClass('selected');
		$('.tabcontent:visible').hide();
		$('#'+$(this).attr('rel')).show();
	});
	
	$('.fancybox').fancybox();
	
	
	var showpoll_ready = true;
	$('a.ankieta').click(function(e){
		e.preventDefault();
		if(showpoll_ready) {
			showpoll_ready = false;
			$.fancybox.showActivity();
			var href = $(this).attr('href');
			$.ajax({
				url: href,
				data: {
					ajax: true
				},
				success: function(response){
					$.fancybox.hideActivity();
					$('#fancydialog').html(response);
					$('#show_fancydialog').trigger('click');
					showpoll_ready = true;
				},
				error: function(response){
					showpoll_ready = true;
					$.fancybox.hideActivity();
					alert('problem');
				}
			});
		}
	});
	
	
	$('#scroller a').hover(function(){
		$(this).children('img').toggleClass('hidden');
	}, function(){
		$(this).children('img').toggleClass('hidden');
	});
	

	marqueeInit({
		uniqueid: 'scroller',
		style: {
			'padding': '0px',
			'width': '1013px',
			'height': '60px'
		},
		inc: 0, //speed - pixel increment for each iteration of this marquee's movement
		mouse: 'cursor driven', //mouseover behavior ('pause' 'cursor driven' or false)
		moveatleast: 1,
		neutral: 150,
		savedirection: true		
	});
});

