
var calDate = new Date();
var month = calDate.getMonth() + 1;
var year = calDate.getFullYear();

$(document).ready(function ()
{
	$("li.dateHeader").text(getMonthName(month - 1) + ", " + year);
	
	$('.tab').click(function () {

	  // Remove the 'active' class from the active tab.
	  $('#pager > ul > li.active').removeClass('active');
	  
	  	// Add the 'active' class to the clicked tab.
    	$(this).parent().addClass('active');
    
    	// Remove the 'tab_contents_active' class from the visible tab contents.
   		$('#event-content > div.tab_contents_active').removeClass('tab_contents_active');
    
    	// Add the 'tab_contents_active' class to the associated tab contents.
    	$(this.rel).addClass('tab_contents_active');
    
  });
});

function showNext()
{
	if (month == 12)
	{
		year++;
		month = 1;
	}
	else month++;
	
	//$("#calendar-container").load("http://localhost/svdevelopment/xmlpipeline/cal-list-view-wrapper.pxml/" + year + "/" + month, "list-view", dataLoaded);
	$("#calendar-container").load("http://www.sunvalley.com/xmlpipeline/cal-list-view-wrapper.pxml?startDate=" + year + "-" + month + "-01&eventDays=" + daysInMonth(year, month), "list-view", dataLoaded);
	$("li.dateHeader").html("loading&hellip;");
}

function showPrevious()
{
	if (month == 1)
	{
		year--;
		month = 12;
	}
	else month--;
	
	//$("#calendar-container").load("http://localhost/svdevelopment/xmlpipeline/cal-list-view-wrapper.pxml/" + year + "/" + month, "list-view", dataLoaded);
	$("#calendar-container").load("http://www.sunvalley.com/xmlpipeline/cal-list-view-wrapper.pxml?startDate=" + year + "-" + month + "-01&eventDays=" + daysInMonth(year, month), "list-view", dataLoaded);
	//$("#event1evt1").load("http://localhost/svdevelopment/xmlpipeline/cal-list-view-wrapper.pxml?startDate=" + year + "-" + month + "-01&eventDays=" + daysInMonth(year, month));
	$("li.dateHeader").html("loading&hellip;");
}

function showToday()
{
	$("#calendar-container").load("http://www.sunvalley.com/xmlpipeline/cal-list-view-wrapper.pxml", "list-view", dataLoaded);
	//reset date to today
	calDate = new Date();
	month = calDate.getMonth() + 1;
	year = calDate.getFullYear();
	$("li.dateHeader").html("loading&hellip;");
}

function dataLoaded(responseText, textStatus, XMLHttpRequest)
{
	calDate.setMonth(month - 1);
	calDate.setFullYear(year);
	$("li.dateHeader").text(getMonthName(month - 1) + ", " + year);
	
	$('.tab').click(function () {

	  // Remove the 'active' class from the active tab.
	  $('#pager > ul > li.active').removeClass('active');
	  
	  	// Add the 'active' class to the clicked tab.
    	$(this).parent().addClass('active');
    
    	// Remove the 'tab_contents_active' class from the visible tab contents.
   		$('#event-content > div.tab_contents_active').removeClass('tab_contents_active');
    
    	// Add the 'tab_contents_active' class to the associated tab contents.
    	$(this.rel).addClass('tab_contents_active');
    
  });
}

function getEventDetail(id, url)
{
	//alert(id);
	//$(id) > p.l2 > a.l2.html("loading&hellip;");
	$(id).html("loading&hellip;");
	$(id).load(url);
	//$("#calendar-container").load(url);
	//$("#event-content").load(url);
}

function getMonthName(month)
{
	if (0 <= month < 12)
	{
		var months = new Array(12);
		months[0]  = "January";
		months[1]  = "February";
		months[2]  = "March";
		months[3]  = "April";
		months[4]  = "May";
		months[5]  = "June";
		months[6]  = "July";
		months[7]  = "August";
		months[8]  = "September";
		months[9]  = "October";
		months[10] = "November";
		months[11] = "December";
		return months[month];
	}
	else return "Undefined";
}

//http://javascript.about.com/library/bllday.htm
function daysInMonth(month,year) {
	var dd = new Date(year, month, 0);
	return dd.getDate();
}