$(document).ready(function(){

	getNextFewDances();
	getNotices();
	getFlyer();
		
	function getNotices(){
		$.getJSON("/scripts/service.php?action=getNotices", function(json) {	
			if (json.notices.length > 0) {
				
				//  Show notice on the top of the home page
				var info = "";
				$.each(json.notices,function() {	
					info += '<div class="notice">';
					info += "<h1 align='center'>" + this['title'] + "</h1>";
					info += "<p align='left'>" + this['details'] + "</p></div>";					
				});	// End of each
				
				//	Add the info to the top of page
				$('#notice').append( info );
			}	// End if json has data
		});	// End getJSON
	}	// END function getNotices
							


	function getFlyer(){
		$.getJSON("/scripts/service.php?action=getFlyer", function(json) {	
			if (json.flyer[0].filename > '') {
				//  Show flyer at the top of the home page
				var info = "";
				$.each(json.flyer,function() {
					info = "<p>*** Here's the flyer for our next dance. Below that is more information ***</p>";
					info += '<div style="text-align: center;"><img style="border:1px solid black;" src="posters/' + this['filename'] +'"; width="680px" /></div>';
				});	// End of each

				//	Add the info to the top of page
				$('#flyer').append( info );
			}	// End if json has data
		});	// End getJSON
	}	// END function getNotices
							


	function getNextFewDances(){		
		$.getJSON("/scripts/service.php?action=getDances", function(json) {		
			if (json.dances.length > 0) {
				
				//  Build the table from each of the dances returned
				var info = '<table width="100%" cellpadding="7">';
				$.each(json.dances,function() {	
					info += '<tr><td width="35%" valign="top">';
					info += this['date'] + '</td><td width="65%" valign="top"><strong>';
					
					//  Show header: Comments, Special Event, No Dance Tonight, or blank if no headers apply
					if(this['comment'] > ''){
						info += '<div class="notice">' + this['comment']  + '</div>';
					}
					if(this['special'] == 1){
						info += '<div>** Special Event **</div>';
					}
					if(this['nodance'] == 1){
						info += '<div>** No Dance Tonight **</div>';
					}
					// Next show the theme in this cell
					info += "<div>" + this['theme'] + "</div></strong>";
					
					// If not a nodance, then put dance info in a subtable in this cell					
					if(this['nodance'] != 1){
						info += '<table width="100%" border="0">';
						info += '<tr><td width="20%">Caller: </td><td>' + this['caller'] + '</td></tr>';
						if(this['cuer'] > ''){
							info += '<tr><td width="20%">Cuer: </td><td>' + this['cuer'] + '</td></tr>';
						} else {
							info += '<tr><td width="20%">Cuer: </td><td>No cuer for tonight</td></tr>';	
						}
						info += '</table>';
					}

					//	Finally, add the non-standard items, if any
					info += '<em>';
					if(this['advanced'] == 1){
						info += '<div> * No Advanced Calls tonight</div>';
					}
					if(this['startsat'].trim() != "8:00 PM"){
						info += "<div>* Starts at " + this['startsat'] + "</div>";
					}
					if(this['admission'].trim() != '$5'){
						info += "<div>* Admission: " + this['admission'] + "</div>";
					}
					info += '</em></td></tr>';  //  End of info for a dance; each 
				});	// End of each
				
				//	Add the info to the schedule section of the page
				$('#schedule').append( info );
			}	// End if json has data
		});	// End getJSON
	}	// END function getNextFewDances
							
});

