var $timeoutID;

function slideChangeElements() {
	$('.slider_item:first').clone().appendTo($('#slider_items'));
	$('.slider_item:first').remove();
	$active = $('#slider #links span.active');
	if ($active.next().length == 0) {
		$('#slider #links span.active').removeClass('active');
		$('#slider #links span:first').addClass('active');
	} else {
		$('#slider #links span.active').removeClass('active');
		$active.next().addClass('active');
	}
}

function slideSwitch() {
	slideChangeElements();
	$('.slider_item:last .image_area').fadeTo(0,0).fadeTo(3000,1);
	$height = $('.slider_item:last .text_area p').height();
	$('.slider_item:last .text_area p').css({'height':'0'}).css({'opacity':'0'}).delay(500).animate({
		'height':$height,
		'opacity':'1'
	},3000);
	
	$timeoutID = setTimeout( 'slideSwitch()', 20000 );  
}

$(function() {
	$('#slider #links span:first').addClass('active');
	$('#slider #links').css({'display':'block'});
	$timeoutID = setTimeout( 'slideSwitch()', 20000 );
	
	$('#slider #links span').bind('mouseenter', function() {
		window.clearTimeout($timeoutID);
		$(this).bind('mouseleave', function() {
			$('#slider #links span').unbind('mouseleave');
			$timeoutID = setTimeout( 'slideSwitch()', 1000 );
		});
		while (!$(this).hasClass('active')) {
			slideChangeElements();
			$('.slider_item:last *').show();
		}
	});
});

// menu efects
$(function() {
	$('#menu li a')
	.bind('mouseenter',function(){
		$(this).css({ 
			'position':'relative', 
			'text-shadow':'2px 2px 7px #000f46'
		}).animate({
			'top':'-3px'
		}, 100);	
	})
	.bind('mouseleave',function(){
		$(this).css({
			'text-shadow':''
		}).animate({
			'top':'0px',
			'text-shadow':''
		}, 200);
	});

	/*	
	$('#menu #nav .first:not(.navigation_opened)')
	.live('mouseenter',function(){
		$('#menu #nav .first').addClass('navigation_opened');
		//$('#slider').stop(true, true);
		//clearTimeout($timeoutID); 
		
		//$('#kurzy_rozcestnik').fadeTo(0,0).css({'display':'block'}).fadeTo(1000,1);
		$('#kurzy_rozcestnik').show(800);

		$('#kurzy_rozcestnik #close_button')
		.bind('click',function(){
			//$('#kurzy_rozcestnik').fadeTo(1000,0);
			$('#kurzy_rozcestnik').hide(400);
			//$timeoutID = setTimeout( 'slideSwitch()', 5000 );
			//slideSwitch();
			$('#menu #nav .first').removeClass('navigation_opened');
		});		
		$('#kurzy_rozcestnik')
		.bind('mouseleave',function(){
			//$('#kurzy_rozcestnik').fadeTo(1000,0);
			$('#kurzy_rozcestnik').hide(100);
			//$timeoutID = setTimeout( 'slideSwitch()', 5000 );
			//slideSwitch();
			$('#menu #nav .first').removeClass('navigation_opened');
		});	
	})
	*/

});


// block efects
$(function() {
	$('.block_stretch a').hide();
	//$('.block_stretch h5').css({'cursor':'pointer'});

	$('.block_stretch').bind('mouseenter',function(){
		$(this).children('a').css({'opacity':'0.75'}).slideDown(400);

		$(this).bind('mouseleave',function(){
			$(this).unbind('mouseleave');
			$(this).children('a').fadeTo(1600,0, function(){ 
				$(this).slideUp(800); 
			});
		});		
	});
});


// gallery

$(function() {

	$('.photo').css('opacity', 0.8);

	$('.photo').bind('focusin mouseenter', function() {
		$(this).animate({
			opacity: 1
		}, 300);
	});
	$('.photo').bind('focusout mouseleave', function() {
		$(this).animate({
			opacity: 0.8
		}, 300);
	});
});

$(document).ready(function() {
	$('a:has(.photo), a:has(.popup_photo)').fancybox({
		'transitionIn'  : 'elastic',
		'transitionOut' : 'elastic',
		'titlePosition' : 'inside',
		'overlayOpacity': 0.7,
		'overlayColor'  : '#111'
	});
});


