$(function() {

    $('.articles').cycle({
	fx:      'scrollUp', 
	speed:    1000, 
	timeout:  10000
    });
    
    var dates = $("#date-arrival, #date-departure").datepicker({
	defaultDate: "+1w",
	changeMonth: true,
	changeYear: true,
	numberOfMonths: 2,
	dateFormat: 'dd. mm. yy',
	showAnim: 'fadeIn',
	showOn: "both",
	beforeShow: function() {
	    setTimeout(function() {
		$(".ui-datepicker").css("z-index", 9999999999);
	    }, 10); 
	},
	buttonImage: "/__img/calendar.png",
	buttonImageOnly: true,
	buttonText: 'Kalendář',
	onSelect: function( selectedDate ) {
	    var option = this.id == "date-arrival" ? "minDate" : "maxDate",
	    instance = $( this ).data( "datepicker" ),
	    date = $.datepicker.parseDate(
		instance.settings.dateFormat ||
		$.datepicker._defaults.dateFormat,
		selectedDate, instance.settings );
	    dates.not( this ).datepicker( "option", option, date );
	}
    });
    
    $("#date-arrival, #date-departure" ).datepicker($.datepicker.regional['cs']);
    
    $('#slider').slides({
	preload: true,
	preloadImage: '/__img/loading.png',
	play: 5000,
	pause: 2500,
	hoverPause: true
    });
   
   
    $('#acc-categories .childs').hide();
    $('#acc-categories .city h3 a').mouseenter(function () {
	var childsId = $(this).parent().attr("id").replace("city", "childs");
	$('#' + childsId).slideDown('slow');			    
    });
    $('#acc-categories .city').mouseleave(function () {
	var childsId = $(this).find('h3').attr("id").replace("city", "childs");
	$('#' + childsId).slideUp('slow');			    
    });
    $('#acc-categories .city h3 a').focusin(function () {
	var childsId = $(this).parent().attr("id").replace("city", "childs");
	$('#' + childsId).slideDown('slow');			    
    });
    
    $("#acc-detail a[rel='object-photo']").colorbox({
	maxWidth:'100%', 
	maxHeight:'100%'
    });
    
    $('#acc-detail .apart').hide();
    $('#acc-detail .links a').click(function() {
	if (!$(this).attr('id'))
	    return true;
	
	$('#acc-detail .links a').removeClass('current');
	
	var linkId = $(this).attr('id');
	var action = linkId.replace('a-', '');
	
	if (!$('#' + action).is(':visible')) {
	    $('.apart').hide();
	    $('#' + action).fadeIn();
	    $(this).addClass('current');
	} else {
	    $('#' + action).hide();
	}
	return false;
    });
    
});
