(function ($j) {
	var E = {
		onClick: function () {
			$j(this).find('>a').each(function () {
				if (this.href) {
					window.location = this.href
				}
			})
		},
		arrowSrc: '',
		subDelay: 300,
		mainDelay: 10
	};
	$j.fn.clickMenu = function (f) {
		var g = false;
		var h = (($j.browser.msie) ? 4 : 2);
		var k = $j.extend({},
		E, f);
		var l = function (a, b) {
			if (a.timer && !a.isVisible) {
				clearTimeout(a.timer)
			} else if (a.timer) {
				return
			}
			if (a.isVisible) {
				a.timer = setTimeout(function () {
					$j(A(z(a, 'UL'), 'LI')).unbind('mouseover', s).unbind('mouseout', u).unbind('click', k.onClick);
					$j(a).hide();
					a.isVisible = false;
					a.timer = null
				},
				b)
			}
		};
		var m = function (b, c) {
			if (b.timer) {
				clearTimeout(b.timer)
			}
			if (!b.isVisible) {
				b.timer = setTimeout(function () {
					if (!C(b.parentNode, 'hover')) {
						return
					}
					$j(A(z(b, 'UL'), 'LI')).mouseover(s).mouseout(u).click(k.onClick);
					if (!C(b.parentNode, 'main')) {
						$j(b).css('left', b.parentNode.offsetWidth - h)
					}
					b.isVisible = true;
					$j(b).show();
					if ($j.browser.msie) {
						var a = $j(z(b, 'UL')).width();
						if (a < 100) {
							a = 100
						}
						$j(b).css('width', a)
					}
					b.timer = null
				},
				c)
			}
		};
		var o = function (e) {
			var p = (e.type == "mouseover" ? e.fromElement: e.toElement) || e.relatedTarget;
			while (p && p != this) {
				try {
					p = p.parentNode
				} catch(e) {
					p = this
				}
			}
			if (p == this) {
				return false
			}
			return true
		};
		var q = function (e) {
			var a = A(this.parentNode, 'LI');
			var b = new RegExp("(^|\\s)hover(\\s|$)");
			for (var i = 0; i < a.length; i++) {
				if (b.test(a[i].className)) {
					$j(a[i]).removeClass('hover')
				}
			}
			$j(this).addClass('hover');
			if (g) {
				t(this, k.mainDelay)
			}
		};
		var s = function (e) {
			if (!o(e)) {
				return false
			}
			if (e.target != this) {
				if (!D(this, e.target)) {
					return
				}
			}
			t(this, k.subDelay)
		};
		var t = function (a, b) {
			var c = z(a, 'DIV');
			var n = a.parentNode.firstChild;
			for (; n; n = n.nextSibling) {
				if (n.nodeType == 1 && n.nodeName.toUpperCase() == 'LI') {
					var d = z(n, 'DIV');
					if (d && d.timer && !d.isVisible) {
						clearTimeout(d.timer);
						d.timer = null
					}
				}
			}
			var e = a.parentNode;
			for (; e; e = e.parentNode) {
				if (e.nodeType == 1 && e.nodeName.toUpperCase() == 'DIV') {
					if (e.timer) {
						clearTimeout(e.timer);
						e.timer = null;
						$j(e.parentNode).addClass('hover')
					}
				}
			}
			$j(a).addClass('hover');
			if (c && c.isVisible) {
				if (c.timer) {
					clearTimeout(c.timer);
					c.timer = null
				} else {
					return
				}
			}
			$j(a.parentNode.getElementsByTagName('DIV')).each(function () {
				if (this != c && this.isVisible) {
					l(this, b);
					$j(this.parentNode).removeClass('hover')
				}
			});
			if (c) {
				m(c, b)
			}
		};
		var u = function (e) {
			if (!o(e)) {
				return false
			}
			if (e.target != this) {
				if (!D(this, e.target)) {
					return
				}
			}
			var a = z(this, 'DIV');
			if (!a) {
				$j(this).removeClass('hover')
			} else {
				if (!a.isVisible) {
					$j(this).removeClass('hover')
				}
			}
		};
		var v = function (e) {
			var a = z(this, 'DIV');
			var b = e.relatedTarget || e.toElement;
			var p;
			if (!g) {
				$j(this).removeClass('hover')
			} else if (!a && b) {
				p = B(e.target, 'UL', 'clickMenu');
				if (p.contains(b)) {
					$j(this).removeClass('hover')
				}
			} else if (b) {
				p = B(e.target, 'UL', 'clickMenu');
				if (!a.isVisible && (p.contains(b))) {
					$j(this).removeClass('hover')
				}
			}
		};
		var w = function () {
			var a = z(this, 'DIV');
			if (a && a.isVisible) {
				y();
				$j(this).addClass('hover')
			} else {
				t(this, k.mainDelay);
				g = true;
				$j(document).bind('mousedown', x)
			}
			return false
		};
		var x = function (e) {
			var a = false;
			var b = B(e.target, 'UL', 'clickMenu');
			if (b) {
				$j(b.getElementsByTagName('DIV')).each(function () {
					if (this.isVisible) {
						a = true
					}
				})
			}
			if (!a) {
				y()
			}
		};
		var y = function () {
			$j('ul.clickMenu div.outerbox').each(function () {
				if (this.timer) {
					clearTimeout(this.timer);
					this.timer = null
				}
				if (this.isVisible) {
					$j(this).hide();
					this.isVisible = false
				}
			});
			$j('ul.clickMenu li').removeClass('hover');
			$j('ul.clickMenu>li li').unbind('mouseover', s).unbind('mouseout', u).unbind('click', k.onClick);
			$j(document).unbind('mousedown', x);
			g = false
		};
		var z = function (a, b) {
			if (!a) {
				return null
			}
			var n = a.firstChild;
			for (; n; n = n.nextSibling) {
				if (n.nodeType == 1 && n.nodeName.toUpperCase() == b) {
					return n
				}
			}
			return null
		};
		var A = function (a, b) {
			if (!a) {
				return []
			}
			var r = [];
			var n = a.firstChild;
			for (; n; n = n.nextSibling) {
				if (n.nodeType == 1 && n.nodeName.toUpperCase() == b) {
					r[r.length] = n
				}
			}
			return r
		};
		var B = function (a, b, c) {
			var d = a.parentNode;
			var e = new RegExp("(^|\\s)" + c + "(\\s|$)");
			for (; d; d = d.parentNode) {
				if (d.nodeType == 1 && d.nodeName.toUpperCase() == b && e.test(d.className)) {
					return d
				}
			}
			return null
		};
		var C = function (a, b) {
			var c = new RegExp("(^|\\s)" + b + "(\\s|$)");
			if (c.test(a.className)) {
				return true
			}
			return false
		};
		var D = function (a, b) {
			var n = a.firstChild;
			for (; n; n = n.nextSibling) {
				if (n == b) {
					return true
				}
			}
			return false
		};
		return this.each(function () {
			if (window.Node && Node.prototype && !Node.prototype.contains) {
				Node.prototype.contains = function (a) {
					return !! (this.compareDocumentPosition(a) & 16)
				}
			}
			if (!C(this, 'clickMenu')) {
				$j(this).addClass('clickMenu')
			}
			$j('ul', this).shadowBox();
			if ($j.browser.msie && (!$j.browser.version || parseInt($j.browser.version) <= 6)) {
				if ($j.fn.bgiframe) {
					$j('div.outerbox', this).bgiframe()
				} else {
					$j('div.outerbox', this).append('<iframe style="display:block;position:absolute;top:0;left:0;z-index:-1;filter:mask();' + 'width:expression(this.parentNode.offsetWidth);height:expression(this.parentNode.offsetHeight)"/>')
				}
			}
			$j(this).bind('closemenu', function () {
				y()
			});
			var b = A(this, 'LI');
			for (var j = 0; j < b.length; j++) {
				if (z(z(z(b[j], 'DIV'), 'UL'), 'LI')) {
					$j(b[j]).click(w)
				}
			}
			$j(b).hover(q, v).addClass('main').find('>div').addClass('inner');
			if (k.arrowSrc) {
				$j('div.inner div.outerbox', this).before('<img src="' + k.arrowSrc + '" class="liArrow" />')
			}
			$j(this).wrap('<div class="cmDiv"></div>').after('<div style="clear: both; visibility: hidden;"></div>')
		})
	};
	$j.fn.clickMenu.setDefaults = function (o) {
		$j.extend(E, o)
	}
})(jQuery);
(function ($j) {
	$j.fn.shadowBox = function () {
		return this.each(function () {
			var a = $j('<div class="outerbox"></div>').get(0);
			if ($j(this).css('position') == 'absolute') {
				$j(a).css({
					position: 'relative',
					width: this.offsetWidth,
					height: this.offsetHeight
				})
			} else {
				$j(a).css('position', 'absolute')
			}
			$j(this).addClass('innerBox').wrap(a).before('<div class="shadowbox1"></div><div class="shadowbox2"></div><div class="shadowbox3"></div>')
		})
	}
})(jQuery);
