var thisPage = 'home';
var myLayout;
var myLayoutSettings = {
   north: {
      resizable: false,
      closable: false,
      size: "auto",
      minSize: 126,
      maxSize: 126,
      spacing_open: 0
   },
   west: {
      resizable: false,
      closable: false,
      slidable: false,
      size: "auto",
      minSize: 200,
      maxSize: 200,
      spacing_open: 0,
      initClosed: false
   },
   south: {
      resizable: false,
      closable: false,
      slidable: false,
      size: 18,
      spacing_open: 0
   }
};

var tmDateTime;
var months = new Array();
   months[0] = "Jan";
   months[1] = "Feb";
   months[2] = "Mar";
   months[3] = "Apr";
   months[4] = "May";
   months[5] = "Jun";
   months[6] = "Jul";
   months[7] = "Aug";
   months[8] = "Sep";
   months[9] = "Oct";
   months[10] = "Nov";
   months[11] = "Dec";
var days = new Array();
   days[0] = "Sun";
   days[1] = "Mon";
   days[2] = "Tue";
   days[3] = "Wed";
   days[4] = "Thu";
   days[5] = "Fri";
   days[6] = "Sat";

function stopTime() {
   clearTimeout(tmDateTime);
}

function startTime() {
   var today = new Date();
   $("#DateTime").html(
      days[today.getDay()] + ", " + months[today.getMonth()] + " " + today.getDate() + ", " + today.getFullYear() + " " +
      formatTime(today)
   );
   tmDateTime = setTimeout('startTime()', 5000);
}

function zeroPad(i,n) {
   var s = "";
   for (var x = 0; x < n; x++) {
      s += "0";
   }
   s += i;
   return s.substr(s.length - n, n);
}

function formatTime(d) {
   var h = d.getHours();
   var m = d.getMinutes();
   var ampm;
   if (h >= 12) {
      ampm = "pm";
      h -= (h > 12 ? 12 : 0);
   } else {
      ampm = "am";
   }
   return zeroPad(h, 2) + ":" + zeroPad(m, 2) + ampm;
}

function buildEmailForm() {
}

function showEmailForm() {
	// Build the email form.
	$("#emailForm").load("html/info-email.html");
	$("#emailForm").dialog({
		bgiFrame: false,
		autoOpen: false,
		height: 600,
		width: 600,
		modal: true,
		buttons: {
			Submit: function() {
				$.post(
					"inc/callback.php",
					"cmd=info&"+$("#infoEmailForm").serialize(),
					function(data,textStatus) {
						alert("Your request has been sent.");
					}
				);
				$("#emailForm").dialog("close");
			},
			Cancel: function() {
				$("#emailForm").dialog("close");
			}
		}
	});
	$("#emailForm").dialog("open");
}

function gotoPage(page) {
	$("#mainContent").load("html/"+page+".php");
}

////////////////////////////////////////////////////////////////////////////////////////////////
SongList = {};

SongList.tableId = null;
SongList.gridRowNumber = -1;
SongList.detailRowIsOpen = false;
SongList.detailRow = null;
SongList.detailColumn = null;
SongList.pageSize = 20;

SongList.openRow = function( tableId, gridRow ) {
   this.tableId = tableId;
   this.gridRowNumber = gridRow;
   var colSpan = $(this.tableId).rows[this.gridRowNumber].cells.length;	// Get the number of columns to create a row that spans all columns.
   this.detailRow = $(this.tableId).insertRow(this.gridRowNumber+1);	// Create a row immediately after the selected row.
   this.detailColumn = newRow.insertCell(0);	// Create a single column;
   //newRow.style.backgroundColor = "#dfdfdf";
   this.detailColumn.colSpan = colSpan;	// The single column will span all columns of the parent row.
   this.detailColumn.id = "DetailRow";	// Name this row.
   this.detailColumn.innerHTML = "";		// Nothing in it. The calling function will populate the row.
   $("view"+editGridRow).src = "/img/plus.png";
   this.detailRowIsOpen = true;
};

SongList.closeRow = function() {
   if (this.detailRowIsOpen) {
      $(this.tableId).deleteRow(this.gridRowNumber+1);
      $("view"+editGridRow).src = "/img/plus.png";
      this.detailRowIsOpen = false;
      this.tableId = null;
		this.gridRowNumber = -1;
		this.detailRowIsOpen = false;
		this.detailRow = null;
		this.detailColumn = null;
   }
};

SongList.loadList = function(pageNum) {
	$("#mainContent").load(
		"html/songlist.php",
		"cmd=init&view=artist&pn="+pageNum+"&ps="+this.pageSize,
		function(data,status) {
			alert(status+"\r\n\r\n"+data);
		}
	);
}

SongList.changeView = function(newView) {
	$("#songlistContent").load(
		"html/songlist.php",
		"cmd=list&view="+newView+"&pn="+pageNum+"&ps="+this.pageSize
	);
}

SongList.loadRow = function() {
	$.post(
		"inc/callback.php",
		"cmd=info&"+$("#infoEmailForm").serialize(),
		function(data,textStatus) {
			alert("Your request has been sent.");
			alert(textStatus+":\r\n\r\n"+data);
		}
	);
}

////////////////////////////////////////////////////////////////////////////////////////////////
$(document).ready(
	function() {
		//alert("I'm ready!");
		//myLayout = $("body").layout(myLayoutSettings);
		startTime();
		//$("#infoEmail").click(
		//	function() {
		//		showEmailForm();
		//	}
		//);
		//$("#menuSongList").click(
		//	function() {
		//		SongList.loadList(1);
		//	}
		//);
		//gotoPage(thisPage);	// 'home' to start
	}
);

