	if(!com) var com = {};
	if(!com.qwidget) com.qwidget = {};

	com.qwidget.version = undefined;
	com.qwidget.guestUserId = 2;
	com.qwidget.colors =
	[
		{rgb: '009805',	key: 'box_green.gif'},
		{rgb: 'FB2000',	key: 'box_red.gif'},
		{rgb: '8338A1',	key: 'box_purple.gif'},
	];
	com.qwidget.answerColorClasses =
	{
		Yes: 	'qw_green',
		No: 	'qw_red',
		Maybe: 	'qw_purple'
	};
	com.qwidget.answerImagePaths =
	{
		Yes: 	'../images/yes.gif',
		No: 	'../images/no.gif',
		Maybe: 	'../images/maybe.gif'
	};

	// com.qwidget.qwid = function (val)
	// {
	// 	
	// }
	var _qwid = function (qwid)
	{
		if (!qwid)
			com.qwidget.error('_qwid - qwid: undefined');
		return '[qwid="'+qwid+'"]';
	}
	
	if (jQuery)
	{
		jQuery.fn.len = function (x, s)
		{
			var log = function (msg) {com.qwidget.error('jQuery.len - ' + msg + (s ? ' ('+s+')' : ''));}
			if (this == undefined)
			{
				log('this undefined');
				return this;
			}
			if (x == undefined && s == undefined)
			{
				if (this.length == 0)
					log('this.length == 0');
				return this;
			}
			if (this.length != x)
				log('this.length != ' + x + ' (length: '+this.length+')');
			return this;
		}
	}
	
	com.qwidget.staticImagePath = function ()
	{
		if (com.qwidget.qwidgetSource == 'qwidget')
			return com.qwidget.webservices + '/chattheplanet/wordpress/qwidget/viewer/images/';
		else
			return com.qwidget.blogUrl + com.qwidget.wordpressPath + '/images/';
	}
	com.qwidget.adjustStaticImageFilepaths = function (node)
	{
		var adjustFilepath = function (filepath)
		{
			var i = filepath.lastIndexOf('/') + 1; // +1 to get past the foreslash...
			var filename = filepath.substr(i);
			adjustedFilepath = com.qwidget.staticImagePath() + filename;
			return adjustedFilepath;
		}
		jQuery('img', node).each(
			function () {this.src = adjustFilepath(this.src);}
		);
	}

	com.qwidget.getHtml = function (filename, callback)
	{
		switch (com.qwidget.qwidgetSource)
		{
		 case 'qwidget':
			com.qwidget.getHtmlViaAjax(filename + '.htm', function (data) {callback(data.html);});
			break;
		 case 'wordpress':
		 	com.qwidget.getHtmlViaGet(filename + '.htm', function (html) {callback(html);});
			break;
		 default:
			com.qwidget.error('com.qwidget.QwidgetManager.getHtml - unknown htmlSource');
			break;
		}
	}
	
	com.qwidget.getHtmlViaAjax = function (name, callback)
	{
		com.qwidget.ajax(com.qwidget.servicesUrl + '/html.jsp', {name: name}, {}, callback);
	}
	
	com.qwidget.getHtmlViaGet = function (name, callback)
	{
		// jQuery.get(com.qwidget.blogUrl + com.qwidget.wordpressPath + 'html/' + name, callback);
		var log = function (msg) {com.qwidget.log('com.qwidget.getHtml - ' + msg);} //{;}
		
		var url = com.qwidget.blogUrl + com.qwidget.wordpressPath + '/html/' + name;
		//var url = 'http://10.0.1.81/chattheplanet/qwidget_xdomain/html/' + name;
		log('url: ' + url);

		try
		{
			jQuery.ajax({
				type: 'GET',
				url: url,
				timeout: 1000,
				success: function (dataIn, status)
				{
					log('success: ' + url);
					if (callback) callback(dataIn);
				},
				error: function (request, status, error)
				{
					log('error - status: ' + status + ', url: ' + url);
				},
				beforeSend: function ()
				{
					log('beforeSend: ' + url);
				},
				complete: function ()
				{
					log('complete: ' + url);
				}
			});
		} 
		catch(e)
		{
			com.qwidget.error('com.qwidget.getHtml - caught error:' + e);
		}
	}
	
	com.qwidget.ajax = function (url, dataOut, dataPass, callback)
	{
		var log = function (msg) {com.qwidget.log('com.qwidget.ajax - ' + msg);}
		
		log('url: ' + url);
		try
		{
			jQuery.ajax({
				type: 'GET',
				url: url,
				data: dataOut,
				dataType: 'jsonp',
				jsonp: 'jsonpCallback',
				timeout: 1000,
				success: function (dataIn, status)
				{
					log('success: ' + url);
					if (callback) callback(dataIn, dataPass);
				},
				error: function (request, status, error)
				{
					log('error - status: ' + status + ', url: ' + url);
				},
				beforeSend: function ()
				{
					log('beforeSend: ' + url);
				},
				complete: function ()
				{
					log('complete: ' + url);
				}
			});
		} 
		catch(e)
		{
			com.qwidget.error('com.qwidget.ajax - caught error:' + e);
		}
	}
	
	com.qwidget.dumpObject = function (object, name, indent)
	{
		// NOTE - no test for recursion loop - use at your own peril
		if (!indent) {indent = '';}
		var log = com.qwidget.log;
		log(indent + '*' + name);
		indent += '..';
		for (var i in object)
		{
			if (typeof object[i] == 'object')
				com.qwidget.dumpObject(object[i], i, indent)
			else
			{
				if (object[i] != null)
					log(indent + i + ': ' + object[i].toString());
				else
					log(indent + i + ': null');
			}
		}
	}

	com.qwidget.GuestAnswers = {
		cookieName: 'guestAnswers',
		questionAnswerList: {},
		questionExists: function (question, answer)
		{
			return (this.questionAnswerList[question] != undefined);
		},
		questionAnswerExists: function (question, answer)
		{
			return (this.questionAnswerList[question] == answer);
		},
		store: function (question, answer)
		{
			this.questionAnswerList[question] = answer;
			this.save();
		},
		remove: function (question)
		{
			delete this.questionAnswerList[question];
			this.save();
		},
		save: function ()
		{
			com.qwidget.Cookie.set(this.cookieName, JSON.stringify(this.questionAnswerList));
		},
		unsave: function ()
		{
		    com.qwidget.Cookie.del(this.cookieName);
		},
		restore: function ()
		{
			var cookie = com.qwidget.Cookie.get(this.cookieName);
		    if (cookie != undefined && cookie.length)
			{
				this.questionAnswerList = JSON.parse(cookie);
			}
		}
	};
	
	com.qwidget.GuestResponseOpinions = {
		cookieName: 'guestResponseOpinions',
		responseOpinionList: {},
		responseOpinion: function (response)
		{
			return this.responseOpinionList[response];
		},
		store: function (response, agree)
		{
			this.responseOpinionList[response] = agree;
			this.save();
		},
		remove: function (response)
		{
			delete this.questionAnswerList[question];
			this.save();
		},
		save: function ()
		{
			com.qwidget.Cookie.set(this.cookieName, JSON.stringify(this.responseOpinionList));
		},
		unsave: function ()
		{
		    com.qwidget.Cookie.del(this.cookieName);
		},
		restore: function ()
		{
			var cookie = com.qwidget.Cookie.get(this.cookieName);
		    if (cookie != undefined && cookie.length)
			{
				this.responseOpinionList = JSON.parse(cookie);
			}
		}
	};

	com.qwidget.Cookie = {
		get: function(name)
		{
			var a = document.cookie ? document.cookie.split('; ') : [];
			var v = null;
			for (var i = 0; i < a.length; i++)
			{
				var m = a[i].split("=");
				if (m[0] == name)
				{
					v = m[1];
					break;
				}
			}
			return v;
		},
		set: function(name, value, expires, path, domain, secure)
		{
			if (expires == undefined)
			{
				expires = new Date();
				expires.setTime(expires.getTime()+(365*24*60*60*1000)); // 1 year in milliseconds
			}
			// should we escape/unescape the value?
			//var cookie = name + "=" + escape(value) + 
			var cookie = name + "=" + value + 
				((expires != undefined) ? "; expires=" + expires.toGMTString() : "") + 
				((path != undefined) ? "; path=" + path : "; path=/") + 
				((domain != undefined) ? "; domain=" + domain : "") + 
				((secure != undefined) ? "; secure" : ""); 
			document.cookie = cookie;
		},
		del: function(name)
		{
			this.set(name,0,new Date(0));
		}
	};

