/*******
dukelib_init.js

The place where all event initialization will (eventually) take place.

Started by Derrek Lemar Croney on 1/25/2012
********/

/**
 * Display Calendar Feed Data
 */
function displayCalendarFeedData(dateList) {
    for (var i = 0; i < dateList.length; i++) {
        $row = $('#hoursTable > tbody > tr#' + i);
        $('.dukeusers .hours', $row).html(dateList[i].dukeHours);
        $('.dukeusers SPAN.title', $row).html(dateList[i].libraryDate);
        $('.genpublic', $row).html(dateList[i].publicHours);
    }
}

$(function(){
	var catalogAutoSuggestInputIDsObject = {
		suggestUrl: "http://autosuggest.trln.org/suggestservice/",
		indexInput: "#catalogcodeinput",
		sourceInput: "#catalogsource",
		suggestionFlagInput: "#catalogsuggestions",
		queryForm: "form[name='searchCatalog']",
		querySubmit: "#catalogsubmit"
	}; // clearIndexOnFirstFocus: true, clearIndexOnFirstChange: false (for auto-focus forms)
	$("#catalogqueryinput").autosuggest(catalogAutoSuggestInputIDsObject);

    // get a timestamp to add to the url
    var now = new Date();
    $.ajax({
        url		: 'http://library.duke.edu/about/hours/json_libdate.php',
        cache	: false,
        dataType: 'json',
        data    : {ts : now.getTime(), mode : 'production'},
        type	: 'GET',
        success	: function(data, textStatus, o) {
            $('DIV#hours').show();
            $('TABLE#hoursTable').show();
            displayCalendarFeedData(data.dateList);
        }
    });
    
});
