$(document).ready(function() {
    
	
		var DatePicked = function() {
                var departure = $("#data1");
                var arrival = $("#data2");
                var departureDate = departure.datepicker("getDate");
                var arrivalDate = arrival.datepicker("getDate");
                var minArrivalDate = new Date();


                if ((departureDate != null) )
		{	
			//minArrivalDate.setDate(departureDate.getMonth());
                        //minArrivalDate.setDate(departureDate.getDate() + 1);
			 minArrivalDate.setMonth(departureDate.getMonth(), departureDate.getDate() + 1);
		
	                arrival.datepicker('option', 'minDate', minArrivalDate);
			arrival.datepicker('setDate', minArrivalDate);
                }

        }


	var DatePicked2 = function() {
                var departure = $("#data1");
                var arrival = $("#data2");
                var departureDate = departure.datepicker("getDate");
                var arrivalDate = arrival.datepicker("getDate");
                var minArrivalDate = new Date();

        }

        var natDays = [
        [1, 1, 'swieto'],
        [4, 4, 'swieto'],
        [4, 5, 'swieto'],
        [5, 23, 'swieto'],
        [5, 1, 'swieto'],
        [5, 3, 'swieto'],
        [6, 3, 'swieto'],
        [8, 15, 'swieto'],
        [11, 1, 'swieto'],
        [11, 11, 'swieto'],
        [12, 25, 'swieto'],
        [12, 26, 'swieto']


        ];

	$.datepicker.regional['pl'] = {
		closeText: 'Zamknij',
		prevText: '&#x3c;Poprzedni',
		nextText: 'Następny&#x3e;',
		currentText: '<b>Dziś</b>',
		formatDate:'yy-mm-dd',
		monthNames: ['Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec',
		'Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień'],
		monthNamesShort: ['Sty','Lu','Mar','Kw','Maj','Cze',
		'Lip','Sie','Wrz','Pa','Lis','Gru'],
		dayNames: ['Niedziela','Poniedzialek','Wtorek','Środa','Czwartek','Piątek','Sobota'],
		dayNamesShort: ['Nie','Pn','Wt','Śr','Czw','Pt','So'],
		dayNamesMin: ['N','Pn','Wt','Śr','Cz','Pt','So'],
		firstDay: 1,
		isRTL: false};
	$.datepicker.setDefaults($.datepicker.regional['pl']);




    function nationalDays(date) {
        for (i = 0; i < natDays.length; i++) {
          if (date.getMonth() == natDays[i][0] - 1 && date.getDate() == natDays[i][1])
          {
            return [true, natDays[i][2]];
          }


        }
      return [true, ''];
    }

        $(function(){
        $("#data1").datepicker({
                beforeShowDay: nationalDays,
                minDate: 0,
                maxDate:  new Date(2030,07-1,01),
                showButtonPanel: true,
                showOn: 'both',
                buttonImage: 'application/additional/images/calendar.jpg',
                buttonText: 'Kalendarz',
                buttonImageOnly: true,
                dateFormat: 'dd.mm.yy',
                showWeek: true,
                firstDay:1,
                showAnim:'',
                onSelect: DatePicked})
                });
        $(function(){
        $("#data3").datepicker({
                beforeShowDay: nationalDays,
                minDate: 0,
                maxDate:  new Date(2030,07-1,01),
                showButtonPanel: true,
                showOn: 'both',
                buttonImage: 'application/additional/images/calendar.jpg',
                buttonText: 'Kalendarz',
                buttonImageOnly: true,
                dateFormat: 'dd.mm.yy',
                showWeek: true,
                firstDay:1,
                showAnim:'',
                onSelect: DatePicked})
                });
        $(function(){
        $("#data2").datepicker({
                beforeShowDay: nationalDays,
                minDate: 0,
                maxDate:  new Date(2030,07-1,01),
                showButtonPanel: true,
                showOn: 'both',
                buttonImage: 'application/additional/images/calendar.jpg',
                buttonText: 'Kalendarz',
                buttonImageOnly: true,
                dateFormat: 'dd.mm.yy',
                showWeek: true,
                firstDay:1,
                showAnim:'',
                onSelect: DatePicked2})
                });
        $(function(){
        $("#data4").datepicker({
                beforeShowDay: nationalDays,
                minDate: 0,
                maxDate:  new Date(2030,07-1,01),
                showButtonPanel: true,
                showOn: 'both',
                buttonImage: 'application/additional/images/calendar.jpg',
                buttonText: 'Kalendarz',
                buttonImageOnly: true,
                dateFormat: 'dd.mm.yy',
                showWeek: true,
                firstDay:1,
                showAnim:'',
                onSelect: DatePicked2})
                });

		
		
		
		
		
		
		$(".menu_div").each(function() {
        $(this).parent("ul").css("display", "block");
        w = 0;
        $(this).children("li").each(function() {
            w = w + $(this).outerWidth(true);
        });
        $(this).css("width", w);
        $(this).parent("ul").css("display", "none");
    });
    
    $(".top_li_selected ul").each(function(){
        left = $(this).parent().position().left;
        root = left - $(".menu_top ul").position().left;
        $(this).css("margin-left", -root + "px");
        $(this).css("display", "block");
    });


//    var obj = $(".top_li_selected");
//    $(".menu_top ul li").hover(function() {
//        $(".menu_top ul li ul").css("display", "none");
//        $(this).children("ul").css("display", "block");
//
//    }, function() {
//
//    })

    var obj = $(".top_li_selected");
    $(".menu_top ul li").hover(function() {
        left = $(this).position().left;
	    
        if (!$(this).hasClass("top_li_selected")) {
            root = left - $(".menu_top ul").position().left + 2;
            //$(".top_li_selected a div").css("background-position","0px 0px");
            $(obj).removeClass("top_li_selected");
        } else
            root = left - $(".menu_top ul").position().left + 2;
	
	
	if(root==2) root = 0;
	
	//alert(root);
        $(this).children("ul").css("margin-left", -root + "px");
        $(this).children("ul").css("display", "block");
	$(this).children("ul").css("z-index", "100");
//	$(this).css("z-index", "100");

    }, function() {
         $(obj).addClass("top_li_selected");
         $(this).children("ul").css("display", "none");
         $(".top_li_selected ul").css("display", "block");
	    	$(this).children("ul").css("z-index", "10");

         //$(".top_li_selected a div").css("background-position","0px 47px");
    });

});
