$(function () {

	// datepicker
	$( ".datepicker" ).datepicker({
			minDate: 0,
			showOn: "both",
			buttonImage: "images/calendar.png",
			buttonImageOnly: true
		});
		
	// beautify select boxes	
    $("select").select_skin();
    
    // scrollTo
    $("#nav > li").click(function () {
        var qu = $(this).attr("id");
        var an = "#" + qu.replace("nav", "a");

        $.scrollTo(an, {
            duration: 800,
            axis: "y",
            onAfter: function () {
                $(an).effect("highlight", {
                    color: "#ddd"
                }, 2000);
            }
        });
    });
	
	// return to top
    $(".return-top").click(function () {
        $.scrollTo(0, {
            duration: 800,
            axis: "y"
        });
    });
	
	// serialize submit for reservation widget
    $('#reserver').submit(function (e) {
        //e.preventDefault();
        $('#myFrame').remove();
        //console.log($('.datepicker').val());
        var dateStringCI = $('.CI').val();
        var dateArrayCI = dateStringCI.split('/');
        var dateStringCO = $('.CO').val();
        var dateArrayCO = dateStringCO.split('/');

        //console.log(dateArrayCI);
        //console.log(dateArrayCO);
        $('#CIM').val(dateArrayCI[0]);
        $('#CID').val(dateArrayCI[1]);
        $('#CIY').val(dateArrayCI[2]);
        $('#COM').val(dateArrayCO[0]);
        $('#COD').val(dateArrayCO[1]);
        $('#COY').val(dateArrayCO[2]);

        //console.log($('#CIM').val());
        var reserveString = $(this).serialize();
        reserveString = 'https://secure.iqres02917.com/iqreservations/default.asp?' + reserveString;
        //console.log(reserveString);
        window.open(reserveString, "Reservations", "width=825,toolbar=0,scrollbars=1");

		/*
		var an = $("#a1");
        $.scrollTo(an, {
            duration: 800,
            axis: "y",
            onAfter: function () {
                $(an).effect("highlight", {
                    color: "#ddd"
                }, 2000);
            }
        });

        if (!document.getElementById('myFrame')) {
            $('<iframe />', {
                name: 'myFrame',
                id: 'myFrame',
                width: '960px',
                height: '1050px',
                overflow: 'hidden',
                src: reserveString
            }).appendTo($('#a1 .content .iframe'));

            $('<a />', {
                id: 'cancel-reservation',
                href: '#',
                html: 'collapse'
            }).appendTo($('#a1 .content .iframe'));

            $("#cancel-reservation").click(function () {
                $('#myFrame').remove();
                $(this).remove();
            });

        }
		*/
        return false;
    });
	
	$('.reserver').click(function () {
		window.open("https://secure.iqres02917.com/iqreservations/default.asp", "Reservations", "width=825,toolbar=0,scrollbars=1");
		return false;
	});
	
	/*
    $('.reserver').click(function () {
        $('#myFrame').remove();

        var an = $("#a1");
        $.scrollTo(an, {
            duration: 800,
            axis: "y",
            onAfter: function () {
                $(an).effect("highlight", {
                    color: "#ddd"
                }, 2000);
            }
        });

        if (!document.getElementById('myFrame')) {
            $('<iframe />', {
                name: 'myFrame',
                id: 'myFrame',
                width: '960px',
                height: '1050px',
                overflow: 'hidden',
                src: 'https://secure.iqres02917.com/iqreservations/default.asp'
            }).appendTo($('#a1 .content .iframe'));

            $('<a />', {
                id: 'cancel-reservation',
                href: '#',
                html: 'collapse'
            }).appendTo($('#a1 .content .iframe'));

            $("#cancel-reservation").click(function () {
                $('#myFrame').remove();
                $(this).remove();
            });

        }
        return false;

    });
    */

	
});

