﻿/// <reference path="jquery-1.3.2-vsdoc.js" />

$(function () {                   //Document ready behaviors

    if (document.documentElement.attachEvent)                   //Eliminate the A tag outline in IE
        document.documentElement.attachEvent('onmousedown', function () {
            event.srcElement.hideFocus = true
        });

    $(".carousel-strip").jac({ leftText: "", rightText: "" });  //Activate the menu item carousel

    $('ul.carousel li a').click(function () {                    //Highlight the selected carousel category
        $(this).css({ 'font-size': '1.2em', 'color': '#ff0000' });
    });

    //Highlight the main nav menu item for the current page
    var loc = window.location.toString().split("/");
    $('#mainMenu li a[href=\"' + loc[loc.length - 1] + '\"]').addClass('on');

    //Animate the main navigation sprites
    $('ul#mainMenu span').css('opacity', '0');
    $('ul#mainMenu span').hover(function () { //mouseover
        $(this).stop().animate({ opacity: 1 }, "slow");
    }, function () { //mouseout
        $(this).stop().animate({ opacity: 0 }, "slow");
    });

    //Create an accordion on the daily specials
    $('ul#accordion li div').css('display', 'none');   //Close the accordion initially
    $('ul#accordion a.dayHeading').click(function () {  //Target the day of week anchor tag
        $(this).css('outline', 'none');
        if ($(this).parent().hasClass('current')) {     //Section clicked is already expanded
            $(this).siblings('div').slideUp('slow', function () { //Slide it up & remove its current class
                $(this).parent().removeClass('current');
            });
        } else {                                        //Section clicked is not expanded
            $('ul#accordion li.current div').slideUp('slow', function () {
                $(this).parent().removeClass('current');
            });
            $(this).parent().toggleClass('current');
            $(this).siblings('div').slideToggle('slow');
            /*         $(this).siblings('div').slideToggle('slow', function() {
            $(this).parent().toggleClass('current');
            }); */
        }
        return false;
    });

    $('.caption').css({ 'display': '' });       //Show the caption text below the daily special images

    //Set up zoom for images
    $('.slateImage').click(function () { $(this).pv_zoom(); });
    $('.menuItemImage').click(function () { $(this).pv_zoom(); });
    $('.menuItemAltImage').click(function () { $(this).pv_zoom(); });
    $('.retailImageLeft').click(function () { $(this).pv_zoom(); });
    $('.retailImageRight').click(function () { $(this).pv_zoom(); });
    $('.aboutImageLeft').click(function () { $(this).pv_zoom(); });
    $('.aboutImageRight').click(function () { $(this).pv_zoom(); });
    $('.storyImageLeft').click(function () {
        $(this).pv_zoom({ imageWidth: 402 });
    });

    //Process async postback events for the Menu page
    Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageLoaded);

    function PageLoaded(sender, args) {       //Get the number of menu items & adjust the background image
        var rowCount = $('#menulist table tr').length;
        if (rowCount > 0 && rowCount % 2 != 0) { //Be sure there are rows to process (or on menu page)
            $('#menulist').css('background', 'url(../Images/menutab_single.png) no-repeat scroll bottom left');
        } else {
            $('#menulist').css('background', 'url(../Images/menutab_double.png) no-repeat scroll bottom left');
        }
        var hdnField = $('#mcaSingle input').val();     //Get the category # from the hidden field
        if (hdnField != "undefined" && hdnField > 0) {  //Reset carousel text to default values
            $('.carousel a')
            .css({ 'font-size': '1em', 'color': '#c8c8c8' })
            .eq(hdnField - 1).css({ 'font-size': '1.2em', 'color': '#ff0000' });   //Modify category clicked text
            $('.menuItemImage').click(function () { $(this).pv_zoom(); });
            $('.menuItemAltImage').click(function () { $(this).pv_zoom(); });
        }
    }

    var places = [
      ['Stocktons Pub and Grill', 38.130739, -92.65078, 2, 'Good Eatin!'],
      ['Coldstone Creamery', 38.145475670, -92.629358768, 2, 'Best ice cream in town!'],
      ['Osage Village Inn', 38.1453744482, -92.629423141, 2, 'Osage Village Inn'],
      ['Holiday Inn Express', 38.145999039, -92.628221512, 2, 'Holiday Inn Express'],
      ['Quails Nest', 38.143636271, -92.630453110, 2, 'Quails Nest']
   ];

    if ($('#datePicker').length) {                      //Make sure this is the events page
        $('input.dateText').daterangepicker({           //Set up the date range picker
            presetRanges: [
            { text: 'Today', dateStart: 'Today', dateEnd: 'Today' },
            { text: 'Next 7 days', dateStart: 'Today', dateEnd: 'Today+7' },
            { text: 'Next 30 Days', dateStart: 'Today', dateEnd: 'Today+30' }
         ],
            earliestDate: '01-01-2010',
            latestDate: Date.parse('+1years')
        });
    }

    var infowindow = new google.maps.InfoWindow

    if ($('#map').length) {                            //Set up the map markers on the location page
        var mapOptions = { zoom: 13, center: new google.maps.LatLng(38.130739, -92.65078), mapTypeId: google.maps.MapTypeId.ROADMAP };
        var map = new google.maps.Map($('#map'), mapOptions);
        var markers = [];
        setMarkers(map, places);
        $(markers).each(function (i, marker) {           //Add click event to each marker
            google.maps.event.addListener(marker, "click", function () {
                displayPoint(marker, i);
            });
            $('<li />')
            .html("Point " + i)
            .click(function () {
                map.panTo(marker.getLatLng());
            })
            .appendTo('#list');
        });
        //      $('#mapMessage').appendTo(map.getPane(G_MAP_FLOAT_SHADOW_PANE));
    }

    function setMarkers(map, locations) {
        for (var i = 0; i < locations.length; i++) {
            var site = locations[i];
            var latLng = new google.maps.LatLng(site[1], site[2]);
            var marker = new google.maps.Marker({ position: latLng, map: map, title: site[0], zIndex: site[3] });
            marker.setMap(map);
            markers[i] = marker;
        }
    }

    function displayPoint(marker, index) {
        $('#mapMessage').hide();
        var moveEnd = google.maps.event.addListener(map, "moveend", function () {
            var markerOffset = map.fromLatLngToDivPixel(marker.getLatLng());
            $('#mapMessage')
            .fadeIn()
            .css({ top: markerOffset.y, left: markerOffset.x });
            google.maps.event.removeListener(moveEnd);
        });
        map.panTo(marker.getLatLng());
    }

});

