/*
 * jQuery UI 1.7.1
 *
 * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI
 */
;jQuery.ui || (function($) {

var _remove = $.fn.remove,
	isFF2 = $.browser.mozilla && (parseFloat($.browser.version) < 1.9);

//Helper functions and ui object
$.ui = {
	version: "1.7.1",

	// $.ui.plugin is deprecated.  Use the proxy pattern instead.
	plugin: {
		add: function(module, option, set) {
			var proto = $.ui[module].prototype;
			for(var i in set) {
				proto.plugins[i] = proto.plugins[i] || [];
				proto.plugins[i].push([option, set[i]]);
			}
		},
		call: function(instance, name, args) {
			var set = instance.plugins[name];
			if(!set || !instance.element[0].parentNode) { return; }

			for (var i = 0; i < set.length; i++) {
				if (instance.options[set[i][0]]) {
					set[i][1].apply(instance.element, args);
				}
			}
		}
	},

	contains: function(a, b) {
		return document.compareDocumentPosition
			? a.compareDocumentPosition(b) & 16
			: a !== b && a.contains(b);
	},

	hasScroll: function(el, a) {

		//If overflow is hidden, the element might have extra content, but the user wants to hide it
		if ($(el).css('overflow') == 'hidden') { return false; }

		var scroll = (a && a == 'left') ? 'scrollLeft' : 'scrollTop',
			has = false;

		if (el[scroll] > 0) { return true; }

		// TODO: determine which cases actually cause this to happen
		// if the element doesn't have the scroll set, see if it's possible to
		// set the scroll
		el[scroll] = 1;
		has = (el[scroll] > 0);
		el[scroll] = 0;
		return has;
	},

	isOverAxis: function(x, reference, size) {
		//Determines when x coordinate is over "b" element axis
		return (x > reference) && (x < (reference + size));
	},

	isOver: function(y, x, top, left, height, width) {
		//Determines when x, y coordinates is over "b" element
		return $.ui.isOverAxis(y, top, height) && $.ui.isOverAxis(x, left, width);
	},

	keyCode: {
		BACKSPACE: 8,
		CAPS_LOCK: 20,
		COMMA: 188,
		CONTROL: 17,
		DELETE: 46,
		DOWN: 40,
		END: 35,
		ENTER: 13,
		ESCAPE: 27,
		HOME: 36,
		INSERT: 45,
		LEFT: 37,
		NUMPAD_ADD: 107,
		NUMPAD_DECIMAL: 110,
		NUMPAD_DIVIDE: 111,
		NUMPAD_ENTER: 108,
		NUMPAD_MULTIPLY: 106,
		NUMPAD_SUBTRACT: 109,
		PAGE_DOWN: 34,
		PAGE_UP: 33,
		PERIOD: 190,
		RIGHT: 39,
		SHIFT: 16,
		SPACE: 32,
		TAB: 9,
		UP: 38
	}
};

// WAI-ARIA normalization
if (isFF2) {
	var attr = $.attr,
		removeAttr = $.fn.removeAttr,
		ariaNS = "http://www.w3.org/2005/07/aaa",
		ariaState = /^aria-/,
		ariaRole = /^wairole:/;

	$.attr = function(elem, name, value) {
		var set = value !== undefined;

		return (name == 'role'
			? (set
				? attr.call(this, elem, name, "wairole:" + value)
				: (attr.apply(this, arguments) || "").replace(ariaRole, ""))
			: (ariaState.test(name)
				? (set
					? elem.setAttributeNS(ariaNS,
						name.replace(ariaState, "aaa:"), value)
					: attr.call(this, elem, name.replace(ariaState, "aaa:")))
				: attr.apply(this, arguments)));
	};

	$.fn.removeAttr = function(name) {
		return (ariaState.test(name)
			? this.each(function() {
				this.removeAttributeNS(ariaNS, name.replace(ariaState, ""));
			}) : removeAttr.call(this, name));
	};
}

//jQuery plugins
$.fn.extend({
	remove: function() {
		// Safari has a native remove event which actually removes DOM elements,
		// so we have to use triggerHandler instead of trigger (#3037).
		$("*", this).add(this).each(function() {
			$(this).triggerHandler("remove");
		});
		return _remove.apply(this, arguments );
	},

	enableSelection: function() {
		return this
			.attr('unselectable', 'off')
			.css('MozUserSelect', '')
			.unbind('selectstart.ui');
	},

	disableSelection: function() {
		return this
			.attr('unselectable', 'on')
			.css('MozUserSelect', 'none')
			.bind('selectstart.ui', function() { return false; });
	},

	scrollParent: function() {

		var scrollParent;
		if(($.browser.msie && (/(static|relative)/).test(this.css('position'))) || (/absolute/).test(this.css('position'))) {
			scrollParent = this.parents().filter(function() {
				return (/(relative|absolute|fixed)/).test($.curCSS(this,'position',1)) && (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1));
			}).eq(0);
		} else {
			scrollParent = this.parents().filter(function() {
				return (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1));
			}).eq(0);
		}

		return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(document) : scrollParent;
	}
});


//Additional selectors
$.extend($.expr[':'], {
	data: function(elem, i, match) {
		return !!$.data(elem, match[3]);
	},

	focusable: function(element) {
		var nodeName = element.nodeName.toLowerCase(),
			tabIndex = $.attr(element, 'tabindex');
		return (/input|select|textarea|button|object/.test(nodeName)
			? !element.disabled
			: 'a' == nodeName || 'area' == nodeName
				? element.href || !isNaN(tabIndex)
				: !isNaN(tabIndex))
			// the element and all of its ancestors must be visible
			// the browser may report that the area is hidden
			&& !$(element)['area' == nodeName ? 'parents' : 'closest'](':hidden').length;
	},

	tabbable: function(element) {
		var tabIndex = $.attr(element, 'tabindex');
		return (isNaN(tabIndex) || tabIndex >= 0) && $(element).is(':focusable');
	}
});


// $.widget is a factory to create jQuery plugins
// taking some boilerplate code out of the plugin code
function getter(namespace, plugin, method, args) {
	function getMethods(type) {
		var methods = $[namespace][plugin][type] || [];
		return (typeof methods == 'string' ? methods.split(/,?\s+/) : methods);
	}

	var methods = getMethods('getter');
	if (args.length == 1 && typeof args[0] == 'string') {
		methods = methods.concat(getMethods('getterSetter'));
	}
	return ($.inArray(method, methods) != -1);
}

$.widget = function(name, prototype) {
	var namespace = name.split(".")[0];
	name = name.split(".")[1];

	// create plugin method
	$.fn[name] = function(options) {
		var isMethodCall = (typeof options == 'string'),
			args = Array.prototype.slice.call(arguments, 1);

		// prevent calls to internal methods
		if (isMethodCall && options.substring(0, 1) == '_') {
			return this;
		}

		// handle getter methods
		if (isMethodCall && getter(namespace, name, options, args)) {
			var instance = $.data(this[0], name);
			return (instance ? instance[options].apply(instance, args)
				: undefined);
		}

		// handle initialization and non-getter methods
		return this.each(function() {
			var instance = $.data(this, name);

			// constructor
			(!instance && !isMethodCall &&
				$.data(this, name, new $[namespace][name](this, options))._init());

			// method call
			(instance && isMethodCall && $.isFunction(instance[options]) &&
				instance[options].apply(instance, args));
		});
	};

	// create widget constructor
	$[namespace] = $[namespace] || {};
	$[namespace][name] = function(element, options) {
		var self = this;

		this.namespace = namespace;
		this.widgetName = name;
		this.widgetEventPrefix = $[namespace][name].eventPrefix || name;
		this.widgetBaseClass = namespace + '-' + name;

		this.options = $.extend({},
			$.widget.defaults,
			$[namespace][name].defaults,
			$.metadata && $.metadata.get(element)[name],
			options);

		this.element = $(element)
			.bind('setData.' + name, function(event, key, value) {
				if (event.target == element) {
					return self._setData(key, value);
				}
			})
			.bind('getData.' + name, function(event, key) {
				if (event.target == element) {
					return self._getData(key);
				}
			})
			.bind('remove', function() {
				return self.destroy();
			});
	};

	// add widget prototype
	$[namespace][name].prototype = $.extend({}, $.widget.prototype, prototype);

	// TODO: merge getter and getterSetter properties from widget prototype
	// and plugin prototype
	$[namespace][name].getterSetter = 'option';
};

$.widget.prototype = {
	_init: function() {},
	destroy: function() {
		this.element.removeData(this.widgetName)
			.removeClass(this.widgetBaseClass + '-disabled' + ' ' + this.namespace + '-state-disabled')
			.removeAttr('aria-disabled');
	},

	option: function(key, value) {
		var options = key,
			self = this;

		if (typeof key == "string") {
			if (value === undefined) {
				return this._getData(key);
			}
			options = {};
			options[key] = value;
		}

		$.each(options, function(key, value) {
			self._setData(key, value);
		});
	},
	_getData: function(key) {
		return this.options[key];
	},
	_setData: function(key, value) {
		this.options[key] = value;

		if (key == 'disabled') {
			this.element
				[value ? 'addClass' : 'removeClass'](
					this.widgetBaseClass + '-disabled' + ' ' +
					this.namespace + '-state-disabled')
				.attr("aria-disabled", value);
		}
	},

	enable: function() {
		this._setData('disabled', false);
	},
	disable: function() {
		this._setData('disabled', true);
	},

	_trigger: function(type, event, data) {
		var callback = this.options[type],
			eventName = (type == this.widgetEventPrefix
				? type : this.widgetEventPrefix + type);

		event = $.Event(event);
		event.type = eventName;

		// copy original event properties over to the new event
		// this would happen if we could call $.event.fix instead of $.Event
		// but we don't have a way to force an event to be fixed multiple times
		if (event.originalEvent) {
			for (var i = $.event.props.length, prop; i;) {
				prop = $.event.props[--i];
				event[prop] = event.originalEvent[prop];
			}
		}

		this.element.trigger(event, data);

		return !($.isFunction(callback) && callback.call(this.element[0], event, data) === false
			|| event.isDefaultPrevented());
	}
};

$.widget.defaults = {
	disabled: false
};


/** Mouse Interaction Plugin **/

$.ui.mouse = {
	_mouseInit: function() {
		var self = this;

		this.element
			.bind('mousedown.'+this.widgetName, function(event) {
				return self._mouseDown(event);
			})
			.bind('click.'+this.widgetName, function(event) {
				if(self._preventClickEvent) {
					self._preventClickEvent = false;
					event.stopImmediatePropagation();
					return false;
				}
			});

		// Prevent text selection in IE
		if ($.browser.msie) {
			this._mouseUnselectable = this.element.attr('unselectable');
			this.element.attr('unselectable', 'on');
		}

		this.started = false;
	},

	// TODO: make sure destroying one instance of mouse doesn't mess with
	// other instances of mouse
	_mouseDestroy: function() {
		this.element.unbind('.'+this.widgetName);

		// Restore text selection in IE
		($.browser.msie
			&& this.element.attr('unselectable', this._mouseUnselectable));
	},

	_mouseDown: function(event) {
		// don't let more than one widget handle mouseStart
		// TODO: figure out why we have to use originalEvent
		event.originalEvent = event.originalEvent || {};
		if (event.originalEvent.mouseHandled) { return; }

		// we may have missed mouseup (out of window)
		(this._mouseStarted && this._mouseUp(event));

		this._mouseDownEvent = event;

		var self = this,
			btnIsLeft = (event.which == 1),
			elIsCancel = (typeof this.options.cancel == "string" ? $(event.target).parents().add(event.target).filter(this.options.cancel).length : false);
		if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
			return true;
		}

		this.mouseDelayMet = !this.options.delay;
		if (!this.mouseDelayMet) {
			this._mouseDelayTimer = setTimeout(function() {
				self.mouseDelayMet = true;
			}, this.options.delay);
		}

		if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
			this._mouseStarted = (this._mouseStart(event) !== false);
			if (!this._mouseStarted) {
				event.preventDefault();
				return true;
			}
		}

		// these delegates are required to keep context
		this._mouseMoveDelegate = function(event) {
			return self._mouseMove(event);
		};
		this._mouseUpDelegate = function(event) {
			return self._mouseUp(event);
		};
		$(document)
			.bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
			.bind('mouseup.'+this.widgetName, this._mouseUpDelegate);

		// preventDefault() is used to prevent the selection of text here -
		// however, in Safari, this causes select boxes not to be selectable
		// anymore, so this fix is needed
		($.browser.safari || event.preventDefault());

		event.originalEvent.mouseHandled = true;
		return true;
	},

	_mouseMove: function(event) {
		// IE mouseup check - mouseup happened when mouse was out of window
		if ($.browser.msie && !event.button) {
			return this._mouseUp(event);
		}

		if (this._mouseStarted) {
			this._mouseDrag(event);
			return event.preventDefault();
		}

		if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
			this._mouseStarted =
				(this._mouseStart(this._mouseDownEvent, event) !== false);
			(this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
		}

		return !this._mouseStarted;
	},

	_mouseUp: function(event) {
		$(document)
			.unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
			.unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);

		if (this._mouseStarted) {
			this._mouseStarted = false;
			this._preventClickEvent = (event.target == this._mouseDownEvent.target);
			this._mouseStop(event);
		}

		return false;
	},

	_mouseDistanceMet: function(event) {
		return (Math.max(
				Math.abs(this._mouseDownEvent.pageX - event.pageX),
				Math.abs(this._mouseDownEvent.pageY - event.pageY)
			) >= this.options.distance
		);
	},

	_mouseDelayMet: function(event) {
		return this.mouseDelayMet;
	},

	// These are placeholder methods, to be overriden by extending plugin
	_mouseStart: function(event) {},
	_mouseDrag: function(event) {},
	_mouseStop: function(event) {},
	_mouseCapture: function(event) { return true; }
};

$.ui.mouse.defaults = {
	cancel: null,
	distance: 1,
	delay: 0
};

})(jQuery);
/*
 * jQuery UI Tabs 1.7.1
 *
 * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI/Tabs
 *
 * Depends:
 *	ui.core.js
 */
(function($) {

$.widget("ui.tabs", {

	_init: function() {
		if (this.options.deselectable !== undefined) {
			this.options.collapsible = this.options.deselectable;
		}
		this._tabify(true);
	},

	_setData: function(key, value) {
		if (key == 'selected') {
			if (this.options.collapsible && value == this.options.selected) {
				return;
			}
			this.select(value);
		}
		else {
			this.options[key] = value;
			if (key == 'deselectable') {
				this.options.collapsible = value;
			}
			this._tabify();
		}
	},

	_tabId: function(a) {
		return a.title && a.title.replace(/\s/g, '_').replace(/[^A-Za-z0-9\-_:\.]/g, '') ||
			this.options.idPrefix + $.data(a);
	},

	_sanitizeSelector: function(hash) {
		return hash.replace(/:/g, '\\:'); // we need this because an id may contain a ":"
	},

	_cookie: function() {
		var cookie = this.cookie || (this.cookie = this.options.cookie.name || 'ui-tabs-' + $.data(this.list[0]));
		return $.cookie.apply(null, [cookie].concat($.makeArray(arguments)));
	},

	_ui: function(tab, panel) {
		return {
			tab: tab,
			panel: panel,
			index: this.anchors.index(tab)
		};
	},

	_cleanup: function() {
		// restore all former loading tabs labels
		this.lis.filter('.ui-state-processing').removeClass('ui-state-processing')
				.find('span:data(label.tabs)')
				.each(function() {
					var el = $(this);
					el.html(el.data('label.tabs')).removeData('label.tabs');
				});
	},

	_tabify: function(init) {

		this.list = this.element.children('ul:first');
		this.lis = $('li:has(a[href])', this.list);
		this.anchors = this.lis.map(function() { return $('a', this)[0]; });
		this.panels = $([]);

		var self = this, o = this.options;

		var fragmentId = /^#.+/; // Safari 2 reports '#' for an empty hash
		this.anchors.each(function(i, a) {
			var href = $(a).attr('href');

			// For dynamically created HTML that contains a hash as href IE < 8 expands
			// such href to the full page url with hash and then misinterprets tab as ajax.
			// Same consideration applies for an added tab with a fragment identifier
			// since a[href=#fragment-identifier] does unexpectedly not match.
			// Thus normalize href attribute...
			var hrefBase = href.split('#')[0], baseEl;
			if (hrefBase && (hrefBase === location.toString().split('#')[0] ||
					(baseEl = $('base')[0]) && hrefBase === baseEl.href)) {
				href = a.hash;
				a.href = href;
			}

			// inline tab
			if (fragmentId.test(href)) {
				self.panels = self.panels.add(self._sanitizeSelector(href));
			}

			// remote tab
			else if (href != '#') { // prevent loading the page itself if href is just "#"
				$.data(a, 'href.tabs', href); // required for restore on destroy

				// TODO until #3808 is fixed strip fragment identifier from url
				// (IE fails to load from such url)
				$.data(a, 'load.tabs', href.replace(/#.*$/, '')); // mutable data

				var id = self._tabId(a);
				a.href = '#' + id;
				var $panel = $('#' + id);
				if (!$panel.length) {
					$panel = $(o.panelTemplate).attr('id', id).addClass('ui-tabs-panel ui-widget-content ui-corner-bottom')
						.insertAfter(self.panels[i - 1] || self.list);
					$panel.data('destroy.tabs', true);
				}
				self.panels = self.panels.add($panel);
			}

			// invalid tab href
			else {
				o.disabled.push(i);
			}
		});

		// initialization from scratch
		if (init) {

			// attach necessary classes for styling
			this.element.addClass('ui-tabs ui-widget ui-widget-content ui-corner-all');
			this.list.addClass('ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all');
			this.lis.addClass('ui-state-default ui-corner-top');
			this.panels.addClass('ui-tabs-panel ui-widget-content ui-corner-bottom');

			// Selected tab
			// use "selected" option or try to retrieve:
			// 1. from fragment identifier in url
			// 2. from cookie
			// 3. from selected class attribute on <li>
			if (o.selected === undefined) {
				if (location.hash) {
					this.anchors.each(function(i, a) {
						if (a.hash == location.hash) {
							o.selected = i;
							return false; // break
						}
					});
				}
				if (typeof o.selected != 'number' && o.cookie) {
					o.selected = parseInt(self._cookie(), 10);
				}
				if (typeof o.selected != 'number' && this.lis.filter('.ui-tabs-selected').length) {
					o.selected = this.lis.index(this.lis.filter('.ui-tabs-selected'));
				}
				o.selected = o.selected || 0;
			}
			else if (o.selected === null) { // usage of null is deprecated, TODO remove in next release
				o.selected = -1;
			}

			// sanity check - default to first tab...
			o.selected = ((o.selected >= 0 && this.anchors[o.selected]) || o.selected < 0) ? o.selected : 0;

			// Take disabling tabs via class attribute from HTML
			// into account and update option properly.
			// A selected tab cannot become disabled.
			o.disabled = $.unique(o.disabled.concat(
				$.map(this.lis.filter('.ui-state-disabled'),
					function(n, i) { return self.lis.index(n); } )
			)).sort();

			if ($.inArray(o.selected, o.disabled) != -1) {
				o.disabled.splice($.inArray(o.selected, o.disabled), 1);
			}

			// highlight selected tab
			this.panels.addClass('ui-tabs-hide');
			this.lis.removeClass('ui-tabs-selected ui-state-active');
			if (o.selected >= 0 && this.anchors.length) { // check for length avoids error when initializing empty list
				this.panels.eq(o.selected).removeClass('ui-tabs-hide');
				this.lis.eq(o.selected).addClass('ui-tabs-selected ui-state-active');

				// seems to be expected behavior that the show callback is fired
				self.element.queue("tabs", function() {
					self._trigger('show', null, self._ui(self.anchors[o.selected], self.panels[o.selected]));
				});
				
				this.load(o.selected);
			}

			// clean up to avoid memory leaks in certain versions of IE 6
			$(window).bind('unload', function() {
				self.lis.add(self.anchors).unbind('.tabs');
				self.lis = self.anchors = self.panels = null;
			});

		}
		// update selected after add/remove
		else {
			o.selected = this.lis.index(this.lis.filter('.ui-tabs-selected'));
		}

		// update collapsible
		this.element[o.collapsible ? 'addClass' : 'removeClass']('ui-tabs-collapsible');

		// set or update cookie after init and add/remove respectively
		if (o.cookie) {
			this._cookie(o.selected, o.cookie);
		}

		// disable tabs
		for (var i = 0, li; (li = this.lis[i]); i++) {
			$(li)[$.inArray(i, o.disabled) != -1 &&
				!$(li).hasClass('ui-tabs-selected') ? 'addClass' : 'removeClass']('ui-state-disabled');
		}

		// reset cache if switching from cached to not cached
		if (o.cache === false) {
			this.anchors.removeData('cache.tabs');
		}

		// remove all handlers before, tabify may run on existing tabs after add or option change
		this.lis.add(this.anchors).unbind('.tabs');

		if (o.event != 'mouseover') {
			var addState = function(state, el) {
				if (el.is(':not(.ui-state-disabled)')) {
					el.addClass('ui-state-' + state);
				}
			};
			var removeState = function(state, el) {
				el.removeClass('ui-state-' + state);
			};
			this.lis.bind('mouseover.tabs', function() {
				addState('hover', $(this));
			});
			this.lis.bind('mouseout.tabs', function() {
				removeState('hover', $(this));
			});
			this.anchors.bind('focus.tabs', function() {
				addState('focus', $(this).closest('li'));
			});
			this.anchors.bind('blur.tabs', function() {
				removeState('focus', $(this).closest('li'));
			});
		}

		// set up animations
		var hideFx, showFx;
		if (o.fx) {
			if ($.isArray(o.fx)) {
				hideFx = o.fx[0];
				showFx = o.fx[1];
			}
			else {
				hideFx = showFx = o.fx;
			}
		}

		// Reset certain styles left over from animation
		// and prevent IE's ClearType bug...
		function resetStyle($el, fx) {
			$el.css({ display: '' });
			if ($.browser.msie && fx.opacity) {
				$el[0].style.removeAttribute('filter');
			}
		}

		// Show a tab...
		var showTab = showFx ?
			function(clicked, $show) {
				$(clicked).closest('li').removeClass('ui-state-default').addClass('ui-tabs-selected ui-state-active');
				$show.hide().removeClass('ui-tabs-hide') // avoid flicker that way
					.animate(showFx, showFx.duration || 'normal', function() {
						resetStyle($show, showFx);
						self._trigger('show', null, self._ui(clicked, $show[0]));
					});
			} :
			function(clicked, $show) {
				$(clicked).closest('li').removeClass('ui-state-default').addClass('ui-tabs-selected ui-state-active');
				$show.removeClass('ui-tabs-hide');
				self._trigger('show', null, self._ui(clicked, $show[0]));
			};

		// Hide a tab, $show is optional...
		var hideTab = hideFx ?
			function(clicked, $hide) {
				$hide.animate(hideFx, hideFx.duration || 'normal', function() {
					self.lis.removeClass('ui-tabs-selected ui-state-active').addClass('ui-state-default');
					$hide.addClass('ui-tabs-hide');
					resetStyle($hide, hideFx);
					self.element.dequeue("tabs");
				});
			} :
			function(clicked, $hide, $show) {
				self.lis.removeClass('ui-tabs-selected ui-state-active').addClass('ui-state-default');
				$hide.addClass('ui-tabs-hide');
				self.element.dequeue("tabs");
			};

		// attach tab event handler, unbind to avoid duplicates from former tabifying...
		this.anchors.bind(o.event + '.tabs', function() {
			var el = this, $li = $(this).closest('li'), $hide = self.panels.filter(':not(.ui-tabs-hide)'),
					$show = $(self._sanitizeSelector(this.hash));

			// If tab is already selected and not collapsible or tab disabled or
			// or is already loading or click callback returns false stop here.
			// Check if click handler returns false last so that it is not executed
			// for a disabled or loading tab!
			if (($li.hasClass('ui-tabs-selected') && !o.collapsible) ||
				$li.hasClass('ui-state-disabled') ||
				$li.hasClass('ui-state-processing') ||
				self._trigger('select', null, self._ui(this, $show[0])) === false) {
				this.blur();
				return false;
			}

			o.selected = self.anchors.index(this);

			self.abort();

			// if tab may be closed
			if (o.collapsible) {
				if ($li.hasClass('ui-tabs-selected')) {
					o.selected = -1;

					if (o.cookie) {
						self._cookie(o.selected, o.cookie);
					}

					self.element.queue("tabs", function() {
						hideTab(el, $hide);
					}).dequeue("tabs");
					
					this.blur();
					return false;
				}
				else if (!$hide.length) {
					if (o.cookie) {
						self._cookie(o.selected, o.cookie);
					}
					
					self.element.queue("tabs", function() {
						showTab(el, $show);
					});

					self.load(self.anchors.index(this)); // TODO make passing in node possible, see also http://dev.jqueryui.com/ticket/3171
					
					this.blur();
					return false;
				}
			}

			if (o.cookie) {
				self._cookie(o.selected, o.cookie);
			}

			// show new tab
			if ($show.length) {
				if ($hide.length) {
					self.element.queue("tabs", function() {
						hideTab(el, $hide);
					});
				}
				self.element.queue("tabs", function() {
					showTab(el, $show);
				});
				
				self.load(self.anchors.index(this));
			}
			else {
				throw 'jQuery UI Tabs: Mismatching fragment identifier.';
			}

			// Prevent IE from keeping other link focussed when using the back button
			// and remove dotted border from clicked link. This is controlled via CSS
			// in modern browsers; blur() removes focus from address bar in Firefox
			// which can become a usability and annoying problem with tabs('rotate').
			if ($.browser.msie) {
				this.blur();
			}

		});

		// disable click in any case
		this.anchors.bind('click.tabs', function(){return false;});

	},

	destroy: function() {
		var o = this.options;

		this.abort();
		
		this.element.unbind('.tabs')
			.removeClass('ui-tabs ui-widget ui-widget-content ui-corner-all ui-tabs-collapsible')
			.removeData('tabs');

		this.list.removeClass('ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all');

		this.anchors.each(function() {
			var href = $.data(this, 'href.tabs');
			if (href) {
				this.href = href;
			}
			var $this = $(this).unbind('.tabs');
			$.each(['href', 'load', 'cache'], function(i, prefix) {
				$this.removeData(prefix + '.tabs');
			});
		});

		this.lis.unbind('.tabs').add(this.panels).each(function() {
			if ($.data(this, 'destroy.tabs')) {
				$(this).remove();
			}
			else {
				$(this).removeClass([
					'ui-state-default',
					'ui-corner-top',
					'ui-tabs-selected',
					'ui-state-active',
					'ui-state-hover',
					'ui-state-focus',
					'ui-state-disabled',
					'ui-tabs-panel',
					'ui-widget-content',
					'ui-corner-bottom',
					'ui-tabs-hide'
				].join(' '));
			}
		});

		if (o.cookie) {
			this._cookie(null, o.cookie);
		}
	},

	add: function(url, label, index) {
		if (index === undefined) {
			index = this.anchors.length; // append by default
		}

		var self = this, o = this.options,
			$li = $(o.tabTemplate.replace(/#\{href\}/g, url).replace(/#\{label\}/g, label)),
			id = !url.indexOf('#') ? url.replace('#', '') : this._tabId($('a', $li)[0]);

		$li.addClass('ui-state-default ui-corner-top').data('destroy.tabs', true);

		// try to find an existing element before creating a new one
		var $panel = $('#' + id);
		if (!$panel.length) {
			$panel = $(o.panelTemplate).attr('id', id).data('destroy.tabs', true);
		}
		$panel.addClass('ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide');

		if (index >= this.lis.length) {
			$li.appendTo(this.list);
			$panel.appendTo(this.list[0].parentNode);
		}
		else {
			$li.insertBefore(this.lis[index]);
			$panel.insertBefore(this.panels[index]);
		}

		o.disabled = $.map(o.disabled,
			function(n, i) { return n >= index ? ++n : n; });

		this._tabify();

		if (this.anchors.length == 1) { // after tabify
			$li.addClass('ui-tabs-selected ui-state-active');
			$panel.removeClass('ui-tabs-hide');
			this.element.queue("tabs", function() {
				self._trigger('show', null, self._ui(self.anchors[0], self.panels[0]));
			});
				
			this.load(0);
		}

		// callback
		this._trigger('add', null, this._ui(this.anchors[index], this.panels[index]));
	},

	remove: function(index) {
		var o = this.options, $li = this.lis.eq(index).remove(),
			$panel = this.panels.eq(index).remove();

		// If selected tab was removed focus tab to the right or
		// in case the last tab was removed the tab to the left.
		if ($li.hasClass('ui-tabs-selected') && this.anchors.length > 1) {
			this.select(index + (index + 1 < this.anchors.length ? 1 : -1));
		}

		o.disabled = $.map($.grep(o.disabled, function(n, i) { return n != index; }),
			function(n, i) { return n >= index ? --n : n; });

		this._tabify();

		// callback
		this._trigger('remove', null, this._ui($li.find('a')[0], $panel[0]));
	},

	enable: function(index) {
		var o = this.options;
		if ($.inArray(index, o.disabled) == -1) {
			return;
		}

		this.lis.eq(index).removeClass('ui-state-disabled');
		o.disabled = $.grep(o.disabled, function(n, i) { return n != index; });

		// callback
		this._trigger('enable', null, this._ui(this.anchors[index], this.panels[index]));
	},

	disable: function(index) {
		var self = this, o = this.options;
		if (index != o.selected) { // cannot disable already selected tab
			this.lis.eq(index).addClass('ui-state-disabled');

			o.disabled.push(index);
			o.disabled.sort();

			// callback
			this._trigger('disable', null, this._ui(this.anchors[index], this.panels[index]));
		}
	},

	select: function(index) {
		if (typeof index == 'string') {
			index = this.anchors.index(this.anchors.filter('[href$=' + index + ']'));
		}
		else if (index === null) { // usage of null is deprecated, TODO remove in next release
			index = -1;
		}
		if (index == -1 && this.options.collapsible) {
			index = this.options.selected;
		}

		this.anchors.eq(index).trigger(this.options.event + '.tabs');
	},

	load: function(index) {
		var self = this, o = this.options, a = this.anchors.eq(index)[0], url = $.data(a, 'load.tabs');

		this.abort();

		// not remote or from cache
		if (!url || this.element.queue("tabs").length !== 0 && $.data(a, 'cache.tabs')) {
			this.element.dequeue("tabs");
			return;
		}

		// load remote from here on
		this.lis.eq(index).addClass('ui-state-processing');

		if (o.spinner) {
			var span = $('span', a);
			span.data('label.tabs', span.html()).html(o.spinner);
		}

		this.xhr = $.ajax($.extend({}, o.ajaxOptions, {
			url: url,
			success: function(r, s) {
				$(self._sanitizeSelector(a.hash)).html(r);

				// take care of tab labels
				self._cleanup();

				if (o.cache) {
					$.data(a, 'cache.tabs', true); // if loaded once do not load them again
				}

				// callbacks
				self._trigger('load', null, self._ui(self.anchors[index], self.panels[index]));
				try {
					o.ajaxOptions.success(r, s);
				}
				catch (e) {}

				// last, so that load event is fired before show...
				self.element.dequeue("tabs");
			}
		}));
	},

	abort: function() {
		// stop possibly running animations
		this.element.queue([]);
		this.panels.stop(false, true);

		// terminate pending requests from other tabs
		if (this.xhr) {
			this.xhr.abort();
			delete this.xhr;
		}

		// take care of tab labels
		this._cleanup();

	},

	url: function(index, url) {
		this.anchors.eq(index).removeData('cache.tabs').data('load.tabs', url);
	},

	length: function() {
		return this.anchors.length;
	}

});

$.extend($.ui.tabs, {
	version: '1.7.1',
	getter: 'length',
	defaults: {
		ajaxOptions: null,
		cache: false,
		cookie: null, // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true }
		collapsible: false,
		disabled: [],
		event: 'click',
		fx: null, // e.g. { height: 'toggle', opacity: 'toggle', duration: 200 }
		idPrefix: 'ui-tabs-',
		panelTemplate: '<div></div>',
		spinner: '<em>Loading&#8230;</em>',
		tabTemplate: '<li><a href="#{href}"><span>#{label}</span></a></li>'
	}
});

/*
 * Tabs Extensions
 */

/*
 * Rotate
 */
$.extend($.ui.tabs.prototype, {
	rotation: null,
	rotate: function(ms, continuing) {

		var self = this, o = this.options;
		
		var rotate = self._rotate || (self._rotate = function(e) {
			clearTimeout(self.rotation);
			self.rotation = setTimeout(function() {
				var t = o.selected;
				self.select( ++t < self.anchors.length ? t : 0 );
			}, ms);
			
			if (e) {
				e.stopPropagation();
			}
		});
		
		var stop = self._unrotate || (self._unrotate = !continuing ?
			function(e) {
				if (e.clientX) { // in case of a true click
					self.rotate(null);
				}
			} :
			function(e) {
				t = o.selected;
				rotate();
			});

		// start rotation
		if (ms) {
			this.element.bind('tabsshow', rotate);
			this.anchors.bind(o.event + '.tabs', stop);
			rotate();
		}
		// stop rotation
		else {
			clearTimeout(self.rotation);
			this.element.unbind('tabsshow', rotate);
			this.anchors.unbind(o.event + '.tabs', stop);
			delete this._rotate;
			delete this._unrotate;
		}
	}
});

})(jQuery);
/*
 * jQuery UI Effects 1.7.1
 *
 * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI/Effects/
 */
;jQuery.effects || (function($) {

$.effects = {
	version: "1.7.1",

	// Saves a set of properties in a data storage
	save: function(element, set) {
		for(var i=0; i < set.length; i++) {
			if(set[i] !== null) element.data("ec.storage."+set[i], element[0].style[set[i]]);
		}
	},

	// Restores a set of previously saved properties from a data storage
	restore: function(element, set) {
		for(var i=0; i < set.length; i++) {
			if(set[i] !== null) element.css(set[i], element.data("ec.storage."+set[i]));
		}
	},

	setMode: function(el, mode) {
		if (mode == 'toggle') mode = el.is(':hidden') ? 'show' : 'hide'; // Set for toggle
		return mode;
	},

	getBaseline: function(origin, original) { // Translates a [top,left] array into a baseline value
		// this should be a little more flexible in the future to handle a string & hash
		var y, x;
		switch (origin[0]) {
			case 'top': y = 0; break;
			case 'middle': y = 0.5; break;
			case 'bottom': y = 1; break;
			default: y = origin[0] / original.height;
		};
		switch (origin[1]) {
			case 'left': x = 0; break;
			case 'center': x = 0.5; break;
			case 'right': x = 1; break;
			default: x = origin[1] / original.width;
		};
		return {x: x, y: y};
	},

	// Wraps the element around a wrapper that copies position properties
	createWrapper: function(element) {

		//if the element is already wrapped, return it
		if (element.parent().is('.ui-effects-wrapper'))
			return element.parent();

		//Cache width,height and float properties of the element, and create a wrapper around it
		var props = { width: element.outerWidth(true), height: element.outerHeight(true), 'float': element.css('float') };
		element.wrap('<div class="ui-effects-wrapper" style="font-size:100%;background:transparent;border:none;margin:0;padding:0"></div>');
		var wrapper = element.parent();

		//Transfer the positioning of the element to the wrapper
		if (element.css('position') == 'static') {
			wrapper.css({ position: 'relative' });
			element.css({ position: 'relative'} );
		} else {
			var top = element.css('top'); if(isNaN(parseInt(top,10))) top = 'auto';
			var left = element.css('left'); if(isNaN(parseInt(left,10))) left = 'auto';
			wrapper.css({ position: element.css('position'), top: top, left: left, zIndex: element.css('z-index') }).show();
			element.css({position: 'relative', top: 0, left: 0 });
		}

		wrapper.css(props);
		return wrapper;
	},

	removeWrapper: function(element) {
		if (element.parent().is('.ui-effects-wrapper'))
			return element.parent().replaceWith(element);
		return element;
	},

	setTransition: function(element, list, factor, value) {
		value = value || {};
		$.each(list, function(i, x){
			unit = element.cssUnit(x);
			if (unit[0] > 0) value[x] = unit[0] * factor + unit[1];
		});
		return value;
	},

	//Base function to animate from one class to another in a seamless transition
	animateClass: function(value, duration, easing, callback) {

		var cb = (typeof easing == "function" ? easing : (callback ? callback : null));
		var ea = (typeof easing == "string" ? easing : null);

		return this.each(function() {

			var offset = {}; var that = $(this); var oldStyleAttr = that.attr("style") || '';
			if(typeof oldStyleAttr == 'object') oldStyleAttr = oldStyleAttr["cssText"]; /* Stupidly in IE, style is a object.. */
			if(value.toggle) { that.hasClass(value.toggle) ? value.remove = value.toggle : value.add = value.toggle; }

			//Let's get a style offset
			var oldStyle = $.extend({}, (document.defaultView ? document.defaultView.getComputedStyle(this,null) : this.currentStyle));
			if(value.add) that.addClass(value.add); if(value.remove) that.removeClass(value.remove);
			var newStyle = $.extend({}, (document.defaultView ? document.defaultView.getComputedStyle(this,null) : this.currentStyle));
			if(value.add) that.removeClass(value.add); if(value.remove) that.addClass(value.remove);

			// The main function to form the object for animation
			for(var n in newStyle) {
				if( typeof newStyle[n] != "function" && newStyle[n] /* No functions and null properties */
				&& n.indexOf("Moz") == -1 && n.indexOf("length") == -1 /* No mozilla spezific render properties. */
				&& newStyle[n] != oldStyle[n] /* Only values that have changed are used for the animation */
				&& (n.match(/color/i) || (!n.match(/color/i) && !isNaN(parseInt(newStyle[n],10)))) /* Only things that can be parsed to integers or colors */
				&& (oldStyle.position != "static" || (oldStyle.position == "static" && !n.match(/left|top|bottom|right/))) /* No need for positions when dealing with static positions */
				) offset[n] = newStyle[n];
			}

			that.animate(offset, duration, ea, function() { // Animate the newly constructed offset object
				// Change style attribute back to original. For stupid IE, we need to clear the damn object.
				if(typeof $(this).attr("style") == 'object') { $(this).attr("style")["cssText"] = ""; $(this).attr("style")["cssText"] = oldStyleAttr; } else $(this).attr("style", oldStyleAttr);
				if(value.add) $(this).addClass(value.add); if(value.remove) $(this).removeClass(value.remove);
				if(cb) cb.apply(this, arguments);
			});

		});
	}
};


function _normalizeArguments(a, m) {

	var o = a[1] && a[1].constructor == Object ? a[1] : {}; if(m) o.mode = m;
	var speed = a[1] && a[1].constructor != Object ? a[1] : (o.duration ? o.duration : a[2]); //either comes from options.duration or the secon/third argument
		speed = $.fx.off ? 0 : typeof speed === "number" ? speed : $.fx.speeds[speed] || $.fx.speeds._default;
	var callback = o.callback || ( $.isFunction(a[1]) && a[1] ) || ( $.isFunction(a[2]) && a[2] ) || ( $.isFunction(a[3]) && a[3] );

	return [a[0], o, speed, callback];
	
}

//Extend the methods of jQuery
$.fn.extend({

	//Save old methods
	_show: $.fn.show,
	_hide: $.fn.hide,
	__toggle: $.fn.toggle,
	_addClass: $.fn.addClass,
	_removeClass: $.fn.removeClass,
	_toggleClass: $.fn.toggleClass,

	// New effect methods
	effect: function(fx, options, speed, callback) {
		return $.effects[fx] ? $.effects[fx].call(this, {method: fx, options: options || {}, duration: speed, callback: callback }) : null;
	},

	show: function() {
		if(!arguments[0] || (arguments[0].constructor == Number || (/(slow|normal|fast)/).test(arguments[0])))
			return this._show.apply(this, arguments);
		else {
			return this.effect.apply(this, _normalizeArguments(arguments, 'show'));
		}
	},

	hide: function() {
		if(!arguments[0] || (arguments[0].constructor == Number || (/(slow|normal|fast)/).test(arguments[0])))
			return this._hide.apply(this, arguments);
		else {
			return this.effect.apply(this, _normalizeArguments(arguments, 'hide'));
		}
	},

	toggle: function(){
		if(!arguments[0] || (arguments[0].constructor == Number || (/(slow|normal|fast)/).test(arguments[0])) || (arguments[0].constructor == Function))
			return this.__toggle.apply(this, arguments);
		else {
			return this.effect.apply(this, _normalizeArguments(arguments, 'toggle'));
		}
	},

	addClass: function(classNames, speed, easing, callback) {
		return speed ? $.effects.animateClass.apply(this, [{ add: classNames },speed,easing,callback]) : this._addClass(classNames);
	},
	removeClass: function(classNames,speed,easing,callback) {
		return speed ? $.effects.animateClass.apply(this, [{ remove: classNames },speed,easing,callback]) : this._removeClass(classNames);
	},
	toggleClass: function(classNames,speed,easing,callback) {
		return ( (typeof speed !== "boolean") && speed ) ? $.effects.animateClass.apply(this, [{ toggle: classNames },speed,easing,callback]) : this._toggleClass(classNames, speed);
	},
	morph: function(remove,add,speed,easing,callback) {
		return $.effects.animateClass.apply(this, [{ add: add, remove: remove },speed,easing,callback]);
	},
	switchClass: function() {
		return this.morph.apply(this, arguments);
	},

	// helper functions
	cssUnit: function(key) {
		var style = this.css(key), val = [];
		$.each( ['em','px','%','pt'], function(i, unit){
			if(style.indexOf(unit) > 0)
				val = [parseFloat(style), unit];
		});
		return val;
	}
});

/*
 * jQuery Color Animations
 * Copyright 2007 John Resig
 * Released under the MIT and GPL licenses.
 */

// We override the animation for all of these color styles
$.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
		$.fx.step[attr] = function(fx) {
				if ( fx.state == 0 ) {
						fx.start = getColor( fx.elem, attr );
						fx.end = getRGB( fx.end );
				}

				fx.elem.style[attr] = "rgb(" + [
						Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0],10), 255), 0),
						Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1],10), 255), 0),
						Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2],10), 255), 0)
				].join(",") + ")";
			};
});

// Color Conversion functions from highlightFade
// By Blair Mitchelmore
// http://jquery.offput.ca/highlightFade/

// Parse strings looking for color tuples [255,255,255]
function getRGB(color) {
		var result;

		// Check if we're already dealing with an array of colors
		if ( color && color.constructor == Array && color.length == 3 )
				return color;

		// Look for rgb(num,num,num)
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
				return [parseInt(result[1],10), parseInt(result[2],10), parseInt(result[3],10)];

		// Look for rgb(num%,num%,num%)
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
				return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];

		// Look for #a0b1c2
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
				return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];

		// Look for #fff
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
				return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];

		// Look for rgba(0, 0, 0, 0) == transparent in Safari 3
		if (result = /rgba\(0, 0, 0, 0\)/.exec(color))
				return colors['transparent'];

		// Otherwise, we're most likely dealing with a named color
		return colors[$.trim(color).toLowerCase()];
}

function getColor(elem, attr) {
		var color;

		do {
				color = $.curCSS(elem, attr);

				// Keep going until we find an element that has color, or we hit the body
				if ( color != '' && color != 'transparent' || $.nodeName(elem, "body") )
						break;

				attr = "backgroundColor";
		} while ( elem = elem.parentNode );

		return getRGB(color);
};

// Some named colors to work with
// From Interface by Stefan Petre
// http://interface.eyecon.ro/

var colors = {
	aqua:[0,255,255],
	azure:[240,255,255],
	beige:[245,245,220],
	black:[0,0,0],
	blue:[0,0,255],
	brown:[165,42,42],
	cyan:[0,255,255],
	darkblue:[0,0,139],
	darkcyan:[0,139,139],
	darkgrey:[169,169,169],
	darkgreen:[0,100,0],
	darkkhaki:[189,183,107],
	darkmagenta:[139,0,139],
	darkolivegreen:[85,107,47],
	darkorange:[255,140,0],
	darkorchid:[153,50,204],
	darkred:[139,0,0],
	darksalmon:[233,150,122],
	darkviolet:[148,0,211],
	fuchsia:[255,0,255],
	gold:[255,215,0],
	green:[0,128,0],
	indigo:[75,0,130],
	khaki:[240,230,140],
	lightblue:[173,216,230],
	lightcyan:[224,255,255],
	lightgreen:[144,238,144],
	lightgrey:[211,211,211],
	lightpink:[255,182,193],
	lightyellow:[255,255,224],
	lime:[0,255,0],
	magenta:[255,0,255],
	maroon:[128,0,0],
	navy:[0,0,128],
	olive:[128,128,0],
	orange:[255,165,0],
	pink:[255,192,203],
	purple:[128,0,128],
	violet:[128,0,128],
	red:[255,0,0],
	silver:[192,192,192],
	white:[255,255,255],
	yellow:[255,255,0],
	transparent: [255,255,255]
};

/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 *
 * Open source under the BSD License.
 *
 * Copyright 2008 George McGinley Smith
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this list of
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list
 * of conditions and the following disclaimer in the documentation and/or other materials
 * provided with the distribution.
 *
 * Neither the name of the author nor the names of contributors may be used to endorse
 * or promote products derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
$.easing.jswing = $.easing.swing;

$.extend($.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert($.easing.default);
		return $.easing[$.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - $.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return $.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return $.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

/*
 *
 * TERMS OF USE - EASING EQUATIONS
 *
 * Open source under the BSD License.
 *
 * Copyright 2001 Robert Penner
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this list of
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list
 * of conditions and the following disclaimer in the documentation and/or other materials
 * provided with the distribution.
 *
 * Neither the name of the author nor the names of contributors may be used to endorse
 * or promote products derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

})(jQuery);
/*
 * jQuery UI Effects Blind 1.7.1
 *
 * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI/Effects/Blind
 *
 * Depends:
 *	effects.core.js
 */
(function($) {

$.effects.blind = function(o) {

	return this.queue(function() {

		// Create element
		var el = $(this), props = ['position','top','left'];

		// Set options
		var mode = $.effects.setMode(el, o.options.mode || 'hide'); // Set Mode
		var direction = o.options.direction || 'vertical'; // Default direction

		// Adjust
		$.effects.save(el, props); el.show(); // Save & Show
		var wrapper = $.effects.createWrapper(el).css({overflow:'hidden'}); // Create Wrapper
		var ref = (direction == 'vertical') ? 'height' : 'width';
		var distance = (direction == 'vertical') ? wrapper.height() : wrapper.width();
		if(mode == 'show') wrapper.css(ref, 0); // Shift

		// Animation
		var animation = {};
		animation[ref] = mode == 'show' ? distance : 0;

		// Animate
		wrapper.animate(animation, o.duration, o.options.easing, function() {
			if(mode == 'hide') el.hide(); // Hide
			$.effects.restore(el, props); $.effects.removeWrapper(el); // Restore
			if(o.callback) o.callback.apply(el[0], arguments); // Callback
			el.dequeue();
		});

	});

};

})(jQuery);
/*
 * jQuery UI Effects Transfer 1.7.1
 *
 * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI/Effects/Transfer
 *
 * Depends:
 *	effects.core.js
 */
(function($) {

$.effects.transfer = function(o) {
	return this.queue(function() {
		var elem = $(this),
			target = $(o.options.to),
			endPosition = target.offset(),
			animation = {
				top: endPosition.top,
				left: endPosition.left,
				height: target.innerHeight(),
				width: target.innerWidth()
			},
			startPosition = elem.offset(),
			transfer = $('<div class="ui-effects-transfer"></div>')
				.appendTo(document.body)
				.addClass(o.options.className)
				.css({
					top: startPosition.top,
					left: startPosition.left,
					height: elem.innerHeight(),
					width: elem.innerWidth(),
					position: 'absolute'
				})
				.animate(animation, o.duration, o.options.easing, function() {
					transfer.remove();
					(o.callback && o.callback.apply(elem[0], arguments));
					elem.dequeue();
				});
	});
};

})(jQuery);
/*
 * My Ajax Class
 */


function connectToServer(returnType,processor)
{
	this.xmlHttpObj             =null;
	this.send                   =send;
	this.createXmlHttpObj       =createXmlHttpObj;
	this.deleteXmlHttpObj       =deleteXmlHttpObj;
	this.processor              =processor;
	this.returnType             =returnType;
    
    connectToServer.call(this);
	
	function connectToServer()
	{
		if(!processor||!returnType)
		{
			if(returnType!="null")
			{
				alert("missing par");	
			}
		}
	
		else if(returnType!="xml" && returnType!="txt" && returnType!="null" &&returnType!="boolean")
		{
			alert("invalid return type");
		}
	}
	
	function send(url)
	{
		if(!this.xmlHttpObj)
		{
			var  self=this;
			this.createXmlHttpObj();
			this.xmlHttpObj.open("GET",url,true);
			this.xmlHttpObj.send(null);
		    
		    if(this.returnType=="xml")
		    {
		    	this.xmlHttpObj.onreadystatechange=function()
		    	                                   {
		    	                                       if(self.xmlHttpObj.readyState==4)
		    	                                       {
		    	                                       	    self.processor(self.xmlHttpObj.responseXML);
		    	                                       }
		    	                                   }
		    }
		    if(this.returnType=="txt")
		    {
		    	this.xmlHttpObj.onreadystatechange=function()
		    	                                   {
                                                        if(self.xmlHttpObj.readyState==4)
		    		                                    {
		    			                                    self.processor(self.xmlHttpObj.responseText);
		    		                                    }
		    	                                   }
		    }
		}
	}
	
	function createXmlHttpObj()
	{
		if(window.XMLHttpRequest){this.xmlHttpObj=new XMLHttpRequest();}
		else if(window.ActiveXObject)
		{
			this.xmlHttpObj=new ActiveXObject("Msxml2.XMLHTTP");
		}
		else 
		{
			window.alert("can not create xmlhttp object");
		}
	}
	
	function deleteXmlHttpObj()
	{
		this.xmlHttpObj=null;
	}

}//end of class


/*
***********************************************************************************

    *Functions in javascript
	 
	 I put the function that do no belong to any classes or 
	 categary. 

**********************************************************************************

@Author Mark Liang
@Library include: JQUERY (With many thanks)

/*********************************************************************************/

function preload()
{
	/*
	 * global variables
	 */
	 global_imgs            = new Array();
	 global_navi            = new Array("Home","Wood","Veneers","Products","Books","Payment","Links","Catalogues");
	 global_pageNo          = global_navi[0];
     global_tabNo           = false;
	 global_admin           = false;
	 global_pageLock        = new pageLocker(false);
	 global_shopCart        = false;
	 global_bookCond        = false;
	 
	/*
	 * functions
	 */	
	checkUserType();
	setTimeout("showAuthor()",1000);
	setTimeout("runWelcome()",2000);
}

//************************************************************

function checkUserType()
{
	var connection=new connectToServer("txt",funs); 
	    connection.send("./systemIntrface.php?reqs=checkRight&&type=txt");
		
	function funs(result)
	{
		if(result=="true")
		{
			global_admin=true;
		}
		else
		{
			global_shopCart=new myCart();
		}
		createPage();
	}
}

//************************************************************

function createPage()
{	
	var header              = document.createElement("div");	
	    header.id           = "header";
	var navi                = document.createElement("div");	
	    navi.id             = "navi";
	var content             = document.createElement("div");
	    content.id          = "content";
	
	var page=document.getElementById("background");
	    page.appendChild(header) ;
	    page.appendChild(navi)   ;
	    page.appendChild(content);
	 
	//err    
	createHeader(header);
	createNavi(navi);
	createContent(content);
}

function createHeader(obj)
{
	var logo        =new Image();
	var title       =document.createElement("h1");
	
	logo.src        ="./imgs/logo.jpg";
	title.id        ="title";
	title.innerHTML ="WWW.WOODWITHTHEWORKS.COM";
	
	obj.appendChild(logo) ;
	obj.appendChild(title);
}

function createNavi(obj)
{
	for(var i=0; i<global_navi.length; i++)
	{
		var item=document.createElement("a");
		    item.href="#";
		    item.innerHTML=global_navi[i];
		    item.onclick  =function(){naviOnClick(this)}
		if(i==0)
		{
			item.className="current";
		}
		obj.appendChild(item);
	}
}

function createContent(obj)
{
	var box                 =document.createElement("div");
	    box.className       ="inner";	    
	var tabs                =document.createElement("div");
	    tabs.id             ="tabs";
	var tags                =document.createElement("div");
	    tags.id             ="tags";
	var main                =document.createElement("div");
	    main.id             ="main";
	    main.innerHTML      ="<div class='stuff'></div>";
	var type                =false;
	
	switch(global_pageNo)
	{
		case global_navi[0]: type=0; break; 
		case global_navi[1]: type=1; break;
		case global_navi[2]: type=1; break;
	    case global_navi[3]: type=1; break;
	    case global_navi[4]: type=1; break;
	    case global_navi[5]: type=0; break;
	    case global_navi[6]: type=0; break;
	    case global_navi[7]: type=0; break;
	}	
	
	//err
	box.appendChild(tabs);
	box.appendChild(tags);
	box.appendChild(main);
	obj.appendChild(box) ;
	
	//create tabs, and load the first tab's data
	if(type==0)
	{
		tags.className ="tagsText";
		loadHtml(createTabs(tabs));
	}
	else
	{
		tags.className ="tagsData";
		loadData(createTabs(tabs));
	}
	
	//enable tabs
	$(function() {$("#tabs").tabs();}); 
}

//This function will return the first tab that it created
function createTabs(obj)
{
	var type=false;
	
	switch(global_pageNo)
	{
		case global_navi[0]: var tabs=new Array("Introduction"); type=0; break; 
		case global_navi[1]: var tabs=new Array("IWCS Samples","Turning Blanks","Tonewood","Timber"); type=1;  break;
		case global_navi[2]: var tabs=new Array("Packs", "Veneers A-Z","Palettes","Video");           type=1;  break;
	    case global_navi[3]: var tabs=new Array("Souvenirs","Specials","Commissions","Seconds");      type=1;  break;
	    case global_navi[4]: var tabs=new Array("Wood","Boats","Crafts","All");                       type=1;  break;
	    case global_navi[5]: var tabs=new Array("Payment");      type=0; break;
	    case global_navi[6]: var tabs=new Array("Links");        type=0; break;
	    case global_navi[7]: var tabs=new Array("Catalogues");   type=0; break;
	}
	
	var box =document.createElement("ul");	
	for(var i=0; i<tabs.length; i++)
	{
		var tab                    =document.createElement("li");
		var innerTab               =document.createElement("a") ;
		    innerTab.href          ="#main";
		    innerTab.innerHTML     =tabs[i];
		    if(type==1)
		    {
		    	innerTab.onclick   =function(){loadData(this)};			
		    }
		    if(type==0)
		    {
		    	innerTab.onclick   =function(){loadHtml(this)};	
		    }
		    if(tabs[i]=="Palettes"||tabs[i]=="Video")
		    {
		    	innerTab.onclick   =function(){loadHtml(this)};
		    }
		    		
		tab.appendChild(innerTab);
	    box.appendChild(tab);
	    
	    //used for return value
	    if(i==0)
	    {
	    	var tmp=innerTab;
	    }
	    
	    if(type==0)
	    {
	    	tab.style.background="rgb(255,243,234)";
	    }
	}
	
    if(type==1&&global_admin)
	{
		var div=document.createElement("div");
		var img=new Image();
		    div.className  ="controlbar";
	        img.src        ="./imgs/insert.ico";
	        img.onmouseover=function(){this.style.border="groove thin #FF0000";}
	        img.onmouseout =function(){this.style.border="none";}
	        img.onclick    =function(){openImporter();}
	        img.alt        ="import";
	    	div.appendChild(img);
	    	box.appendChild(div);
	}
	obj.appendChild(box);
	return tmp;
}

function naviOnClick(obj)
{
	if(global_pageNo!=obj.innerHTML)
	{
		//set global variable
		global_pageNo=obj.innerHTML;
		global_tagNo =false;
		
		var box      =document.getElementById("content");
	    var innerBox =box.getElementsByTagName("div")[0];
		    box.removeChild(innerBox);
		    
		//reconstructure the content
		createContent(box);
		
		//change the navi bar
		var navi=document.getElementById("navi");
		for(var i=0; i<navi.getElementsByTagName("a").length; i++)
		{
			navi.getElementsByTagName("a")[i].className="";
		}
		obj.className="current";
		
		//Change the title
		if(global_pageNo==global_navi[0])
		{
			document.getElementById("title").innerHTML="WWW.WOODWITHTHEWORKS.COM";
		}
		else
		{
			document.getElementById("title").innerHTML=global_pageNo.toUpperCase();
		}
	}
}

//************************************************************

function loadData(obj)
{
	var connection=new connectToServer("xml",funs);
	var locker    =new pageLocker(true);
	var count     =0;  //if load failed, count+1, max 3 times
		connection.send("./systemIntrface.php?reqs=loadData&&pageNo="+obj.innerHTML+"&&type=xml");
	    global_tabNo=obj.innerHTML;
	    locker.lock();
	    
	    function funs(result)
	    {
	    	if(typeof(result)=="object")
	    	{ 
	    	    //An array which record the colums name
	    		var colums=result.documentElement.childNodes.item(0);			
	    		
	    		/*
	    		 * create title
	    		 */
	    	    document.getElementById("tags").innerHTML="";
	    		
	    		//display the table title
	    		for(var i=1; i<colums.childNodes.length; i++)
	    		{
	    			var div =document.createElement("div");
                    div.innerHTML="<span>"+standerOutput(getNodeValue(colums.childNodes.item(i)))+"</span>";
                    setTableStyle(div,colums.childNodes.length,i)   ;
                    document.getElementById("tags").appendChild(div);	
	    		}
	    		
	    		/*
	    		 * create table
	    		 */
	    		dataset                          = document.createElement("ul"); //create table	  			
	    		dataset .className               ="myData";	  
	    	        	    
	    		var rows                         = result.documentElement.childNodes.item(1);
	    		for(var i=0; i<rows.childNodes.length; i++)
	    		{
	    			var li                       =document.createElement("li") ;
	    			var controlBar               =document.createElement("div");
	    			var row                      =rows.childNodes.item(i);
	    			    li.myChilds              =new Array();
	    			    controlBar.className     ="bar";
	    			    if(global_admin)
	    			    {
	    			    	var closeBtn         =document.createElement("img");
	    			    	    closeBtn.target  =li;
	    			    	    closeBtn.myId    =getNodeValue(row.childNodes.item(0));
	    			    	    closeBtn.onclick =function(){openDeleter(this)}
	    			    	    closeBtn.src     ="./imgs/close.PNG";
	    			    	    controlBar.appendChild(closeBtn);
	    			    }
	    			    li.appendChild(controlBar);
	    			
	    			//get colum's data, 0 is id 
	    			for(var j=1; j<row.childNodes.length; j++)
	    			{
	    				//@myid and @coluName is used for edit data
	    			    var div                  =document.createElement("div");
	    				var value                =getNodeValue(row.childNodes.item(j));
	    				    div.myId             =getNodeValue(row.childNodes.item(0));
	    				    div.coluName         =getNodeValue(colums.childNodes.item(j));
	    				    li.myChilds[j-1]     =new mataData(div.coluName,value);
	    				
                        //set style
                        setTableStyle(div,row.childNodes.length,j);
	    				
	    				//set value    				
	    				if(div.coluName=="PHOTO")//if it is the img
	    				{
	    					div.imgObj=new imgOperater(value);   
	    									  	    				    
	    				    if(global_admin)
	    				    {
	    				        div.imgObj.showImgName(div);
	    				        div.onmouseover  =function(){this.style.background="#0099CC"}
	    				    	div.onmouseout   =function(){this.style.background="rgb(255,243,234)"}
	    				    	div.onclick      =function(){openImgEditer(this);}		
	    				    }			
	    				    else
	    				    {
	    				    	if(div.imgObj.imageObj[0].avaiable)
	    				    	{
	    				    	    div.onclick      =function(){openImgViewer(this);}	
	    				    	    div.onmouseover  =function(){document.getElementsByTagName('body')[0].style.cursor="./imgs/p1.cur" ;} 	
	    				    	    div.onmouseout   =function(){document.getElementsByTagName('body')[0].style.cursor="default" ;}		
	    				    	}
	    				    	div.imgObj.showImg(0,div);	    	
	    				    }	    				    
	    				}
	    				else if(div.coluName=="COST"&&global_shopCart!=false)
	    				{
	    					var text               =document.createElement("span");
	    					var cart               =new Image;
	    					    text.innerHTML     =value;
	    					    cart.src           ="./imgs/cart.PNG";
	    					    cart.title         ="shopping cart";
	    					    cart.style.height  ="15px" ;
	    					    cart.style.width   ="15px" ;
	    					    cart.style.border  ="none" ;
	    					    cart.style.margin  ="auto" ;
	    					    cart.style.display ="block";
	    					    cart.target        =li.myChilds;
	    					    cart.onclick       =function(){global_shopCart.addItem(this)};
	    					    cart.onmouseover   =function(){this.style.border="1px solid"; this.style.cursor="hand";}
	    					    cart.onmouseout    =function(){this.style.border="none";}
	    					   	    					
	    					div.appendChild(text);
	    					div.appendChild(cart);
	    				}
	    				else if(div.coluName=="COND"&&global_admin==false)
	    				{
	    					var text               =document.createElement("span");
	    					var what               =new Image;
	    					    text.innerHTML     =value;
	    					    what.src           ="./imgs/why.PNG";
	    					    what.title         ="Explanation of condition code";
	    					    what.style.height  ="15px" ;
	    					    what.style.width   ="15px" ;
	    					    what.style.border  ="none" ;
	    					    what.style.margin  ="auto" ;
	    					    what.style.display ="block";
	    					    what.onclick       =function(){showBookCond();}
	    					    what.onmouseover   =function(){this.style.border="1px solid"; this.style.cursor="hand";}
	    					    what.onmouseout    =function(){this.style.border="none";}
	    					   	    					
	    					div.appendChild(text);
	    					div.appendChild(what);	    					
	    				}
	    				else
	    				{   
	    				    //set function
	    				    if(global_admin)
	    				    {
	    				    	div.onmouseover  =function(){this.style.background="#0099CC"}
	    				    	div.onmouseout   =function(){this.style.background="rgb(255,243,234)"}
	    				    	div.ondblclick   =function(){openTxtEditer(this)}
	    				    }
	    				    if(div.coluName=="Botanical_Name")
	    				    {
	    				        div.className="italicFont";
	    				    }	
	    				    div.innerHTML=value;
	    				}
	    			    //insert
	    		        li.appendChild(div);			    
	    			}
	    			dataset.appendChild(li); 
	    		} 
	    		document.getElementById("main").innerHTML="";
	    		document.getElementById("main").appendChild(dataset);  
	    		
	    		/*
	    		 * padding
	    		 */
                if(rows.childNodes.length>5)
                {
                	document.getElementById("main").style.height="auto";
                }
                else
                {
                	document.getElementById("main").style.height="420px";
                } 
                locker.unlock();		 
	    	}	
	    	else if(count<2)
	    	{
	    		loadData(obj);
	    		count+=1;
	    	}
	    	else
	    	{
	    		alert("Error, please press F5, to refresh the page. Sorry");
	    		locker.unlock();
	    	}
	    }
//end of function
}

function setTableStyle(div,totalColum,numColum)
{
	//set style 450=750-100-50-200;	
	div.style.width=parseInt(450/(totalColum-3))+"px";
	switch(numColum)
	{
		case 1           :div.style.width="100px"; break;
	    case totalColum-2:div.className="r"; div.style.width="50px" ; break;
	    case totalColum-1:div.className="d"; div.style.width="200px"; break;
	}	
}

function getNodeValue(node)
{
	var temp;
	if(node.firstChild.nodeValue=="[[empty]]")
	{
		temp="";
	}
	else
	{
		temp=node.firstChild.nodeValue;
	}
	return temp;
}

function mataData(clumName,value)
{
	this.cName   =clumName;
	this.value   =value;
}

//***********************************************************

function loadHtml(obj)
{
	var connection=new connectToServer("txt",funs);
	var locker    =new pageLocker(true);
	var count     =0;
		connection.send("./systemIntrface.php?reqs=loadHtml&&pageNo="+obj.innerHTML+"&&type=text");
	    global_tabNo=obj.innerHTML;
	    locker.lock();
	    
	    function funs(result)
	    {
	    	if(result!="error")
	    	{
	    		document.getElementById("main").innerHTML=result;
	    		if(obj.innerHTML=="Palettes")
	    		{
	    			document.getElementById("tags").innerHTML="<span style='padding-left:5px'>These palettes have samples of 24 timber veneers in each. I have included them here so you can get an idea of what the different species look like.</span>";
		    	    document.getElementById("main").style.height="auto";	    			
	    		}
	    		if(obj.innerHTML=="Vedio")
	    		{
	    			document.getElementById("tags").innerHTML="";
	    		}
	    	    locker.unlock();
	    	}
	        else if(count<2)
	    	{
	    		loadHTML(obj);
	    		count+=1;
	    	}
	    	else
	    	{
	    		alert("Error, please press F5, to refresh the page. Sorry");
	    		locker.unlock();
	    	}
	    }
//end of function
}

//************************************************************

function login()
{
	var pass=document.getElementById("password").value;
	var connection=new connectToServer("txt",funs); 
		connection.send("./systemIntrface.php?reqs=login&&pass="+pass+"&&type=txt"); 	
		
	function funs(result)
	{
		if(result=="true")
		{
			location="./index.html";
		}
		else
		{
			alert(result);
		}
	}
}

//************************************************************

function openInserter()
{
	var popupWindow            =document.createElement("div");
	    popupWindow.id         ="popupWindow";
	    popupWindow.innerHTML  ="<ul>";
	    popupWindow.innerHTML +="<li><h4>Botanical Name:</h4><input type='text' /></li>";
	    popupWindow.innerHTML +="<li><h4>Common Name:   </h4><input type='text' /></li>";
	    popupWindow.innerHTML +="<li><h4>Price:         </h4><input type='text' /></li>";
	    popupWindow.innerHTML +="<li><h4>photo:         </h4><input type='button' value='explore'/></li>";
	    popupWindow.innerHTML +="<li><div></div></li>";	    
	    popupWindow.innerHTML +="</ul>";
	    popupWindow.innerHTML +="<input type='button' value='submit' onclick=addNewData() id='submitBtn' />";
	    popupWindow.innerHTML +="<input type='button' value='cancel' onclick=closePopup() />";
	    popupWindow.style.top  =document.documentElement.scrollTop+100+"px";
        
	    document.body.appendChild(popupWindow); 
	    global_pageLock.lock();     	    				    
}

function openTxtEditer(obj)
{
	var popupWindow            =document.createElement("div");
	var submit                 =document.createElement("input");
	var cancel                 =document.createElement("input");
	    obj.target             =popupWindow;
	    obj.submit             =submit;
	    
	    popupWindow.id         ="popupWindow";
	    submit.type            ="button";
	    cancel.type            ="button";
	    submit.value           ="submit";
	    cancel.value           ="cancel";
	    submit.onclick         =function(){editTxtData(obj);}
	    cancel.onclick         =function(){closePopup()    ;}
	    
	    popupWindow.innerHTML  ="<li><textarea cols='25' style='margin-top:40px' rows='10'>"+obj.innerHTML+"</textarea></li>";
	    popupWindow.appendChild(submit);
	    popupWindow.appendChild(cancel);    
	    popupWindow.style.top  =document.documentElement.scrollTop+100+"px";	    
	    document.body.appendChild(popupWindow);
	    global_pageLock.lock();
}

function openImgEditer(obj)
{
	var popupWindow            =document.createElement("div");
	var values                 =document.createElement("input");
	var submit                 =document.createElement("input");
	var cancel                 =document.createElement("input");
	    obj.target             =popupWindow;
	    values.type            ="text";
	    values.value           =obj.imgObj.getImgNames();
	    submit.type            ="button";
	    submit.id              ="submitBtn"
	    submit.value           ="Submit";
	    cancel.type            ="button";
	    cancel.value           ="Cancel";
	    submit.onclick         =function(){editImgData(obj);}
	    cancel.onclick         =function(){closePopup();}
	    popupWindow.id         ="popupWindow";
	    popupWindow.style.top  =document.documentElement.scrollTop+100+"px";
	    
	    popupWindow.appendChild(values);
	    popupWindow.appendChild(submit);
	    popupWindow.appendChild(cancel);

	    document.body.appendChild(popupWindow);
	    global_pageLock.lock();
}

function openImporter()
{
	var popupWindow            =document.createElement("div");
	var iframe                 =document.createElement("iframe");
	var submit                 =document.createElement("input");
	var cancel                 =document.createElement("input");
	    iframe.src             ="./importer.php";
	    iframe.id              ="importer";
	    submit.type            ="button";
	    submit.onclick         =function(){importData()}
	    submit.id              ="submitBtn"
	    submit.value           ="Submit";
	    cancel.type            ="button";
	    cancel.onclick         =function(){closePopup();}
	    cancel.value           ="Cancel";
	    popupWindow.id         ="popupWindow";
	    popupWindow.style.top  =document.documentElement.scrollTop+100+"px";
	    
	    popupWindow.appendChild(iframe);
	    popupWindow.appendChild(submit);
	    popupWindow.appendChild(cancel);

	    document.body.appendChild(popupWindow);
	    global_pageLock.lock();
}

function openDeleter(obj)
{
	if(confirm("r u sure to delete it?"))
	{
		deleteData(obj);
	}
}

function openImgViewer(obj)
{
	var pos             = getPosition(obj);
	var div             = document.createElement("div") ; 
	var img             = document.createElement("div") ;
	var bar             = document.createElement("span");
	    div.className   = "imgViewer";
	    bar.className   = "bar";
	    img.className   = "pic";
	    img.onclick     = function()
	                      { 
	                      	div.style.visibility="hidden"; runTransfer(div,obj,miusPicture);                      	
	                      }	  
	    img.onmouseover = function(){document.getElementsByTagName('body')[0].style.cursor="./imgs/p2.cur";} 
	    img.onmouseout  = function(){document.getElementsByTagName('body')[0].style.cursor="default";} 
	    
	    div.style.left  = pos.x-150+"px";
	    div.style.top   = pos.y-100+"px";
	    
	    div.appendChild(bar);
	    div.appendChild(img);
	    document.getElementById("main").appendChild(div);
	    
	    function plusPicture()
	    {
	    	//create bar
	    	var num=obj.imgObj.numOfImg();
	    	for(var i=0; i<num; i++)
	    	{
	    		var imgIndex=document.createElement("a");
	    		var indexNum=i+1;
	    		    imgIndex.num =i;
	    		    imgIndex.href="#";
	                imgIndex.innerHTML="["+indexNum+"]" ;
	                imgIndex.onclick=function(){obj.imgObj.showImg(this.num,img,1);}
	                bar.appendChild(imgIndex);
	        }	    	
	    	
	    	//show picture
	    	obj.imgObj.showImg(0,img,1);	    	
	    	
	    	//change style
	        div.style.visibility="visible"; 
	    	document.getElementsByTagName('body')[0].style.cursor="./imgs/p2.cur";
	    }
	    function miusPicture()
	    {
	    	//change style
	    	document.getElementById("main").removeChild(div);
	    	document.getElementsByTagName('body')[0].style.cursor="default";
	    }
	    runTransfer(obj,div,plusPicture);
}

//************************************************************

function closePopup(locker)
{
	document.body.removeChild(document.getElementById("popupWindow"));
	global_pageLock.unlock(false);	
}

//************************************************************

function importData()
{
	document.getElementById('importer').contentWindow.document.getElementsByTagName('form')[0].submit();
}

function editImgData(obj)
{
	var id     = obj.myId;
	var colum  = obj.coluName;
	var value  = obj.target.getElementsByTagName("input")[0].value;
	var pageNo = global_tabNo;

    var connection=new connectToServer("txt",funs); 
		connection.send("./systemIntrface.php?reqs=editData&&id="+id+"&&colum="+colum+"&&pageNo="+pageNo+"&&data="+value+"&&type=txt");	
	
		function funs(result)
		{
			if(result=="ok")
			{
				var connection=new connectToServer("txt",funs); 
				    connection.send("./systemIntrface.php?reqs=loadData&&id="+id+"&&colum="+colum+"&&pageNo="+pageNo+"&&type=txt");
				    
				    function funs(result)
				    {
				    	obj.imgObj=new imgOperater(result);
				    	obj.imgObj.showImgName(obj);
				    	closePopup();
				    }	
			}
			else
			{
				alert(result); closePopup();
			}
		}	
//end of function	
}

function editTxtData(obj)
{
	var id     = obj.myId;
	var colum  = obj.coluName;
	var value  = obj.target.getElementsByTagName("textarea")[0].value;
	var pageNo = global_tabNo;
	 
	var connection=new connectToServer("txt",funs); 
		connection.send("./systemIntrface.php?reqs=editData&&id="+id+"&&colum="+colum+"&&pageNo="+pageNo+"&&data="+value+"&&type=txt");
		
		function funs(result)
		{
			if(result=="ok")
			{
				obj.innerHTML=value;
				closePopup();
			}
			else
			{
				alert(result);
				closePopup();
			}
		}
//end of function		
}


function deleteData(obj)
{
	var pageNo    =global_tabNo;
	var id        =obj.myId;
	
	var connection=new connectToServer("txt",funs); 
		connection.send("./systemIntrface.php?reqs=deltData&&id="+id+"&&pageNo="+pageNo+"&&type=txt");
		
		function funs(result)
		{
			if(result=="ok")
			{
				runHide(obj.target);
			}
			else
			{
				alert(result);
			}
		}
//end of function	
}

//************************************************************

function myCart()
{
	this.items            =new Array();
	this.popup            =false;
	this.cartBtn          =false;
	
	this.setNum           =setNum;
	this.delItem          =delItem;
	this.addItem          =addItem;
	this.showItems        =showItems;
	this.makeBook         =makeBook;
	this.getBookedData    =getBookedData;
	this.getAttributeType =getAttributeType;
	this.getAddress       =getAddress;
	
    myCart.call(this);
    
    /*********************************************
                 Constructer and other
    **********************************************/		
    
    function myCart()
    {
    	var box            =document.getElementById("topText");
    	var div            =document.createElement("div");
    	var me             =this;
    	    me.cartBtn     =div;
    	    div.id         ="cart";
    	    div.innerHTML  ="<img src='./imgs/cart.PNG' style='vertical-align:-4px; margin-right:2px;' /><span>Shopping Cart</span>"; 	    
    	    div.onclick    =function(){me.showItems()};
    	    div.onmouseover=function(){this.style.color="#FF0000";};
    	    div.onmouseout =function(){this.style.color="#000000";};
    	    box.appendChild(div);
    }
    
    function addItem(obj)
    {
    	var num=1;
    	this.items[this.items.length]=new itemObj(obj.target,num);
    	alert("Dear customer, this item has been added to your shopping cart. You can change the quantity of each item ordered in the shopping cart.");
    }
        
    function delItem(obj)
    {    
    	this.items[obj.target.index]=null;
    	runHide(obj.target);
    }
    
    function showItems()
    {
    	var popupWindow                =document.createElement("div");
        var head                       =document.createElement("div");
	    var body                       =document.createElement("div");
    	var submit                     =document.createElement("input");
    	var cancel                     =document.createElement("input");
    	var me                         =this;
	    
	        popupWindow.id             ="popupWindow";
	        popupWindow.className      ="cartPopup";
	        submit.type                ="button";
	        cancel.type                ="button";
	        submit.value               ="Order"  ;
	        cancel.value               ="Exit"  ;
	        submit.onclick             =function(){me.getAddress()}
	        cancel.onclick             =function(){closePopup();}
	        popupWindow.style.top      ="100px";
	        head.style.fontSize        ="12px";
	        head.style.background      ="#999999";
	        head.style.marginTop       ="0px";
	    
	    //create content
	    if(this.items.length==0)
	    {
	    	popupWindow.innerHTML="<div>Dear Customer: You shopping cart is currently empty</div>";
	    	cancel.style.marginLeft="125px";
	    	cancel.style.marginTop ="5px";
	        popupWindow.appendChild(cancel); 
	    }
	    else
	    {
	        
	    	head.style.height   ="30px";
	    	head.style.width    ="96%";
	    	body.style.height   ="auto";
	    	body.style.width    ="90%";
	    	body.style.overflow ="hidden";
	    	submit.style.marginLeft="70px";
	    	
	        //create head
	        var head_str="Items you selected:";
	        	    	
	    	//create body
	    	for(var i=0; i<this.items.length; i++)
	    	{
	    		//create item box;
	    		var body_str          ="";
	    		var itemBox           =document.createElement("div")  ;
	    		var deleBtn           =document.createElement("input");
	    		    itemBox.index     =i;
	    		    itemBox.className ="itemBox";
	    		    deleBtn.type      ="button" ;
	    		    deleBtn.value     ="Delete this item";
	    		    deleBtn.target    =itemBox;
	    		    deleBtn.onclick   =function(){me.delItem(this)}
	    		
	    		
	    		if(this.items[i]!=null)
	    		{
	    			body_str="<table>";
	    			for(var j=0; j<this.items[i].item.length; j++)
	    			{
	    				//set general type, some attribute do not display in cart (e.g:description)
                        var type=this.getAttributeType(this.items[i].item[j].cName);
   			        
   			            //create body string
	    			    if(type==1)
	    			    {
	    				    body_str+="<tr><td>"+standerOutput(this.items[i].item[j].cName)+"</td>";
	    				    body_str+="<td>:</td>";
	    				    body_str+="<td>"+this.items[i].item[j].value+"</td>";
	    				    body_str+="</tr>";
	    			    }
	    			    if(type==2)
	    			    {
	    				    var img  =new imgOperater(this.items[i].item[j].value);
	    				    var url  =img.showUrl(0);  
	    				    body_str+="<tr><td><img src='"+url+"' style='height:65px; width:90px;'/></td></tr>";  						
	    			    }
	    		    }
	    		    body_str+="<tr><td>Quantity</td><td>:</td><td>";
	    		    body_str+="<input type='text' style='width:40px' onkeyup='global_shopCart.setNum("+i+",this)' value='"+this.items[i].num+"' /></td>";
	    		    body_str+="</table>";
	    		    itemBox.innerHTML=body_str  ;
	    		    itemBox.appendChild(deleBtn);
	    		    body.appendChild(itemBox);
	    		}	
	    	}
	    	
	    	//insert items
	    	head.innerHTML=head_str ;
	    	head.appendChild(submit); 
	    	head.appendChild(cancel);
	    	
	    	popupWindow.appendChild(head);
	    	popupWindow.appendChild(body);
	    	
	    	//set class attribute
	    	this.popup=popupWindow; 
	    }	    
	    
	    //insert popup window
	    document.body.appendChild(popupWindow);
	    
	    //show popup
	    global_pageLock.lock();
	    var options={to: "#popupWindow", className: 'ui-effects-transfer'};
	    $("#cart").effect("transfer",options,1000);
    }
    
    function makeBook()
    {
    	var data                   =this.getBookedData();
    	var email                  =this.popup.getElementsByTagName("input")[0].value;
    	var address                =this.popup.getElementsByTagName("input")[1].value;
        var connection=new connectToServer("txt",funs); 
	        connection.send("./systemIntrface.php?reqs=makeBook&&email="+email+"&&address="+address+"&&data="+data+"&&type=txt");	        
	        function funs(result){}
	    closePopup();
    }
    
    function getBookedData()
    {
    	var str="";
    	for(var i=0; i<this.items.length; i++)
	    {
	    	if(this.items[i]!=null)
	    	{
	    		for(var j=0; j<this.items[i].item.length; j++)
	    		{	    		
	    		    //different cname
	    		    var type=this.getAttributeType(this.items[i].item[j].cName);
	    	        if(type==1)
	    	        {
	    	            str+=this.items[i].item[j].cName+":";
	    			    str+=this.items[i].item[j].value+";";
	    		    }
	    		    if(type==2)
	    		    {
	    			    var img=new imgOperater(this.items[i].item[j].value);
	    			    var url=img.showUrl(0);  
	    			    str+=this.items[i].item[j].cName+":";
	    			    str+=url+";";		  						
	    		    }	    		
	    	    }   
	    	    str+="Quantity:"+this.items[i].num+";";	
	    	} 	
	    }
	    return str;
    }
    
    
    function getAttributeType(par)
    {
    	var type=1;
	    switch(par)
	    {
	    	case "DESCRIPTION": type=3; break;
	        case "PHOTO":       type=2; break;
	    }
	    return type;
    }
    
    function getAddress()
    {
    	var me                         =this;
    	var submit                     =document.createElement("input");
    	var cancel                     =document.createElement("input");
 	        submit.type                ="button";
	        cancel.type                ="button";
	        submit.style.marginLeft    ="10px"  ;
	        submit.value               ="Order" ;
	        cancel.value               ="Exit"  ;   	    
    	    submit.onclick             =function(){me.makeBook()}
	        cancel.onclick             =function(){closePopup();}
	    
	    this.popup.innerHTML ="";
	    this.popup.innerHTML+="<div>Please enter your email address</div>";
	    this.popup.innerHTML+="<div><input type='text' /></div>";
	    this.popup.innerHTML+="<div>Please enter your home address</div>";
	    this.popup.innerHTML+="<div><input type='text' /></div><br/><br/>";
	    this.popup.appendChild(submit);
	    this.popup.appendChild(cancel);
    }
    
    function setNum(index,inputObj)
    {
    	var reg=/[0-9]+$/;
    	if(reg.test(inputObj.value))
    	{
    		this.items[index].num=inputObj.value;	
    	}
    	else
    	{
    		alert("Please enter a number");
    		inputObj.value=this.items[index].num;
    	}
    }
    
//end of class
}

function itemObj(item,num)
{
	this.item=item;
	this.num =num;
}


//************************************************************
function imgOperater(str)
{
	this.strArray         =false ;
	this.imageObj         =false ;
	
	this.getImgObjs       =getImgObjs;
	this.getImgNames      =getImgNames;
	this.showImg          =showImg;
	this.showImgName      =showImgName;
	this.numOfImg         =numOfImg;
	this.showUrl          =showUrl;
	
	imgOperater.call(this);
   
    /*********************************************
                 Constructer and other
    **********************************************/	
	
	function imgOperater()
	{
		this.strArray = str.split(";");
		this.imageObj = this.getImgObjs();
	}
	
	function getImgObjs()
	{
		var temp=new Array();
		for(var i=1; i<this.strArray.length; i++)
		{
			var imgArray =this.strArray[i].split(":");
			var id       =imgArray[0];
			var url_s    =this.strArray[0]+"_s/"+id+".jpg" ;
			var url_b    =this.strArray[0]+"_b/"+id+".JPG" ;
			var avaiable =eval(imgArray[1]);
			temp[i-1]    =new imgObject(id,url_s,url_b,avaiable);
		}
		return temp;
	}
	
    function getImgNames()
    {
		var string="";
		
		for(var i=0; i<this.imageObj.length; i++)
		{
			if(this.imageObj[i].id!="")
			{
				string+=this.imageObj[i].id;
			}
			else
			{
				string+="";
			}
			if(i!=this.imageObj.length-1)
			{
				string+=" & ";
			}
		}
		return string;
    }
	
	function numOfImg()
	{
		var num=0;
		for(var i=0; i<this.imageObj.length; i++)
		{
			if(this.imageObj[i].avaiable)
			{
				num++;
			}
		}
		return num;
	}
	
	function showImg(index,target,type)
	{
		var img                 =new Image();
		var tmp                 =new Image();
		var obj                 =this.imageObj[index];
		    tmp.src             ="./imgs/loadings.gif";
		    tmp.style.height    ="20px";
		    tmp.style.width     ="20px";
		    tmp.style.border    ="none";	    
		    target.innerHTML    ="";
		    
		    if(obj.avaiable)
		    {
		    	if(type==0)
		    	{
		    		img.src=obj.url_s;
		    		img.title="Click to view big photo";
		    	}
		    	else if(type==1)
		    	{
		    		img.src=obj.url_b;
		    		img.title="Click to close";
		    	}
		    	else
		    	{
		    		img.src=obj.url_s;
		    		img.title="Click to view big photo";
		    	}
		    }
		    else
		    {
		    	img.src ="./imgs/noPic.JPG";
		    	img.title ="Photo not avaiable as yet";
		    }
		    
		    if(img.complete)
		    {
		    	target.appendChild(img);
		    }
		    else
		    {
		        target.appendChild(tmp);
		    	img.onload=function(){target.removeChild(tmp); target.appendChild(img);}
		    }  
	}
	
	function showUrl(index,type)
	{
		var obj                 =this.imageObj[index];
	    var url                 ="";
		    
		    if(obj.avaiable)
		    {
		    	if(type==0)
		    	{
		    		url =obj.url_s;	
		    	}
		    	else if(type==1)
		    	{
		    		url =obj.url_b;	
		    	}
		    	else
		    	{
		    		url =obj.url_s;	
		    	}
		    }
		    else
		    {
		    	url ="./imgs/noPic.JPG";
		    }
	   return url;		
	}
	
	function showImgName(target)
	{
		var string="";
		
		for(var i=0; i<this.imageObj.length; i++)
		{
			if(this.imageObj[i].id!="")
			{
				if(this.imageObj[i].avaiable)
				{
					string+="<span style='color:#33FF00'>"+this.imageObj[i].id+"</span>";	
				}
				else
				{
					string+="<span style='color:#FF0000'>"+this.imageObj[i].id+"</span>";				
				}
			}
			else
			{
				string+="No Photo";
			}
			if(i!=this.imageObj.length-1)
			{
				string+=" & ";
			}
		}
		if(target)
		{
			target.innerHTML=string;	
		}
		else
		{
			return string;
		}
	}	
//end of class
}

function imgObject(id,url_s,url_b,avaiable)
{
	this.id =id;
	this.url_s=url_s;
	this.url_b=url_b;
	this.avaiable=avaiable;
}

//************************************************************
function pageLocker(load)
{
	this.baffle           = false;
	this.msg              = false;
	this.lock             = lock;
	this.load             = load;
	this.unlock           = unlock;
	this.showLoading      = showLoading;
	this.unshowLoading    = unshowLoading;


    /*********************************************
                 Constructer and other
    **********************************************/	
    		
	function lock()  
	{	
	    //add baffle
	    this.baffle=document.createElement("div");
	    //this.baffle.innerHTML="<div id='pageLoading'><img src='./imgs/loadings.gif' /><span>Please wait a second</span></div>";
		this.baffle.className="baffle";
		document.getElementById("background").appendChild(this.baffle);
		
		//change body
		if(!global_admin)
		{
			document.body.style.height   =document.documentElement.offsetHeight+"px";
			document.body.style.overflow ="hidden";	
		}
		
		//change mouse
		document.body.style.cursor="wait" ;
       		
		//set baffle size
		this.baffle.style.height=document.body.offsetHeight+"px";
		this.baffle.style.width =document.body.offsetWidth +"px";
	
        //show loading
		this.load?this.showLoading():"";
	}
		
	function unlock()
	{
		this.load?this.unshowLoading():"";
			
		//delete baffle
		document.getElementById("background").removeChild(this.baffle);
		this.baffle=false;

        //change mouse
        document.body.style.cursor="default";
        				
		//change body
		if(!global_admin)
		{
			document.body.style.height  ="auto";
			document.body.style.overflow="auto";	
		}
	}	
	
	function showLoading()
	{
		this.msg    =document.createElement("div");
		this.msg.id ="pageLoading";
		this.msg.innerHTML="<img src='./imgs/loadings.gif' /><span>Loading..... please wait for a few seconds</span>";
	    document.getElementById("background").appendChild(this.msg);
	}
	
	function unshowLoading()
	{
		document.getElementById("background").removeChild(this.msg);	
	}
}
//************************************************************

/*
 * From internet, with many thanks
 */
function getElementPos(elementId) 
{
	 var ua      = navigator.userAgent.toLowerCase();
	 var isOpera = (ua.indexOf('opera') != -1);
	 var isIE    = (ua.indexOf('msie') != -1 && !isOpera); // not opera spoof 
     var el      = document.getElementById(elementId);
     if(el.parentNode === null || el.style.display == 'none') 
     {
     	return false;
     }      
     
     var parent = null;
     var pos = [];     
     var box;     
     if(el.getBoundingClientRect)    //IE
     {         
     	box = el.getBoundingClientRect();
     	var scrollTop  = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
     	var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
     	return {x:box.left + scrollLeft, y:box.top + scrollTop};
     }
     else if(document.getBoxObjectFor)    // gecko    
     {
     	box = document.getBoxObjectFor(el); 
     	var borderLeft = (el.style.borderLeftWidth)?parseInt(el.style.borderLeftWidth):0; 
     	var borderTop  = (el.style.borderTopWidth)?parseInt(el.style.borderTopWidth):0; 
     	pos = [box.x - borderLeft, box.y - borderTop];
     } 
     // safari & opera 
     else       
     {
     	pos = [el.offsetLeft, el.offsetTop];  
     	parent = el.offsetParent;     
     	if (parent != el) 
     	{ 
     		while (parent) 
     		{  
     			pos[0] += parent.offsetLeft; 
     			pos[1] += parent.offsetTop; 
     			parent  = parent.offsetParent;
     		}  
     	}   
     	if (ua.indexOf('opera') != -1 || ( ua.indexOf('safari') != -1 && el.style.position == 'absolute' )) 
     	{ 
     		pos[0] -= document.body.offsetLeft;
     		pos[1] -= document.body.offsetTop;         
     	}    
     }              
     if (el.parentNode) 
     { 
     	parent  = el.parentNode;
     } 
     else 
     {
     	parent  = null;
     }
     // account for any scrolled ancestors
     while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML') 
     {
     	pos[0] -= parent.scrollLeft;
     	pos[1] -= parent.scrollTop;
     	if (parent.parentNode) 
     	{
     		parent = parent.parentNode;
     	} 
     	else 
     	{
     		parent = null;
     	}
     }
     return {x:pos[0], y:pos[1]};
}

//************************************************************
    
/*
 * Some addition functions
 */
    function getPosition(object)
    {
    	object.id="t_source";
    	var pos=getElementPos("t_source");
    	object.id="";
    	return pos;
    } 
     
     
    function runShow(object)
	{
	   object.id="t_source";
	   $("#t_source").hide();
	   $("#t_source").show("blind","",500);   
	   object.id="";
	}
	
	function runHide(object)
	{
	   object.id="t_source";
	   $("#t_source").hide();
	   $("#t_source").hide("blind","",500); 
	   object.id="";		
	}
	
	function runTransfer(source,target,funs)
	{
	   source.id="t_source";
	   target.id="t_target";

	   var options  ={to: "#t_target", className: 'ui-effects-transfer'};
	   $("#t_source").effect("transfer",options,500,funs);
	   
	   source.id="";
	   target.id="";
	}
	
    function showAuthor()
	{
	   document.getElementById("start").getElementsByTagName("div")[0].innerHTML="The Web Site was designed by Liang Xia, welcome!";
	}
	
	function standerOutput(string)
	{
		var re=/_/g;
		string=string.replace(re," ");
		return string;
	}
    
    function runWelcome()
	{
	   $("#start").hide("blind","",2800);
	}
	
	function showBookCond()
	{
		if(global_bookCond!=false)
	    {
	    	global_bookCond.close();
	    	global_bookCond=window.open("./html/BookCond.html","import","height=210px,width=335px,status=no,toolbar=no,location=center,left=250px")
	    }
	    else
	    {
	    	global_bookCond=window.open("./html/BookCond.html","import","height=210px,width=335px,status=no,toolbar=no,location=center,left=250px");
	    }
	}
	
	function preloadImgs()
	{
		global_imgs['loadingb']=new Image();
		global_imgs['loadings']=new Image();
		global_imgs['loadingb'].src="./imgs/loading.gif" ;
		global_imgs['loadings'].src="./imgs/loadings.gif";
	}
	

