// ****************************************************************************************************************************************
// Wall Paper Display Javascript
// Version 1.0.0
//
// Date Created:  2005-04-11
// Last Modified: 2005-04-13
//
// Requires: general.js v1.4.0+
//
// Created by MeMSO of NeueTECH Software and A Far Site Better
// (c) Copyright 2005

// ------------------------------------------------------------------------------------------------
// NOTES
// Scramble Ready
// NTSCRAMBLED-Prepend="absterWP"
// ------------------------------------------------------------------------------------------------

// ********************************************************************************************************************
// Constants



// ********************************************************************************************************************
// External Use Data
// NTSCRAMBLED-External

var wallpaper_columns         = 4;
var wallpaper_rows            = 3;

var wallpaper_imagewid        = 150;
var wallpaper_imagehei        = 112;

var wallpaper_spacingh        = 4;
var wallpaper_spacingv        = 4;

var wallpaper_borderwid       = 2;
var wallpaper_borderhei       = 2;

var wallpaper_bgclass         = 'WallpaperBG';
var wallpaper_borderclass     = 'WallpaperBorder';
var wallpaper_imageclass      = 'WallpaperImage';
var wallpaper_overlayimageclass = 'WallpaperImageOverlay';
var wallpaper_overlaytextclass = 'WallpaperTextOverlay';
var wallpaper_linksclass      = 'WallpaperLinks';
var wallpaper_linkonclass     = 'WallpaperOnLink';

var wallpaper_linkseparator   = ' - ';

var wallpaper_thumbdirectory  = '/images/temp/thumbs/';
var wallpaper_fulldirectory   = '/images/temp/full/';

// Number of wall papers in the wall paper data array
var wallpaper_num             = 0;

// An array of arrays
// Each index is a different wall paper
// For each wall paper:
// 0 - Thumb image file name
// 1 - Full image file name (use Thumb Image if blank or not used)
// 2 - Caption text (ignore if blank or not used)
// 3 - Overlay text (ignore if blank or not used)
var wallpaper_data            = new Array();



// ********************************************************************************************************************
// Internal Use Variables
// NTSCRAMBLED-Internal

// BITS
// 0 - 0001 - Initialization is complete
var wallpaper_curflags        = 0;

var wallpaper_numperpage      = 0;
var wallpaper_curpageid       = 0;
var wallpaper_maxpageid       = 0;



// ####################################################################################################################
// ####################################################################################################################
// ####################################################################################################################
// Function Listing

// ********************************************************************************************************************
// DONE
function Wallpaper_Initialize() {
	if (wallpaper_curflags & 0x01)
		return;

	// Get the number of wall papers
	wallpaper_num = wallpaper_data.length;
	// Get the number we can show per page
	wallpaper_numperpage = wallpaper_columns * wallpaper_rows;
	// Calculate the maximum page ID
	wallpaper_maxpageid = Math.floor(wallpaper_num / wallpaper_numperpage);
	if (wallpaper_num % wallpaper_numperpage)
		wallpaper_maxpageid++;
	// Subtract one since this is the count, and we want the max
	wallpaper_maxpageid--;

	// Get query data
	Request_QueryData();
	// Get the current page index ID
	wallpaper_curpageid = nullwrap(Request_Get('pageid'), C_NUM);

	if (wallpaper_curpageid < 0 || wallpaper_curpageid > wallpaper_maxpageid)
		wallpaper_curpageid = 0;

	wallpaper_curflags |= 0x01;
} // Wallpaper_Initialize



// ********************************************************************************************************************
function DisplayWallpaper() {
	if (!(wallpaper_curflags & 0x01))
		Wallpaper_Initialize();

	if (!wallpaper_num)
		return;

	var curhtml = '', innerhtml;
	var fullspan = (wallpaper_columns << 1) + 1;
	var q, p, curindex, curlength;
	var cururl, curimage, captiontext, overlaytext;

	// ----------------------------------------------------------------------------------------------
	// Build the HTML

	// ..........................................................................
	// Build the top of the table
	curhtml += '<table border="0" cellspacing="0" cellpadding="0" class="' + wallpaper_bgclass + '">\n' +
		'<tr class="' + wallpaper_borderclass + '">\n' +
			'<td width="' + wallpaper_borderwid + '">' +
				'<img src="/images/dot.gif" width="' + wallpaper_borderwid + '" height="' + wallpaper_borderhei + '" alt="" />' +
			'</td>\n';
	for (q = 0; q < wallpaper_columns; q++) {
		if (q)
			curhtml += '<td width="' + wallpaper_spacingh + '"><img src="/images/dot.gif" width="' + wallpaper_spacingh + '" height="1" alt="" /></td>\n';
		curhtml += '<td width="' + wallpaper_imagewid + '"><img src="/images/dot.gif" width="' + wallpaper_imagewid + '" height="1" alt="" /></td>\n';
	}
	curhtml +=
			'<td width="' + wallpaper_borderwid + '">' +
				'<img src="/images/dot.gif" width="' + wallpaper_borderwid + '" height="' + wallpaper_borderhei + '" alt="" />' +
			'</td>\n' +
		'</tr>\n';

	// ..........................................................................
	// Build the table content
	curindex = wallpaper_curpageid * wallpaper_numperpage;
	for (p = 0; p < wallpaper_rows; p++) {
		curhtml += '<tr>\n' +
			'<td class="' + wallpaper_borderclass + '"><img src="/images/dot.gif" width="1" height="' + wallpaper_imagehei + '" alt="" /></td>\n';

		for (q = 0; q < wallpaper_columns; q++) {
			if (q)
				curhtml += '<td><img src="/images/dot.gif" width="1" height="1" alt="" /></td>\n';

			// &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
			// Do we need to read wall paper data?
			if (curindex < wallpaper_num) {
				// ::::::::::::::::::::::::::::::::::::::::::::::::
				// Get the data

				// //////////////////////////////////////
				// Get the length of the current array
				curlength = wallpaper_data[curindex].length;

				// //////////////////////////////////////
				// Get the base image
				curimage = wallpaper_data[curindex][0];

				// //////////////////////////////////////
				// Get the full URL
				cururl = (curlength > 1) ? wallpaper_data[curindex][1] : '';
				if (cururl == '')
					cururl = curimage;
				cururl = wallpaper_fulldirectory + cururl;

				// //////////////////////////////////////
				// Set the path of the thumbnail
				curimage = wallpaper_thumbdirectory + curimage;

				// //////////////////////////////////////
				// Get the caption text
				captiontext = (curlength > 2) ? wallpaper_data[curindex][2] : '';

				// //////////////////////////////////////
				// Get the overlay text
				overlaytext = (curlength > 3) ? wallpaper_data[curindex][3] : '';

				// ::::::::::::::::::::::::::::::::::::::::::::::::
				// Build the HTML!

				// //////////////////////////////////////
				// Is there overlay text?
				if (overlaytext != '') {
					curhtml += '<td class="' + wallpaper_overlayimageclass + '" style="background-image: url(' + curimage + ');"' +
						' onclick="window.open(\'' + cururl + '\', \'\', \'scrollbars=yes,resizable=yes\');">';
					curhtml += '<span class="' + wallpaper_overlaytextclass + '">' + formfix(overlaytext) + '</span>';
					curhtml += '</td>\n';

				// //////////////////////////////////////
				// Otherwise, it's just a simple image. ;)
				} else {
					curhtml += '<td><a href="' + cururl + '" target="_blank">' +
						'<img src="' + curimage + '" width="' + wallpaper_imagewid + '" height="' + wallpaper_imagehei + '"' +
							' alt="' + formfix(captiontext) + '" title="' + formfix(captiontext) + '" class="' + wallpaper_imageclass + '" />' +
						'</td>\n';

				}

			// &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
			// Otherwise, it's blank
			} else {
				curhtml += '<td><img src="/images/dot.gif" width="1" height="1" alt="" /></td>\n';

			}
			curindex++;
		} // for (q = 0; q < wallpaper_columns; q++)

		curhtml += '<td class="' + wallpaper_borderclass + '"><img src="/images/dot.gif" width="1" height="1" alt="" /></td>\n' +
			'</tr>\n';
		if (p + 1 != wallpaper_rows) {
			curhtml +=
				'<tr>\n' +
					'<td class="' + wallpaper_borderclass + '"><img src="/images/dot.gif" width="1" height="1" alt="" /></td>\n' +
					'<td colspan="' + (fullspan - 2) + '"><img src="/images/dot.gif" width="1" height="' + wallpaper_spacingv + '" alt="" /></td>\n' +
					'<td class="' + wallpaper_borderclass + '"><img src="/images/dot.gif" width="1" height="1" alt="" /></td>\n' +
				'</tr>\n';
		}
	} // for (p = 0; p < wallpaper_rows; p++)

	curhtml += '<tr class="' + wallpaper_borderclass + '">\n' +
			'<td colspan="' + fullspan + '"><img src="/images/dot.gif" width="1" height="' + wallpaper_borderhei + '" alt="" /></td>\n' +
		'</tr>\n' +
		'</table>';

	document.write(curhtml);
} // DisplayWallpaper



// ********************************************************************************************************************
// DONE
function DisplayWallpaperLinks() {
	if (!(wallpaper_curflags & 0x01))
		Wallpaper_Initialize();

	if (!wallpaper_maxpageid)
		return;

	var curhtml, q;

	curhtml = '<span class="' + wallpaper_linksclass + '">';
	for (q = 0; q <= wallpaper_maxpageid; q++) {
		if (q)
			curhtml += wallpaper_linkseparator;
		if (q == wallpaper_curpageid)
			curhtml += '<span class="' + wallpaper_linkonclass + '">' + (q + 1) + '</span>';
		else
			curhtml += '<a href="' + WindowLocation + '?pageid=' + q + '">' + (q + 1) + '</a>';
	}
	curhtml += '</span>';

	document.write(curhtml);
} // DisplayWallpaperLinks



