function formatDestination(val, inList) {
	var dest = val.toString().split(";");
	if(dest[6] == '2') {
		var str = dest[0] + ", " + dest[1] + ", " + dest[5] + " (" + dest[2] + ")";
		return (inList) ? "<img src='/whisper/flags/" + dest[4] + ".gif'/> " + str : str;
	} else if(dest[6] == '1') {
		var str = dest[0] + ", " + dest[1] + " (" + dest[2] + ")";
		return (inList) ? "<img src='/whisper/space.gif'/>" + str : str;
	} else {
		var str = dest[0] + ", " + dest[5] + " (" + dest[3] + ")";
		return (inList) ? "<img src='/whisper/flags/" + dest[4] + ".gif'/> " + str : str;
	}
}
  
function formatAirport(val, inList) {
	var dest = val.toString().split(";");
	if(dest[dest.length-1] == '2') {
		var str = dest[1] + ", " + dest[2] + ", " + dest[5] + " (" + dest[0] + ")";
		return (inList) ? "<img src='/whisper/flags/" + dest[4] + ".gif'/> " + str : str;
	} else if(dest[dest.length-1] == '1') {
		var str = dest[1] + ", " + dest[2] + " (" + dest[0] + ")";
		return (inList) ? "<img src='/whisper/space.gif'/>" + str : str;
	} else {
		var str = dest[1] + ", " + dest[5] + " (" + dest[3] + ")";
		return (inList) ? "<img src='/whisper/flags/" + dest[4] + ".gif'/> " + str : str;
	}
}
  
function formatCity(val, inList) {
	var dest = val.toString().split(";");
	var str = dest[1] + ", " + dest[3] + " (" + dest[0] + ")";
	return (inList) ? "<img src='/whisper/flags/" + dest[2] + ".gif'/> " + str : str;
}
  	
$(document).ready(function(){
	$("#airportcs").autocomplete("/whisper/whisper_airport.php?lng=cs", {
	  formatItem: function(value, i, n, search) {
	  	return formatAirport(value, true)
	  },
	  formatResult: function(value) {
			return formatAirport(value, false);
	  },
	  matchSubset: false,
	  minChars: 3,
		max: 30,
		//cacheLength: 1,
		width: 300
	});
		
	$("#airportcs2").autocomplete("/whisper/whisper_airport.php?lng=cs", {
	  formatItem: function(value, i, n, search) {
	  	return formatAirport(value, true)
	  },
	  formatResult: function(value) {
			return formatAirport(value, false);
	  },
	  matchSubset: false,
	  minChars: 3,
		max: 30,
		//cacheLength: 1,
		width: 300
	});

	$("#DEP_1").autocomplete("/whisper/whisper_airport.php?lng=cs", {
	  formatItem: function(value, i, n, search) {
	  	return formatAirport(value, true)
	  },
	  formatResult: function(value) {
			return formatAirport(value, false);
	  },
	  matchSubset: false,
	  minChars: 3,
		max: 30,
		//cacheLength: 1,
		width: 300
	});
  	
	$("#airporten").autocomplete("/whisper/whisper_airport.php?lng=en", {
	  formatItem: function(value, i, n, search) {
	  	return formatAirport(value, true)
	  },
	  formatResult: function(value) {
			return formatAirport(value, false);
	  },
	  matchSubset: false,
	  minChars: 3,
		max: 30,
		//cacheLength: 1,
		width: 300
	});
		
	$("#airporten2").autocomplete("/whisper/whisper_airport.php?lng=en", {
	  formatItem: function(value, i, n, search) {
	  	return formatAirport(value, true)
	  },
	  formatResult: function(value) {
			return formatAirport(value, false);
	  },
	  matchSubset: false,
	  minChars: 3,
		max: 30,
		//cacheLength: 1,
		width: 300
	});
  	
	$("#hotelcs").autocomplete("/whisper/whisper_city.php?lng=cs", {
	  formatItem: function(value, i, n, search) {
	  	return formatCity(value, true)
	  },
	  formatResult: function(value) {
			return formatCity(value, false);
	  },
	  matchSubset: false,
	  minChars: 3,
		max: 30,
		//cacheLength: 1,
		width: 300
	});

	$("#hotelcs2").autocomplete("/whisper/whisper_city.php?lng=cs", {
	  formatItem: function(value, i, n, search) {
	  	return formatCity(value, true)
	  },
	  formatResult: function(value) {
			return formatCity(value, false);
	  },
	  matchSubset: false,
	  minChars: 3,
		max: 30,
		//cacheLength: 1,
		width: 300
	});
		
	$("#hotelen").autocomplete("/whisper/whisper_city.php?lng=en", {
	  formatItem: function(value, i, n, search) {
	  	return formatCity(value, true)
	  },
	  formatResult: function(value) {
			return formatCity(value, false);
	  },
	  matchSubset: false,
	  minChars: 3,
		max: 30,
		//cacheLength: 1,
		width: 300
	});	
		
	$("#hotelen2").autocomplete("/whisper/whisper_city.php?lng=en", {
	  formatItem: function(value, i, n, search) {
	  	return formatCity(value, true)
	  },
	  formatResult: function(value) {
			return formatCity(value, false);
	  },
	  matchSubset: false,
	  minChars: 3,
		max: 30,
		//cacheLength: 1,
		width: 300
	});	
    
	// Nastaveni datepickera
	$.datepicker.regional['cs'] = {
		closeText: 'Zavřít',
		prevText: '&#x3c;Dříve',
		nextText: 'Později&#x3e;',
		currentText: 'Nyní',
		monthNames: ['leden','únor','březen','duben','květen','červen','červenec','srpen','září','říjen','listopad','prosinec'],
		monthNamesShort: ['leden','únor','březen','duben','květen','červen','červenec','srpen','září','říjen','listopad','prosinec'],
		dayNames: ['neděle', 'pondělí', 'úterý', 'středa', 'čtvrtek', 'pátek', 'sobota'],
		dayNamesShort: ['ne', 'po', 'út', 'st', 'čt', 'pá', 'so'],
		dayNamesMin: ['ne','po','út','st','čt','pá','so'],
		weekHeader: 'Týd',
		dateFormat: 'dd.mm.yy',
		firstDay: 1,
		isRTL: false,
		showMonthAfterYear: false,
		yearSuffix: ''
	};
	$.datepicker.setDefaults($.datepicker.regional['cs']);
    
	$(".datepicker").datepicker({
		changeMonth: true,
		changeYear: true,
		showOn: 'both',
		buttonImage: '/_img/img/calendar.png',
		buttonImageOnly: true
	});	
	
	// Script pre novinky na HP
	var first = 0;
	var speed = 550;
	var pause = 7000;
			
	$('#novinky-content p').each(function() {
		$(this).hide();
	});
	$('#novinky-content p:first').fadeIn('slow');
			
	function removeFirst(){
		first = $('#novinky-content p:first').html();
		if (first != null){
			$('#novinky-content p:first')
				.animate({opacity: 0}, speed)
				.fadeOut('slow', function() {
					$(this).remove();
					$('#novinky-content p:first').fadeIn('slow');
				});
			addLast(first);
		}
	}
			
	function addLast(first){
		last = '<p style="display: none">' + first + '</p>';
		$('#novinky-content').append(last);
	}
		
	var interval = setInterval(removeFirst, pause);
});
	
$(function() {
	vyska = $('#novinky').height();
	
	$('#novinky-tab').css('height', vyska - 4);
	$('#novinky-tab').css('line-height', (vyska - 4) + 'px');
	
	$('#novinky-newsletter').css('padding-top', (vyska / 2) - 20);
});
	
$(document).ready(function(){

    $('#showAll').click(function() {
        if($('#homepage-right .none').css('display') == 'none'){
            $('#homepage-right .none').css('display', 'table-row');
            $('#showAll').html('Skrýt další nabídky letenek');
        }else{
             $('#homepage-right .none').css('display', 'none');
             $('#showAll').html('Další nabídky letenek');
        }
        return false;
    });

});

