/* core */


// jquery.bind.js

(function($){

$.bind = function(object, method){
	var args = Array.prototype.slice.call(arguments, 2);
	if(args.length){
		return function() {
			var args2 = [this].concat(args, $.makeArray( arguments ));
			return method.apply(object, args2);
		};
	} else {
		return function() {
			var args2 = [this].concat($.makeArray( arguments ));
			return method.apply(object, args2);
		};
	}
};
	
})(jQuery);
/* end */

// ui.checkbox.js
(function($){
    $.widget('ui.checkBox', {
        _init: function(){
            var that = this, 
			
				opts = this.options,
					
				toggleHover = function(e){
					if(this.disabledStatus){
						return false;
					}
					that.hover = (e.type == 'focus' || e.type == 'mouseenter');
					that._changeStateClassChain();
				};
			if(!this.element.is(':radio,:checkbox')){
				return false;
			}
            this.labels = $([]);
			
            this.checkedStatus = false;
			this.disabledStatus = false;
			this.hoverStatus = false;
            
            this.radio = (this.element.is(':radio'));
			
			this.visualElement = $('<span />')
				.addClass(this.radio ? 'ui-radio' : 'ui-checkbox')
				.bind('mouseenter.checkBox mouseleave.checkBox', toggleHover)
				.bind('click.checkBox', function(e){
					that.element[0].click();
					//that.element.trigger('click');
					return false;
				});		
            
            if (opts.replaceInput) {
				this.element
					.addClass('ui-helper-hidden-accessible')
					.after(this.visualElement[0])
					.bind('usermode', function(e){
	                    (e.enabled &&
	                        that.destroy.call(that, true));
	                });
            }
			
			this.element
				.bind('click.checkBox', $.bind(this, this.reflectUI))
				.bind('focus.checkBox blur.checkBox', toggleHover);
				
			if(opts.addLabel){
				//ToDo: Add Closest Ancestor
				this.labels = $('label[for=' + this.element.attr('id') + ']')
					.bind('mouseenter.checkBox mouseleave.checkBox', toggleHover);
			}
			
            this.reflectUI({type: 'initialReflect'});
        },
		_changeStateClassChain: function(){
			var stateClass = (this.checkedStatus) ? '-checked' : '',
				baseClass = 'ui-'+((this.radio) ? 'radio' : 'checkbox')+'-state';
			
			stateClass += (this.disabledStatus) ? '-disabled' : '';
			stateClass += (this.hover) ? '-hover' : '';
				
			if(stateClass){
				stateClass = baseClass + stateClass;
			}
			
			function switchStateClass(){
				var classes = this.className.split(' '),
					found = false;
				$.each(classes, function(i, classN){
					if(classN.indexOf(baseClass) === 0){
						found = true;
						classes[i] = stateClass;
						return false;
					} 
				});
				if(!found){
					classes.push(stateClass);
				}
				
				this.className = classes.join(' ');
			}
			
			this.labels.each(switchStateClass);
			this.visualElement.each(switchStateClass);
		},
        destroy: function(onlyCss){
            this.element.removeClass('ui-helper-hidden-accessible');
			this.visualElement.addClass('ui-helper-hidden');
            if (!onlyCss) {
                var o = this.options;
                this.element.unbind('.checkBox');
				this.visualElement.remove();
                this.labels
					.unbind('.checkBox')
					.removeClass('ui-state-hover ui-state-checked ui-state-disabled');
            }
        },
		
        disable: function(){
            this.element[0].disabled = true;
            this.reflectUI({type: 'manuallyDisabled'});
        },
		
        enable: function(){
            this.element[0].disabled = false;
            this.reflectUI({type: 'manuallyenabled'});
        },
		
        toggle: function(e){
            this.changeCheckStatus((this.element.is(':checked')) ? false : true, e);
        },
		
        changeCheckStatus: function(status, e){
            if(e && e.type == 'click' && this.element[0].disabled){
				return false;
			}
			this.element.attr({'checked': status});
            this.reflectUI(e || {
                type: 'changeCheckStatus'
            });
        },
		
        propagate: function(n, e, _noGroupReflect){
			if(!e || e.type != 'initialReflect'){
				if (this.radio && !_noGroupReflect) {
					//dynamic
	                $(document.getElementsByName(this.element.attr('name')))
						.checkBox('reflectUI', e, true);
	            }
	            return this._trigger(n, e, {
	                options: this.options,
	                checked: this.checkedStatus,
	                labels: this.labels,
					disabled: this.disabledStatus
	            });
			}
        },
		
        reflectUI: function(elm, e){
            var oldChecked = this.checkedStatus, 
				oldDisabledStatus = this.disabledStatus;
            e = e ||
            	elm;
					
			this.disabledStatus = this.element.is(':disabled');
			this.checkedStatus = this.element.is(':checked');
			
			if (this.disabledStatus != oldDisabledStatus || this.checkedStatus !== oldChecked) {
				this._changeStateClassChain();
				
				(this.disabledStatus != oldDisabledStatus &&
					this.propagate('disabledChange', e));
				
				(this.checkedStatus !== oldChecked &&
					this.propagate('change', e));
			}
            
        }
    });
    $.ui.checkBox.defaults = {
        replaceInput: true,
		addLabel: true
    };
    
})(jQuery);

/* end */
/*	ColorBox v1.3.3 - a full featured, light-weight, customizable lightbox based on jQuery 1.3 */
(function(c) { var s = "colorbox", B = "hover", o = true, g = false, e, E = !c.support.opacity, N = E && !window.XMLHttpRequest, O = "click.colorbox", fa = "cbox_open", J = "cbox_load", P = "cbox_complete", Q = "cbox_cleanup", aa = "cbox_closed", R = "resize.cbox_resize", u, j, x, p, S, T, U, V, h, r, n, K, L, ba, W, y, F, G, M, C, D, z, A, m, k, a, H, I, X, Y = { transition: "elastic", speed: 350, width: g, height: g, innerWidth: g, innerHeight: g, initialWidth: "400", initialHeight: "400", maxWidth: g, maxHeight: g, scalePhotos: o, scrolling: o, inline: g, html: g, iframe: g, photo: g, href: g, title: g, rel: g, opacity: 0.9, preloading: o, current: "image {current} of {total}", previous: "previous", next: "next", close: "close", open: g, overlayClose: o, slideshow: g, slideshowAuto: o, slideshowSpeed: 2500, slideshowStart: "start slideshow", slideshowStop: "stop slideshow", preloadIMG: o }; function v(b, d) { d = d === "x" ? document.documentElement.clientWidth : document.documentElement.clientHeight; return typeof b === "string" ? Math.round(b.match(/%/) ? d / 100 * parseInt(b, 10) : parseInt(b, 10)) : b } function Z(b) { return a.photo || b.match(/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i) } function ca() { for (var b in a) if (typeof a[b] === "function") a[b] = a[b].call(m) } e = c.fn.colorbox = function(b, d) { this.length ? this.each(function() { var i = c(this).data(s) ? c.extend({}, c(this).data(s), b) : c.extend({}, Y, b); c(this).data(s, i).addClass("cboxelement") }) : c(this).data(s, c.extend({}, Y, b)); c(this).unbind(O).bind(O, function(i) { m = this; a = c(m).data(s); ca(); X = d || g; var l = a.rel || m.rel; if (l && l !== "nofollow") { h = c(".cboxelement").filter(function() { var f = c(this).data(s).rel || this.rel; return f === l }); k = h.index(m); if (k < 0) { h = h.add(m); k = h.length - 1 } } else { h = c(m); k = 0 } if (!H) { I = H = o; c().bind("keydown.cbox_close", function(f) { if (f.keyCode === 27) { f.preventDefault(); e.close() } }).bind("keydown.cbox_arrows", function(f) { if (f.keyCode === 37) { f.preventDefault(); G.click() } else if (f.keyCode === 39) { f.preventDefault(); F.click() } }); a.overlayClose && u.css({ cursor: "pointer" }).one("click", e.close); m.blur(); c.event.trigger(fa); M.html(a.close); u.css({ opacity: a.opacity }).show(); a.w = v(a.initialWidth, "x"); a.h = v(a.initialHeight, "y"); e.position(0); N && r.bind("resize.cboxie6 scroll.cboxie6", function() { u.css({ width: r.width(), height: r.height(), top: r.scrollTop(), left: r.scrollLeft() }) }).trigger("scroll.cboxie6") } e.slideshow(); e.load(); i.preventDefault() }); b && b.open && c(this).triggerHandler(O); return this }; e.init = function() { function b(d) { return c('<div id="cbox' + d + '"/>') } r = c(window); j = c('<div id="colorbox"/>'); u = b("Overlay").hide(); x = b("Wrapper"); p = b("Content").append(n = b("LoadedContent").css({ width: 0, height: 0 }), K = b("LoadingOverlay"), L = b("LoadingGraphic"), ba = b("Title"), W = b("Current"), y = b("Slideshow"), F = b("Next"), G = b("Previous"), M = b("Close")); x.append(c("<div/>").append(b("TopLeft"), S = b("TopCenter"), b("TopRight")), c("<div/>").append(T = b("MiddleLeft"), p, U = b("MiddleRight")), c("<div/>").append(b("BottomLeft"), V = b("BottomCenter"), b("BottomRight"))).children().children().css({ "float": "left" }); c("body").prepend(u, j.append(x)); if (E) { j.addClass("cboxIE"); N && u.css("position", "absolute") } p.children().addClass(B).mouseover(function() { c(this).addClass(B) }).mouseout(function() { c(this).removeClass(B) }).hide(); C = S.height() + V.height() + p.outerHeight(o) - p.height(); D = T.width() + U.width() + p.outerWidth(o) - p.width(); z = n.outerHeight(o); A = n.outerWidth(o); j.css({ "padding-bottom": C, "padding-right": D }).hide(); F.click(e.next); G.click(e.prev); M.click(e.close); p.children().removeClass(B) }; e.position = function(b, d) { var i = document.documentElement.clientHeight; i = Math.max(i - a.h - z - C, 0) / 2 + r.scrollTop(); var l = Math.max(document.documentElement.clientWidth - a.w - A - D, 0) / 2 + r.scrollLeft(); b = j.width() === a.w + A && j.height() === a.h + z ? 0 : b; x[0].style.width = x[0].style.height = "9999px"; function f(q) { S[0].style.width = V[0].style.width = p[0].style.width = q.style.width; L[0].style.height = K[0].style.height = p[0].style.height = T[0].style.height = U[0].style.height = q.style.height } j.dequeue().animate({ width: a.w + A, height: a.h + z, top: i, left: l }, { duration: b, complete: function() { f(this); I = g; x[0].style.width = a.w + A + D + "px"; x[0].style.height = a.h + z + C + "px"; d && d() }, step: function() { f(this) } }) }; e.resize = function(b) { if (H) { function d(w) { e.position(w, function() { if (H) { if (E) { q && n.fadeIn(100); j[0].style.removeAttribute("filter") } p.children().show(); if (a.iframe) n.append("<iframe id='cboxIframe'" + (a.scrolling ? " " : "scrolling='no'") + " name='iframe_" + (new Date).getTime() + "' frameborder=0 src='" + (a.href || m.href) + "' />"); K.hide(); L.hide(); y.hide(); if (h.length > 1) { W.html(a.current.replace(/\{current\}/, k + 1).replace(/\{total\}/, h.length)); F.html(a.next); G.html(a.previous); a.slideshow && y.show() } else { W.hide(); F.hide(); G.hide() } ba.html(a.title || m.title); c.event.trigger(P); X && X.call(m); a.transition === "fade" && j.fadeTo(t, 1, function() { E && j[0].style.removeAttribute("filter") }); r.bind(R, function() { e.position(0) }) } }) } function i() { a.h = a.h || n.height(); return a.h } function l() { a.w = a.w || n.width(); return a.w } var f, q, t = a.transition === "none" ? 0 : a.speed; r.unbind(R); if (b) { n.remove(); n = c('<div id="cboxLoadedContent"/>').html(b); n.hide().appendTo(u).css({ width: l(), overflow: a.scrolling ? "auto" : "hidden" }).css({ height: i() }).prependTo(p); c("#cboxPhoto").css({ cssFloat: "none" }); N && c("select:not(#colorbox select)").filter(function() { return this.style.visibility !== "hidden" }).css({ visibility: "hidden" }).one(Q, function() { this.style.visibility = "inherit" }); a.transition === "fade" && j.fadeTo(t, 0, function() { d(0) }) || d(t); if (a.preloading && h.length > 1) { b = k > 0 ? h[k - 1] : h[h.length - 1]; f = k < h.length - 1 ? h[k + 1] : h[0]; f = c(f).data(s).href || f.href; b = c(b).data(s).href || b.href; Z(f) && c("<img />").attr("src", f); Z(b) && c("<img />").attr("src", b) } } else b = setTimeout(function() { var w = n.wrapInner("<div style='overflow:auto'></div>").children(); a.h = w.height(); n.css({ height: a.h }); w.replaceWith(w.children()); e.position(t) }, 1) } }; e.load = function() { var b, d, i, l = e.resize; I = o; function f(q) { var t = c(q), w = t.find("img"), $ = w.length; function da() { var ea = new Image; $ -= 1; if ($ >= 0 && a.preloadIMG) { ea.onload = da; ea.src = w[$].src } else l(t) } da() } m = h[k]; a = c(m).data(s); ca(); c.event.trigger(J); a.h = a.height ? v(a.height, "y") - z - C : a.innerHeight ? v(a.innerHeight, "y") : g; a.w = a.width ? v(a.width, "x") - A - D : a.innerWidth ? v(a.innerWidth, "x") : g; a.mw = a.w; a.mh = a.h; if (a.maxWidth) { a.mw = v(a.maxWidth, "x") - A - D; a.mw = a.w && a.w < a.mw ? a.w : a.mw } if (a.maxHeight) { a.mh = v(a.maxHeight, "y") - z - C; a.mh = a.h && a.h < a.mh ? a.h : a.mh } b = a.href || c(m).attr("href"); K.show(); L.show(); M.show(); if (a.inline) { c('<div id="cboxInlineTemp" />').hide().insertBefore(c(b)[0]).bind(J + " " + Q, function() { c(this).replaceWith(n.children()) }); l(c(b)) } else if (a.iframe) l(" "); else if (a.html) f(a.html); else if (Z(b)) { d = new Image; d.onload = function() { var q; d.onload = null; d.id = "cboxPhoto"; c(d).css({ margin: "auto", border: "none", display: "block", cssFloat: "left" }); if (a.scalePhotos) { i = function() { d.height -= d.height * q; d.width -= d.width * q }; if (a.mw && d.width > a.mw) { q = (d.width - a.mw) / d.width; i() } if (a.mh && d.height > a.mh) { q = (d.height - a.mh) / d.height; i() } } if (a.h) d.style.marginTop = Math.max(a.h - d.height, 0) / 2 + "px"; l(d); h.length > 1 && c(d).css({ cursor: "pointer" }).click(e.next); if (E) d.style.msInterpolationMode = "bicubic" }; d.src = b } else c("<div />").load(b, function(q, t) { t === "success" ? f(this) : l(c("<p>Request unsuccessful.</p>")) }) }; e.next = function() { if (!I) { k = k < h.length - 1 ? k + 1 : 0; e.load() } }; e.prev = function() { if (!I) { k = k > 0 ? k - 1 : h.length - 1; e.load() } }; e.slideshow = function() { var b, d, i = "cboxSlideshow_"; y.bind(aa, function() { y.unbind(); clearTimeout(d); j.removeClass(i + "off " + i + "on") }); function l() { y.text(a.slideshowStop).bind(P, function() { d = setTimeout(e.next, a.slideshowSpeed) }).bind(J, function() { clearTimeout(d) }).one("click", function() { b(); c(this).removeClass(B) }); j.removeClass(i + "off").addClass(i + "on") } b = function() { clearTimeout(d); y.text(a.slideshowStart).unbind(P + " " + J).one("click", function() { l(); d = setTimeout(e.next, a.slideshowSpeed); c(this).removeClass(B) }); j.removeClass(i + "on").addClass(i + "off") }; if (a.slideshow && h.length > 1) a.slideshowAuto ? l() : b() }; e.close = function() { c.event.trigger(Q); H = g; c().unbind("keydown.cbox_close keydown.cbox_arrows"); r.unbind(R + " resize.cboxie6 scroll.cboxie6"); u.css({ cursor: "auto" }).fadeOut("fast"); j.stop(o, g).fadeOut("fast", function() { n.remove(); j.css({ opacity: 1 }); p.children().hide(); c.event.trigger(aa) }) }; e.element = function() { return c(m) }; e.settings = Y; c(e.init) })(jQuery);



/* input erase */
(function($) {
    $.fn.nInputDefault = function(options) {
        var defaults = {
            focusClass: 'focus'
        };
        var options = $.extend(defaults, options);
        return this.each(function() {
            var obj = $(this);
            if (obj.attr('type') == "text") {
                var strDefault = '';
                obj.unbind('focus');
                obj.bind('focus', function() {
                    if (obj.val() == strDefault || obj.val() == '') {
                        obj.val('');
                        obj.addClass(options.focusClass);
                    }
                });
                obj.bind('blur', function() {
                    if (obj.val() == strDefault || obj.val() == '') {
                        obj.removeClass(options.focusClass);
                        obj.val(strDefault);
                    }
                });
            }
        });
    };
})(jQuery);



(function($) {

$.widget("ui.selectmenu", {
	_init: function() {
		var self = this, o = this.options;
		
		//quick array of button and menu id's
		var num = Math.round(Math.random() * 1000);
		this.ids = [this.element.attr('id') + '_' + 'button' + '_' + num, this.element.attr('id') + '_' + 'menu' + '_' + num];
		
		//define safe mouseup for future toggling
		this._safemouseup = true;
		
		//create menu button wrapper
		this.newelement = $('<a class="'+ this.widgetBaseClass +' ui-widget ui-state-default ui-corner-all" id="'+this.ids[0]+'" role="button" href="#" aria-haspopup="true" aria-owns="'+this.ids[1]+'" aria-expanded="false"></a>')
			.insertAfter(this.element);
		
		//transfer tabindex
		var tabindex = this.element.attr('tabindex') || '0'; 
		this.newelement.attr('tabindex', tabindex);
		
		//save reference to select in data for ease in calling methods
		this.newelement.data('selectelement', this.element);
		
		//menu icon
		this.selectmenuIcon = $('<span class="'+ this.widgetBaseClass +'-icon ui-icon"></span>')
			.prependTo(this.newelement)
			.addClass( (o.style == "popup")? 'ui-icon-triangle-2-n-s' : 'ui-icon-triangle-1-s' );	

			
		//make associated form label trigger focus
		$('label[for='+this.element.attr('id')+']')
			.attr('for', this.ids[0])
			.bind('click', function(){
				self.newelement.focus();
				return false;
			});	

		//click toggle for menu visibility
		this.newelement
			.bind('mousedown', function(event){
				self._toggle(event);
				//make sure a click won't open/close instantly
				if(o.style == "popup"){
					self._safemouseup = false;
					setTimeout(function(){self._safemouseup = true;}, 300);
				}	
				return false;
			})
			.bind('click',function(){
				return false;
			})
			.keydown(function(event){
				var ret = true;
				switch (event.keyCode) {
					case $.ui.keyCode.ENTER:
						ret = true;
						break;
					case $.ui.keyCode.SPACE:
						ret = false;
						self._toggle(event);	
						break;
					case $.ui.keyCode.UP:
					case $.ui.keyCode.LEFT:
						ret = false;
						self._moveSelection(-1);
						break;
					case $.ui.keyCode.DOWN:
					case $.ui.keyCode.RIGHT:
						ret = false;
						self._moveSelection(1);
						break;	
					case $.ui.keyCode.TAB:
						ret = true;
						break;	
					default:
						ret = false;
						self._typeAhead(event.keyCode, 'mouseup');
						break;	
				}
				return ret;
			})
			.bind('mouseover focus', function(){ 
				$(this).addClass(self.widgetBaseClass+'-focus ui-state-hover'); 
			})
			.bind('mouseout blur', function(){  
				$(this).removeClass(self.widgetBaseClass+'-focus ui-state-hover'); 
			});
		
		//document click closes menu
		$(document)
			.mousedown(function(event){
				self.close(event);
			});

		//change event on original selectmenu
		this.element
			.click(function(){ this._refreshValue(); })
			.focus(function(){ this.newelement.focus(); });
		
		//create menu portion, append to body
		var cornerClass = (o.style == "dropdown")? " ui-corner-bottom" : " ui-corner-all"
		this.list = $('<ul class="' + self.widgetBaseClass + '-menu ui-widget ui-widget-content'+cornerClass+'" aria-hidden="true" role="listbox" aria-multiselectable="false" aria-labelledby="'+this.ids[0]+'" id="'+this.ids[1]+'"></ul>').appendTo('body');				
		
		//serialize selectmenu element options	
		var selectOptionData = [];
		this.element
			.find('option')
			.each(function(){
				selectOptionData.push({
					value: $(this).attr('value'),
					text: self._formatText(jQuery(this).text()),
					selected: $(this).attr('selected'),
					classes: $(this).attr('class'),
					parentOptGroup: $(this).parent('optgroup').attr('label')
				});
			});		
				
		//active state class is only used in popup style
		var activeClass = (self.options.style == "popup") ? " ui-state-active" : "";
		
		//write li's
		for(var i in selectOptionData){
			var thisLi = $('<li><a href="#" tabindex="-1" role="option" aria-selected="false">'+ selectOptionData[i].text +'</a></li>')
				.data('index',i)
				.addClass(selectOptionData[i].classes)
				.data('optionClasses', selectOptionData[i].classes)
				.mouseup(function(event){
						if(self._safemouseup){
							var changed = $(this).data('index') != self._selectedIndex();
							self.value($(this).data('index'));
							self.select(event);
							if(changed){ self.change(event); }
							self.close(event,true);
						}
					return false;
				})
				.click(function(){
					return false;
				})
				.bind('mouseover focus', function(){ 
					self._selectedOptionLi().addClass(activeClass); 
					self._focusedOptionLi().removeClass(self.widgetBaseClass+'-item-focus ui-state-hover'); 
					$(this).removeClass('ui-state-active').addClass(self.widgetBaseClass + '-item-focus ui-state-hover'); 
				})
				.bind('mouseout blur', function(){ 
					if($(this).is( self._selectedOptionLi() )){ $(this).addClass(activeClass); }
					$(this).removeClass(self.widgetBaseClass + '-item-focus ui-state-hover'); 
				});
				
			//optgroup or not...
			if(selectOptionData[i].parentOptGroup){
				var optGroupName = self.widgetBaseClass + '-group-' + selectOptionData[i].parentOptGroup;
				if(this.list.find('li.' + optGroupName).size()){
					this.list.find('li.' + optGroupName + ':last ul').append(thisLi);
				}
				else{
					$('<li class="'+self.widgetBaseClass+'-group '+optGroupName+'"><span class="'+self.widgetBaseClass+'-group-label">'+selectOptionData[i].parentOptGroup+'</span><ul></ul></li>')
						.appendTo(this.list)
						.find('ul')
						.append(thisLi);
				}
			}
			else{
				thisLi.appendTo(this.list);
			}
			
			//this allows for using the scrollbar in an overflowed list
			this.list.bind('mousedown mouseup', function(){return false;});
			
			//append icon if option is specified
			if(o.icons){
				for(var j in o.icons){
					if(thisLi.is(o.icons[j].find)){
						thisLi
							.data('optionClasses', selectOptionData[i].classes + ' ' + self.widgetBaseClass + '-hasIcon')
							.addClass(self.widgetBaseClass + '-hasIcon');
						var iconClass = o.icons[j].icon || "";
						
						thisLi
							.find('a:eq(0)')
							.prepend('<span class="'+self.widgetBaseClass+'-item-icon ui-icon '+iconClass + '"></span>');
					}
				}
			}
		}	
		
		//add corners to top and bottom menu items
		this.list.find('li:last').addClass("ui-corner-bottom");
		if(o.style == 'popup'){ this.list.find('li:first').addClass("ui-corner-top"); }
		
		//transfer classes to selectmenu and list
		if(o.transferClasses){
			var transferClasses = this.element.attr('class') || ''; 
			this.newelement.add(this.list).addClass(transferClasses);
		}
		
		//original selectmenu width
		var selectWidth = this.element.width();
		
		//set menu button width
		this.newelement.width( (o.width) ? o.width : selectWidth);
		
		//set menu width to either menuWidth option value, width option value, or select width 
		if(o.style == 'dropdown'){ this.list.width( (o.menuWidth) ? o.menuWidth : ((o.width) ? o.width : selectWidth)); }
		else { this.list.width( (o.menuWidth) ? o.menuWidth : ((o.width) ? o.width - o.handleWidth : selectWidth - o.handleWidth)); }	
		
		//set max height from option 
		if(o.maxHeight && o.maxHeight < this.list.height()){ this.list.height(o.maxHeight); }	
		
		//save reference to actionable li's (not group label li's)
		this._optionLis = this.list.find('li:not(.'+ self.widgetBaseClass +'-group)');
				
		//transfer menu click to menu button
		this.list
			.keydown(function(event){
				var ret = true;
				switch (event.keyCode) {
					case $.ui.keyCode.UP:
					case $.ui.keyCode.LEFT:
						ret = false;
						self._moveFocus(-1);
						break;
					case $.ui.keyCode.DOWN:
					case $.ui.keyCode.RIGHT:
						ret = false;
						self._moveFocus(1);
						break;	
					case $.ui.keyCode.HOME:
						ret = false;
						self._moveFocus(':first');
						break;	
					case $.ui.keyCode.PAGE_UP:
						ret = false;
						self._scrollPage('up');
						break;	
					case $.ui.keyCode.PAGE_DOWN:
						ret = false;
						self._scrollPage('down');
						break;
					case $.ui.keyCode.END:
						ret = false;
						self._moveFocus(':last');
						break;			
					case $.ui.keyCode.ENTER:
					case $.ui.keyCode.SPACE:
						ret = false;
						self.close(event,true);
						$(event.target).parents('li:eq(0)').trigger('mouseup');
						break;		
					case $.ui.keyCode.TAB:
						ret = true;
						self.close(event);
						break;	
					case $.ui.keyCode.ESCAPE:
						ret = false;
						self.close(event,true);
						break;	
					default:
						ret = false;
						self._typeAhead(event.keyCode,'focus');
						break;		
				}
				return ret;
			});
			
		//selectmenu style
		if(o.style == 'dropdown'){
			this.newelement
				.addClass(self.widgetBaseClass+"-dropdown");
			this.list
				.addClass(self.widgetBaseClass+"-menu-dropdown");	
		}
		else {
			this.newelement
				.addClass(self.widgetBaseClass+"-popup");
			this.list
				.addClass(self.widgetBaseClass+"-menu-popup");	
		}
		
		//append status span to button
		this.newelement.prepend('<span class="'+self.widgetBaseClass+'-status">'+ selectOptionData[this._selectedIndex()].text +'</span>');
		
		//hide original selectmenu element
		this.element.hide();
		
		//transfer disabled state
		if(this.element.attr('disabled') == true){ this.disable(); }
		
		//update value
		this.value(this._selectedIndex());
	},
	destroy: function() {
		this.element.removeData(this.widgetName)
			.removeClass(this.widgetBaseClass + '-disabled' + ' ' + this.namespace + '-state-disabled')
			.removeAttr('aria-disabled');
	
		//unbind click on label, reset its for attr
		$('label[for='+this.newelement.attr('id')+']')
			.attr('for',this.element.attr('id'))
			.unbind('click');
		this.newelement.remove();
		this.list.remove();
		this.element.show();	
	},
	_typeAhead: function(code, eventType){
		var self = this;
		//define self._prevChar if needed
		if(!self._prevChar){ self._prevChar = ['',0]; }
		var C = String.fromCharCode(code);
		c = C.toLowerCase();
		var focusFound = false;
		function focusOpt(elem, ind){
			focusFound = true;
			$(elem).trigger(eventType);
			self._prevChar[1] = ind;
		};
		this.list.find('li a').each(function(i){	
			if(!focusFound){
				var thisText = $(this).text();
				if( thisText.indexOf(C) == 0 || thisText.indexOf(c) == 0){
						if(self._prevChar[0] == C){
							if(self._prevChar[1] < i){ focusOpt(this,i); }	
						}
						else{ focusOpt(this,i); }	
				}
			}
		});
		this._prevChar[0] = C;
	},
	_uiHash: function(){
		return {
			value: this.value()
		};
	},
	open: function(event){
		var self = this;
		this._refreshPosition();
		this._closeOthers(event);
		this.newelement
			.attr('aria-expanded', true)
			.addClass('ui-state-active');
		
		this.list
			.appendTo('body')
			.addClass(self.widgetBaseClass + '-open')
			.attr('aria-hidden', false)
			.find('li:not(.'+ self.widgetBaseClass +'-group):eq('+ this._selectedIndex() +') a').focus();	
		if(this.options.style == "dropdown"){ this.newelement.removeClass('ui-corner-all').addClass('ui-corner-top'); }	
		this._refreshPosition();
		this._trigger("open", event, this._uiHash());
	},
	close: function(event, retainFocus){
		if(this.newelement.is('.ui-state-active')){
			this.newelement
				.attr('aria-expanded', false)
				.removeClass('ui-state-active');
			this.list
				.attr('aria-hidden', true)
				.removeClass(this.widgetBaseClass+'-open');
			if(this.options.style == "dropdown"){ this.newelement.removeClass('ui-corner-top').addClass('ui-corner-all'); }
			if(retainFocus){this.newelement.focus();}	
			this._trigger("close", event, this._uiHash());
		}
	},
	change: function(event) {
		this.element.trigger('change');
		this._trigger("change", event, this._uiHash());
	},
	select: function(event) {
		this._trigger("select", event, this._uiHash());
	},
	_closeOthers: function(event){
		$('.'+ this.widgetBaseClass +'.ui-state-active').not(this.newelement).each(function(){
			$(this).data('selectelement').selectmenu('close',event);
		});
		$('.'+ this.widgetBaseClass +'.ui-state-hover').trigger('mouseout');
	},
	_toggle: function(event,retainFocus){
		if(this.list.is('.'+ this.widgetBaseClass +'-open')){ this.close(event,retainFocus); }
		else { this.open(event); }
	},
	_formatText: function(text){
		return this.options.format ? this.options.format(text) : text;
	},
	_selectedIndex: function(){
		return this.element[0].selectedIndex;
	},
	_selectedOptionLi: function(){
		return this._optionLis.eq(this._selectedIndex());
	},
	_focusedOptionLi: function(){
		return this.list.find('.'+ this.widgetBaseClass +'-item-focus');
	},
	_moveSelection: function(amt){
		var currIndex = parseInt(this._selectedOptionLi().data('index'), 10);
		var newIndex = currIndex + amt;
		return this._optionLis.eq(newIndex).trigger('mouseup');
	},
	_moveFocus: function(amt){
		if(!isNaN(amt)){
			var currIndex = parseInt(this._focusedOptionLi().data('index'), 10);
			var newIndex = currIndex + amt;
		}
		else { var newIndex = parseInt(this._optionLis.filter(amt).data('index'), 10); }
		
		if(newIndex < 0){ newIndex = 0; }
		if(newIndex > this._optionLis.size()-1){
			newIndex =  this._optionLis.size()-1;
		}
		this._focusedOptionLi().find('a:eq(0)').blur();
		this._optionLis.eq(newIndex).find('a:eq(0)').focus();
	},
	_scrollPage: function(direction){
		var numPerPage = Math.floor(this.list.outerHeight() / this.list.find('li:first').outerHeight());
		numPerPage = (direction == 'up') ? -numPerPage : numPerPage;
		this._moveFocus(numPerPage);
	},
	_setData: function(key, value) {
		this.options[key] = value;
		if (key == 'disabled') {
			this.element
				.add(this.newelement)
				.add(this.list)
					[value ? 'addClass' : 'removeClass'](
						this.widgetBaseClass + '-disabled' + ' ' +
						this.namespace + '-state-disabled')
					.attr("aria-disabled", value);
		}
	},
	value: function(newValue) {
		if (arguments.length) {
			this.element[0].selectedIndex = newValue;
			this._refreshValue();
			this._refreshPosition();
		}
		return this.element[0].selectedIndex;
	},
	_refreshValue: function() {
		var activeClass = (this.options.style == "popup") ? " ui-state-active" : "";
		//deselect previous
		this.list
			.find('.'+ this.widgetBaseClass +'-item-selected')
			.removeClass(this.widgetBaseClass + "-item-selected" + activeClass)
			.find('a')
			.attr('aria-selected', 'false');
		//select new
		this._selectedOptionLi()
			.addClass(this.widgetBaseClass + "-item-selected"+activeClass)
			.find('a')
			.attr('aria-selected', 'true');
		//toggle any class brought in from option
		var currentOptionClasses = this.newelement.data('optionClasses') ? this.newelement.data('optionClasses') : "";
		var newOptionClasses = this._selectedOptionLi().data('optionClasses') ? this._selectedOptionLi().data('optionClasses') : "";
		this.newelement
			.removeClass(currentOptionClasses)
			.data('optionClasses', newOptionClasses)
			.addClass( newOptionClasses )
			.find('.'+this.widgetBaseClass+'-status')
			.html( 
				this._selectedOptionLi()
					.find('a:eq(0)')
					.html() 
			);
	},
	_refreshPosition: function(){	
		//set left value
		this.list.css('left', this.newelement.offset().left);
		
		//set top value
		var menuTop = this.newelement.offset().top;
		var scrolledAmt = this.list[0].scrollTop;
		this.list.find('li:lt('+this._selectedIndex()+')').each(function(){
			scrolledAmt -= $(this).outerHeight();
		});
		
		if(this.newelement.is('.'+this.widgetBaseClass+'-popup')){
			menuTop+=scrolledAmt; 
			this.list.css('top', menuTop); 
		}	
		else { 
			menuTop += this.newelement.height();
			this.list.css('top', menuTop); 
		}
	}
});

$.extend($.ui.selectmenu, {
	getter: "value",
	version: "@VERSION",
	eventPrefix: "selectmenu",
	defaults: {
		transferClasses: true,
		style: 'popup', 
		width: null, 
		menuWidth: null, 
		handleWidth: 26, 
		maxHeight: null,
		icons: null, 
		format: null
	}
});

})(jQuery);

