
/** MUBLA! JavaScript Engine */

var agent = navigator.userAgent.toLowerCase();
var is_gecko = (agent.indexOf('gecko') != -1);
var scr_wide = screen.width;
var scr_high = screen.height;
var last_win_handle = 0;

/** about_mubla() */
function about_mubla () {
	var win_wide = 320;
	var win_high = 240;
	var left = (screen.width - win_wide) / 2;
	var top = (screen.height - win_high) / 2;
	var winAttribs =
		'toolbar=0,status=0,menubar=0,resizable=0,scrollbars=no,directories=0,dependent=yes'
		+ ',width=' + win_wide + ',height=' + win_high + ',top=' + top + ',left=' + left;
	var winHandler = window.open('', 'about', winAttribs);
	var htmlContent = '<html><head><title>About MUBLA!</title>'
		+ '<style>body{background-color:' + cap_backcolor + ';color:' + cap_forecolor + ';font-family:' + cap_fontfamily + ';font-size:8pt;'
		+ 'margin: 2%;text-align:justify} a{text-decoration:underline;color:' + cap_linkcolor + ';} hr {width: 100%;border:2px solid ' + cap_linkcolor + ' }</style></head><body>'
		+ '<hr /><br /><b>MUBLA!</b> uses PHP, JavaScript, and CSS to create an easy to manage, '
		+ 'user-friendly, and aesthetically-pleasing image gallery. It was programmed from the ground-up to be '
		+ 'a <i>flat-file only</i>&mdash;that means no messy databases! The script is free to use and can be installed on any '
		+ 'server running PHP4 with GD installed. MUBLA! features template-based styling, a flat-file caching system, five thumbnailing '
		+ 'modes, captions support, DHTML options, screen-name tracking, and more! Please visit '
		+ '<a target="_blank" href="http://wildcard.sketchworx.net/">Wildcard Software</a> for more info. Thank you for using MUBLA!<br />'
		+ '<hr /><div align="center"><a href="#" onClick="javascript:self.close();">Close Window</a></div></body></html>';
	winHandler.document.open();
	winHandler.document.write(htmlContent);
	winHandler.document.close();
	winHandler.focus();
}

/** hover() */
function hover (imagenum, status) {
	if (captions_preview == 1) {
		if (is_gecko) {
			var caption_target = document.getElementById('CaptionPreview');
		} else {
			var caption_target = document.all.CaptionPreview;
		}

		if (captions[imagenum]) {
			caption_text = captions[imagenum];
		} else {
			caption_target = cap_default;
			return;
		}
		if (status == 0) {
			caption_target.innerHTML = cap_default;
		} else {
			caption_target.innerHTML = caption_text;
		}
	}
}

/** zoom() */
function zoom (img_src, imagenum, img_wide, img_high) {

	var scrollbar = 'no';
	var win_properties = 'toolbar=0,status=0,menubar=0,resizable=0,directories=0,dependent=yes,';
	var html_content = '<html><head><title>(' + img_src + ')</title><style>'
					 + 'a { color: ' + cap_linkcolor + '; text-decoration: underline}'
					 + 'div.content{position:absolute;top:0;left:0}'
					 + 'table{padding:0;border:0;width:100%;height:100%;background-color:' + cap_backcolor +';color:' + cap_forecolor + '}'
					 + 'tr{border:0;padding:0}'
					 + 'td.image{border:0;padding:2px;width:' + img_wide + 'px;height:' + img_high + 'pxl}'
					 + 'td.caption{border:0;padding:2px;overflow:auto;font-family:' + cap_fontfamily + ';font-size:8pt;text-align:' + cap_align + ';';
	var td_image = '<td class="image" onClick="self.close();"><img border="0" src="' + img_src + '" /></td>';
	var pagemenu = '';
	var retval=0;

	var caption = '';
	if (captions[imagenum]) caption = captions[imagenum];

	if (album_seeking == 1) {
		pagemenu = '<br />[ ';
		if (imagenum > 0) {
			pagemenu += '<a href="javascript:if (lookupimage(' + (imagenum - 1) + ')) self.close();">' + prev_text + '</a>';
		} else {
			pagemenu += prev_text;
		}
		if (imagenum < numImages) {
			pagemenu += ' | <a href="javascript:if (lookupimage(' + (imagenum + 1)+ ')) self.close();">' + next_text + '</a>';
		} else {
			pagemenu += ' | ' + next_text;
		}
		pagemenu += ' ]';
		caption += pagemenu;
	}

	var td_caption = '<td class="caption">' + caption + '</td>';

	// determine window properties & html styling
	if (img_wide > scr_wide) { var win_wide = scr_wide; win_high += 16; scrollbar = 'yes'; }
	else { var win_wide = img_wide; }
	if (img_high > scr_high) { var win_high = scr_high; win_wide += 16; scrollbar = 'yes'; }
	else { var win_high = img_high; }
	win_wide += 4;
	win_high += 4;
	if (album_seeking == 1 || caption != '') {
		switch (cap_float) {
			case 0: case 1:
				var cap_dims = 'width:100px;height:' + img_high;
				var cap_midpt = '</td>';
				win_wide += 100;
			break;
			case 2: case 3:
				var cap_dims = 'height:100px;width:' + img_wide;
				var cap_midpt = '</td></tr><tr>';
				win_high += 100;
		}
	} else {
		td_caption = '';
		var cap_midpt = '';
	}

	// generate html
	html_content += cap_dims + '}</style>';

	html_content += '</head><body leftmargin="0" topmargin="0"><div class="content"><table cellpadding="0" cellspacing="0"><tr>';

	switch (cap_float) {
		case 0: case 2:
			html_content += td_caption + cap_midpt + td_image;
			break;
		case 1: case 3:
			html_content += td_image + cap_midpt + td_caption;
	}

	html_content += '</tr></table></div></body></html>';

	// display
	if (win_wide >= scr_wide) { var x = 0; }
	else { var x = (scr_wide - win_wide) / 2; }
	if (win_high >= scr_high) { var y = 0; }
	else { var y = (scr_high - win_high) / 2; }

	// if there's no existing window we can just create a new one in the default position
	if (last_win_handle) {
		if (!last_win_handle.closed) {
			// if a window does exist we'll make the new one appear in the same place
			if ((navigator.appName=="Microsoft Internet Explorer") && (last_win_handle.screenX == undefined) && (last_win_handle.screenY == undefined)) {
				// IE is stupid
				y = last_win_handle.screenTop-22;
				x = last_win_handle.screenLeft-3;
			} else {
				// other browsers are easy
				y = last_win_handle.screenY;
				x = last_win_handle.screenX;
			}
		}
	}

	win_properties += 'scrollbars=' + scrollbar + ',width=' + win_wide + ',height=' + win_high + ',top=' + y + ',left=' + x;

	var win_handle = window.open('', 'zoom_' + win_wide + win_high, win_properties);

	// if the new window we created is not the same as the old one
	if (last_win_handle) {
		if ((last_win_handle != win_handle) && (!last_win_handle.closed)) {
			// tell the old one to close
			retval = 1;
		}
	}

	// if there's a popup blocker, we don't want to throw an error, so we just abort
	if (win_handle != null) {
		win_handle.document.write(html_content);
		win_handle.document.close();
		win_handle.focus();
		win_handle.lookupimage = lookupimage;
		last_win_handle = win_handle;
	}

	return retval;
}
