var test = 0;
var test1 = 0;

$(function() {
			$("#b_kontakty").bind('click', 
				function() {
					if ( test == 0) {
						$(this).animate( { height:"180px"}, 800, "easeOutCubic" );
						$("#nav2").fadeIn();
						$("#but_kontakty").animate( { color: "#99EF01" }, 1000);
						test = 1;
						if ( test1 == 1) {
							$("#b_novinky").animate( { height:"0px"}, 1000 );
							$("#nav1").fadeOut();
							$("#but_novinky").animate( { color: "#656565" }, 1000);
							test1 = 0;
						}
					}
					else {
						$(this).animate( { height:"0px"}, 1000 );
						$("#nav2").fadeOut();
						$("#but_kontakty").animate( { color: "#656565" }, 1000);
						test = 0;
					}
					setTimeout(function(){
						$('#but_novinky').attr('href', '#');
					}, 100);
				}
			);

			$("#b_novinky").bind('click',
				function() {
					if ( test1 == 0) {
						$(this).animate( { height:"180px"}, 800, "easeOutCubic" );
						$("#nav1").fadeIn();
						$("#but_novinky").animate( { color: "#99EF01" }, 1000);
						test1 = 1;
						if ( test == 1) {
							$("#b_kontakty").animate( { height:"0px"}, 1000 );
							$("#nav2").fadeOut();
							$("#but_kontakty").animate( { color: "#656565" }, 1000);
							test = 0;
						}
						setTimeout(function(){
							$('#but_novinky').attr('href', '/cs/#/ostatni-sekce/aktuality');
						}, 500);
					}
					else {
						$(this).animate( { height:"0px"}, 1000 );
						$("#nav1").fadeOut();
						$("#but_novinky").animate( { color: "#656565" }, 1000);
						test1 = 0;
						setTimeout(function(){
							$('#but_novinky').attr('href', '#');
						}, 100);
					}
				}
			);
			$("#b_novinky p a").click(
				function() {
					test1 = 0;
				}
			);
			$("#b_kontakty p a").click(
				function() {
					test = 0;
				}
			);
			
		$('#nav1 .next').click(function(){
			$('#nav1 .prev').show();
			nextNewsClick();
			return false;
		});
		$('#nav1 .prev').click(function(){
			prevNewsClick();
			return false;
		});
		
					
		$('#nav2 .next').click(function(){
			$('#nav2 .prev').show();
			nextWorkroomsClick();
			return false;
		});
		$('#nav2 .prev').click(function(){
			prevWorkroomsClick();
			return false;
		});
		
	/*	setTimeout(function(){
			$("#b_novinky").trigger('click');
		}, 500); */
	});
	
var nextWorkroomsClick = function() {
	var found = 'no';
	size = 0;
	$('.workroomsRow').each(function(i){
		if ($(this).is(':visible')) {
			$(this).hide();
			found = i;
		}
		size++;
	});
	if (size == found + 1) found = -1;
//	console.log(size + '|' + found);
	if (found != 'no') {
		$('.workroomsRow').eq(found + 1).show();
	}
};	
var prevWorkroomsClick = function() {
	var found = 'no';
	size = 0;
	$('.workroomsRow').each(function(i){
		if ($(this).is(':visible')) {
			$(this).hide();
			found = i;
		}
		size++;
	});
	if (size == found + 1) found = -1;
//	console.log(size + '|' + found);
	if (found != 'no' && found > 0) {
		$('.workroomsRow').eq(found - 1).show();
		if (found == 1) $('#nav2 .prev').hide();
	} else {
		$('.workroomsRow').eq(0).show();
		$('#nav2 .prev').hide();
	}
};
var nextNewsClick = function() {
	var found = 'no';
	size = 0;
	$('.newsRow').each(function(i){
		if ($(this).is(':visible')) {
			$(this).hide();
			found = i;
		}
		size++;
	});
	if (size == found + 1) found = -1;
//	console.log(size + '|' + found);
	if (found != 'no') {
		$('.newsRow').eq(found + 1).show();
	}
};

var prevNewsClick = function() {
	var found = 'no';
	size = 0;
	$('.newsRow').each(function(i){
		if ($(this).is(':visible')) {
			$(this).hide();
			found = i;
		}
		size++;
	});
	if (size == found + 1) found = -1;
//	console.log(size + '|' + found);
	if (found != 'no' && found > 0) {
		$('.newsRow').eq(found - 1).show();
		if (found == 1) $('#nav1 .prev').hide();
	} else {
		$('.newsRow').eq(0).show();
		$('#nav1 .prev').hide();
	}
};
