/*
* timeago: a jQuery plugin, version: 0.7.1 (2009-02-18)
* @requires jQuery v1.2 or later
*
* Timeago is a jQuery plugin that makes it easy to support automatically
* updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
*
* For usage and examples, visit:
* http://timeago.yarp.com/
*
* Licensed under the MIT:
* http://www.opensource.org/licenses/mit-license.php
*
* Copyright (c) 2008-2009, Ryan McGeary (ryanonjavascript -[at]- mcgeary [*dot*] org)
*/
(function($) {
	$.timeago = function(timestamp) {
		if (timestamp instanceof Date) return inWords(timestamp);
		else if (typeof timestamp == "string") return inWords($.timeago.parse(timestamp));
		else return inWords($.timeago.parse($(timestamp).attr("title")));
	};
	var $t = $.timeago;

	$.extend($.timeago, {
		settings: {
			refreshMillis: 60000,
			allowFuture: false,
			strings: {
				prefixAgo: null,
				prefixFromNow: null,
				suffixAgo: "ago",
				suffixFromNow: "from now",
				ago: null, // DEPRECATED, use suffixAgo
				fromNow: null, // DEPRECATED, use suffixFromNow
				seconds: "less than a minute",
				minute: "about a minute",
				minutes: "%d minutes",
				hour: "about an hour",
				hours: "about %d hours",
				day: "a day",
				days: "%d days",
				month: "about a month",
				months: "%d months",
				year: "about a year",
				years: "%d years"
			}
		},
		inWords: function(distanceMillis) {
			var $l = this.settings.strings;
			var prefix = $l.prefixAgo;
			var suffix = $l.suffixAgo || $l.ago;
			if (this.settings.allowFuture) {
				if (distanceMillis < 0) {
					prefix = $l.prefixFromNow;
					suffix = $l.suffixFromNow || $l.fromNow;
				}
				distanceMillis = Math.abs(distanceMillis);
			}

			var seconds = distanceMillis / 1000;
			var minutes = seconds / 60;
			var hours = minutes / 60;
			var days = hours / 24;
			var years = days / 365;

			var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) ||
        seconds < 90 && substitute($l.minute, 1) ||
        minutes < 45 && substitute($l.minutes, Math.round(minutes)) ||
        minutes < 90 && substitute($l.hour, 1) ||
        hours < 24 && substitute($l.hours, Math.round(hours)) ||
        hours < 48 && substitute($l.day, 1) ||
        days < 30 && substitute($l.days, Math.floor(days)) ||
        days < 60 && substitute($l.month, 1) ||
        days < 365 && substitute($l.months, Math.floor(days / 30)) ||
        years < 2 && substitute($l.year, 1) ||
        substitute($l.years, Math.floor(years));

			return $.trim([prefix, words, suffix].join(" "));
		},
		parse: function(iso8601) {
			var s = $.trim(iso8601);
			s = s.replace(/-/, "/").replace(/-/, "/");
			s = s.replace(/T/, " ").replace(/Z/, " UTC");
			s = s.replace(/([\+-]\d\d)\:?(\d\d)/, " $1$2"); // -04:00 -> -0400
			return new Date(s);
		}
	});

	$.fn.timeago = function() {
		var self = this;
		self.each(refresh);

		var $s = $t.settings;
		if ($s.refreshMillis > 0) {
			setInterval(function() { self.each(refresh); }, $s.refreshMillis);
		}
		return self;
	};

	function refresh() {
		var date = $t.parse(this.title);
		if (!isNaN(date)) {
			$(this).text(inWords(date));
		}
		return this;
	}

	function inWords(date) {
		return $t.inWords(distance(date));
	}

	function distance(date) {
		return (new Date().getTime() - date.getTime());
	}

	function substitute(stringOrFunction, value) {
		var string = $.isFunction(stringOrFunction) ? stringOrFunction(value) : stringOrFunction;
		return string.replace(/%d/i, value);
	}

	// fix for IE6 suckage
	if ($.browser.msie && $.browser.version < 7.0) {
		document.createElement('abbr');
	}
})(jQuery);

/// <reference path="jquery-1.4.4-vsdoc.js" />
jQuery.fn.clickOutside = function (callback) {
	var outside = 1, self = $(this);
	self.cb = callback;
	this.click(function () {
		outside = 0;
	});
	$(document).click(function () {
		outside && self.cb();
		outside = 1;
	});
	return $(this);
}

$(document).ready(function () {
	$('#bar').jixedbar();
	$('#bar').show();

	$('abbr.timeago').timeago();
	function addDefaultKey(element, target) {
		$(element).keypress(function (e) {
			if (e.keyCode == 13) {
				e.returnValue = false;
				target();
				e.preventDefault();
				return false;
			}
		});
	}
	$('#alertList').click(function () {
		var url = $(this).data('clear');
		$.post(url);
		$('.alerts-new').addClass('alerts').removeClass('alerts-new');
		return false;
	});

	$.fn.checkField = function (options) {
		var defaults = {
			cssClass: 'hidden',
			msg: 'Error'
		};
		var options = $.extend({}, defaults, options);

		this.blur(function () {
			$.post(options.url,
				{
					value: $(this).val()
				},
				function (data) {
					if (data == 'False') {
						$(options.field).addClass(options.cssClass).text(options.msg);
					}
					else {
						$(options.field).removeClass(options.cssClass).text(options.msg);
					}
				}
			);
		});
		};
		
		if (notification) {
			$("#notification span").text(notification);
			$("#notification").fadeIn("slow");
		}
		$("#notification a.close-notify").click(function () {
			$("#notification").fadeOut("slow");
			return false;
		});

	$('.error-notification').live('click', function () {
		$(this).fadeOut('fast', function () { $(this).remove(); });
	});

	var $loginButton = $('#loginButton');
	var $loginBox = $('#loginBox');
	var $loginForm = $('#loginForm');

	var $accountButton = $('#accountButton');
	var $accountBox = $('#accountBox');

	$loginButton.removeAttr('href');
	$loginButton.click(function () {
		$loginBox.toggle();
		$loginButton.toggleClass('active');
		return false;
	});
	$accountButton.click(function () {
		$accountBox.toggle();
		$accountButton.toggleClass('active');
		return false;
	});
	$loginForm.click(function () {
		return false;
	});
	$loginForm.clickOutside(function () { $loginBox.hide(); });
	$accountBox.clickOutside(function () { $accountBox.hide(); });
	$('#forgotPassword').click(function() { location.href = $(this).attr('href'); return false; });
	$('#login').click(function () {
		$loginForm.submit();
	});
	$accountBox.find('a').click(function () {
		location.href = $(this).attr('href');
	});
});

function showErrorBox(message, $el) {
	$('.error-notification').remove();
	var $err = $('<div>').addClass('error-notification')
														.html(message + '(click on this box to close)');
	$el.after($err);
	var height = $err.outerHeight();
	var top = $el.position().top;
	var scrollTop = $(document).scrollTop();
	var winHeight = $(window).height();
	var bottomOfBox = top + height + $el.outerHeight() - scrollTop;
	if (bottomOfBox > winHeight) {
		$err.css('top', $el.position().top - height - $el.outerHeight());
	}
	$err.css('left', $el.position().left);
	$err.fadeIn('fast');
}
// GOOGLE ANALYTICS
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
try {
	var pageTracker = _gat._getTracker("UA-1607383-3");
	pageTracker._trackPageview();
} catch (err) { }
setInterval("update_page()", 60000);
function update_page() {
	$.post(userOnlineUrl, function (data) {
		$('#onlineUsers').html(data);
	});
}
//END GOOGLE ANALYTICS
/*
 * jixedbar - a jQuery fixed bar plugin.
 * http://code.google.com/p/jixedbar/
 * 
 * Version 0.0.4 (Beta)
 * 
 * Copyright (c) 2009-2010 Ryan Yonzon, http://ryan.rawswift.com/
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Last update - August 16, 2010
 */

(function($) { // start jixedbar's anonymous function

	// jixedbar plugin
	$.fn.jixedbar = function(options) {
		var constants = { // constant variables, magic variables that'll make the bar stick on the bottom or the top portion of any browser
				constOverflow: "hidden",
				constBottom: "0px"
			};
		var defaults = { // default options
				showOnTop: false, // show bar on top, instead of default bottom
				transparent: false, // enable/disable bar's transparent effect
				opacity: 0.9, // default bar opacity
				opaqueSpeed: "fast", // default opacity speed effect
				slideSpeed: "fast", // default slide effect
				roundedCorners: true, // rounded corners only works on FF, Chrome, Latest Opera and Safari
				roundedButtons: true, // only works on FF, Chrome, Latest Opera and Safari
				menuFadeSpeed: 250, // menu fade effect
				tooltipFadeSpeed: "slow", // tooltip fade effect
				tooltipFadeOpacity: 0.8 // tooltip fade opacity effect
			};
		var options = $.extend(defaults, options); // extend options
		/* IE6 detection method */
		var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
		/* var ie7 = window.XMLHttpRequest; // simple way to detect IE7 (see variable below) */
		var ie7 = (document.all && !window.opera && window.XMLHttpRequest); // ...but I guess this is a much more accurate method
		var button_active = false; // active button flag
		var active_button_name = ""; // name of current active button
		
		this.each(function() {
			var obj = $(this); // reference to selected element
			var screen = jQuery(this); // reference to client screen size
			var fullScreen = screen.width(); // get screen width
			var centerScreen = (fullScreen/2) * (1); // get screen center
			var hideBar = false; // default bar hide/show status

			obj.clickOutside(function () {
				if (active_button_name != '') {
					var $am = $('.jx-nav-menu-active');
					var $n = $('.jx-nav-menu');
					$n.hide();
					var $activeButton = $('a[name="' + active_button_name + '"]');
					$activeButton.next().addClass('jx-arrow-up').removeClass('jx-arrow-down');
					$activeButton.parent().removeClass('jx-nav-menu-active jx-nav-menu-active-rounded');
				}
			});

			if ($(this).checkCookie("JXID")) { // check if cookie already exists
				if ($(this).readCookie("JXHID") == "true") {
					this.hideBar = true; // hide bar
				}
			} else { // else drop cookie
				$(this).createCookie("JXID", $(this).genRandID()); // set random ID and create cookie
				$(this).createCookie("JXHID", false); // set bar hide to false then create cookie
			}
			
			// set html and body style for jixedbar to work
			if (($.browser.msie && ie6) || ($.browser.msie && ie7)) { // check if we have an IE client browser
                $("html").css({"overflow" : "hidden", "height" : "100%"});
                $("body").css({"margin": "0px", "overflow": "auto", "height": "100%"});
			} else { // else for FF, Chrome, Opera, Safari and other browser
				$("html").css({"height" : "100%"});
				$("body").css({"margin": "0px", "height": "100%"});
			}

			/* check what position method to use */
			if (($.browser.msie && ie6) || ($.browser.msie && ie7)) { // for IE browsers
				pos = "absolute";
			} else { // else for other browsers
				pos = "fixed";
			}
			
			// create hide container and button
			if ($(".jx-bar-button-right", this).exists()) { // check if there are currently an item on the right side portion of the bar
				$("<ul />").attr("id", "jx-hid-con-id").insertBefore($(this).find(".jx-bar-button-right:first")); // insert hide/show button "before" the existing item and let the "float right" do its magic
			} else { // else just append it and it'll automatically set to the right side of the bar
				$("<ul />").attr("id", "jx-hid-con-id").appendTo(this);
			}
			
				if ($.browser.msie && ie6) {
					$("#jx-hid-con-id").css({"width": "1px", "float": "right"}); // fix hide container width to prevent float drop issue on IE6 (any width other than "auto" or none specified)
				} else if ($.browser.msie && ie7) {
					$("#jx-hid-con-id").css({"width": "40px", "float": "right"}); // fix hide container width to prevent float drop issue on IE7
				}

			/* check what position should be the arrow indicator will be */
			if (defaults.showOnTop) {
				hideIndicator = "jx-hide-top"; // on the top
			} else {
				hideIndicator = "jx-hide"; // on the bottom
			}
			
			// insert the hide button indicator and add appropriate CSS class
			$("#jx-hid-con-id").html('<li alt="Hide toolbar"><a id="jx-hid-btn-id" class="' + hideIndicator + '"></a></li>');
			$("#jx-hid-con-id").addClass("jx-bar-button-right");
			
			// insert hide button separator and CSS class
			$("<span />").attr("id", "jx-hid-sep-id").insertAfter("#jx-hid-con-id");
			$("#jx-hid-sep-id").addClass("jx-hide-separator");
			
			// add click event on hide button
			$("#jx-hid-btn-id").parent().click(function() {
				$("#jx-menu-con-id").fadeOut();
				$(obj).slideToggle(defaults.slideSpeed, function() {
					$(this).createCookie("JXHID", true); // set bar hide to true
					if (!$(this).checkCookie("JXID")) { // check if cookie JXID exists, if not create one
						$(this).createCookie("JXID", $(this).genRandID()); // set random ID and drop cookie
					}
					$("#jx-uhid-con-id").slideToggle(defaults.slideSpeed);
				});
				return false;
			});
			
			// initialize bar
			$(this).css({
				"overflow": constants["constOverflow"],
				"position": pos
			});
			
			// set location: top or bottom
			if (defaults.showOnTop) {
				$(this).css({
					"top": constants["constBottom"]
				});				
			} else {
				$(this).css({
					"bottom": constants["constBottom"]
				});
			}
			
			// add bar style (theme)
			$(this).addClass("jx-bar");
			
			// rounded corner style (theme)
			if (defaults.roundedCorners) {
				if (defaults.showOnTop) {
					$(this).addClass("jx-bar-rounded-bl jx-bar-rounded-br");
				} else {
					$(this).addClass("jx-bar-rounded-tl jx-bar-rounded-tr");
				}
			}

			// button style (theme)
			$(this).addClass("jx-bar-button");
			
			// rounded button corner style (theme)
			if (defaults.roundedButtons) {
				$(this).addClass("jx-bar-button-rounded");
			}

			// calculate and adjust bar to the center
			marginLeft = centerScreen-($(this).width()/2);
			$(this).css({"margin-left": marginLeft});

			// fix image vertical alignment and border
			$("img", obj).css({
				"vertical-align": "bottom",
				"border": "#fff solid 0px" // no border
			});
			
			// check for alt attribute and set it as button text
			$(this).find("img").each(function() {
				if ($(this).attr("alt") != "") { // if image's ALT attribute is not empty then do the code below
					altName = "&nbsp;" + $(this).attr("alt"); // set button text using the image's ALT attribute
					$(this).parent().append(altName); // append it
				}
			});

			// check of transparency is enabled
			if (defaults.transparent) {
				$(this).fadeTo(defaults.opaqueSpeed, defaults.opacity); // do transparent effect
			}

			// create menu container first before creating the tooltip container, so tooltip will be on foreground
			$("<div />").attr("id", "jx-menu-con-id").appendTo("body");

			// add transparency effect on menu container if "transparent" is true
			if (defaults.transparent) {
				$("#jx-menu-con-id").fadeTo(defaults.opaqueSpeed, defaults.opacity);
			}
			
			/*
			 * create show/unhide container and button
			 */
			$("<div />").attr("id", "jx-uhid-con-id").appendTo("body"); // create div element and append in html body
			$("#jx-uhid-con-id").addClass("jx-show");
			$("#jx-uhid-con-id").css({
				"overflow": constants["constOverflow"],
				"position": pos,
				"margin-left": ($(this).offset().left + $(this).width()) - $("#jx-uhid-con-id").width() // calculate the show/unhide left margin/position
			});
			
			// set show/unhide location: top or bottom
			if (defaults.showOnTop) {
				$("#jx-uhid-con-id").css({
					"top": constants["constBottom"]
				});				
			} else {
				$("#jx-uhid-con-id").css({
					"bottom": constants["constBottom"]
				});				
			}
			
			// check if we need to add transparency to menu container
			if (defaults.transparent) {
				$("#jx-uhid-con-id").fadeTo(defaults.opaqueSpeed, defaults.opacity); 
			}

			// check if we need to hide the bar (based on cookie)
			if (this.hideBar) {
				$(this).css({
					"display": "none" // do not display the main bar
				});				
			}
			
			// check if we need to hide the show/unhide button (based on cookie)
			if (!this.hideBar) {
				$("#jx-uhid-con-id").css({
					"display": "none" // do not display the show/unhide button
				});
			}
			
			// create/append the show/unhide button item
			$("<ul />").attr("id", "jx-uhid-itm-id").appendTo($("#jx-uhid-con-id"));
			if (defaults.showOnTop) { // do we need to show this on top
				unhideIndicator = "jx-show-button-top";
			} else { // or on bottom (default)
				unhideIndicator = "jx-show-button";
			}
			// add the show/unhide item ("Show toolbar" button)
			$("#jx-uhid-itm-id").html('<li alt="Show toolbar"><a id="jx-uhid-btn-id" class="' + unhideIndicator + '"></a></li>');

			// show/unhide container and button style
			if (defaults.roundedCorners) {
				if (defaults.showOnTop) { // rounded corner CSS for top positioned bar
					$("#jx-uhid-con-id").addClass("jx-bar-rounded-bl jx-bar-rounded-br");
				} else { // rounded corner CSS for bottom positioned bar
					$("#jx-uhid-con-id").addClass("jx-bar-rounded-tl jx-bar-rounded-tr");
				}
			}
			$("#jx-uhid-con-id").addClass("jx-bar-button"); // add CSS style on show/unhide button based on the current theme
			if (defaults.roundedButtons) { // additional CSS style for rounded buttons
				$("#jx-uhid-con-id").addClass("jx-bar-button-rounded");
			}
			
			// add click event on show/unhide button
			$("#jx-uhid-con-id").click(function() {
				$(this).slideToggle(defaults.slideSpeed, function() {
					$(this).createCookie("JXHID", false); // set bar hide to false
					if (!$(this).checkCookie("JXID")) { // check if cookie JXID exists, if not create one
						$(this).createCookie("JXID", $(this).genRandID()); // set random ID and drop cookie
					}
					$(obj).slideToggle(defaults.slideSpeed); // slide toggle effect
					if (active_button_name != "") { // check if we have an active button (menu button)
						$("#jx-menu-con-id").fadeIn(); // if we have then do fade in effect
					}
				});
				return false; // return false to prevent any unnecessary click action
			});

			// create tooltip container
			$("<div />").attr("id", "jx-ttip-con-id").appendTo("body"); // create div element and append in html body
			$("#jx-ttip-con-id").css({ // CSS for tooltip container (invisible to viewer(s))
				"height": "auto",
				"margin-left": "0px",
				"width": "100%", // use entire width
				"overflow": constants["constOverflow"],
				"position": pos
			});
			
			// set tooltip container: top or bottom
			if (defaults.showOnTop) { // show on top?
				$("#jx-ttip-con-id").css({
					"margin-top": $(this).height() + 6, // put spacing between tooltip container and fixed bar
					"top": constants["constBottom"]
				});
			} else { // else bottom
				$("#jx-ttip-con-id").css({
					"margin-bottom": $(this).height() + 6, // put spacing between tooltip container and fixed bar
					"bottom": constants["constBottom"]
				});
			}
			
			// prevent browser from showing tooltip; replace title tag with alt tag; comply with w3c standard
			$("li", obj).each(function() { // iterate through LI element
				var _title = $(this).attr("title");
				if (_title != "") {
					$(this).removeAttr("title"); // remove TITLE attribute
					$(this).attr("alt", _title); // add (replace with) ALT attribute
				}
			});
			
			// bar container hover in and out event handler
			$("li", obj).hover(
				function () { // hover in method event
					var elemID = $(this).attr("id"); // get ID (w/ or w/o ID, get it anyway)					
					var barTooltipID = elemID + "jx-ttip-id"; // set a tooltip ID
					var tooltipTitle = $(this).attr("title");
			
					if (tooltipTitle == "") { // if no 'title' attribute then try 'alt' attribute
						tooltipTitle = $(this).attr("alt"); // this prevents IE from showing its own tooltip
					}
					
					if (tooltipTitle != "") { // show a tooltip if it's not empty
						// create tooltip wrapper; fix IE6's float double-margin bug
						barTooltipWrapperID = barTooltipID + "_wrapper";
						$("<div />").attr("id", barTooltipWrapperID).appendTo("#jx-ttip-con-id");
						// create tooltip div element and put it inside the wrapper
						$("<div />").attr("id", barTooltipID).appendTo("#" + barTooltipWrapperID);
						
						// tooltip default style
						$("#" + barTooltipID).css({
							"float": "left"
						});
						
						// theme for tooltip (theme)
						if ((defaults.showOnTop) && !($.browser.msie && ie6)) { // IE6 workaround; Don't add tooltip pointer if IE6
							$("<div />").addClass("jx-tool-point-dir-up").appendTo("#" + barTooltipID);
						}
							$("<div />").html(tooltipTitle).addClass("jx-bar-button-tooltip").appendTo("#" + barTooltipID);
							
						if ((!defaults.showOnTop) && !($.browser.msie && ie6)) { // IE6 workaround; Don't add tooltip pointer if IE6							
							$("<div />").addClass("jx-tool-point-dir-down").appendTo("#" + barTooltipID);
						}
						
						// fix tooltip wrapper relative to the associated button
						lft_pad = parseInt($(this).css("padding-left"));
						$("#" + barTooltipWrapperID).css({
							"margin-left": ($(this).offset().left - ($("#" + barTooltipID).width() / 2)) + ($(this).width()/2) + lft_pad // calculate left margin
						});
						
						/* check for active buttons; tooltip behavior */
						if ((($(this).find("a:first").attr("name") == "") || (button_active == false))) {
							$("#" + barTooltipID).fadeTo(defaults.tooltipFadeSpeed, defaults.tooltipFadeOpacity);
						} else if (active_button_name != $(this).find("a:first").attr("name")) {
							$("#" + barTooltipID).fadeTo(defaults.tooltipFadeSpeed, defaults.tooltipFadeOpacity);
						} else { // we got an active button here! (clicked state)
							$("#" + barTooltipID).css({ // prevent the tooltip from showing; if button if currently on-clicked state
								"display": "none"
							});
						}
						
					}
				}, 
				function () { // hover out method event
					var elemID = $(this).attr("id"); // get ID (whether there is an ID or none)					
					var barTooltipID = elemID + "jx-ttip-id"; // set a tooltip ID
					var barTooltipWrapperID = barTooltipID + "_wrapper";
					$("#" + barTooltipID).remove(); // remove tooltip element
					$("#" + barTooltipWrapperID).remove(); // remove tooltip's element DIV wrapper
				}
			);
			
			// show/unhide container hover in and out event handler
			$("li", $("#jx-uhid-con-id")).hover(
				function () { // in/over event
					var elemID = $(this).attr("id"); // get ID (w/ or w/o ID, get it anyway)					
					var barTooltipID = elemID + "jx-ttip-id"; // set a tooltip ID
					var tooltipTitle = $(this).attr("title");
					
					if (tooltipTitle == "") { // if no 'title' attribute then try 'alt' attribute
						tooltipTitle = $(this).attr("alt"); // this prevents IE from showing its own tooltip
					}
					
					if (tooltipTitle != "") { // show a tooltip if it is not empty
						// create tooltip wrapper; fix IE6's float double-margin bug
						barTooltipWrapperID = barTooltipID + "_wrapper";
						$("<div />").attr("id", barTooltipWrapperID).appendTo("#jx-ttip-con-id");
						// create tooltip div element and put it inside the wrapper
						$("<div />").attr("id", barTooltipID).appendTo("#" + barTooltipWrapperID);
						
						// tooltip default style
						$("#" + barTooltipID).css({
							"float": "left"
						});
						
						// theme for show/unhide tooltip
						if ((defaults.showOnTop) && !($.browser.msie && ie6)) {
							$("<div />").addClass("jx-tool-point-dir-up").appendTo("#" + barTooltipID);
						}

							$("<div />").html(tooltipTitle).addClass("jx-bar-button-tooltip").appendTo("#" + barTooltipID);
						
						if ((!defaults.showOnTop) && !($.browser.msie && ie6)) { 
							$("<div />").addClass("jx-tool-point-dir-down").appendTo("#" + barTooltipID);
						}
						
						// fix tooltip wrapper relative to the associated button
						ulft_pad = parseInt($(this).css("padding-left"));
						$("#" + barTooltipWrapperID).css({
							"margin-left": ($(this).offset().left - ($("#" + barTooltipID).width() / 2)) + ($(this).width()/2) + ulft_pad // calculate tooltip position
						});
						
						/* check for active buttons; tooltip behavior */
						if ((($(this).find("a:first").attr("name") == "") || (button_active == false))) {
							$("#" + barTooltipID).fadeTo(defaults.tooltipFadeSpeed, defaults.tooltipFadeOpacity);
						} else if (active_button_name != $(this).find("a:first").attr("name")) {
							$("#" + barTooltipID).fadeTo(defaults.tooltipFadeSpeed, defaults.tooltipFadeOpacity);
						} else {
							$("#" + barTooltipID).css({ // prevent the tooltip from showing; if button if currently on-clicked state
								"display": "none"
							});
						}
						
					}
				}, 
				function () { // out event
					var elemID = $(this).attr("id"); // get ID (whether there is an ID or none)
					var barTooltipID = elemID + "jx-ttip-id"; // set a tooltip ID
					var barTooltipWrapperID = barTooltipID + "_wrapper";
					$("#" + barTooltipID).remove(); // remove tooltip element
					$("#" + barTooltipWrapperID).remove(); // remove tooltip's element DIV wrapper
				}
			);

			// fix PNG transparency problem on IE6
			if ($.browser.msie && ie6) {
				$(this).find("li").each(function() {
					$(this).find("img").each(function() {
						imgPath = $(this).attr("src");
						altName = $(this).attr("alt");
						if (altName == "") { // workaround for IE6 bug: Menu item text does not show up on the popup menu
							altName = "&nbsp;&nbsp;" + $(this).attr("title");
						}
						srcText = $(this).parent().html();
						$(this).parent().html( // wrap with span element
							'<span style="cursor:pointer;display:inline-block;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + imgPath + '\');">' + srcText + '</span>&nbsp;' + altName
						);
					});
					$(this).find("img").each(function() {
						$(this).attr("style", "filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);"); // show image
					})
				});
			}
			
			// adjust bar on window resize event
			$(window).resize(
				function(){
					var screen = jQuery(this); // reference to client/viewers screen
					var screenWidth = screen.width(); // get current screen width
					var centerScreen = (screenWidth / 2) * (1); // get current screen center
					var marginLeft = centerScreen - ($(obj).width() / 2); // re-calculate and adjust bar's position
					$(obj).css({"margin-left": marginLeft}); // do it!
				}
			);
			
			/**
			 * Element click events
			 */
		
			// hide first level menu
			$("li", obj).find("ul").each(function() {
				$(this).css({"display": "none"}); // hide it! but we're listening to any click event
			});

			// create menu ID
			i = 1;
			$("li", obj).find("ul").each(function() {
				$(this).attr("id", "nav-" + i);
				$(this).parent().find("a:first").attr("href", "#"); // replace href attribute
				$(this).parent().find("a:first").attr("name", "nav" + i); // replace href attribute				

				if (defaults.showOnTop) { // check what position to use
					buttonIndicator = "jx-arrow-down"; // top
				} else {
					buttonIndicator = "jx-arrow-up"; // bottom
				}

				/* IE6/IE7 arrow indicator float drop fix: user replaced insertAfter with insertBefore */
				if (($.browser.msie && ie6) || ($.browser.msie && ie7)) {
					$("<div />").attr("class", buttonIndicator).insertBefore($(this).parent().find("a")).css({"background-position": "top"}); // IE6 and IE7 fix background position
				} else { // else any other browser
					$("<div />").attr("class", buttonIndicator).insertAfter($(this).parent().find("a")); // prevent Chrome from wrapping button text
				}
				
				// add click event (button)
				$(this).parent().find("a:first").click(function() {
					var elemID = $(this).attr("id"); // get ID (whether there is an ID or none)					
					var barTooltipID = elemID + "jx-ttip-id"; // set a tooltip ID
					var barTooltipWrapperID = barTooltipID + "_wrapper";
					
					$("#" + barTooltipID).remove(); // remove tooltip element
					$("#" + barTooltipWrapperID).remove(); // remove tooltip's element DIV wrapper

					if ((button_active) && (active_button_name == $(this).attr("name"))) { // is this an active button?
						if (defaults.showOnTop) { // check bar position
							buttonIndicator = "jx-arrow-down"; // top
						} else {
							buttonIndicator = "jx-arrow-up"; // bottom
						}
						$(this).parent().find("div").attr("class", buttonIndicator); // change button indicator
						
						$("#jx-menu-con-id").fadeOut(defaults.menuFadeSpeed); // remove/hide menu using fade effect
						$(this).parent().removeClass("jx-nav-menu-active"); // remove active state for this button (style)

						if (defaults.roundedButtons) { // remove additional CSS style if rounded corner button
							$(this).parent().removeClass("jx-nav-menu-active-rounded");
						}
						
						button_active = false; // remove button's active state
						active_button_name = "";
						$(this).blur(); // unfocus link/href
					} else {
						if (defaults.showOnTop) { // is bar's on the top position?
							buttonIndicator = "jx-arrow-up";
						} else {
							buttonIndicator = "jx-arrow-down";
						}
						$(this).parent().find("div").attr("class", buttonIndicator); // change button indicator
						
						$("#jx-menu-con-id").css({"display": "none"}); // hide menu container
						$("#jx-menu-con-id").html("<ul>" + $(this).parent().find("ul").html() + "</ul>");
						$("#jx-menu-con-id").css({
												"overflow": constants["constOverflow"],
												"position": pos,
												"margin-left": $(this).parent().offset().left // calculate menu container position by setting its left margin
											});

						// set menu container location: top or bottom
						if (defaults.showOnTop) { // top
							$("#jx-menu-con-id").css({
								"top": constants["constBottom"],
								"margin-top": $(obj).height() + 6
							});
						} else { // bottom
							$("#jx-menu-con-id").css({
								"bottom": constants["constBottom"],
								"margin-bottom": $(obj).height() + 6
							});
						}
						
						$("#jx-menu-con-id").addClass("jx-nav-menu");

							if ($.browser.msie && ie6) {	
								$("#jx-menu-con-id ul li a").css({"width": "100%"}); // IE6 and IE7 right padding/margin fix
							}

						if (defaults.roundedButtons) { // additional CSS style for rounded corner button
							$("#jx-menu-con-id").addClass("jx-nav-menu-rounded");
						}
						
						$(this).parent().addClass("jx-nav-menu-active"); // add active state CSS style
						
						if (defaults.roundedButtons) {
							$(this).parent().addClass("jx-nav-menu-active-rounded");
						}
						
						if (active_button_name != "") { // remove/hide any active button (on-clicked state)
							$("a[name='" + active_button_name + "']").parent().removeClass("jx-nav-menu-active");
							$("a[name='" + active_button_name + "']").parent().removeClass("jx-nav-menu-active-rounded");
							
							if (defaults.showOnTop) { // change button indicator (depends on the current bar's position)
								buttonIndicator = "jx-arrow-down";
							} else {
								buttonIndicator = "jx-arrow-up";
							}
							$("a[name='" + active_button_name + "']").parent().find("div").attr("class", buttonIndicator);
						}
						
						button_active = true; // change button's active state
						active_button_name = $(this).attr("name"); // save button name for future reference (e.g. remove active state)
						$(this).blur(); // unfocus link/href
						
						$("#jx-menu-con-id").fadeIn(defaults.menuFadeSpeed); // show menu container and its item(s)
					}
					return false; // prevent normal click action
				});
				
				i = i + 1;
			});
			
			// nav items click event
			$("li", obj).click(function () {
				if ($("ul", this).exists()) {
					$(this).find("a:first").click();
					return false;
				} else if ($(this).parent().attr("id") == "jx-hid-con-id") {
					// do nothing
					return false;
				}
				window.location = $(this).find("a:first").attr("href"); // emulate normal click event action (e.g. follow link)
				return false;
			});
			
		});
		
		return this;
		
	};
	
})(jQuery); // end of anonymous function

jQuery.fn.exists = function(){return jQuery(this).length>0;};

/**
 * Create a cookie
 */
jQuery.fn.createCookie = function(cookie_name, value) {
	var expiry_date = new Date(2037, 01, 01); // virtually, never expire!
	document.cookie = cookie_name + "=" + escape(value) + ";expires=" + expiry_date.toUTCString();
};

/**
 * Check cookie
 */
jQuery.fn.checkCookie = function(cookie_name) {
	if (document.cookie.length > 0) {
  		cookie_start = document.cookie.indexOf(cookie_name + "=");
  			if (cookie_start != -1) {
    			cookie_start = cookie_start + cookie_name.length + 1;
    			cookie_end = document.cookie.indexOf(";", cookie_start);
    			if (cookie_end == -1) cookie_end = document.cookie.length
    				return true;
			}
  	}
	return false;
}

/**
 * Extract cookie value
 */
jQuery.fn.extractCookieValue = function(value) {
	  if ((endOfCookie = document.cookie.indexOf(";", value)) == -1) {
	     endOfCookie = document.cookie.length;
	  }
	  return unescape(document.cookie.substring(value, endOfCookie));
}

/**
 * Read cookie
 */
jQuery.fn.readCookie = function(cookie_name) {
	  var numOfCookies = document.cookie.length;
	  var nameOfCookie = cookie_name + "=";
	  var cookieLen = nameOfCookie.length;
	  var x = 0;
	  while (x <= numOfCookies) {
	        var y = (x + cookieLen);
	        if (document.cookie.substring(x, y) == nameOfCookie)
	           return (this.extractCookieValue(y));
	           x = document.cookie.indexOf(" ", x) + 1;
	           if (x == 0){
	              break;
	           }
	  }
	  return (null);
}	

/**
 * Generate random ID
 */
jQuery.fn.genRandID = function() {
	var id = "";
	var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	for(var i=0; i < 24; i++) {
		id += str.charAt(Math.floor(Math.random() * str.length));
	}
    return id;
}

// end jixedbar package
/*
 * SimpleModal 1.4.1 - jQuery Plugin
 * http://www.ericmmartin.com/projects/simplemodal/
 * Copyright (c) 2010 Eric Martin (http://twitter.com/ericmmartin)
 * Dual licensed under the MIT and GPL licenses
 * Revision: $Id: jquery.simplemodal.js 261 2010-11-05 21:16:20Z emartin24 $
 */

/**
 * SimpleModal is a lightweight jQuery plugin that provides a simple
 * interface to create a modal dialog.
 *
 * The goal of SimpleModal is to provide developers with a cross-browser
 * overlay and container that will be populated with data provided to
 * SimpleModal.
 *
 * There are two ways to call SimpleModal:
 * 1) As a chained function on a jQuery object, like $('#myDiv').modal();.
 * This call would place the DOM object, #myDiv, inside a modal dialog.
 * Chaining requires a jQuery object. An optional options object can be
 * passed as a parameter.
 *
 * @example $('<div>my data</div>').modal({options});
 * @example $('#myDiv').modal({options});
 * @example jQueryObject.modal({options});
 *
 * 2) As a stand-alone function, like $.modal(data). The data parameter
 * is required and an optional options object can be passed as a second
 * parameter. This method provides more flexibility in the types of data
 * that are allowed. The data could be a DOM object, a jQuery object, HTML
 * or a string.
 *
 * @example $.modal('<div>my data</div>', {options});
 * @example $.modal('my data', {options});
 * @example $.modal($('#myDiv'), {options});
 * @example $.modal(jQueryObject, {options});
 * @example $.modal(document.getElementById('myDiv'), {options});
 *
 * A SimpleModal call can contain multiple elements, but only one modal
 * dialog can be created at a time. Which means that all of the matched
 * elements will be displayed within the modal container.
 *
 * SimpleModal internally sets the CSS needed to display the modal dialog
 * properly in all browsers, yet provides the developer with the flexibility
 * to easily control the look and feel. The styling for SimpleModal can be
 * done through external stylesheets, or through SimpleModal, using the
 * overlayCss, containerCss, and dataCss options.
 *
 * SimpleModal has been tested in the following browsers:
 * - IE 6, 7, 8, 9
 * - Firefox 2, 3, 4
 * - Opera 9, 10
 * - Safari 3, 4, 5
 * - Chrome 1, 2, 3, 4, 5, 6
 *
 * @name SimpleModal
 * @type jQuery
 * @requires jQuery v1.2.4
 * @cat Plugins/Windows and Overlays
 * @author Eric Martin (http://ericmmartin.com)
 * @version 1.4.1
 */
;(function ($) {
	var ie6 = $.browser.msie && parseInt($.browser.version) === 6 && typeof window['XMLHttpRequest'] !== 'object',
		ie7 = $.browser.msie && parseInt($.browser.version) === 7,
		ieQuirks = null,
		w = [];

	/*
	 * Create and display a modal dialog.
	 *
	 * @param {string, object} data A string, jQuery object or DOM object
	 * @param {object} [options] An optional object containing options overrides
	 */
	$.modal = function (data, options) {
		return $.modal.impl.init(data, options);
	};

	/*
	 * Close the modal dialog.
	 */
	$.modal.close = function () {
		$.modal.impl.close();
	};

	/*
	 * Set focus on first or last visible input in the modal dialog. To focus on the last
	 * element, call $.modal.focus('last'). If no input elements are found, focus is placed
	 * on the data wrapper element.
	 */
	$.modal.focus = function (pos) {
		$.modal.impl.focus(pos);
	};

	/*
	 * Determine and set the dimensions of the modal dialog container.
	 * setPosition() is called if the autoPosition option is true.
	 */
	$.modal.setContainerDimensions = function () {
		$.modal.impl.setContainerDimensions();
	};

	/*
	 * Re-position the modal dialog.
	 */
	$.modal.setPosition = function () {
		$.modal.impl.setPosition();
	};

	/*
	 * Update the modal dialog. If new dimensions are passed, they will be used to determine
	 * the dimensions of the container.
	 *
	 * setContainerDimensions() is called, which in turn calls setPosition(), if enabled.
	 * Lastly, focus() is called is the focus option is true.
	 */
	$.modal.update = function (height, width) {
		$.modal.impl.update(height, width);
	};

	/*
	 * Chained function to create a modal dialog.
	 *
	 * @param {object} [options] An optional object containing options overrides
	 */
	$.fn.modal = function (options) {
		return $.modal.impl.init(this, options);
	};

	/*
	 * SimpleModal default options
	 *
	 * appendTo:		(String:'body') The jQuery selector to append the elements to. For .NET, use 'form'.
	 * focus:			(Boolean:true) Focus in the first visible, enabled element?
	 * opacity:			(Number:50) The opacity value for the overlay div, from 0 - 100
	 * overlayId:		(String:'simplemodal-overlay') The DOM element id for the overlay div
	 * overlayCss:		(Object:{}) The CSS styling for the overlay div
	 * containerId:		(String:'simplemodal-container') The DOM element id for the container div
	 * containerCss:	(Object:{}) The CSS styling for the container div
	 * dataId:			(String:'simplemodal-data') The DOM element id for the data div
	 * dataCss:			(Object:{}) The CSS styling for the data div
	 * minHeight:		(Number:null) The minimum height for the container
	 * minWidth:		(Number:null) The minimum width for the container
	 * maxHeight:		(Number:null) The maximum height for the container. If not specified, the window height is used.
	 * maxWidth:		(Number:null) The maximum width for the container. If not specified, the window width is used.
	 * autoResize:		(Boolean:false) Automatically resize the container if it exceeds the browser window dimensions?
	 * autoPosition:	(Boolean:true) Automatically position the container upon creation and on window resize?
	 * zIndex:			(Number: 1000) Starting z-index value
	 * close:			(Boolean:true) If true, closeHTML, escClose and overClose will be used if set.
	 							If false, none of them will be used.
	 * closeHTML:		(String:'<a class="modalCloseImg" title="Close"></a>') The HTML for the default close link.
								SimpleModal will automatically add the closeClass to this element.
	 * closeClass:		(String:'simplemodal-close') The CSS class used to bind to the close event
	 * escClose:		(Boolean:true) Allow Esc keypress to close the dialog?
	 * overlayClose:	(Boolean:false) Allow click on overlay to close the dialog?
	 * position:		(Array:null) Position of container [top, left]. Can be number of pixels or percentage
	 * persist:			(Boolean:false) Persist the data across modal calls? Only used for existing
								DOM elements. If true, the data will be maintained across modal calls, if false,
								the data will be reverted to its original state.
	 * modal:			(Boolean:true) User will be unable to interact with the page below the modal or tab away from the dialog.
								If false, the overlay, iframe, and certain events will be disabled allowing the user to interact
								with the page below the dialog.
	 * onOpen:			(Function:null) The callback function used in place of SimpleModal's open
	 * onShow:			(Function:null) The callback function used after the modal dialog has opened
	 * onClose:			(Function:null) The callback function used in place of SimpleModal's close
	 */
	$.modal.defaults = {
		appendTo: 'body',
		focus: true,
		opacity: 50,
		overlayId: 'simplemodal-overlay',
		overlayCss: {},
		containerId: 'simplemodal-container',
		containerCss: {},
		dataId: 'simplemodal-data',
		dataCss: {},
		minHeight: null,
		minWidth: null,
		maxHeight: null,
		maxWidth: null,
		autoResize: false,
		autoPosition: true,
		zIndex: 1000,
		close: true,
		closeHTML: '<a class="modalCloseImg" title="Close"></a>',
		closeClass: 'simplemodal-close',
		escClose: true,
		overlayClose: false,
		position: null,
		persist: false,
		modal: true,
		onOpen: null,
		onShow: null,
		onClose: null
	};

	/*
	 * Main modal object
	 * o = options
	 */
	$.modal.impl = {
		/*
		 * Contains the modal dialog elements and is the object passed
		 * back to the callback (onOpen, onShow, onClose) functions
		 */
		d: {},
		/*
		 * Initialize the modal dialog
		 */
		init: function (data, options) {
			var s = this;

			// don't allow multiple calls
			if (s.d.data) {
				return false;
			}

			// $.boxModel is undefined if checked earlier
			ieQuirks = $.browser.msie && !$.boxModel;

			// merge defaults and user options
			s.o = $.extend({}, $.modal.defaults, options);

			// keep track of z-index
			s.zIndex = s.o.zIndex;

			// set the onClose callback flag
			s.occb = false;

			// determine how to handle the data based on its type
			if (typeof data === 'object') {
				// convert DOM object to a jQuery object
				data = data instanceof jQuery ? data : $(data);
				s.d.placeholder = false;

				// if the object came from the DOM, keep track of its parent
				if (data.parent().parent().size() > 0) {
					data.before($('<span></span>')
						.attr('id', 'simplemodal-placeholder')
						.css({display: 'none'}));

					s.d.placeholder = true;
					s.display = data.css('display');

					// persist changes? if not, make a clone of the element
					if (!s.o.persist) {
						s.d.orig = data.clone(true);
					}
				}
			}
			else if (typeof data === 'string' || typeof data === 'number') {
				// just insert the data as innerHTML
				data = $('<div></div>').html(data);
			}
			else {
				// unsupported data type!
				alert('SimpleModal Error: Unsupported data type: ' + typeof data);
				return s;
			}

			// create the modal overlay, container and, if necessary, iframe
			s.create(data);
			data = null;

			// display the modal dialog
			s.open();

			// useful for adding events/manipulating data in the modal dialog
			if ($.isFunction(s.o.onShow)) {
				s.o.onShow.apply(s, [s.d]);
			}

			// don't break the chain =)
			return s;
		},
		/*
		 * Create and add the modal overlay and container to the page
		 */
		create: function (data) {
			var s = this;

			// get the window properties
			w = s.getDimensions();

			// add an iframe to prevent select options from bleeding through
			if (s.o.modal && ie6) {
				s.d.iframe = $('<iframe src="javascript:false;"></iframe>')
					.css($.extend(s.o.iframeCss, {
						display: 'none',
						opacity: 0,
						position: 'fixed',
						height: w[0],
						width: w[1],
						zIndex: s.o.zIndex,
						top: 0,
						left: 0
					}))
					.appendTo(s.o.appendTo);
			}

			// create the overlay
			s.d.overlay = $('<div></div>')
				.attr('id', s.o.overlayId)
				.addClass('simplemodal-overlay')
				.css($.extend(s.o.overlayCss, {
					display: 'none',
					opacity: s.o.opacity / 100,
					height: s.o.modal ? w[0] : 0,
					width: s.o.modal ? w[1] : 0,
					position: 'fixed',
					left: 0,
					top: 0,
					zIndex: s.o.zIndex + 1
				}))
				.appendTo(s.o.appendTo);

			// create the container
			s.d.container = $('<div></div>')
				.attr('id', s.o.containerId)
				.addClass('simplemodal-container')
				.css($.extend(s.o.containerCss, {
					display: 'none',
					position: 'fixed',
					zIndex: s.o.zIndex + 2
				}))
				.append(s.o.close && s.o.closeHTML
					? $(s.o.closeHTML).addClass(s.o.closeClass)
					: '')
				.appendTo(s.o.appendTo);

			s.d.wrap = $('<div></div>')
				.attr('tabIndex', -1)
				.addClass('simplemodal-wrap')
				.css({height: '100%', outline: 0, width: '100%'})
				.appendTo(s.d.container);

			// add styling and attributes to the data
			// append to body to get correct dimensions, then move to wrap
			s.d.data = data
				.attr('id', data.attr('id') || s.o.dataId)
				.addClass('simplemodal-data')
				.css($.extend(s.o.dataCss, {
						display: 'none'
				}))
				.appendTo('body');
			data = null;

			s.setContainerDimensions();
			s.d.data.appendTo(s.d.wrap);

			// fix issues with IE
			if (ie6 || ieQuirks) {
				s.fixIE();
			}
		},
		/*
		 * Bind events
		 */
		bindEvents: function () {
			var s = this;

			// bind the close event to any element with the closeClass class
			$('.' + s.o.closeClass).bind('click.simplemodal', function (e) {
				e.preventDefault();
				s.close();
			});

			// bind the overlay click to the close function, if enabled
			if (s.o.modal && s.o.close && s.o.overlayClose) {
				s.d.overlay.bind('click.simplemodal', function (e) {
					e.preventDefault();
					s.close();
				});
			}

			// bind keydown events
			$(document).bind('keydown.simplemodal', function (e) {
				if (s.o.modal && e.keyCode === 9) { // TAB
					s.watchTab(e);
				}
				else if ((s.o.close && s.o.escClose) && e.keyCode === 27) { // ESC
					e.preventDefault();
					s.close();
				}
			});

			// update window size
			$(window).bind('resize.simplemodal', function () {
				// redetermine the window width/height
				w = s.getDimensions();

				// reposition the dialog
				s.o.autoResize ? s.setContainerDimensions() : s.o.autoPosition && s.setPosition();

				if (ie6 || ieQuirks) {
					s.fixIE();
				}
				else if (s.o.modal) {
					// update the iframe & overlay
					s.d.iframe && s.d.iframe.css({height: w[0], width: w[1]});
					s.d.overlay.css({height: w[0], width: w[1]});
				}
			});
		},
		/*
		 * Unbind events
		 */
		unbindEvents: function () {
			$('.' + this.o.closeClass).unbind('click.simplemodal');
			$(document).unbind('keydown.simplemodal');
			$(window).unbind('resize.simplemodal');
			this.d.overlay.unbind('click.simplemodal');
		},
		/*
		 * Fix issues in IE6 and IE7 in quirks mode
		 */
		fixIE: function () {
			var s = this, p = s.o.position;

			// simulate fixed position - adapted from BlockUI
			$.each([s.d.iframe || null, !s.o.modal ? null : s.d.overlay, s.d.container], function (i, el) {
				if (el) {
					var bch = 'document.body.clientHeight', bcw = 'document.body.clientWidth',
						bsh = 'document.body.scrollHeight', bsl = 'document.body.scrollLeft',
						bst = 'document.body.scrollTop', bsw = 'document.body.scrollWidth',
						ch = 'document.documentElement.clientHeight', cw = 'document.documentElement.clientWidth',
						sl = 'document.documentElement.scrollLeft', st = 'document.documentElement.scrollTop',
						s = el[0].style;

					s.position = 'absolute';
					if (i < 2) {
						s.removeExpression('height');
						s.removeExpression('width');
						s.setExpression('height','' + bsh + ' > ' + bch + ' ? ' + bsh + ' : ' + bch + ' + "px"');
						s.setExpression('width','' + bsw + ' > ' + bcw + ' ? ' + bsw + ' : ' + bcw + ' + "px"');
					}
					else {
						var te, le;
						if (p && p.constructor === Array) {
							var top = p[0]
								? typeof p[0] === 'number' ? p[0].toString() : p[0].replace(/px/, '')
								: el.css('top').replace(/px/, '');
							te = top.indexOf('%') === -1
								? top + ' + (t = ' + st + ' ? ' + st + ' : ' + bst + ') + "px"'
								: parseInt(top.replace(/%/, '')) + ' * ((' + ch + ' || ' + bch + ') / 100) + (t = ' + st + ' ? ' + st + ' : ' + bst + ') + "px"';

							if (p[1]) {
								var left = typeof p[1] === 'number' ? p[1].toString() : p[1].replace(/px/, '');
								le = left.indexOf('%') === -1
									? left + ' + (t = ' + sl + ' ? ' + sl + ' : ' + bsl + ') + "px"'
									: parseInt(left.replace(/%/, '')) + ' * ((' + cw + ' || ' + bcw + ') / 100) + (t = ' + sl + ' ? ' + sl + ' : ' + bsl + ') + "px"';
							}
						}
						else {
							te = '(' + ch + ' || ' + bch + ') / 2 - (this.offsetHeight / 2) + (t = ' + st + ' ? ' + st + ' : ' + bst + ') + "px"';
							le = '(' + cw + ' || ' + bcw + ') / 2 - (this.offsetWidth / 2) + (t = ' + sl + ' ? ' + sl + ' : ' + bsl + ') + "px"';
						}
						s.removeExpression('top');
						s.removeExpression('left');
						s.setExpression('top', te);
						s.setExpression('left', le);
					}
				}
			});
		},
		/*
		 * Place focus on the first or last visible input
		 */
		focus: function (pos) {
			var s = this, p = pos && $.inArray(pos, ['first', 'last']) !== -1 ? pos : 'first';

			// focus on dialog or the first visible/enabled input element
			var input = $(':input:enabled:visible:' + p, s.d.wrap);
			setTimeout(function () {
				input.length > 0 ? input.focus() : s.d.wrap.focus();
			}, 10);
		},
		getDimensions: function () {
			var el = $(window);

			// fix a jQuery/Opera bug with determining the window height
			var h = $.browser.opera && $.browser.version > '9.5' && $.fn.jquery < '1.3'
						|| $.browser.opera && $.browser.version < '9.5' && $.fn.jquery > '1.2.6'
				? el[0].innerHeight : el.height();

			return [h, el.width()];
		},
		getVal: function (v, d) {
			return v ? (typeof v === 'number' ? v
					: v === 'auto' ? 0
					: v.indexOf('%') > 0 ? ((parseInt(v.replace(/%/, '')) / 100) * (d === 'h' ? w[0] : w[1]))
					: parseInt(v.replace(/px/, '')))
				: null;
		},
		/*
		 * Update the container. Set new dimensions, if provided.
		 * Focus, if enabled. Re-bind events.
		 */
		update: function (height, width) {
			var s = this;

			// prevent update if dialog does not exist
			if (!s.d.data) {
				return false;
			}

			// reset orig values
			s.d.origHeight = s.getVal(height, 'h');
			s.d.origWidth = s.getVal(width, 'w');

			// hide data to prevent screen flicker
			s.d.data.hide();
			height && s.d.container.css('height', height);
			width && s.d.container.css('width', width);
			s.setContainerDimensions();
			s.d.data.show();
			s.o.focus && s.focus();

			// rebind events
			s.unbindEvents();
			s.bindEvents();
		},
		setContainerDimensions: function () {
			var s = this,
				badIE = ie6 || ie7;

			// get the dimensions for the container and data
			var ch = s.d.origHeight ? s.d.origHeight : $.browser.opera ? s.d.container.height() : s.getVal(badIE ? s.d.container[0].currentStyle['height'] : s.d.container.css('height'), 'h'),
				cw = s.d.origWidth ? s.d.origWidth : $.browser.opera ? s.d.container.width() : s.getVal(badIE ? s.d.container[0].currentStyle['width'] : s.d.container.css('width'), 'w'),
				dh = s.d.data.outerHeight(true), dw = s.d.data.outerWidth(true);

			s.d.origHeight = s.d.origHeight || ch;
			s.d.origWidth = s.d.origWidth || cw;

			// mxoh = max option height, mxow = max option width
			var mxoh = s.o.maxHeight ? s.getVal(s.o.maxHeight, 'h') : null,
				mxow = s.o.maxWidth ? s.getVal(s.o.maxWidth, 'w') : null,
				mh = mxoh && mxoh < w[0] ? mxoh : w[0],
				mw = mxow && mxow < w[1] ? mxow : w[1];

			// moh = min option height
			var moh = s.o.minHeight ? s.getVal(s.o.minHeight, 'h') : 'auto';
			if (!ch) {
				if (!dh) {ch = moh;}
				else {
					if (dh > mh) {ch = mh;}
					else if (s.o.minHeight && moh !== 'auto' && dh < moh) {ch = moh;}
					else {ch = dh;}
				}
			}
			else {
				ch = s.o.autoResize && ch > mh ? mh : ch < moh ? moh : ch;
			}

			// mow = min option width
			var mow = s.o.minWidth ? s.getVal(s.o.minWidth, 'w') : 'auto';
			if (!cw) {
				if (!dw) {cw = mow;}
				else {
					if (dw > mw) {cw = mw;}
					else if (s.o.minWidth && mow !== 'auto' && dw < mow) {cw = mow;}
					else {cw = dw;}
				}
			}
			else {
				cw = s.o.autoResize && cw > mw ? mw : cw < mow ? mow : cw;
			}

			s.d.container.css({height: ch, width: cw});
			s.d.wrap.css({overflow: (dh > ch || dw > cw) ? 'auto' : 'visible'});
			s.o.autoPosition && s.setPosition();
		},
		setPosition: function () {
			var s = this, top, left,
				hc = (w[0]/2) - (s.d.container.outerHeight(true)/2),
				vc = (w[1]/2) - (s.d.container.outerWidth(true)/2);

			if (s.o.position && Object.prototype.toString.call(s.o.position) === '[object Array]') {
				top = s.o.position[0] || hc;
				left = s.o.position[1] || vc;
			} else {
				top = hc;
				left = vc;
			}
			s.d.container.css({left: left, top: top});
		},
		watchTab: function (e) {
			var s = this;

			if ($(e.target).parents('.simplemodal-container').length > 0) {
				// save the list of inputs
				s.inputs = $(':input:enabled:visible:first, :input:enabled:visible:last', s.d.data[0]);

				// if it's the first or last tabbable element, refocus
				if ((!e.shiftKey && e.target === s.inputs[s.inputs.length -1]) ||
						(e.shiftKey && e.target === s.inputs[0]) ||
						s.inputs.length === 0) {
					e.preventDefault();
					var pos = e.shiftKey ? 'last' : 'first';
					s.focus(pos);
				}
			}
			else {
				// might be necessary when custom onShow callback is used
				e.preventDefault();
				s.focus();
			}
		},
		/*
		 * Open the modal dialog elements
		 * - Note: If you use the onOpen callback, you must "show" the
		 *	        overlay and container elements manually
		 *         (the iframe will be handled by SimpleModal)
		 */
		open: function () {
			var s = this;
			// display the iframe
			s.d.iframe && s.d.iframe.show();

			if ($.isFunction(s.o.onOpen)) {
				// execute the onOpen callback
				s.o.onOpen.apply(s, [s.d]);
			}
			else {
				// display the remaining elements
				s.d.overlay.show();
				s.d.container.show();
				s.d.data.show();
			}

			s.o.focus && s.focus();

			// bind default events
			s.bindEvents();
		},
		/*
		 * Close the modal dialog
		 * - Note: If you use an onClose callback, you must remove the
		 *         overlay, container and iframe elements manually
		 *
		 * @param {boolean} external Indicates whether the call to this
		 *     function was internal or external. If it was external, the
		 *     onClose callback will be ignored
		 */
		close: function () {
			var s = this;

			// prevent close when dialog does not exist
			if (!s.d.data) {
				return false;
			}

			// remove the default events
			s.unbindEvents();

			if ($.isFunction(s.o.onClose) && !s.occb) {
				// set the onClose callback flag
				s.occb = true;

				// execute the onClose callback
				s.o.onClose.apply(s, [s.d]);
			}
			else {
				// if the data came from the DOM, put it back
				if (s.d.placeholder) {
					var ph = $('#simplemodal-placeholder');
					// save changes to the data?
					if (s.o.persist) {
						// insert the (possibly) modified data back into the DOM
						ph.replaceWith(s.d.data.removeClass('simplemodal-data').css('display', s.display));
					}
					else {
						// remove the current and insert the original,
						// unmodified data back into the DOM
						s.d.data.hide().remove();
						ph.replaceWith(s.d.orig);
					}
				}
				else {
					// otherwise, remove it
					s.d.data.hide().remove();
				}

				// remove the remaining elements
				s.d.container.hide().remove();
				s.d.overlay.hide();
				s.d.iframe && s.d.iframe.hide().remove();
				setTimeout(function(){
					// opera work-around
					s.d.overlay.remove();

					// reset the dialog object
					s.d = {};
				}, 10);
			}
		}
	};
})(jQuery);


