var $active;
var $next = null;
var slideShow;
var mhe;
var icon_base = 'systemy-it';


function iconHover_up(id) {

	$("a#"+id+" img.pngfix").attr('opacity',0);
	$("a#"+id+" img.img_hover").show();

 }
 
function iconHover_down(id) {

	$("a#"+id+" img.pngfix").css('display','block').attr('opacity',1);
	$("a#"+id+" img.img_hover").hide();

 }

	function slideSwitch() {
		$('ul#leftNav a.topLink').removeClass('menuhover');
		$active = $('#slideshow IMG.active');
		if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
		iconHover_down(icon_base);
		$next =  $active.next().length ? $active.next()
			: $('#slideshow IMG:first');

		$active.addClass('last-active');
			
		var menu = $next.attr('class').split(' ');
		var menu2 = menu[0].split('_');
		
		icon_base = menu2[1];
		
		iconHover_up(menu2[1]);
		
		
		$('ul#leftNav a#'+menu2[1]).addClass('menuhover');
		
		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1500, function() {
				$active.removeClass('active last-active');
			});
	}


function progressSwitch() {

	$('#progress_bar').css({width: "1px"});
	$('#progress_bar').animate({width: "181px"}, 4500, function() {
				slideSwitch();
			});

}
	
function uruchom(){

slideShow = setInterval( "progressSwitch()", 6100 );

//slideShow = setInterval( "slideSwitch()", 4500 );

}


	function toggleMenu(name) {

		if( $('ul#leftNav ul').is(':visible') ) 
				{ $('ul#leftNav ul').slideUp(500); }

		if( $('ul#leftNav ul.sub_'+name).is(':visible') == false ) {
				$('ul#leftNav ul.sub_'+name).slideDown(500);
			}
	}

	function positionFooter(){
		if($(document.body).height() < $(window).height()){
			$("#footer").css({position: "absolute", bottom: "0px", left: "0px"})
		}
	}

			
$(document).ready(function() {
  
		$('ul#leftNav li.leftNav_li ul').hide();
  
		$('ul#leftNav a#systemy-it').addClass('menuhover');
		positionFooter();
		
		slideShow = setInterval( "progressSwitch()", 6100 );
		
		//slideShow = setInterval( "slideSwitch()", 4500 );

		
		$("ul#leftNav li.current_page_item:parent").parent().toggle();
		
		$("#header ul li.top_maps_map a").hover(
			function() { $(this).stop().animate({opacity: 1.0}, 300); },
			function() { $(this).stop().animate({opacity: 0.15}, 300);} 
			);
		
			/* hover na menu */
		$("ul#leftNav a.topLink").mouseenter( function () {
		
				/* hover ikonek */
					iconHover_down('');
					icon_base = $(this).attr('id')
					iconHover_up(icon_base);	
					
		
			$('ul#leftNav a.topLink').removeClass('menuhover');
				
			clearInterval(slideShow);
			//if($next != null) $next.stop();
			$('#progress_bar').stop();
			
			$('#slideshow IMG.active').removeClass('active');
			$('#slideshow IMG').css({opacity: 0.0});
			
			$('#slideshow IMG.img_'+$(this).attr('id')).addClass('active');
			$('#slideshow IMG.img_'+$(this).attr('id')).css({opacity: 1.0});
		
			$(this).addClass('menuhover');
		
		}); 
		
		$("ul#leftNav a.topLink").mouseleave( function () {
			iconHover_down(icon_base);
		});
		
		$('ul#leftNav').mouseleave(function() { 
		
			iconHover_up(icon_base);
			//setTimeout("progressSwitch()",0);
		//	slideSwitch();
			progressSwitch();
			uruchom();
				
		});
		
	});

			


