$(document).ready(function(){

 $('#cycle').cycle({
		fx:     'fade', 
		speed:   1000, 
		timeout: 5000,
		pagerAnchorBuilder: function(idx, slide) { 
			// return selector string for existing anchor 
			var page = '#nav li:eq(' + idx + ') a'; 
			return page; 
		},
		before: onAfter	
	});
	function onAfter(curr,next,opts) { 
		$('#nav li > a').removeClass('active');
		var pagenr;
		var cycle = parseInt($('#cycle').attr("alt"));
		cycle = cycle + 1;
		if (cycle < 2){
			pagenr = 0;
			$('#cycle').attr("alt",cycle);
			}
		else 
			pagenr = opts.nextSlide;
		$('#nav li:eq('+pagenr+')').children('a').addClass('active')
	}	
	$('#nav > li').click(function(e){
		$('#cycle').cycle('pause');
	});
	
	$('.zemyn').click(function(e){
		var pag = $(this).attr("name");
		var blokas = $(".zemyn_"+pag);
		if ((blokas).is(":visible") ){
			blokas.slideUp('slow');
			$(this).children('h3').addClass('secont_header');	
		}
		else {
			blokas.slideDown('slow');
			$(this).children('h3').removeClass('secont_header');	
			}
			
	});
	
$('.navi > li > ul > li').mouseover(function(){
		var parent = $(this).parent().width();
		var subm = $(this).find('ul').show();
		$(this).parent().find('ul li').show();
		
		
	});
	
	$('.navi > li').mouseout(function(){
		$(this).find('li > ul').hide();
	});
	
	$('.navi > li > ul > li > ul').mouseover(function(){	

		$(this).show();
		//$(this).parent().find('a').css({textDecoration: 'underline'});
	});
	
	$('.navi > li > ul > li > ul').mouseout(function(){	
		$(this).hide();
		//$(this).parent().find('a').css({textDecoration: 'none'});
	});	
	
	
	$('.menu_top > ul > li').mouseenter(function(){
		$(this).children("a").addClass("active");
		var subm = $(this).find("ul");
		var off = $(this).offset();
		
		var width=$(this).width();
		$(subm).width(width-24);
		$(subm).css('top',(off.top+$(".menu_top").height())+'px');
		$(subm).css('left',(off.left)+'px');
		subm.show();
	});
	
	$('.menu_top > ul > li').mouseleave(function(e){
		
		$(this).children("a").removeClass("active");
		var hide = $(e.target).closest(".menu_top > ul > li").find("ul").hide();
		//$(this).find("ul").hide();
		
			//console.log(hide);
		
	});


	
	
	
	});
