/* Copyright (c) 2010 Dmitriy Pakhtinov
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Version: 1.6.7b
 * Updated: 15.04.2011
 * 
 */

	var element = document.createElement("div");

	if (typeof element.firstElementChild == "undefined")
	{
		var ElementTravrsal = {
			firstElementChild: function() {
				var node = this.firstChild;
				while(node && node.nodeType != 1) node = node.nextSibling;
				return node;
			},

			lastElementChild: function() {
				var node = this.lastChild;
				while(node && node.nodeType != 1) node = node.previousSibling;
				return node;
			},

			nextElementSibling: function() {
				var node = this;
				do node = node.nextSibling
				while(node && node.nodeType != 1);
				return node;
			},

			previousElementSibling: function() {
				var node = this;
				do node = node.previousSibling;
				while(node && node.nodeType != 1);
				return node;
			},

			childElementCount: typeof element.children == "undefined" ? function() {
				var list = this.childNodes,
				i = list.length,
				j = 0;
				while(i--)
					if(list[i].nodeType == 1)
						j++;
				return j;
			} : function() {
				return this.children.length;
			}
		};

		if (Object.defineProperty)
			for (var property in ElementTravrsal)
				if (ElementTravrsal.hasOwnProperty(property))
					Object.defineProperty(Element.prototype, property, {
						get: ElementTravrsal[property]
					});

		if (Object.__defineGetter__)
			for(var property in ElementTravrsal)
				if(ElementTravrsal.hasOwnProperty(property))
					HTMLElement.prototype.__defineGetter__(property, ElementTravrsal[property]);
	}

	jQuery.fn.offsetTop = function()
	{
		var e = this.get(0);
		if (!e.offsetParent) return e.offsetTop;
		return e.offsetTop + jQuery(e.offsetParent).offsetTop();
	};

	jQuery.fn.offsetLeft = function()
	{
		var e = this.get(0);
		if (!e.offsetParent) return e.offsetLeft;
		return e.offsetLeft + jQuery(e.offsetParent).offsetLeft();
	};

	function innerSize()
	{
		var de = document.documentElement;
		var h = window.innerHeight || ( de && de.clientHeight ) || document.body.clientHeight;
		var w = window.innerWidth || ( de && de.clientWidth ) || document.body.clientWidth;
		var fh = ((document.body.offsetHeight > h) ? document.body.offsetHeight : h);
		var fw = ((document.body.offsetWidth > h) ? document.body.offsetWidth : w);
		return {"width": w, "height": h, "offsetWidth": fw, "offsetHeight": fh};
	}

	function screenHeight()
	{
		return jQuery.browser.opera ? window.innerHeight : jQuery(window).height();
	}

	function screenWidth()
	{
		return jQuery.browser.opera ? window.innerWidth : jQuery(window).width();
	}

	function _scrollTop()
	{
		return jQuery.browser.opera ? window.scrollY : jQuery(window).scrollTop();
	}

	function _scrollLeft()
	{
		return jQuery.browser.opera ? window.scrollX : jQuery(window).scrollLeft();
	}

	function hasClass(obj, name)
	{
		return obj && (new RegExp('(\\s|^)' + name + '(\\s|$)')).test(obj.className);
	}

	function addClass(obj, name)
	{
		if (obj && !hasClass(obj, name)) obj.className = (obj.className ? obj.className + ' ' : '') + name;
	}

	function removeClass(obj, name)
	{
		if (obj && hasClass(obj, name)) obj.className = obj.className.replace((new RegExp('(\\s|^)' + name + '(\\s|$)')), ' ');
	}

	function trim(str, charlist)
	{
		charlist = !charlist ? ' \xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
		var re = new RegExp('^[' + charlist + ']+|[' + charlist + ']+$', 'g');
		return str.replace(re, '');
	}

	function getStyle(selector, overrideStyle, retAttr)
	{
		var retval = {};

		var foundStyles = new Array();

		var sheet = document.styleSheets;
		for(var i = 0; i < sheet.length; i++)
		{
			try
			{
				var rules = ((sheet[i].cssRules) ? sheet[i].cssRules : ((sheet[i].rules) ? sheet[i].rules : []));
			} catch(e) {
				var rules = [];
			}

			for(var j = 0; j < rules.length; j++)
			{
				if (rules[j].selectorText)
				{
					if (rules[j].selectorText.toLowerCase() == selector.toLowerCase())
					{
						foundStyles.push(rules[j].style);
					}
				}
			}
		}

		if (overrideStyle)
		{
			if (typeof overrideStyle == "string")
			{
				overrideStyle = {"cssText": overrideStyle};
			} else if (!overrideStyle.cssText)
			{
				var cssText = "";
				for(var key in overrideStyle)
				{
					if (key != "length")
					{
						if (((typeof overrideStyle[key] == "string") || (typeof overrideStyle[key] == "number")) && (overrideStyle[key] !== ""))
						{
							cssText += key + ": " + overrideStyle[key] + "; ";
						}
					}
				}
				overrideStyle["cssText"] = cssText;
			}
			foundStyles.push(overrideStyle);
		}

		for(var i = 0; i < foundStyles.length; i++)
		{
			var params = foundStyles[i].cssText.split(";");
			for(var j = 0; j < params.length; j++)
			{
				var param = params[j].split(":");
				if (param.length > 1)
				{
					param.reverse();
					var key = param.pop();
					param.reverse();
					retval[trim(key).toLowerCase()] = trim(param.join(":"));
				}
			}
		}

		if (retAttr)
		{
			return ((retval[retAttr.toLowerCase()]) ? retval[retAttr.toLowerCase()] : '');
		}

		return retval;
	}

	jQuery.fn.blockEnter = function()
	{
		this.keypress(function(b){
			if (b.which == 13)
			{
				return false;
			}
		});
	}

	jQuery(document).ready(function()
	{
		function init()
		{
			function _createSelect(uid, elem, readonly, cn)
			{
				var test = jQuery('<div><div style="height:200px;">1<br/>1<br/>1<br/>1<br/></div></div>');
				test.css({"overflow-y": "scroll", "position": "absolute", "width": "100px", "height": "100px"});
				jQuery("body").append(test);
				var scrollbarWidth = test[0].offsetWidth - test.find('div')[0].offsetWidth - 1;
				test.remove();

				eclassName = cn;

				var margin = ((scrollbarWidth - 7) / 2);

				// create editable element
				var self = jQuery('<div id="' + eclassName + '_box_' + uid + '"></div>');

				if (readonly)
				{
					var input = jQuery('<input class="' + eclassName + '-input" value="' + elem.value + '" style="border-style: none; border: 0px; background-color: transparent; width: 0px !important;" />');
					var input_box = jQuery('<div id="' + eclassName + '_input_' + uid + '" style="position: absolute; overflow: hidden; margin: 0px; margin-bottom: -2px; padding: 0px; border-style: none; border: 0px; background-color: transparent; width: 0px !important;"></div>');
				} else {
					var input = jQuery('<input name="custom_' + elem.name + '" class="' + eclassName + '-input" value="' + elem.value + '" style="border-style: none; border: 0px; background-color: transparent;" />');
					var input_box = jQuery('<div id="' + eclassName + '_input_' + uid + '" style="position: absolute; overflow: hidden; margin: 0px; margin-bottom: -2px; padding: 0px; border-style: none; border: 0px; background-color: transparent;"></div>');
				}

				var preview = jQuery('<div class="' + eclassName + '-preview">' + elem.value + '</div>');
				var preview_box = jQuery('<div id="' + eclassName + '_preview_' + uid + '"></div>');

				var inputs_td = jQuery('<td style="vertical-align: top;"></td>');
				var selector_td = jQuery('<td style="vertical-align: top;"></td>');
				var table = jQuery('<table border="0" cellpadding="0" cellspacing="0"><tr></tr></table>');
				table.find('tr').append(inputs_td).append(selector_td);

				var dropdown = jQuery('<div></div>');
				var list = jQuery('<ul style="list-style-type: none; margin: 0; padding: 0; zoom: 1;"></ul>');
				var selector = jQuery('<table border="0" cellspacing="0" cellpadding="0"><tr><td style="border: 0px;"><div class="' + eclassName + '_selector_' + uid + '" style="overflow: hidden;">'+
						'<div style="margin-left: ' + margin + 'px; overflow: hidden; height: 1px; line-height: 1px; font-size: 1px; background-color: #000; width: 7px;">&nbsp;</div>'+
						'<div style="margin-left: ' + (margin + 1) + 'px; overflow: hidden; height: 1px; line-height: 1px; font-size: 1px; background-color: #000; width: 5px;">&nbsp;</div>'+
						'<div style="margin-left: ' + (margin + 2) + 'px; overflow: hidden; height: 1px; line-height: 1px; font-size: 1px; background-color: #000; width: 3px;">&nbsp;</div>'+
						'<div style="margin-left: ' + (margin + 3) + 'px; overflow: hidden; height: 1px; line-height: 1px; font-size: 1px; background-color: #000; width: 1px;">&nbsp;</div>'+
						'</div></td></tr></table>');

				preview_box.append(preview)
				input_box.append(input)
				inputs_td.append(input_box);
				inputs_td.append(preview_box);
				selector_td.append(selector);

				dropdown[0].hidden_on_empty = false;

				elem.new_select = self;
				self[0].mouseout_timer = null;
				self[0].input = input;
				self[0].input_box = input_box;
				self[0].preview = preview;
				self[0].preview_box = preview_box;
				self[0].selector = selector;
				self[0].dropdown = dropdown;
				self[0].list = list;
				self[0].readonly = readonly;
				self[0].outside = true;
				self[0].switch_outside = true;
				self[0].width_auto = false;
				elem.eclassName = eclassName;
				self[0].elem = elem;

				// set to unique identifier
				self[0].uid = uid;

				// save link to original input element
				self[0].input_element = jQuery(elem);

				// get style from document styleSheet and set over current input style
				var self_style = getStyle("." + eclassName, elem.style);
				var selector_style = getStyle("." + eclassName + "-selector");
				//var preview_style = getStyle("." + eclassName + "-preview");
				var dropdown_style = getStyle("." + eclassName + "-dropdown");
				var list_style = getStyle("." + eclassName + "-list");
				var input_style = getStyle("." + eclassName + "-input");

				if (!input_style["margin-bottom"])
				{
					input.css({"margin-bottom": "-2px"});
				}

				selector.css({"background-color": "#d0D6dd"});
				self[0].selector_default_bgcolor = "#d0D6dd";
				self[0].selector_over_bgcolor = "#E1E8ED";

				if (dropdown_style["visibility"])
				{
					dropdown[0].hidden_on_empty = true;
					delete dropdown_style["visibility"];
				}

				if ((elem.style["visibility"]) || (self_style["visibility"] == 'hidden'))
				{
					delete self_style["visibility"];
					elem.style["visibility"] = 'visible';
				}

				if (selector_style["background-color"])
				{
					selector.css({"background-color": selector_style["background-color"]});
					self[0].selector_default_bgcolor = selector_style["background-color"];
				}

				if (selector_style["color"])
				{
					selector.find("div").find("div").css("background-color", selector_style["color"]);
				}

				if (selector_style["outline-color"])
				{
					self[0].selector_over_bgcolor = selector_style["outline-color"];
					delete selector_style["outline-color"];
				}

				if (selector_style["width"])
				{
					scrollbarWidth = parseInt(selector_style["width"]);
				}

				if (self_style["width"])
				{
					if (self_style["width"].toLowerCase() == 'auto')
					{
						self[0].width_auto = true;
					}
				} else {
					self[0].width_auto = true;
					self_style["width"] = 'auto';
				}

				// put created element after current input
				jQuery(elem).after(self);

				var w = jQuery(elem).width();
				if (w == 0)
				{
					w = parseInt(jQuery(elem).css("width"));
				}

				var h = jQuery(elem).height();
				if (h == 0)
				{
					h = parseInt(jQuery(elem).css("height"));
				}

				if (self[0].width_auto) w += 8;

				// Fix IE
				var hideSelect = jQuery('<div style="display: none;"></div>');
				jQuery(elem).before(hideSelect);
				jQuery(elem).remove();
				hideSelect.append(elem);

				// set default style to new input element
				self.css("border", "1px solid #C0CAD5");
				self.css("width", w + "px");
				self.css("height", h + "px");

				dropdown.css({"border": "1px solid #C0CAD5"}).css(dropdown_style);

				// set generated style to new element and overriden "overflow" and "white-space"
				self.css(self_style).css({"white-space": "nowrap", "text-align": "left"});

				if (self.width() > 0)
				{
					w = self.width();
				}

				if (self.height() > 0)
				{
					h = self.height();
				}

				self.css("width", w + "px");
				self.css("height", h + "px");

				if (!readonly)
				{
					input.css({"width": (w - scrollbarWidth) + "px", "height": h + "px"});
					input_box.css({"width": (w - scrollbarWidth) + "px", "height": h + "px", "opacity": 0});
					if (!jQuery.browser.mozilla)
					{
						input_box.css({"padding-left": "1px", "width": (w - scrollbarWidth - 1) + "px", "height": h + "px"});
					} else {
						input_box.css({"width": (w - scrollbarWidth) + "px", "height": h + "px"});
					}
				}
				preview_box.css({"overflow": "hidden", "white-space": "nowrap", "width": (w - scrollbarWidth) + "px", "height": h + "px"});

				var padding = ((h - 4) / 2);
				selector.css({"height": (h - padding) + "px", "padding-top": padding + "px", "width": scrollbarWidth + "px"}).find('div.' + eclassName + '_selector_' + uid).css({"width": scrollbarWidth + "px"});

				selector.css(selector_style);

				self.append(table);
				self.after(dropdown);

				dropdown.css({"display": "none", "position": "absolute", "z-index": "100", "margin-top": "-1px", "overflow-x": "hidden", "overflow-y": "auto", "white-space": "nowrap", "width": w + "px"});

				list.css(list_style).css({"width": "100%"});

				dropdown[0].old_border = dropdown[0].style.border;
				dropdown[0].old_scrollTop = 0;

				dropdown.html(list);

				elem.optionActivate = function(this_opt)
				{
					this_opt.elem[0].new_select[0].preview.html(jQuery(this_opt).find("div").html());
					var value = jQuery("<div></div>").html(jQuery(this).find("div").html());
					var elcount = ((value[0].childElementCount) ? value[0].childElementCount : value[0].children.length);

					if (this_opt.close_dropdown)
					{
						if (elcount == 0)
						{
							this_opt.elem[0].new_select[0].input.val(jQuery(this_opt).find("div").html());
						} else {
							this_opt.elem[0].new_select[0].input.val(jQuery(jQuery(this_opt).find("div").html()).text());
						}
					}

					var old_selected = this_opt.elem[0].new_select[0].input_element.find('option:selected');

					if (this_opt.option !== old_selected[0])
					{
						old_selected.removeAttr("selected");
						//jQuery(this_opt.option).attr("selected", "selected");
						this_opt.option.selected = true;

						if (this_opt.elem[0].new_select[0].temp_item_selected)
						{
							removeClass(this_opt.elem[0].new_select[0].temp_item_selected, this_opt.elem[0].eclassName + '-list-selected');
							this_opt.elem[0].new_select[0].temp_item_selected = null;
						}

						if (this_opt.elem[0].new_select[0].item_selected !== null)
						{
							removeClass(this_opt.elem[0].new_select[0].item_selected, this_opt.elem[0].eclassName + '-list-selected');
						}

						addClass(this_opt, this_opt.elem[0].eclassName + '-list-selected');
						this_opt.elem[0].new_select[0].item_selected = this;

						this_opt.elem[0].new_select[0].input_element[0].value = this_opt.option.value;
						this_opt.elem[0].new_select[0].input_element.change();

						//if (this_opt.elem[0].new_select[0].input_element.change)
						//{
						//	this_opt.elem[0].new_select[0].input_element.change();
						//}
					}

					this_opt.elem[0].new_select[0].dropdown[0].old_scrollTop = this_opt.elem[0].new_select[0].dropdown[0].scrollTop;
					if (this_opt.close_dropdown)
					{
						this_opt.elem[0].new_select[0].dropdown.css("display", "none");
						this_opt.elem[0].new_select[0].preview_box.show();
						this_opt.elem[0].new_select[0].input_box.css({"opacity": 0, "position": "absolute"});
					}
					this_opt.close_dropdown = true;
				};

				elem.updateOptions = function()
				{
					var elem = jQuery(this);
					var select_options = elem.find("option");

					elem[0].new_select[0].dropdown.css({"height": "auto", "border": elem[0].new_select[0].dropdown[0].old_border, "width": elem[0].new_select.css("width")});
					elem[0].new_select[0].list.html("");
					elem[0].new_select[0].item_selected = null;
					elem[0].new_select[0].temp_item_selected = null;

					var current_width = parseInt(elem[0].new_select.css("width"));
					var current_preview_width = parseInt(elem[0].new_select[0].preview.css("width"));

					var tst = elem.html().toLowerCase().split('</option>');
					elem[0].is_custom = null;

					for(var i = 0; i < select_options.length; i++)
					{
						if (tst[i].replace(/<option/g, "").replace(/selected/g, "").replace(/>(.*)/g, "").replace(/[\s\t]+/g, "").indexOf('value') !== -1)
						{
							if (i == 11)
							{
								var h = elem[0].new_select[0].dropdown.height();
								if (h == 0)
								{
									var test = jQuery('<div style="position: absolute; left: -1000px;">' + elem[0].new_select[0].dropdown.html() + '</div>');
									jQuery("body").append(test);
									h = test.height();
									test.remove();
								}
								elem[0].new_select[0].dropdown.css({"height": h + "px", "border-right": "0px", "width": (parseInt(elem[0].new_select[0].dropdown.css("width")) + 1) + "px"});
							}

							option = jQuery('<li class="' + elem[0].eclassName + '-list-item"><div></div></li>');

							option[0].elem = elem;
							option[0].option = select_options[i];
							option[0].close_dropdown = true;
							select_options[i].option = option;

							option[0].activate = elem[0].optionActivate;

							option.mousedown(function(){
								this.activate(this);
							}).mouseover(function(){
								addClass(this, this.elem[0].eclassName + '-list-over');
							}).mouseout(function(){
								removeClass(this, this.elem[0].eclassName + '-list-over');
							});

							elem[0].new_select[0].list.append(option);

							var title = jQuery(select_options[i]).text();
							title = jQuery("<div>" + title + "</div>")[0].childElementCount == 0 ? title : jQuery("<div>" + title + "</div>").text();

							option.find('div').attr("title", title).html(jQuery(select_options[i]).text());

							if (select_options[i].selected)
							{
								addClass(option[0], elem[0].eclassName + '-list-selected');
								elem[0].new_select[0].item_selected = option[0];
							}
						} else {
							elem[0].is_custom = jQuery(select_options[i]);
						}

						if (select_options[i].selected)
						{
							elem[0].new_select[0].preview.html(jQuery(select_options[i]).text());

							var value = jQuery('<div></div>').html(jQuery(select_options[i]).text());
							var elcount = ((value[0].childElementCount) ? value[0].childElementCount : value[0].children.length);

							if (elcount == 0)
							{
								elem[0].new_select[0].input.val(jQuery(select_options[i]).text());
							} else {
								elem[0].new_select[0].input.val(jQuery(jQuery(select_options[i]).text()).text());
							}
						}

						if (elem[0].new_select[0].width_auto)
						{
							var save_html = elem[0].new_select[0].preview.html();
							elem[0].new_select[0].preview.html(jQuery(select_options[i]).text());
							if (elem[0].new_select.width() > current_width)
							{
								current_width = elem[0].new_select.width();
								current_preview_width = elem[0].new_select[0].preview.width();
							}
							elem[0].new_select[0].preview.html(save_html);
						}
					}

					if (elem[0].new_select[0].width_auto)
					{
						elem[0].new_select[0].dropdown.css({"width": current_width + "px"});
						elem[0].new_select.css("width", current_width + "px");
						elem[0].new_select[0].preview.css("width", current_preview_width + "px");
					}

					if (elem[0].is_custom == null)
					{
						elem[0].is_custom = jQuery('<option></option>');
						elem.prepend(elem[0].is_custom);
					} else {
						elem[0].is_custom.html('');
					}

					elem[0].new_select[0].dropdown[0].original_height = elem[0].new_select[0].dropdown[0].style.height;

				};

				elem.customVal = function(new_val)
				{
					if (typeof new_val != "undefined")
					{
						this.new_select[0].input.val(new_val);
						this.new_select[0].preview.html(new_val);
					}

					return this.new_select[0].input.val();
				};

				elem.checkText = function()
				{
					this.new_select[0].checkText = true;
					this.new_select[0].input.keyup();
					this.new_select[0].checkText = false;
				}

				self[0].input.keydown(function(e){
					self[0].keyEvent = e;
					if ((jQuery.browser.msie) && ((e.keyCode == 38) || (e.keyCode == 40)))
					{
						jQuery(this).keypress();
					}

					if ((typeof e.keyCode != "undefined") && (self[0].elem.onCustomKeyDown))
					{
						return self[0].elem.onCustomKeyDown(e, this);
					}
				}).keyup(function(e){
					if ((self[0].checkText) || ((!self[0].readonly) && (e.keyCode != 9) && (e.keyCode != 38) && (e.keyCode != 40)))
					{
						var options = jQuery(self[0].elem).find("option");
						var found = false;

						var dropdown_none = false;
						if (self[0].dropdown.css('display') == 'block')
						{
							self[0].dropdown.css('display', 'none');
							dropdown_none = true;
						}
						if (this.value.length > 0)
						{
							for(var i = 0; i < options.length; i++)
							{
								var text = jQuery(options[i]).text();

								var value = jQuery('<div></div>').html(text);
								if (value[0].childElementCount > 0)
								{
									text = jQuery(text).text();
								}

								if (text.toLowerCase() == this.value.toLowerCase())
								{
									options[i].option[0].close_dropdown = false;
									options[i].option[0].activate(options[i].option[0]);
									found = true;
								} else if (text.toLowerCase().indexOf(this.value.toLowerCase()) == 0) {
									if (options[i].option)
									{
										options[i].option.css("display", "block");
									}
								} else if (options[i].option) {
									options[i].option.css("display", "none");
									if ((self[0].temp_item_selected) && (self[0].temp_item_selected === options[i].option[0]))
									{
										removeClass(self[0].temp_item_selected, self[0].elem.eclassName + '-list-selected');
										self[0].temp_item_selected = null;
									}
								}
							}
						} else {
							for(var i = 0; i < options.length; i++)
							{
								if (options[i].option) {
									options[i].option.css("display", "block");
								}
							}
						}
						if (dropdown_none)
						{
							self[0].dropdown.css('display', 'block');
						}

						if (!found)
						{
							self[0].preview.html(this.value);

							self[0].input_element.find('option:selected').removeAttr("selected");
							self[0].elem.is_custom.attr("selected", "selected");

							if (self[0].item_selected !== null)
							{
								removeClass(self[0].item_selected, self[0].elem.eclassName + '-list-selected');
								self[0].item_selected = null;
								if ((self[0].temp_item_selected) && (!hasClass(self[0].temp_item_selected, self[0].elem.eclassName + '-list-selected')))
								{
									self[0].temp_item_selected = null;
								}
							}
						}

						if (self[0].dropdown[0].original_height != 'auto')
						{
							if (self[0].list.height() < self[0].dropdown[0].clientHeight)
							{
								if (self[0].dropdown[0].original_height == self[0].dropdown.css("height"))
								{
									self[0].dropdown.css({"height": "auto", "border": self[0].dropdown[0].old_border, "width": (parseInt(self[0].dropdown.css("width")) - 1) + "px"});
								}
							} else if (self[0].list.height() > parseInt(self[0].dropdown[0].original_height)) {
								if (self[0].dropdown[0].original_height != self[0].dropdown.css("height"))
								{
									self[0].dropdown.css({"height": self[0].dropdown[0].original_height, "border-right": "0px", "width": (parseInt(self[0].dropdown.css("width")) + 1) + "px"});
								}
							}
						}
						self[0].recalculateTop(self[0], false);
					}

					if ((!self[0].checkText) && (typeof e.keyCode != "undefined") && (self[0].elem.onCustomKeyUp))
					{
						return self[0].elem.onCustomKeyUp(e, this);
					}
				}).mousedown(function(e){
					if (self[0].dropdown.css("display") !== 'none')
					{
						self[0].checkText = true;
						jQuery(this).keyup();
						self[0].checkText = false;
					}
					if (self[0].elem.onCustomMouseDown)
					{
						return self[0].elem.onCustomMouseDown(e);
					}
				}).blur(function(e){
					if (!self[0].readonly)
					{
						options = jQuery(self[0].elem).find("option");
						var found = false;
						if (this.value.length > 0)
						{
							for(var i = 0; i < options.length; i++)
							{
								var text = jQuery(options[i]).text();

								var value = jQuery('<div></div>').html(text);
								if (value[0].childElementCount > 0)
								{
									text = jQuery(text).text();
								}

								if (text.toLowerCase() == this.value.toLowerCase())
								{
									options[i].option.mousedown();
									found = true;
								}
								if (options[i].option)
								{
									options[i].option.css("display", "block");
								}
							}
						}
						if (!found)
						{
							self[0].preview.html(this.value);

							self[0].input_element.find('option:selected').removeAttr("selected");
							self[0].elem.is_custom.attr("selected", "selected");

							if (self[0].item_selected !== null)
							{
								removeClass(self[0].item_selected, self[0].elem.eclassName + '-list-selected');
								self[0].item_selected = null;
							}

							if ( !self[0].dropdown[0].mouse_downeds ) {
								self[0].dropdown.css("display", "none");
								self[0].preview_box.show();
								self[0].input_box.css({"opacity": 0, "position": "absolute"});
							}
						}

						if (self[0].outside)
						{
							self.mouseout();
						}
					} else {
						if ( !self[0].dropdown[0].mouse_downeds ) {
							self[0].dropdown.css("display", "none");
							self[0].preview_box.show();
							self[0].input_box.css({"opacity": 0, "position": "absolute"});
						}

						if (self[0].outside)
						{
							self.mouseout();
						}
					}
					if (self[0].elem.onCustomBlur)
					{
						return self[0].elem.onCustomBlur(e);
					}
				}).focus(function(e){
					if (self[0].input_box.css('position') !== 'relative')
					{
						self[0].activate(self[0], true);
						self[0].switch_outside = false;
						self.mouseover();
						self[0].switch_outside = true;
					}
					if (self[0].elem.onCustomFocus)
					{
						return self[0].elem.onCustomFocus(e);
					}
				}).keypress(function(e){
					if (!e.keyCode)
					{
						e = self[0].keyEvent;
					}

					if ((jQuery.browser.mozilla) && (e.keyCode == 9))
					{
						jQuery(this).blur();
					}

					if ((e.keyCode == 38) || (e.keyCode == 40))
					{
						if ((self[0].item_selected) &&
							(self[0].item_selected.style.display !== 'none') &&
							((!self[0].temp_item_selected) ||
							(self[0].temp_item_selected.style.display == 'none'))
							)
						{
							self[0].temp_item_selected = self[0].item_selected;
						}

						if ((!self[0].temp_item_selected) ||
							(self[0].temp_item_selected.style.display == 'none'))
						{
							self[0].temp_item_selected = null;
						}

						if (e.keyCode == 40)
						{
							if (self[0].dropdown[0].style.display == 'none')
							{
								self[0].activate(self[0]);
							}

							var next_item_selected = null;
							if (self[0].temp_item_selected)
							{
								var next_item = jQuery(self[0].temp_item_selected).nextUntil();
								for(var i = 0; i < next_item.length; i++)
								{
									if (next_item[i].style.display !== 'none')
									{
										next_item_selected = next_item[i];
										break;
									}
								}
							} else {
								var list_children = self[0].list.children();
								for(var i = 0; i < list_children.length; i++)
								{
									if (list_children[i].style.display !== 'none')
									{
										next_item_selected = list_children[i];
										break;
									}
								}
							}
						} else if (e.keyCode == 38)
						{
							var next_item_selected = null;
							if (self[0].temp_item_selected)
							{
								var next_item = jQuery(self[0].temp_item_selected).prevUntil();
								for(var i = 0; i < next_item.length; i++)
								{
									if (next_item[i].style.display !== 'none')
									{
										next_item_selected = next_item[i];
										break;
									}
								}
							} else {
								var list_children = self[0].list.children();
								for(var i = list_children.length - 1; i >= 0; i--)
								{
									if (list_children[i].style.display !== 'none')
									{
										next_item_selected = list_children[i];
										break;
									}
								}
							}
						}

						if ((next_item_selected !== null) && (self[0].temp_item_selected))
						{
							removeClass(self[0].temp_item_selected, self[0].elem.eclassName + '-list-selected');
							self[0].temp_item_selected = null;
						}

						if (next_item_selected !== null)
						{
							addClass(next_item_selected, self[0].elem.eclassName + '-list-selected');
							self[0].temp_item_selected = next_item_selected;
							if (next_item_selected.offsetTop + next_item_selected.offsetHeight > self[0].dropdown[0].clientHeight + self[0].dropdown[0].old_scrollTop)
							{
								self[0].dropdown[0].old_scrollTop = next_item_selected.offsetTop - (self[0].dropdown[0].clientHeight) + next_item_selected.offsetHeight;
								self[0].dropdown[0].scrollTop = self[0].dropdown[0].old_scrollTop;
							} else if (next_item_selected.offsetTop < self[0].dropdown[0].old_scrollTop)
							{
								self[0].dropdown[0].old_scrollTop = next_item_selected.offsetTop;
								self[0].dropdown[0].scrollTop = self[0].dropdown[0].old_scrollTop;
							}
						}
					}

					if (e.keyCode == 13)
					{
						if (self[0].temp_item_selected)
						{
							self[0].temp_item_selected.activate(self[0].temp_item_selected);
							self[0].temp_item_selected = null;
						}
					}

					if ((typeof e.keyCode != "undefined") && (self[0].elem.onCustomKeyPress))
					{
						return self[0].elem.onCustomKeyPress(e, this);
					}

					// 38 = up, 40 = down
					if ((e.keyCode == 38) || (e.keyCode == 40) || (e.keyCode == 13))
					{
						return false;
					}
				});

				elem.updateOptions();

				// hide old input element
				jQuery(elem).css("display", "none");

				dropdown.mouseover(function(){
					self.mouseover();
				}).mouseout(function(){
					self.mouseout();
				});

				dropdown.mousedown(function(e){
					dropdown[0].mouse_downeds = true;
					if (!e)
					{
						e = window.event;
					}
					e.returnValue = false;
					if (e.stopPropagation) e.stopPropagation();
					else e.cancelBubble = true;
					if (e.preventDefault) e.preventDefault();
					else e.returnValue = false;
				}).mouseup(function(){
					dropdown[0].mouse_downeds = false;
				});

				dropdown[0].onmousewheel = function(e)
				{
					var wheelDelta = 0;
					var stop = false;

					if (!e)
					{
						e = window.event;
						stop = true;
					}

					if (e.wheelDelta)
					{
						wheelDelta = e.wheelDelta / 120;
					} else if (e.detail) {
						wheelDelta = -e.detail / 3;
					}

					var target = ((e.currentTarget) ? e.currentTarget : dropdown[0]);

					if (wheelDelta < 0)
					{
						if (stop)
						{
							target.scrollTop += 120;
						} else {
							if (target.scrollHeight - target.scrollTop <= target.clientHeight)
							{
								stop = true;
							}
						}
					} else if (wheelDelta > 0) {
						if (stop)
						{
							target.scrollTop -= 120;
						} else {
							if (target.scrollTop == 0)
							{
								stop = true;
							}
						}
					} else {
						stop = true;
					}

					if (stop)
					{
						if (e.preventDefault)
						{
							e.preventDefault();
						}
						e.returnValue = false;
						if (e.stopPropagation) e.stopPropagation();
						else e.cancelBubble = true;
						if (e.preventDefault) e.preventDefault();
						else e.returnValue = false;
					}
				}

				if (dropdown[0].addEventListener)
				{
					dropdown[0].addEventListener('DOMMouseScroll', dropdown[0].onmousewheel, false);
				} else {
					dropdown[0].attachEvent("onDOMMouseScroll", dropdown[0].onmousewheel);
				}

				self.mouseover(function(){
					if (this.switch_outside) this.outside = false;
					if (this.mouseout_timer)
					{
						clearTimeout(this.mouseout_timer);
						this.mouseout_timer = null;
					}
  					this.selector.stop(true, false).animate({
						backgroundColor: this.selector_over_bgcolor
					}, 200 );
				});

				self.mouseout(function(){
					if (this.switch_outside) this.outside = true;
					if (dropdown.css("display") == 'none')
					{
						elem = this;
						this.mouseout_timer = setTimeout(function(){
							elem.selector.stop(true, false).animate({
								backgroundColor: elem.selector_default_bgcolor
							}, 200);
						}, 0);
					}
				});

				function body_mousedown(e)
				{
					if (self[0].outside)
					{
						dropdown[0].mouse_downeds = false;
						dropdown.css("display", "none");
						self[0].preview_box.show();
						self[0].input_box.css({"opacity": 0, "position": "absolute"});
						self.mouseout();
					} else if (self[0].readonly) {
						if (!e) {
							e = window.event;
						}
						e.returnValue = false;
						if (e.stopPropagation) e.stopPropagation();
						else e.cancelBubble = true;
						if (e.preventDefault) e.preventDefault();
						else e.returnValue = false;
					}
				}

				jQuery(document).mousedown(function(e){
					body_mousedown(e);
				});

				self[0].recalculateTop = function(this_opt, updatescrollbar, selector_click)
				{
					var upHeight = screenHeight() - (screenHeight() - jQuery(this_opt).offsetTop()) - _scrollTop();
					var downHeight = ((screenHeight() - jQuery(this_opt).offsetTop()) - jQuery(this_opt).height()) + _scrollTop();
					var elemTop = jQuery(this_opt).offsetTop() + this_opt.offsetHeight;

					if (upHeight + _scrollTop() > dropdown[0].offsetHeight)
					{
						if ((downHeight < dropdown[0].offsetHeight) && (upHeight > downHeight))
						{
							elemTop = jQuery(this_opt).offsetTop() - dropdown[0].clientHeight;
						}
					}

					if (this_opt.item_selected !== null)
					{
						if (this_opt.item_selected.offsetTop > dropdown[0].clientHeight + dropdown[0].old_scrollTop)
						{
							dropdown[0].old_scrollTop = this_opt.item_selected.offsetTop - (dropdown[0].clientHeight / 2) + this_opt.item_selected.offsetHeight;
						}
					}

					dropdown.css("top", "0px");

					dropdown.css({"top": ((elemTop - dropdown.offsetTop()) - 1) + "px", "visibility": "hidden"});
					if (updatescrollbar)
					{
						dropdown[0].scrollTop = dropdown[0].old_scrollTop;
					}

					list[0].active_elemnt_count = 0;
					list[0].inactive_elemnt_count = 0;
					list.children().each(function(){
						if (this.style.display !== 'none')
						{
							dropdown.css({"visibility": "visible"});
							list[0].active_elemnt_count++;
						} else {
							list[0].inactive_elemnt_count++;
						}
					});

					if ((dropdown[0].hidden_on_empty) && (input[0].value.length == 0) && (!selector_click) && (list[0].inactive_elemnt_count == 0))
					{
						dropdown.css({"visibility": "hidden"});
					}

					if ((this_opt.item_selected !== null) && (list[0].active_elemnt_count == 1))
					{
						dropdown.css({"visibility": "hidden"});
					}
				};

				self[0].activate = function(this_opt, is_focus, selector_click){
					if ((this_opt.readonly) && (dropdown.css("display") !== 'none') && (!is_focus))
					{
						dropdown[0].mouse_downeds = false;
						dropdown.css("display", "none");
						this_opt.preview_box.show();
						this_opt.input_box.css({"opacity": 0, "position": "absolute"});
					} else if (dropdown.css("display") == 'none') {

						dropdown.css("display", "block");

						this_opt.recalculateTop(this_opt, false, selector_click);

						if (dropdown[0].original_height != 'auto')
						{
							if (list.height() < dropdown[0].clientHeight)
							{
								if (dropdown[0].original_height == dropdown.css("height"))
								{
									dropdown.css({"height": "auto", "border": dropdown[0].old_border, "width": (parseInt(dropdown.css("width")) - 1) + "px"});
								}
							} else if (list.height() > parseInt(dropdown[0].original_height)) {
								if (dropdown[0].original_height != dropdown.css("height"))
								{
									dropdown.css({"height": dropdown[0].original_height, "border-right": "0px", "width": (parseInt(dropdown.css("width")) + 1) + "px"});
								}
							}
						}

						if (this_opt.readonly)
						{
							this_opt.preview_box.show();
							this_opt.input_box.css({"opacity": 0, "position": "absolute"});
							if (!is_focus)
							{
								this_opt.input.focus();
							}
						} else {
							this_opt.preview_box.hide();
							this_opt.input_box.css({"opacity": 1, "position": "relative"});
							//this_opt.input.keyup();
						}

						this_opt.recalculateTop(this_opt, true, selector_click);
					}
				};

				self.mousedown(function(e){
					if (this.readonly) {
						this.activate(this);
					}
				});

				selector.mousedown(function(e){
					if (!self[0].readonly) {
						self[0].activate(self[0], false, true);
					}
				});

				self.mouseup(function(e){
					if ((!this.readonly) && (dropdown.css("display") !== 'none'))
					{
						this.input.focus();
					}
				});
			}

			window.updateSelects = function(selector) {
				var context = jQuery(selector);

				context.find(".de-select").each(function(uid, elem){
					var classes = jQuery(this).attr("class").split(" ");
					var cs = "de-select";

					for(var i = 0; i < classes.length; i++)
					{
						if (trim(classes[i]) == "de-select")
						{
							if (i + 1 < classes.length)
							{
								cs = trim(classes[i + 1]);
								break;
							}
						}
					}

					_createSelect(uid, elem, false, cs);
				});

				context.find(".de-select-readonly").each(function(uid, elem){
					var classes = jQuery(this).attr("class").split(" ");
					var cs = "de-select-readonly";

					for(var i = 0; i < classes.length; i++)
					{
						if (trim(classes[i]) == "de-select-readonly")
						{
							if (i + 1 < classes.length)
							{
								cs = trim(classes[i + 1]);
								break;
							}
						}
					}

					_createSelect(uid, elem, true, cs);
				});
			}

			updateSelects(document.body);
		}

		init();

		var current_button_downed = false;
		var current_button_overed = null;
		var current_button = null;

		jQuery("button.de-button").each(function(){
			var self = jQuery(this);

			var self_style = {};
			var sss = ((self.attr("style")) ? self.attr("style") : "").split(";");
			
			for(var i = 0; i < sss.length; i++) {
				var spl = sss[i].split(":");
				self_style[trim(spl[0])] = ((spl[1]) ? trim(spl[1]) : "");
			}
			
			var css = ((self.attr("style")) ? self.attr("style") : "");

			var classes = self.attr("class").split(" ");
			var cs = "";

			for(var i = classes.length - 1; i >= 0; i--)
			{
				self_style = getStyle("." + trim(classes[i]), self_style);
				if (trim(classes[i]) != "de-button")
				{
					cs = trim(classes[i]) + " " + cs;
				}
			}

			self.attr("class", "de-button");

			var skin_image = "";
			if (self_style['background-image'])
			{
				if (self_style['background-image'].match(/^url\(["']?([^'"]+)["']?\)$/i))
				{
					skin_image = RegExp.$1;
				}
			}

			if ((skin_image != "") && (self_style['height']))
			{
				self.css({"visibility": "hidden", "opacity": 1, "font-size": "1px", "overflow": "hidden"});

				var skin_image_load = new Image();

				self[0].button_style = self_style;
				self[0].skin_image = skin_image;
				self[0].new_class = cs;
				self[0].new_css = css;
				skin_image_load.self = self;

				jQuery(skin_image_load).load(function(){

					var button = jQuery('<table class="'+this.self[0].new_class+'" style="padding: 0; margin: 0; background-image: none; border-collapse: collapse; border: 0;'+this.self[0].new_css+'"><tr style="padding: 0; margin: 0;"></tr></table>');
					var button_tr = button.find("tr");
					var button_left_td = jQuery('<td style="padding: 0; margin: 0; text-align: left; vertical-align: top;"></td>');
					var button_center_td = jQuery('<td class="'+((this.self.attr("disabled")) ? 'disabled': 'normal') + '" style="padding-top: 0px; padding-bottom: 0px; margin: 0; background-image: url(\''+this.self[0].skin_image+'\'); background-repeat: repeat-x; text-align: center;" unselectable="on">'+this.self.html()+'</td>');
					var button_right_td = jQuery('<td style="padding: 0; margin: 0;"></td>');

					button_tr.append(button_left_td);
					button_tr.append(button_center_td);
					button_tr.append(button_right_td);
					this.self.before(button);

					delete this.self[0].button_style['visibility'];
					this.self[0].button_style['background-image'] = 'none';
					this.self[0].button_style['background-color'] = 'transparent';
					var clone = jQuery('<img src="/images/spacer.gif" />').css(this.self[0].button_style);
					if (this.self[0].button_style['z-index']) {
						clone[0].style.zIndex = parseInt(this.self[0].button_style['z-index']) + 100;
					}


					this.self.css({"visibility": "hidden", "position": "absolute", "width": "0px", "height": "0px"});


					clone[0].button_style = this.self[0].button_style;
					clone[0].skin_image = this.self[0].skin_image;
					clone[0].new_class = this.self[0].new_class;
					clone[0].new_css = this.self[0].new_css;
					clone[0].self = this.self;

					this.self[0].button_style = this.self[0].button_style;
					this.self[0].skin_image = this.self[0].skin_image;
					this.self[0].new_class = this.self[0].new_class;
					this.self[0].new_css = this.self[0].new_css;
					this.self[0].clone = clone;

					//this.self.remove();

					this.self[0].ie6support_trigger = false;

					clone.css({"position": "absolute"});

					button_left_td.append(clone);
					button_left_td.append('<div style="padding: 0; margin: 0; height: '+clone[0].button_style['height']+'; background-image: url(\''+this.self[0].skin_image+'\'); background-repeat: no-repeat;"></div>');
					button_right_td.append('<div style="padding: 0; margin: 0; height: '+clone[0].button_style['height']+'; background-image: url(\''+this.self[0].skin_image+'\'); background-repeat: no-repeat;"></div>');

					// Fix for IE6 and IE7 value parameter send.
					if (this.self[0].outerHTML)
					{
						if (this.self[0].outerHTML.match(/^<[^>]+\svalue="([^"]+)"[^>]{0,}>/i))
						{
							this.self.html(RegExp.$1);
						}
					}

					button[0].main_tr = button_tr;
					button[0].left_td = button_left_td;
					button[0].center_td = button_center_td;
					button[0].right_td = button_right_td;

					button[0].self = clone;
					clone[0].button = button;
					clone[0].image = this;
					clone[0].htmlContent = button_center_td;

					this.self[0].button = button;
					this.self[0].image = this;
					this.self[0].htmlContent = button_center_td;

					button.mouseover(function(){
						this.self.css({"width": jQuery(this).width() + "px"});
						if (clone[0].ie6support_trigger)
						{
							this.self.mouseover();
						}
					});

					button.mouseout(function(){
						if (clone[0].ie6support_trigger)
						{
							this.self.mouseout();
						}
					});

					button.mousedown(function(){
						if (clone[0].ie6support_trigger)
						{
							this.self.mousedown();
						}
					});

					button.mouseup(function(){
						if (clone[0].ie6support_trigger)
						{
							this.self.mouseup();
						}
					});

					button.click(function(){
						if (clone[0].ie6support_trigger)
						{
							this.self.click();
						}
					});

					this.self.focus(function(){
						jQuery(this).css({"width": this.button.width() + "px"});
					});

					this.self[0].ie6support = function(trigger)
					{
						this.ie6support_trigger = trigger;
						if (trigger)
						{
							jQuery(this).css("display", "none");
						} else {
							jQuery(this).css("display", "block");
						}
					}

					this.self[0].html = function(context)
					{
						if (!context) {
							return this.button[0].center_td.html();
						} else {
							this.button[0].center_td.html(context);
						}
					}

					this.self[0].setDisabledState = function()
					{
						this.button[0].left_td.children('div').css({"background-position": "0 0", "height": this.button_style['height'], "width": this.image.width + "px"});
						this.button[0].center_td.attr("class", "disabled").css("background-position", "0 -" + parseInt(this.button_style['height']) + "px");
						this.button[0].right_td.children('div').css({"background-position": "0 -" + (parseInt(this.button_style['height']) * 2) + "px", "height": this.button_style['height'], "width": this.image.width + "px"});
						if (this.button_style['width'])
						{
							this.button[0].center_td.css("width", (parseInt(this.button_style['width']) - (this.image.width * 2)) + "px");
						}
						jQuery(this.clone).css({"width": this.button.width() + "px", "height": this.button[0].right_td.find("div").css("height")});
						jQuery(this).attr("disabled", "disabled");
					}

					this.self[0].setNormalState = function()
					{
						this.button[0].left_td.children('div').css({"background-position": "0 -" + (parseInt(this.button_style['height']) * 3) + "px", "height": this.button_style['height'], "width": this.image.width + "px"});
						this.button[0].center_td.attr("class", "normal").css("background-position", "0 -" + (parseInt(this.button_style['height']) * 4) + "px");
						this.button[0].right_td.children('div').css({"background-position": "0 -" + (parseInt(this.button_style['height']) * 5) + "px", "height": this.button_style['height'], "width": this.image.width + "px"});
						if (this.button_style['width'])
						{
							this.button[0].center_td.css("width", (parseInt(this.button_style['width']) - (this.image.width * 2)) + "px");
						}
						jQuery(this.clone).css({"width": this.button.width() + "px", "height": this.button[0].right_td.find("div").css("height")});
						if (jQuery(this).attr("disabled"))
						{
							jQuery(this).removeAttr("disabled");
						}
					}

					this.self[0].setOverState = function()
					{
						this.button[0].left_td.children('div').css({"background-position": "0 -" + (parseInt(this.button_style['height']) * 6) + "px", "height": this.button_style['height'], "width": this.image.width + "px"});
						this.button[0].center_td.attr("class", "hover").css("background-position", "0 -" + (parseInt(this.button_style['height']) * 7) + "px");
						this.button[0].right_td.children('div').css({"background-position": "0 -" + (parseInt(this.button_style['height']) * 8) + "px", "height": this.button_style['height'], "width": this.image.width + "px"});
						if (this.button_style['width'])
						{
							this.button[0].center_td.css("width", (parseInt(this.button_style['width']) - (this.image.width * 2)) + "px");
						}
						jQuery(this.clone).css({"width": this.button.width() + "px", "height": this.button[0].right_td.find("div").css("height")});
						if (jQuery(this).attr("disabled"))
						{
							jQuery(this).removeAttr("disabled");
						}
					}

					this.self[0].setClickState = function()
					{
						this.button[0].left_td.children('div').css({"background-position": "0 -" + (parseInt(this.button_style['height']) * 9) + "px", "height": this.button_style['height'], "width": this.image.width + "px"});
						this.button[0].center_td.attr("class", "click").css("background-position", "0 -" + (parseInt(this.button_style['height']) * 10) + "px");
						this.button[0].right_td.children('div').css({"background-position": "0 -" + (parseInt(this.button_style['height']) * 11) + "px", "height": this.button_style['height'], "width": this.image.width + "px"});
						if (this.button_style['width'])
						{
							this.button[0].center_td.css("width", (parseInt(this.button_style['width']) - (this.image.width * 2)) + "px");
						}
						jQuery(this.clone).css({"width": this.button.width() + "px", "height": this.button[0].right_td.find("div").css("height")});
						if (jQuery(this).attr("disabled"))
						{
							jQuery(this).removeAttr("disabled");
						}
					}

					this.self[0].setAutoState = function()
					{
						if (current_button_overed == this)
						{
							this.setOverState();
						} else {
							this.setNormalState();
						}
					}

					if (this.self.attr("disabled"))
					{
						this.self[0].setDisabledState();
					} else {
						this.self[0].setNormalState();
					}

					clone.mouseover(function(e){
						current_button_overed = this.self[0];
						if (!this.self.attr("disabled"))
						{
							if (!current_button_downed)
							{
								this.self[0].setOverState();
							}
						}
						if (!e) {
							e = window.event;
						}
						if (e.stopPropagation) e.stopPropagation()
							else e.cancelBubble = true;
						if (e.preventDefault) e.preventDefault()
							else e.returnValue = false;
					}).mouseout(function(e){
						current_button_overed = null;
						if (!this.self.attr("disabled"))
						{
							if (!current_button_downed)
							{
								this.self[0].setNormalState();
							}
						}
						if (!e) {
							e = window.event;
						}
						if (e.stopPropagation) e.stopPropagation()
							else e.cancelBubble = true;
						if (e.preventDefault) e.preventDefault()
							else e.returnValue = false;
					}).mousedown(function(e){
						if (!this.self.attr("disabled"))
						{
							current_button = this.self[0];
							this.self[0].setClickState();
							current_button_downed = true;
						}
						if (!e) {
							e = window.event;
						}
						if (e.stopPropagation) e.stopPropagation()
							else e.cancelBubble = true;
						if (e.preventDefault) e.preventDefault()
							else e.returnValue = false;
					}).mouseup(function(e){
						if (!this.self.attr("disabled"))
						{
							if (this.self[0] == current_button)
							{
								if (current_button_overed == this.self[0])
								{
									this.self[0].setOverState();
								} else {
									this.self[0].setNormalState();
								}
								if ((current_button_overed == this.self[0]) && (current_button_downed))
								{
									jQuery(this.self[0]).trigger('click');
								}
							} else {
								current_button_overed = null;
								current_button_downed = false;
								if (current_button != null) jQuery(current_button).mouseup();
								this.self.mouseover();
							}
						} else {
							current_button_overed = null;
							current_button_downed = false;
							if (current_button != null) jQuery(current_button).mouseup();
							this.self.mouseover();
						}
						current_button = null;
						current_button_downed = false;

						if (!e) {
							e = window.event;
						}
						if (e.stopPropagation) e.stopPropagation()
							else e.cancelBubble = true;
						if (e.preventDefault) e.preventDefault()
							else e.returnValue = false;
					});
				});

				skin_image_load.src = skin_image;
			}
		});

		function body_mouseup(e)
		{
			if (current_button != null)
			{
				jQuery(current_button).mouseup();
				if (!e) {
					e = window.event;
				}
				if (e.stopPropagation) e.stopPropagation()
					else e.cancelBubble = true;
				if (e.preventDefault) e.preventDefault()
					else e.returnValue = false;
			}
		}

		jQuery(document).mouseup(function(e){
			body_mouseup(e);
		}).mousedown(function(){
			jQuery("input.de-checkbox").each(function(){
				if (this.focused) jQuery(this).blur();
			});
		}).mousemove(function(e){
			if (current_button_downed)
			{
				if (!e) {
					e = window.event;
				}
				if (e.stopPropagation) e.stopPropagation()
					else e.cancelBubble = true;
				if (e.preventDefault) e.preventDefault()
					else e.returnValue = false;
			}
		});

		jQuery("input.de-checkbox").each(function(){
			var checkbox = jQuery("<span class=\"de-checkbox\"></span>");
			checkbox.attr("style", jQuery(this).attr("style"));
			var clone = jQuery(this).css({"position": "absolute", "opacity": 0, "margin": "0px"}).clone(true);
			clone[0].checkbox_span = checkbox;
			clone[0].focused = false;
			clone[0].overed = false;
			checkbox.append(clone);
			jQuery(this).after(checkbox).remove();
			if (clone.is(':checked'))
			{
				checkbox.addClass("checked");
			}
			clone.focus(function(){
				if (!this.overed)
				{
					if (this.checked)
					{
						this.checkbox_span.removeClass('checked');
						this.checkbox_span.addClass("checked-hover");
					} else {
						this.checkbox_span.addClass("hover");
					}
				}
				this.focused = true;
			}).blur(function(){
				if (!this.overed)
				{
					if (this.checked)
					{
						this.checkbox_span.removeClass('checked-hover');
						this.checkbox_span.addClass("checked");
					} else {
						this.checkbox_span.removeClass("hover");
					}
				}
				this.focused = false;
			}).change(function(){
				if (!this.checked)
				{
					if (this.checkbox_span.hasClass('checked-hover'))
					{
						this.checkbox_span.addClass("hover");
						this.checkbox_span.removeClass('checked-hover');
					} else {
						this.checkbox_span.removeClass('checked');
					}
				} else {
					if (this.checkbox_span.hasClass("hover"))
					{
						this.checkbox_span.removeClass("hover");
						this.checkbox_span.addClass("checked-hover");
					} else {
						this.checkbox_span.addClass("checked");
					}
				}
			}).mouseover(function(){
				if (!this.focused)
				{
					if (this.checked)
					{
						if (!this.checkbox_span.hasClass("checked-hover"))
						{
							this.checkbox_span.addClass("checked-hover")
							this.checkbox_span.removeClass('checked');
						}
					} else {
						if (!this.checkbox_span.hasClass("hover"))
						{
							this.checkbox_span.addClass("hover")
						}
					}
				}
				this.overed = true;
			}).mouseout(function(){
				if (!this.focused)
				{
					if (this.checked)
					{
						this.checkbox_span.removeClass("checked-hover");
						this.checkbox_span.addClass("checked");
					} else {
						this.checkbox_span.removeClass("hover")
					}
				}
				this.overed = false;
			}).bind('check', function(){
				if (!this.checked)
				{
					this.checked = true;
					if (this.checkbox_span.hasClass("hover"))
					{
						this.checkbox_span.removeClass("hover");
						this.checkbox_span.addClass("checked-hover");
					} else {
						this.checkbox_span.addClass("checked");
					}
				}
			}).bind('uncheck', function(){
				if (this.checked)
				{
					this.checked = false;
					if (this.checkbox_span.hasClass("checked-hover"))
					{
						this.checkbox_span.addClass("hover");
						this.checkbox_span.removeClass("checked-hover");
					} else {
						this.checkbox_span.removeClass('checked');
					}
				}
			});
			if ((clone.attr("id")) && (clone.attr("id") != ""))
			{
				jQuery('label[for="' + clone.attr("id") + '"]').each(function(){
					this.input_element = clone;
					jQuery(this).mouseover(function(){
						this.input_element.mouseover();
					}).mouseout(function(){
						this.input_element.mouseout();
					});
				});
			}
		});

		jQuery("input.de-radio").each(function(){
			var radio = jQuery("<span class=\"de-radio\"></span>");
			radio.attr("style", jQuery(this).attr("style"));
			var clone = jQuery(this).css({"position": "absolute", "opacity": 0, "margin": "0px"}).clone(true);
			clone[0].radio_span = radio;
			clone[0].focused = false;
			clone[0].overed = false;
			radio.append(clone);
			jQuery(this).after(radio).remove();
			if (!this.form)
			{
				if (!document.body.null_form)
				{
					document.body.null_form = new Array();
				}
				document.body.null_form.push(clone);
			}
			if (clone.is(':checked'))
			{
				radio.addClass("checked");
			}
			clone.focus(function(){
				if (!this.overed)
				{
					if (this.checked)
					{
						this.radio_span.removeClass('checked');
						this.radio_span.addClass("checked-hover");
					} else {
						this.radio_span.addClass("hover");
					}
				}
				this.focused = true;
			}).blur(function(){
				if (!this.overed)
				{
					if (this.checked)
					{
						this.radio_span.removeClass('checked-hover');
						this.radio_span.addClass("checked");
					} else {
						this.radio_span.removeClass("hover");
					}
				}
				this.focused = false;
			}).change(function(){
				if (!this.form)
				{
					for(var i = 0; i < document.body.null_form.length; i++)
					{
						if ((document.body.null_form[i].attr("name")) &&
							(document.body.null_form[i].attr("name") != "") &&
							(document.body.null_form[i].attr("name") == jQuery(this).attr("name"))
							)
						{
							document.body.null_form[i][0].radio_span.removeClass('checked');
							document.body.null_form[i][0].radio_span.removeClass('checked-hover');
							if (document.body.null_form[i][0].overed)
							{
								document.body.null_form[i][0].radio_span.addClass('hover');
							}
						}
					}
				} else if ((jQuery(this).attr("name")) && (jQuery(this).attr("name") != "")) {
					jQuery(this.form).find('input[name="' + jQuery(this).attr("name") + '"]').each(function(){
						this.radio_span.removeClass('checked');
						this.radio_span.removeClass('checked-hover');
						if (this.overed)
						{
							this.radio_span.addClass('hover');
						}
					});
				}
				if (!this.checked)
				{
					this.radio_span.removeClass('checked');
					this.radio_span.removeClass('checked-hover');
					this.radio_span.addClass("hover");
				} else {
					this.radio_span.removeClass("hover");
					this.radio_span.addClass("checked-hover");
				}
			}).mouseover(function(){
				if (this.checked)
				{
					if (!this.radio_span.hasClass("checked-hover"))
					{
						this.radio_span.addClass("checked-hover")
					}
				} else {
					if (!this.radio_span.hasClass("hover"))
					{
						this.radio_span.addClass("hover")
					}
				}
				this.overed = true;
			}).mouseout(function(){
				if (this.checked)
				{
					if (!this.focused)
					{
						this.radio_span.removeClass("checked-hover");
						this.radio_span.addClass("checked");
					}
				} else {
					if (!this.focused)
					{
						this.radio_span.removeClass("hover")
					}
				}
				this.overed = false;
			});
			if ((clone.attr("id")) && (clone.attr("id") != ""))
			{
				jQuery('label[for="' + clone.attr("id") + '"]').each(function(){
					this.input_element = clone;
					jQuery(this).mouseover(function(){
						this.input_element.mouseover();
					}).mouseout(function(){
						this.input_element.mouseout();
					});
				});
			}
		});
	});

