﻿$(document).ready(function() {

    $("#checkForm").validate();
    $('#checkIn').datepicker({ dateFormat: 'dd/mm/yy', minDate: +0, hideIfNoPrevNext: true });
    $('#checkIn').val('dd/mm/yyyy');
    $('#checkOut').datepicker({ dateFormat: 'dd/mm/yy', minDate: +1, hideIfNoPrevNext: true });
    $('#checkOut').val('dd/mm/yyyy');
    $('#ccheckin').datepicker({
        dateFormat: 'DD, dd MM yy',
        minDate: +0,
        hideIfNoPrevNext: true,
        beforeShow: function(input) {
            if ($('#ccheckin').val() == 'Click to select date') {
                $('#ccheckin').val("");
            }
        },
        onSelect: function(dateText, inst) {
            var ciDate = new Date($('#ccheckin').val());
            var valueofciDate = ciDate.valueOf();
            var AddedDate = valueofciDate + (24 * 60 * 60 * 1000);
            var coDate = new Date(AddedDate);

            if (dateText != 'Click to select date' && $(this).val() != 'Click to select date') {
                $('#ccheckin').removeClass('error');
                $('#ccheckin').next("label.error").hide();
            }

            $('#ccheckout').datepicker('option', 'minDate', coDate);
            $('#ccheckout').val('Click to select date');
        }
    });
    $('#ccheckin').val('Click to select date');
    $('#ccheckout').datepicker({
        dateFormat: 'DD, dd MM yy',
        minDate: +1,
        hideIfNoPrevNext: true,
        beforeShow: function(input) {
            if ($('#ccheckout').val() == 'Click to select date') {
                $('#ccheckout').val("");
            }
        },
        onSelect: function(dateText, inst) {
            if (dateText != 'Click to select date' && $(this).val() != 'Click to select date') {
                $('#ccheckout').removeClass('error');
                $('#ccheckout').next("label.error").hide();
            }
        }
    });
    $('#ccheckout').val('Click to select date');
    $("#subscribeForm").validate();
    $('#cdinein').datepicker({
        dateFormat: 'DD, dd MM yy',
        altField: '#realdate',
        altFormat: 'dd/mm/yy',
        minDate: +0,
        hideIfNoPrevNext: true,
        onSelect: function(dateText, inst) {
            $("#cmenu").load("/food/hillside-set-menu.aspx?date=" + $('#realdate').val(), 1000);
        }
    });
    $('#cdinein').val('Click to select date');
});

$(window).load(function() {
    //Start the timer for the slideShow
    var refreshId = setInterval(slideShow, 6500);

    function slideShow() {
        $.galleria.next();
    }

    $('.gallery>img').css('display', 'block'); // adds new class name to maintain degradability

    $('ul.gallery').galleria({
        history: false, // activates the history object for bookmarking, back-button etc.
        clickNext: true, // helper for making the image clickable
        insert: '#main_image', // the containing selector for our main image
        onImage: function(image, caption, thumb) { // let's add some image effects for demonstration purposes

            // fade in the image & caption
            image.css('display', 'none').fadeIn(1000);
            caption.css('display', 'none').fadeIn(1000);

            // fetch the thumbnail container
            var _li = thumb.parents('li');

            // fade out inactive thumbnail
            _li.siblings().children('img.selected').fadeTo(1000, 0.75);

            // fade in active thumbnail
            thumb.fadeTo('fast', 1).addClass('selected');

            // add a title for the clickable image and stops the slideShow
            image.attr('title', 'Next image >>').click(function() { clearInterval(refreshId); });

        },
        onThumb: function(thumb) { // thumbnail effects goes here

            // fetch the thumbnail container
            var _li = thumb.parents('li');

            // if thumbnail is active, fade all the way.
            var _fadeTo = _li.is('.active') ? '1' : '0.75';

            // fade in the thumbnail when finnished loading and stops the slideShow
            thumb.css({ display: 'none', opacity: _fadeTo }).fadeIn(1500).click(function() { clearInterval(refreshId); });

            // hover effects
            thumb.hover(
				function() { thumb.fadeTo('fast', 1); },
				function() { _li.not('.active').children('img').fadeTo('fast', 0.75); } // don't fade out if the parent is active
			)
        }
    });
});

function GetMenuHeight() {
    $(document).ready(function() {
    if ($("ul.menu-a").height() > $("ul.menu-b").height()) {
            $("#menubp").css({ marginTop: $("ul.menu-a").height() - $("ul.menu-b").height() });
            $("ul.menu-b").css({ height: $("ul.menu-a").height() });        
        }
        else {
            $("#menuap").css({ marginTop: $("ul.menu-b").height() - $("ul.menu-a").height() });
            $("ul.menu-a").css({ height: $("ul.menu-b").height() });
        }

    });

}
