function sty(obj) {
	var p = ref(obj);
	
	if(p) {
		p = p.style;
	}
		
	return(p);
}

function ref(obj) {
	return($(obj));
}

function elemGetTop(obj) {
	var t = 0;
	t = obj.style.top;
	return(t);
}

function elemGetHeight(obj) {
	return(px(obj.offsetHeight));
}

function elemSetTop(obj, height) {
	obj.style.top = height + 'px';
}

function px(str) {
	var n;
	
	str = "" + str;
	if((n = str.indexOf('px')) != -1) {
		return(parseInt(str.substr(0, n), 10));
	}
	else {
		return(parseInt(str, 10));
	}
}

function TextWidth(str, width) {
	var words = str.split(' ');
	var len = 0;
	var i;

	for(i = 0; i < words.length; i++) {
		var wlength = proportionalLength(words[i]);
		len = len + wlength + 1;
	}
	
	return(len);
}

function Prune(str, width) {
	var words = str.split(' ');
	var ret = "";
	var count = 0;
	var len = 0;
	var i;

	for(i = 0; i < words.length; i++) {
		var wlength = proportionalLength(words[i]);
		if(len + wlength > width) {
			ret = ret + "...";
			return(ret);
		}
		
		if(ret.length > 0) {
			ret = ret + " ";
		}
		
		ret = ret + words[i];
		len = len + wlength + 1;
	}
	
	return(ret); 
}

function proportionalLength(str) {
	var len = 0;
	var i;
	for(i = 0; i < str.length; i++) {
		var c = str.substr(i, 1);
		if(c >= 'A' && c <= 'Z') {
			len += 1.55;
			continue;
		}
		
		if(c >= '0' && c <= '9') {
			len += 1.5;
			continue;
		}
		
		len += 1;
	}
	
	if(len > 9 && len < 14) {
		len *= 1.6;
	}
	
	return(len);
}

function waitimageload(imgid, callback, count) {
	var img = ge(imgid);
	if(typeof(img.complete) != "undefined" && img.complete === false && count > 0) {
		window.setTimeout("waitimageload('" + imgid + "', '" + callback + "', " + (count - 20)+ ")", 20);
		return;
	}

	eval(callback + "()");
}

function tvdisplay(e, n) {
	e = ge(e);
	var tv = e._ThumbViewer;
	tv.displayitem(n);
}

function tvslideright(e) {
	e = ge(e);
	var tv = e._ThumbViewer;
	tv.slideright();
}

function tvthumbover(e, n) {
	e = ge(e);
	var tv = e._ThumbViewer;
	tv.thumbover(tv, n + tv.curleft);
}

function tvthumbout(e, n) {
	e = ge(e);
	var tv = e._ThumbViewer;
	tv.thumbout(tv, n + tv.curleft);
}

function tvslideleft(e) {
	e = ge(e);
	var tv = e._ThumbViewer;
	tv.slideleft();
}

var modalctr = 0;

function modalMessage(title, msg, width) {
	msg = msg + '<div class="button"><a class="button" href="javascript:modalClose()"><span>Close</span></a></div>';
	modalctr += 1;
	var id = "modalmsg" + modalctr;
	modalDialog(title, msg, width, id, null);
}

function modalDialog(title, msg, width, id, closefunc) {
	if(closefunc === null) {
		closefunc = "modalClose()";
	}
	
//	if(ge(id)) {
//		ge(id + "msg").innerHTML = msg;
//		modalElement(id);
//	}
//	else {
		var html = new Array();

		html.push('<table class="lb" id="' + id + '" cellpadding="0" cellspacing="0">');
		html.push('<tr>');
		html.push('<td class="lbtl"></td>');
		html.push('<td class="lbtop" style="width: ' + width + 'px;"><table class="bare" cellspacing="0" cellpadding="0"><tr><td style="width: ' + width + 'px;">' + title + '</td><td style="text-align: right; width: 27px;">');
		if(closefunc != 'NoClOsE') {
			html.push('<a class="titlelink"  href="javascript:' + closefunc + '">X</a>');
		}
		html.push('</td></tr></table></td>');
		html.push('<td class="lbtr"></td>');
		html.push('</tr>');
		html.push('<tr>');
		html.push('<td class="lbl"></td>');
		html.push('<td class="lbmid" id="' + id + 'msg" style="width: ' + width + 'px;">');
		html.push(msg);
	
		html.push('</td>');
		html.push('<td class="lbr"></td>');
		html.push('</tr>');
		html.push('<tr>');
		html.push('<td class="lbbl"></td>');
		html.push('<td class="lbbot"></td>');
		html.push('<td class="lbbr"></td>');
		html.push('</tr>');
		html.push('</table>');
		modalContent(html.join(''));
//	}
}

function modalBackdrop(state) {
	if(! $("#modalbg").length) {
		$("body").append('<div id="modalbg"></div>');
		$("#modalbg").click(function() {
			modalClose();
		});
	}
	
	$("#modalbg").css({ 'display' : 'block', 'height' : $(document).height() + "px" });
}

var saveds = null;

function modalContent(s) {
	if(! $("#modal").length) {
		$("body").append('<div id="modal"></div>');
	}
	
	if($("#modal").css("display") == 'block') {
		saveds = s;
		window.setTimeout("modalContent(saveds)", 50);
		return;
	}
	
	modalReplaceContent(s);
}

function modalReplaceContent(s) {
	$("#modal").html(s);
	$("#modal").css({ 'display' : 'block' });
	modalCenter();
	modalBackdrop();
	hardenButtons();
	$("select").css("display","none");
}

function modalElement(id) {
	var modal = modalDiv();
	if(modal.style.display == 'block' && modal.childNodes[0].id != id) {
		window.setTimeout("modalElement('" + id + "')", 50);
		return;
	}
	
	if(modal.childNodes[0].id != id) {
		modal.innerHTML = "";
		modal.appendChild(ge(id));
	}
	
	modal.style.display = 'block';
	modalCenter();
	modalBackdrop();
	hardenButtons();
}

function modalDiv() {
	var modal = ge("modal");
	if(modal === null) {
		modal = document.createElement("div");
		modal.setAttribute('id', 'modal');
		document.body.appendChild(modal);
	}
	
	return(modal);
}

function modalCenter() {
	var top = centerVertically($("#modal").height(), 10);

	$("#modal").css({ 'top' : top + 'px', 'left' : centerHorizontally($("#modal").width()) + 'px' });
}
	
function modalHide() {
	$("#modal").css({ 'display' : 'none' });
}

function modalClose() {
	$("#modal").css({ 'display' : 'none' });
	$("#modalbg").css({ 'display' : 'none' });
	$("#modal").html('');
	$("select").css("display","inline");
}

function bde(id, display, top, left, height, width, boffx, boffy, repeat) {
	var img;
	var e = ge(id);
	
	if(display == "none") {
		if(e) {
			e.style.display = "none";
		}
		return;
	}
	
	if(e === null) {
		e = document.createElement("div");
		e.setAttribute('id', id);
		e.style.position = "absolute";
		e.style.zIndex = 950400;
		
		if(InternetExploderFive || InternetExploderSix) {
			img = document.createElement("img");
			img.src = "/images/" + id + ".png";
			img.setAttribute('id', id + 'png');
			img.style.width = width + "px";
			img.style.height = height + "px";
			el_fnFixPng(img);
			e.appendChild(img);
		}
		else {
			e.style.backgroundImage = "url('/images/dropshadow.png')";
			e.style.backgroundRepeat = repeat;
			e.style.backgroundPosition = (boffx === 0 ? "" : "-") + boffx + "px " + (boffy === 0 ? "" : "-") + boffy + "px"; 
		}

		document.body.appendChild(e);
	}

	e.style.top = top + "px";
	e.style.left = left + "px";
	e.style.width = width + "px";
	e.style.height = height + "px";
	if(InternetExploderFive || InternetExploderSix) {
		img = ge(id + "png");
		img.style.width = width + "px";
		img.style.height = height + "px";
	}
	
	e.style.display = display;
}

var zswapimg;

function Zdisplay(tv, imgno) {
	var zoomer = tv.Zoomer;

	zoomer.cbtv = tv;
	zoomer.cbimgno = imgno;
	zoomer.imgno = imgno;
	zoomer.renderCaption();
	
	$("#zoomer").attr('src', zoomer.smURI[imgno]);
	$("#zoomer").attr('src', zoomer.zmURI[imgno]);
}

function Zoomer() {
	this.gallery = false;
	this.gallerycb = null;
	this.gallerycbdata = null;
	
	this.zoomgallery = function(args) {
		if(args) {
			for(var key in args) {
				this[key] = args[key];
			}

		}

		this.gallery = true;
		this.displayed = new Array();
		this.displayed[args.imgno] = true;
		this.displayCallback = args.displayCallback ? args.displayCallback : Zdisplay;
		this.smURI = args.normalpics;
		this.zmURI = args.zoompics;
		this.cbimgno = args.imgno;
		
		this.tv = args.tv.clone("zoomertv");
		this.tv.css = args.css;

		var profile = siteprofile[siteid];

		this.tv.shadow = profile.gvShadow;
		if(profile.ident == 'fl') {
			this.tv.arrowPrevOff = '/images/warrowprevoff.png';
			this.tv.arrowPrevOn =  '/images/warrowprevon.png';
			this.tv.arrowNextOff = '/images/warrownextoff.png';
			this.tv.arrowNextOn =  '/images/warrownexton.png';	
		}
		
		this.tv.original = args.tv;
		var div = ge("zoomertv");
		if(div === null) {
			div = document.createElement("div");
			div.setAttribute('id', "zoomertv");
			div.style.position = "absolute";
			div.style.display = "none";
			div.style.zIndex = 950400;
			div.style.background = "#fff";
			div.style.padding = "11px";
			div.style.width = (args.width - 22) + "px";
			div.style.height = (this.htmlheight ? this.htmlheight - 22 : this.tv.thumbHeight) + "px";
			document.body.appendChild(div);
		}
		
		$("#zoomertv").html('');
				
		this.tv.displayCallback = this.displayCallback;
		this.tv.thumbSlots = args.slots;
		this.tv.generate();
		this.tv.slideto(args.imgno);

		this.htmlheight = args.htmlheight ? args.htmlheight : 22 + this.tv.thumbHeight;
		this.overallheight = this.htmlheight + args.height;
		
		this.tv.Zoomer = this;
		this.caption = args.caption;
		this.by = args.by;
		
		var smimg = args.initialloadimg ? args.initialloadimg : this.smURI[args.imgno];
		this.zoom(args.sourceimg, smimg, this.zmURI[args.imgno], args.width, args.height);
	};
	
	this.zoom = function(imgid, src1, src2, width, height) {
		this.imgheight = height;
		this.imgwidth = width;

		var img = ge(imgid.substr(1));
		this.zoomedimg = img;
		this.zoomedimgid = imgid;
		this.dimensions = new Object;
		this.dimensions.width = $(imgid).width();
		this.dimensions.height = $(imgid).height();

		var top = findTopCoord(img);
		var left = findLeftCoord(img);
		var a;
		
		img = ge("zoomercl");
		if(img === null) {
			img = document.createElement("img");
			img.style.display = "none";
			img.Zoomer = this;
			img.setAttribute('src', '/images/close.png');
			img.setAttribute('id', 'zoomercl');

			img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/close.png', sizingMethod='crop');";
			img.style.zIndex = "950600";
			img.style.position = "absolute";
			img.style.width = "52px";
			img.style.height = "52px";
			img.style.border = "none";
			el_fnFixPng(img);
			a = document.createElement("a");
			a.appendChild(img);
			a.setAttribute('href', "javascript:zoomerCloseZoom()");
			a.style.cursor = "url('/images/zcursorout.cur'), pointer";
			document.body.appendChild(a);
		}
		img.Zoomer = this;
		$("zoomercl").attr("Zoomer", this);
	
		img = ge("zoomer");
		if(img === null) {
			img = document.createElement("img");
			img.setAttribute('id', 'zoomer');
			img.setAttribute('class', 'zphoto');
			img.style.display = "none";
			a = document.createElement("a");
			a.appendChild(img);
			a.setAttribute('href', "javascript:zoomerCloseZoom()");
			a.setAttribute('class', 'zphoto');
			a.style.cursor = "url('/images/zoomcursorout.cur'), pointer";
			document.body.appendChild(a);
		}
	
		$("zoomer").attr("Zoomer", this);
		img.Zoomer = this;
		img.setAttribute('src', '/images/invisodot.png');
		img.setAttribute('src', src1);
		img.style.position = "absolute";
		img.style.top = top + "px";
		img.style.left = left + "px";
		img.style.width = this.dimensions.width + 'px';
		img.style.height = this.dimensions.height + 'px';
		img.style.border = "none";
		img.style.display = "block";
		img.style.zIndex = "950500";
		var totop = centerVertically(this.overallheight ? this.overallheight : height, 12);
		if(InternetExploderSix) {
			$("select").css({"display" : "none"});
		}
		
		$("#zoomer").animate({ width: this.imgwidth + "px", height: this.imgheight + "px",
							top: totop + "px", left: centerHorizontally(width) + "px"}, 150, "swing",
							function() {
								this.Zoomer.backdropZoom();
							});
		zswapimg = src2;
		if(Gecko && Macintosh) {
			$(".zphoto").each(function(i) { this.style.cursor = "-moz-zoom-out"; });
		}
	};

	this.backdropZoom = function() {
		modalBackdrop();
	
		$("#modalbg").click(function() {
			zoomerCloseZoom();
		});

		var img = ge("zoomer");
		img.style.width = img.Zoomer.imgwidth + "px";
		img.style.height = img.Zoomer.imgheight + "px";
		img.src = zswapimg;

		var width = $("#zoomer").width();
		var height = $("#zoomer").height();

		var totop = centerVertically(this.overallheight ? this.overallheight : height, 12);

		var toleft = centerHorizontally(width);
		img = ge("zoomercl");
		img.style.top = (totop - 26) + "px";
		img.style.left = (toleft + width - 26) + "px";
		img.style.display = "block";
		
		height += this.htmlheight;
		
		bde("zbdtl", "block", totop - 20, toleft - 20, 40, 40, 0, 0, "no-repeat");
		bde("zbdt", "block", totop - 20, toleft + 20, 20, width - 40, 0, 80, "repeat-x");
		bde("zbdtr", "block", totop - 20, toleft + width - 20, 40, 40, 40, 0, "no-repeat");
		bde("zbdl", "block", totop + 20, toleft - 20, height - 40, 20, 0, 120, "repeat-y");
		bde("zbdr", "block", totop + 20, toleft + width, height - 40, 20, 60, 120, "repeat-y");
		bde("zbdbr", "block", totop + height - 20, toleft - 20, 40, 40, 0, 40, "no-repeat");
		bde("zbdb", "block", totop + height, toleft + 20, 20, width - 40, 40, 100, "repeat-x");
		bde("zbdbl", "block", totop + height - 20, toleft + width - 20, 40, 40, 40, 40, "no-repeat");

		if(this.gallery) {
			var thetop = (totop + height - (this.html ? this.htmlheight : this.tv.thumbHeight + 22));
			$("#zoomertv").css({ 'top' : thetop + "px",
								 'left' : toleft + "px",
								 'display' : "block" });
		}

		if(this.html) {
			$("#zoomertv").append(this.html);
		}

		this.renderCaption();
		modalBackdrop();
	};

	this.renderCaption = function() {
		var captioned = 0;
		if(this.caption) {
			var c = this.caption[this.imgno] ? this.caption[this.imgno] : "";
			c += this.by[this.imgno] ? " Submitted by " + this.by[this.imgno] : "";
			$("#zoomer").attr("title", c);
		}
		else {
			$("#zoomer").attr("title", "");
		}
	};
	
	this.closeZoom = function() {
		this.closeZoomWithoutAnimation(false);
		var img = ge("zoomer");

		var offset = $(this.zoomedimgid).offset();
		var width = $(this.zoomedimgid).width();
		var height = $(this.zoomedimgid).height();

		$("#zoomer").animate({ width: width + "px", height: height + "px",
							   top: offset.top + "px", left: offset.left + "px"}, 150, "swing", this.completeCloseZoom);
		this.gallery = null;
	};

	this.closeZoomWithoutAnimation = function(hidepix) {
		this.hideZoomer(hidepix);
		modalClose();
		this.completeCloseZoom();
		this.gallery = null;
	};

	this.hideZoomer = function(hidepix) {
		if(hidepix) {
			$("#zoomer").css({ 'display' : 'none' });
		}
		$("#zoomercl").css({ 'display' : 'none' });
		$("#zbdtl").css({ 'display' : 'none' });
		$("#zbdt").css({ 'display' : 'none' });
		$("#zbdtr").css({ 'display' : 'none' });
		$("#zbdl").css({ 'display' : 'none' });
		$("#zbdr").css({ 'display' : 'none' });
		$("#zbdbr").css({ 'display' : 'none' });
		$("#zbdb").css({ 'display' : 'none' });
		$("#zbdbl").css({ 'display' : 'none' });
		$("#zoomertv").css({ 'display' : 'none' });
		$("#zoomerhtml").css({ 'display' : 'none' });
		$("#zoomercaption").css({ 'display' : 'none' });
	};


	this.completeCloseZoom = function() {
		var zoomer = ge("zoomercl").Zoomer;
	
		if(typeof(zoomer.gallerycb) == 'function') {
			zoomer.gallerycb(zoomer);
		}

		ge("zoomer").style.display = "none";
		if(InternetExploderSix) {
			$("select").css({"display" : "inline"});
		}
	};
	
	this.setGalleryCallback = function(n) {
		this.gallerycb = n;
	};
}

function zoomerCloseZoom() {
	ge("zoomercl").Zoomer.closeZoom();
}

function el_fnFixPng(img) {
	if(InternetExploderFive || InternetExploderSix) {
		var src = img.src;
		img.style.width = img.width + "px";
		img.style.height = img.height + "px";
		img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
		img.src = '/etc/x.gif';
	}
}

function limitChars(textid, limit, infodiv) {
	var text = $('#' + textid).val(); 
	var textlength = text.length;
	if(textlength > limit) {
		$('#' + infodiv).html('0 characters remaining');
		$('#'+textid).val(text.substr(0,limit));
		return false;
	}
	else {
		$('#' + infodiv).html((limit - textlength) +' characters remaining');
		return true;
	}
}

function ThumbViewer(element) {
	// setup some private variables
	this.thumbURI = null;
	this.thumbDesc = null;
	this.thumbA = null;
	this.thumbIMG = null;
	this.thumbAlt = null;
	this.curleft = 0;
	this.element = element;
	this.styleClass = "";
	this.blankImageURI = '/images/invisodot.png';
	this.emptyViewerImageURI = '/images/unavailable.jpg';
	this.thumbover = null;
	this.thumbout = null;
	this.css = 'tvbar';
	this.divheight = 0;
	this.divcss = '';
	this.thumbcss = 'tvthumb';
	this.thumbBorder = 0;
	this.acss = 'photo';
	this.caption = null;
	this.widthArrow = 22;
	this.heightArrow = 22;
	this.shadow = null;
	this.note = null;
	this.arrowCss = 14;
	this.prevArrowCssHover = 'url(/images/gplogo7.png) no-repeat -890px -300px';
	this.prevArrowCssActive = 'url(/images/gplogo7.png) no-repeat -890px -270px';
	this.prevArrowCssInactive = 'url(/images/gplogo7.png) no-repeat -890px -240px';
	this.nextArrowCssHover = 'url(/images/gplogo7.png) no-repeat -930px -300px';
	this.nextArrowCssActive = 'url(/images/gplogo7.png) no-repeat -930px -270px';
	this.nextArrowCssInactive = 'url(/images/gplogo7.png) no-repeat -930px -240px';
	
	// setup some default parameters
	this.thumbWidth = 50;
	this.thumbHeight = 50;
	this.thumbSlots = 4;
	this.thumbPad = 6;
	this.shadowh = null;
	this.shadown = null;

	this.clone = function(element) {
		var ret = new ThumbViewer(element);
		ret.blankImageURI = this.blankImageURI;
		ret.emptyViewerImageURI = this.emptyViewerImageURI;
		ret.css = this.css;
		ret.divheight = this.divheight;
		ret.divcss = this.divcss;
		ret.thumbcss = this.thumbcss;
		ret.thumboncss = this.thumboncss;
		ret.acss = this.acss;
		ret.arrowCss = this.arrowCss;
		ret.caption = this.caption;
		ret.widthArrow = this.widthArrow;
		ret.shadow = this.shadow;
		ret.thumbWidth = this.thumbWidth;
		ret.thumbHeight = this.thumbHeight;
		ret.thumbSlots = this.thumbSlots;
		ret.thumbPad = this.thumbPad;
		ret.shadowh = this.shadowh;
		ret.shadown = this.shadown;
		ret.thumbURI = this.thumbURI;
		ret.divheight = this.divheight;
		ret.divwidth = this.divwidth;
		ret.prevArrowCssHover = this.prevArrowCssHover;
		ret.prevArrowCssActive = this.prevArrowCssActive;
		ret.nextArrowCssHover = this.nextArrowCssHover;
		ret.nextArrowCssActive = this.nextArrowCssActive;

		return(ret);
	};

	this.setImageURIs = function(n) {
		this.thumbURI = n;
		var i;
		for(i = 0; i < this.thumbURI.length; i++) {
 			var img = ge(this.element + "_img" + i);
			if(img) {
				img.src = this.thumbURI[i];
			}
		}
	};
	
	this.setAlt = function(n) {
		this.thumbAlt = n;
	};

	this.setCaption = function(n) {
		this.caption = n;
	};

	this.generate = function() {
		var a, idiv, div, img, html = '';
		var i;

		wdiv = document.createElement("div");
		wdiv.setAttribute('id', this.element + "_div_wrapper");
//		wdiv.setAttribute('class', this.css);
		
		div = document.createElement("div");
		div.setAttribute('class', this.css);
//		div.style.position = 'absolute';
		wdiv.appendChild(div);
		wdiv = div;
		
		if(this.thumbURI.length > 0) {
			idiv = document.createElement("div");
			idiv.setAttribute('id', this.element + '_div_prev');
			idiv.style.position = 'absolute';
			idiv.style.top = '0px';
			idiv.style.left = '0px';
			idiv.style.height = '50px';
			idiv.style.width = this.widthArrow + 'px';
			
//			if(this.thumbURI.length > this.thumbSlots)
//			{
				a = document.createElement("a");
				a._ThumbViewer = this;
				a.setAttribute('id', this.element + '_a_prev');
				a.setAttribute('class', 'photo');
				a.style.display = 'block';
				a.style.width = this.widthArrow + 'px';
				a.style.height = this.heightArrow + 'px';
				a.style.marginTop = this.arrowCss + 'px';
				a.style.background = this.prevArrowCssInactive;
				idiv.appendChild(a);
//			}
			
			wdiv.appendChild(idiv);
			
			var tvdiv = document.createElement("div");
			var tvwidth = (this.thumbSlots * this.divwidth);
//			alert("tvwidth=" + tvwidth + ",this.thumbSlots=" + this.thumbSlots + ", this.divwidth=" + this.divwidth + ",this.tag=" + this.tag + ",caller=" + arguments.callee.caller.toString());
			tvdiv.style.width = tvwidth + 'px';
			tvdiv.style.height = (this.divheight === 0 ? this.thumbHeight : this.divheight) + 'px';
			tvdiv.style.position = 'absolute';
			tvdiv.style.top = '0px';
			tvdiv.style.left = (this.widthArrow + this.thumbPad + (this.thumbPad / 2)) + 'px';
			wdiv.appendChild(tvdiv);

			div = document.createElement("div");
			div.setAttribute('id', this.element + '_mask');
			div.style.position = "absolute";
			div.style.width = tvwidth + 'px';
			div.style.height = (this.divheight === 0 ? this.thumbHeight : this.divheight) + 'px';
			div.style.overflow = 'hidden';
			tvdiv.appendChild(div);
			tvdiv = div;
			
			div = document.createElement("div");
			div.setAttribute('id', this.element + '_scroller');
			div.style.position = "absolute";
			div.style.width = tvwidth + 'px';
			div.style.height = (this.divheight === 0 ? this.thumbHeight : this.divheight) + 'px';
			tvdiv.appendChild(div);
			tvdiv = div;
			
			for(i = 0; i < this.thumbURI.length; i++) {
				idiv = document.createElement("div");
				idiv.setAttribute('id', this.element + '_div' + i);
				if(this.divcss.length > 0) {
					idiv.setAttribute('class', this.divcss);
				}
				
				idiv.style.position = 'absolute';
				idiv.style.zIndex = "500000";
				idiv.style.top = '0px';
				idiv.style.left = (i * (this.thumbWidth + this.thumbPad + this.thumbBorder + this.thumbBorder))+'px';
		
				img = document.createElement("img");
				img.setAttribute('class', this.thumbcss);
				img.setAttribute('id', this.element + '_img' + i);
				if(this.title) {
					if(this.title[i].length > 0) {
						img.setAttribute('title', this.title[i]);
					}
				}
				
//				if(this.thumbWidth == 50) {
					img.style.width = this.thumbWidth + "px";
					img.style.height = this.thumbHeight + "px";
//				}
					
				if(typeof(this.thumboncss) === 'undefined') {
					img.style.border = 'none';
				}
				
//				if(i < this.thumbURI.length && i < this.thumbSlots)
//				{
//					img.setAttribute('src', this.thumbURI[i]);
//				}
//				else
//				{
					img.setAttribute('src', this.loadingimg ? this.loadingimg : this.blankImageURI);
//				}
				img.setAttribute('alt','');
				if(this.thumbAlt) {
					img.setAttribute('title', this.thumbAlt[i]);
				}
				a = document.createElement("a");
				a.setAttribute('id', this.element + '_a' + i);
				a._ThumbViewer = this;
				if(i < this.thumbURI.length) {
					a.setAttribute('href', "javascript:tvdisplay('" + this.element + '_a' + i + "'," + i + ")");
				}

				if(this.thumbout) {
					a.setAttribute('onmouseout', "tvthumbout('" + this.element + '_a' + i + "'," + i + ")");
				}
				
				if(this.thumbover) {
					a.setAttribute('onmouseover', "tvthumbover('" + this.element + '_a' + i + "'," + i + ")");
				}
				
				a.setAttribute('class', this.acss);
				if(this.acss != 'photo') {
					a.style.cursor = 'url(/images/zoomcursorin.cur), pointer, default';
				}
				a.appendChild(img);
		
				idiv.appendChild(a);
				
				if(this.caption) {
					var p = document.createElement("p");
					p.innerHTML = this.caption[i];
					idiv.appendChild(p);
				}

				tvdiv.appendChild(idiv);
			}

			idiv = document.createElement("div");
			idiv.setAttribute('id', this.element + '_div_next');
			idiv.style.position = 'absolute';
			idiv.style.top = '0px';
			idiv.style.left = (tvwidth + this.widthArrow + (2 * this.thumbPad)) + 'px';
		
			wdiv.appendChild(idiv);
		}
	
		var e = ge(this.element);
		e.appendChild(wdiv);
		$(wdiv).removeClass().addClass(this.css);

//		if(this.thumbURI.length > 0 && this.thumbURI.length > this.thumbSlots)
//		{
			a = document.createElement("a");
			a._ThumbViewer = this;
			a.setAttribute('id', this.element + '_a_next');
			a.setAttribute('class', 'photo');
			a.style.display = 'block';
			a.style.width = this.widthArrow + 'px';
			a.style.height = this.heightArrow + 'px';
			a.style.background = this.prevArrowCssInactive;
			a.style.marginTop = this.arrowCss + 'px';
			idiv.appendChild(a);
//		}

		if(this.thumbURI.length > 0 && this.thumbURI.length > this.thumbSlots) {
			$("#" + this.element + "_a_prev").css({"cursor" : "default", "background" : this.prevArrowCssInactive});
			$("#" + this.element + "_a_next").css({"cursor" : "pointer", "background" : this.nextArrowCssActive})
				.click(function() {
					this._ThumbViewer.slideright();
				})
				.mouseenter(function() {
					this.style.background=this._ThumbViewer.nextArrowCssHover;
				})
				.mouseleave(function() {
					this.style.background=this._ThumbViewer.nextArrowCssActive;
				}
			);
		}
		else {
			$("#" + this.element + "_a_prev").css({"cursor" : "default", "background" : this.prevArrowCssInactive});
			$("#" + this.element + "_a_next").css({"cursor" : "default", "background" : this.nextArrowCssInactive});
		}

		if(InternetExploderFive || InternetExploderSix) {
			$("a").focus(function() { this.blur(); });
		}
	};
	
	this.width = function() {
		var width = this.thumbSlots * this.thumbWidth;
		width += (this.thumbSlots + 2) * this.thumbPad;
		width += this.widthArrow * 2;
		return(width);
	};
	
	this.getImage = function(i) {
		return('#' + this.element + '_img' + i);
	};
	
	this.setDisplayCallback = function(n) {
		this.displayCallback = n;
	};

	this.displayitem = function(n) {
		if(typeof(this.displayCallback) == 'function') {
			this.displayCallback(this, n);
		}
	};

	this.slideto = function(imgno) {
		this.curleft = imgno - (imgno % this.thumbSlots);
		this.slide(false);
	};

	this.animatedslideto = function(imgno) {
		this.curleft = imgno - (imgno % this.thumbSlots);
		this.slide(true);
	};

	this.slideright = function() {
		if(this.curleft + this.thumbSlots >= this.thumbURI.length) {
			return;
		}
		
		this.curleft += this.thumbSlots;
		this.slide(true);
	};

	this.slideleft = function() {
		if(this.curleft === 0) {
			return;
		}
		
		this.curleft -= this.thumbSlots;
		this.slide(true);
	};

	this.loadViewableImages = function() {
		var i;
		
		for(i = this.curleft; i < this.curleft + this.thumbSlots; i++) {
			if(i < this.thumbURI.length) {
				var src = $("#" + this.element + "_img" + i).attr("src");
				if(src == this.blankImageURI || src == this.loadingimg) {
					if(this.loadingimg) {
						loadImg("#" + this.element + "_img" + i, this.thumbURI[i], this.loadingimg);
					}
					else {
						$("#" + this.element + "_img" + i).attr("src", this.thumbURI[i]);
					}
				}
			}
			else {
				$("#" + this.element + "_img" + i).attr("src", this.blankImageURI);
			}
		}
	};

	this.slide = function(animate) {
		var a;
		var i;
		var div;

		this.loadViewableImages();
		var newx = - this.curleft * (this.thumbWidth + this.thumbPad + this.thumbBorder + this.thumbBorder);
		if(animate) {
			$('#' + this.element + '_scroller').animate({ left: newx}, 400, "swing");
		}
		else {
			$('#' + this.element + '_scroller').css({ "left" : newx + "px" });
		}

		if(this.thumbURI.length > this.thumbSlots) {
			if(this.thumbSlots + this.curleft >= this.thumbURI.length) {
				$("#" + this.element + "_a_next")
					.css({"cursor" : "default", "background" : this.nextArrowCssInactive})
					.unbind();
			}
			else {
				$("#" + this.element + "_a_next").css({"cursor" : "pointer", "background" : this.nextArrowCssActive})
					.unbind()
					.click(function() {
						this._ThumbViewer.slideright();
					})
					.mouseenter(function() {
						this.style.background=this._ThumbViewer.nextArrowCssHover;
					})
					.mouseleave(function() {
						this.style.background=this._ThumbViewer.nextArrowCssActive;
					}
				);
			}

			if(this.curleft === 0) {
				$("#" + this.element + "_a_prev")
					.css({"cursor" : "default", "background" : this.prevArrowCssInactive})
					.unbind();
			}
			else {
				$("#" + this.element + "_a_prev").css({"cursor" : "pointer", "background" : this.prevArrowCssActive})
					.unbind()
					.click(function() {
						this._ThumbViewer.slideleft();
					})
					.mouseenter(function() {
						this.style.background=this._ThumbViewer.prevArrowCssHover;
					})
					.mouseleave(function() {
						this.style.background=this._ThumbViewer.prevArrowCssActive;
					}
				);
			}
		}
	};

	this.highlight = function(n) {
		var i;

		if(this.thumboncss) {
			for(i = 0; i < this.thumbURI.length; i++) {
				$("#" + this.element + "_img" + i).removeClass().addClass(i === n ? this.thumboncss : this.thumbcss);
			}
		}
	};

	this.slider = function() {
		var a;
		var i;
		var img;
	
		for(i = 0; i < this.thumbSlots; i++) {
			if(i < this.thumbURI.length) {
				$("#" + this.element + "_img" + i).attr("src", this.thumbURI[i + this.curleft]);
		 	}
			else {
				$("#" + this.element + "_img" + i).attr("src", this.blankImageURI);
			}
		}
	
		if(this.thumbURI.length > this.thumbSlots) {
			img = ge(this.element + '_next');
			if(this.thumbSlots + this.curleft >= this.thumbURI.length) {
				a = ge(this.element + '_a_next');
				a.style.cursor = 'default';
				a.removeAttribute('href');
				img.src = this.arrowNextOff;
			}
			else {
				a = ge(this.element + '_a_next');
				a.style.cursor = 'pointer';
				a.setAttribute('href', "javascript:tvslideright('" + this.element + "_a_next');");
				img.src = this.arrowNextOn;
			}

			img = ge(this.element + '_prev');
			if(this.curleft === 0) {
				a = ge(this.element + '_a_prev');
				a.style.cursor = 'default';
				a.removeAttribute('href');
				img.src = this.arrowPrevOff;
			}
			else {
				a = ge(this.element + '_a_prev');
				a.style.cursor = 'pointer';
				a.setAttribute('href', "javascript:tvslideleft('" + this.element + "_a_prev');");
				img.src = this.arrowPrevOn;
			}
		}
	};
}

function setTabControlWidth(el) {
	var width = 0;
	$("#" + el + "_tc").children().each(function(index) {
		var w = $(this).width();
		width += w;
//		$(this).children().each(function(index)
//		{
//			var w = $(this).width();
//			width += w;
//		});
	});
	$("#" + el + "_tc").css({ "width" : width + "px"});
}

function TabBar(obj) {
	this.element = "tabbar";
	this.tabcss = "tab";

	if(obj) {
		for(var key in obj) {
			this[key] = obj[key];
		}
	}
	
	this.initialize = function() {
		var html = new Array();
		var i;
		html.push('<div id="' + this.element + '_tc" style="display: table; margin-left: auto; margin-right: auto;">');
		for(i = 0; i < this.tabnames.length; i++) {
			html.push('<a id="' + this.element + "tab" + i + '">');
			html.push('<span id="' + this.element + "butt" + i + '">' + this.tabnames[i] + '</span>');
			html.push('</a>');
		}
		html.push('</div>');
		var h = html.join('');
		$("#" + this.element).html(h);

		if(InternetExploder) {
			window.setTimeout('setTabControlWidth("' + this.element + '")', 1);
		}
		
		for(i = 0; i < this.tabnames.length; i++) {
			var id = "#" + this.element + "tab" + i;
			$(id).data("tab", this);
			$(id).data("tabno", i);
			$(id).click(function() {
				$(this).data("tab").callback($(this).data("tabno"), $(this).data("tab").callbackdata);
			});
			id = "#" + this.element + "butt" + i;
			$(id).mouseenter(function() {
				if($(this).data("active") === false) {
					$(this).css({'color' : '#ff17a3', 'cursor' : 'pointer'});
				}
			})
			.mouseleave(function() {
				if($(this).data("active") === false) {
					$(this).css({'color' : '#444'});
				}
			});
		}
		
		this.selectTab(0);
	};
	
	this.selectTab = function(tabno) {
		if(this.selectedTab == tabno) {
			return;
		}
		
		var i;
		for(i = 0; i < this.tabnames.length; i++) {
			var tabcss = (i == tabno) ? this.tabcss + "active" : this.tabcss + "inactive";
			var buttcss = (i == tabno) ? this.tabcss + "activejoint" : this.tabcss + "inactivejoint";
			
			if(i === 0) {
				tabcss = (i == tabno) ? this.tabcss + "activelead" : this.tabcss + "inactivelead";
			}
			
			if(i === tabno - 1) {
				buttcss = this.tabcss + "inactivejoint";
			}
				
			if(i === this.tabnames.length - 1) {
				buttcss = (i == tabno) ? this.tabcss + "activebutt" : this.tabcss + "inactivebutt";
			}
			
			if(i === 0) {
				buttcss = buttcss + " " + this.tabcss + "primary";
			}
			else {
				buttcss = buttcss + " " + this.tabcss + "secondary";
			}
			$("#" + this.element + "tab" + i).removeClass().addClass(tabcss);
			$("#" + this.element + "butt" + i).removeClass().addClass(buttcss);
			$("#" + this.element + "butt" + i).data("active", i == tabno);
			this.selectedTab = tabno;
			$("#" + this.element + "butt" + i).css({'color' : (i == tabno) ? '#fff' : '#444'});
		}
	};
}

function loadImg(idstr, imgurl, loadimgurl) {
//	var s = imgurl.substr(11);
//	imgurl = "http://www" + s;
	var el = $(idstr).get(0);
	$(idstr).attr("src", "");
	$(idstr).attr("src", imgurl);
	window.setTimeout("loadImgChk('" + idstr + "','" + imgurl + "','" + loadimgurl + "')", 1);
}

function loadImgChk(idstr, imgurl, loadimgurl) {
	var el = $(idstr).get(0);
	var complete = el.complete;
	var readyState = el.readyState;
//	console.log("complete = " + complete + ", readyState = " + readyState + ", imgurl=" + imgurl + ", loadimgurl=" + loadimgurl);
	if(complete === true) {
		return;
	}
	
	if(readyState === 4) {
		return;
	}
	
	$(idstr).attr("src", loadimgurl);
	window.setTimeout("loadImgSwap('" + idstr + "','" + imgurl + "','" + loadimgurl + "')", 1);
}

function loadImgSwap(idstr, imgurl, loadimgurl) {
	$(idstr).attr("src", imgurl);
}

