
// --- begin: list of cards
// The entry in loveinc_cards[] is either null or a card object.
//     A null value indicates leaving the cell displaying nothing
	// card: {basename:, type:, title:}
	//   basename: base part of the filename.
	//   type: 'single', 'all', 'no2', 'no3', 'no2_4', 'no3_4'.
	//         'single' for single card, 'all' if card has all C1~C4, 'no2' if no C2, ...
loveinc_cards = [
  {basename:'Takeout-C1', type:'no2_3', title:'Take Out'},
  {basename:'Xmas-2004-BenAndChris-C1', type:'no3', title:'Christmas Gift'},
  {basename:'Xmas-DudeHohoho-C1', type:'single', title:'Ho Ho Ho!'},
  {basename:'BDay-2005-Hugs-C1', type:'no2', title:'Hugs for Sale'},
  {basename:'YearOfRat-C1', type:'no2_3', title:'Year of Rat'},
  {basename:'VDay-2007-HeartTree-C1', type:'no2', title:'Heart Tree'},
  {basename:'BDay-2002-OwlsShh-C1', type:'all', title:'Birthday Surprise'},
  {basename:'BMark-2000-Giraffe', type:'single', title:'Bookmark: Giraffe'},

  {basename:'Easter-2002-CoolMeBunny-C1', type:'single', title:'Cool Me Bunny'},
  {basename:'Thanks-2004-LittleGirlFlower-C1', type:'no2', title:'Thank You'},
  {basename:'Misc-2004-SummerSwing-C1', type:'all', title:'Summer Swing By'},

  {basename:'Val-2001-Hippo-C1', type:'all', title:'Valentine Hippo'},
  {basename:'MDay-2005-ShortLegs-C1', type:'no2', title:'Short Legs'},
  {basename:'BDay-2004-ZZZ-C1', type:'no2', title:'Birthday Z\'s'}
	];
	/* more cards: 
	// {basename:'', type:'', title:''},
  {basename:'BDay-2004-BearNoWorkCake-C1', type:'no2', title:'Birthday Cake'}, 
	{basename:'Easter-2004-BearBunny-C1', type:'no2', title:'Beary Bunny'},
	{basename:'Xmas-2001-Hippo-C1', type:'all', title:'Double Christmas'},

	{basename:'', type:'', title:''},
	*/

loveinc_cards_map = init_map_with_basename(loveinc_cards);

// ---   end: list of cards

// --- begin: generate cards table
function generateCardsTable(n_cols) {
	genCardsTable(n_cols, loveinc_cards);
}

// Generate the table that displays cards, n_cols: number of columns in a row
function genCardsTable(n_cols, cards_arr) {
	cols_blank_rows = 2*n_cols-1; // colspan required for an empty padding row
	document.writeln('<table>');
	n_cells = cards_arr.length;
	if ((n_cells % n_cols) != 0)    // pad the total number of cells 
		n_cells += n_cols - (n_cells % n_cols);
	for (i=0; i < n_cells; i++) {
		is_first_col = ((i % n_cols) == 0) ? true : false;
		is_last_col = ((i % n_cols) == (n_cols-1)) ? true : false;
		if (is_first_col)
			document.writeln('<tr>');
		if (i < cards_arr.length) {
			cardobj = cards_arr[i];
			if (cardobj == null) {
				document.writeln('<td>&nbsp;</td>');
			} else {
				document.writeln('<td valign="bottom" align="center">');
				document.write('<a href="#" onClick="return zoom_card(\'');
				document.write(cardobj.basename);
				document.writeln('\');\">');
				document.write('<img class="card" src="');
				document.write(cardobj.basename);
				document.writeln('-150.jpg"></a><br>');
				document.write(cardobj.title);
				document.writeln('</td>');
			}
		} else {  // Last row of the table as all cards have been displayed
			if (is_last_col) {
				document.write('<td valign="bottom" align=right>');
				document.write('<br><a style="font-size: 9pt;" href="morecards.html">Once upon a time...</a><br>');
				document.writeln('<br></td>');
			}
		}
		if (is_last_col) {  // Last column, terminate the row and write out the row padding
			document.writeln('</tr>');
			document.writeln('<tr><td colspan="' + cols_blank_rows + '" height="10px">&nbsp;</td></tr>');
		} else  // gap between columns
			document.writeln('<td width="50px">&nbsp;</td>');
	}
	document.writeln('</table>');
}

function debug_gen() {
	tbl = document.getElementById("foo");
	alert(tbl.innerHTML);
}
// ---   end: generate cards table

// ---   begin: poping up card zooming window
var cardSelected = null;

function getCardObject() {
	return cardSelected;
}

// zoom_card(base): pops up the detailed card window for the case specified by its basename
var card_win = null;
function zoom_card(base) {
	card_index = loveinc_cards_map[base];
	if (card_index == "undefined" || card_index == null)
		alert("Undefined card: " + base);
	if (card_index < 0 || card_index > loveinc_cards.length) alert(base + ": No such card in the card list");
	cardSelected = loveinc_cards[card_index];
	if (card_win == null || card_win.closed) {
		width = 480;  height = 340;
		card_win = window.open('carddetails.html', 'details', 'width='+width+',height='+height+ ',scrollbars=no,menubar=no,toolbar=no,location=no,status=no,resizable=no');
	}
	try {
		card_win.setCardObject(cardSelected);
	} catch (_e) { }
	card_win.focus();
	return false;  // false to stop processing clicking event for the caller
}

// ---     end: poping up card zooming window

