
function mycarousel_itemLoadCallback(carousel, state)
{
// Since we get all URLs in one file, we simply add all items
// at once and set the size accordingly.
if (state != 'init')
return;
carousel_itemAddCallback(carousel,carousel.first, carousel.last);
/*
jQuery.get('dynamic_ajax.txt', function(data) {
mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, data);
});
*/
};
function carousel_itemAddCallback(carousel,first, last)
{ 
var numOfDays = 21;
var offset = -7;
var dayCount = 0;
//alert("scheduleDate" + jQuery("#scheduleDate").attr("numericaldate"));
for (var i=0; i < numOfDays; i++)
{
var menuItem = new ScheduleTab();
menuItem.date.setDate(new Date().getDate() + i + offset);
menuItem.setTabId(i + 1);
// Pull main schedule html
var html = menuItem.getHtml();
carousel.add(i+1, html);	
//jQuery("#menu").append(html);
dayCount++;
}
carousel.size(dayCount);
}	
function updateSchedule() {
}
jQuery(document).ready(function() {
specifiedDate = jQuery("#scheduleDate").attr("numericaldate");
today = new Date();
todayAsString = (today.getMonth() + 1) + "/" + today.getDate() + "/" + today.getFullYear();
offsetDaysfromToday = diffDates(specifiedDate,todayAsString);
var offsetScroll = 8;
if (offsetDaysfromToday < 0) {
offsetScroll = 0;
} else if (offsetDaysfromToday > 0 && offsetDaysfromToday < 8) {
offsetScroll = 8;
} else if (offsetDaysfromToday > 8) {
offsetScroll = 15;
}
jQuery('#mycarousel').jcarousel({
scroll:7,
start:offsetScroll, 
itemLoadCallback: mycarousel_itemLoadCallback
});
var storedDate = jQuery("#scheduleDate").attr("numericaldate");
if ( storedDate != "empty") {
var selectedTab = jQuery(".scheduleTab[numericdate='" + storedDate + "']");
//select the new tag
jQuery(selectedTab).addClass("id");
jQuery(selectedTab).attr("id", "selected");
jQuery(selectedTab).attr("class","scheduleTabSelected");
} 
jQuery(".scheduleTab").click(function () {
//deselect the old selected tab
jQuery("#selected").removeAttr("id");
jQuery(".scheduleTabSelected").attr("class","scheduleTab" );
//select the new tag
jQuery(this).addClass("id");
jQuery(this).attr("id", "selected");
jQuery(this).attr("class","scheduleTabSelected");
//set tabid
var tabId = jQuery(this).attr("tabid");
jQuery("#scheduleBdy2").attr("tabid",tabId);
//alert("date to be passed " + jQuery(this).attr("numericdate"));
//load the schedule with the selected date
loadScheduleTab(jQuery(this).attr("numericdate"));
});
});

