	$.fn.enhanceTextField=function(){
		$(this).each(function(){
			var me=$(this);
			var body=me.find("span .body")

			body.focus(function(e){
				me.addClass("focus");
			}).blur(function(e){
				me.removeClass("focus");
			});
		});
		return $(this);
	};


	$.fn.enhanceTextArea=function(){
		$(this).each(function(){
			var me=$(this);
			var text=me.find("textarea");
			var body=$('<div class="textBody"></div>')
			body.css("width",(parseInt(me.css("width"))-35)+"px");
			var container=$('<div class="textContainer"></div>').append(body);
			text.wrap(container);

			text.css("width",(parseInt(me.css("width"))-35-22)+"px");

			container.css("width",(parseInt(me.css("width"))-35)+"px");


			var wheel=function(e,delta){
				e.preventDefault();
				e.stopPropagation();
				var d=parseInt(delta/Math.abs(delta));

				scrollingIndex+=-d;
				if(scrollingIndex<0){
					scrollingIndex=0;
				}else if(scrollingIndex>scrollingMax){
					scrollingIndex=scrollingMax;
				}
				text.scrollTop(scrollingIndex*20);
				bar.css("top",parseInt(27+scrollingIndex*barDifY)+"px");
			};

			me.mousewheel(wheel);

			var clone=(function(){
				var props = ['height','width','lineHeight','textDecoration','letterSpacing',"font-size","overflow"],
				propOb = {};

				$.each(props, function(i, prop){
					propOb[prop] = text.css(prop);
				});

				return text.clone().removeAttr('id').removeAttr('name').css({
				position:'absolute',
				top:0,
				left:"-9999px"
				}).css(propOb).attr('tabIndex','-1').insertBefore(text);
			})();

			var scroll=$('<div class="scroll" />');
			me.append(scroll);

			var scrollingThreshold=7;
			var scrollingIndex=0;
			var scrollingMax=0;
			var scrollTimer;
			var barDifY;
			var barHeight;

			var scrollUp=function(e){
				scrollingIndex--;
				if(scrollingIndex<0)scrollingIndex=0;
				text.scrollTop(scrollingIndex*20);
				bar.css("top",parseInt(27+scrollingIndex*barDifY)+"px");
				scrollTimer=setTimeout(scrollUp,250);
			};
			var scrollDown=function(e){
				scrollingIndex++
				if(scrollingIndex>scrollingMax)scrollingIndex=scrollingMax
				text.scrollTop(scrollingIndex*20);
				bar.css("top",parseInt(27+scrollingIndex*barDifY)+"px");
				scrollTimer=setTimeout(scrollDown,250);
			};


			var up=$('<div class="up" />').mouseenter(function(e){
				up.addClass("over");
			}).mouseleave(function(e){
				up.removeClass("over");
			}).mousedown(scrollUp).mouseup(function(e){
				clearTimeout(scrollTimer)
			});

			var down=$('<div class="down" />').mouseenter(function(e){
				down.addClass("over");
			}).mouseleave(function(e){
				down.removeClass("over");
			}).mousedown(scrollDown).mouseup(function(e){
				clearTimeout(scrollTimer)
			});


			var isOver;
			var checkOver=function(e){
				isOver=true;
			};
			var checkOut=function(e){
				isOver=false;
			};

			var setDraggable=function(e){
				var baseMouse=e.pageY;
				var baseBar=$(this).position().top;

				var drag=function(e){
					var y = baseBar+e.pageY-baseMouse;
					if(y<27){
						y=27;
					}else if(y>27+107-barHeight){
						y=27+107-barHeight;
					}
					scrollingIndex=parseInt((y-27)/barDifY+0.5);
					text.scrollTop(scrollingIndex*20);
					bar.css("top",parseInt(27+scrollingIndex*barDifY)+"px");
				};

				var up=function(e){
					$(document).unbind("mousemove",drag);
					$(document).unbind("mouseup",up);

					if(!isOver){
						bar.removeClass("over")
					}
					bar.unbind("mouseenter");

					bar.mouseenter(function(e){
						bar.addClass("over");
					}).mouseleave(function(e){
						bar.removeClass("over");
					});
				};

				isOver=true;
				bar.unbind("mouseleave mouseenter");
				bar.mouseenter(checkOver).mouseleave(checkOut);

				$(document).mousemove(drag).mouseup(up);
			};

			var bar=$('<div class="bar"><div class="top"></div></div>').mouseenter(function(e){
				bar.addClass("over");
			}).mouseleave(function(e){
				bar.removeClass("over");
			});
			scroll.append(up).append(bar).append(down);

			var draggable;
			var update = function() {
 				clone.height(1).val(text.val()).scrollTop(10000);

				var totalHeight = Math.max( clone.scrollTop() , 1000 );

//				body.add(clone);

				if(totalHeight==140){
					scrollingMax=0;
					barHeight=107;
					barDifY=0;
					scrollingIndex=0;
					draggable=false
					bar.unbind("mousedown",setDraggable)
				}else{
					scrollingMax=totalHeight/20-scrollingThreshold;
					barHeight=parseInt( 107 * 140 / totalHeight )
					barDifY=(107-barHeight)/scrollingMax;

					scrollingIndex=parseInt(Math.round(text.scrollTop()/10)/2)

					if(!draggable){
						draggable=true
						bar.bind("mousedown",setDraggable)
					}


				}

				bar.height(barHeight);
				bar.css("top",parseInt(27+barDifY*scrollingIndex)+"px");

				text.trigger('autoResize')
			};

			var timer;
			var textLength;
			var checkInput=function(e){
				if(text.val().length!=textLength){
					textLength=text.val().length;
					update();
				}
				timer=setTimeout(checkInput,100)
			}

			var stopCheckInput=function(e){
				clearTimeout(timer)
			}

			var startCheckInput=function(e){
				textLength=text.val().length
				checkInput();

			}

			text.focus(function(e){
				startCheckInput();
				me.addClass("over");
			}).blur(function(e){
				stopCheckInput();
				me.removeClass("over");
			}).bind("keydown",update).bind("keyup",update).bind("change",update).bind("select",update);


			if($.browser.msie&&parseInt($.browser.version)<8){
				var func=function(){
					text.trigger("keyup");
				};
				setTimeout(func,1000);
			}

			text.trigger("keyup")


		});
		return $(this);
	};




	$.fn.enhanceRadioButton=function(){

		$(this).each(function(){
			var parent=$(this);
			var radios=parent.find(".radiobutton");
			var radioCount=radios.length;
			var tabindex=parent.attr("tabindex");


			var toggleRadio=function(e){
				var tabindex=radios.filter(".checked").attr("tabindex");

				var r;
				if(e.which==39||e.which==40){//right,down
					e.preventDefault();
					e.stopPropagation();

					var prev=radios.index(radios.filter(".checked"));
					var current=(prev+1)%radioCount;



					r=radios.eq(prev);
					r.removeClass("checked");
					r.removeClass("over");
					r.find("input").removeAttr("checked");
					r.removeAttr("tabindex");
					r.blur()

					var r=radios.eq(current);
					r.addClass("checked");
					r.find("input").attr( "checked" , "checked" );
					r.attr("tabindex",tabindex);
					r.focus();

				}else if(e.which==37||e.which==38){//left,up
					e.preventDefault();
					e.stopPropagation();

					var prev=radios.index(radios.filter(".checked"));
					var current=(prev-1+radioCount)%radioCount;



					r=radios.eq(prev);
					r.removeClass("checked");
					r.removeClass("over");
					r.find("input").removeAttr("checked");
					r.removeAttr("tabindex");
					r.blur()

					var r=radios.eq(current);
					r.addClass("checked");
					r.find("input").attr("checked","checked");
					r.attr("tabindex",tabindex);
					r.focus();
				}
			};


			radios.each(function(){

				var me=$(this);
				me.click(function(e){
					e.preventDefault();

					if(me[0]==radios.filter(".checked")[0]){
						return;
					}

					if(parent.attr("tabindex")>0){
						me.attr("tabindex",parent.attr("tabindex"));
						parent.removeAttr("tabindex");
					}else{
						me.attr("tabindex",radios.filter(".checked").attr("tabindex"));
						radios.filter(".checked").removeAttr("tabindex");
					}


					me.find("input").attr("checked","checked");
					$.each(radios,function(){
						$(this).removeClass("checked");
					});
					me.addClass("checked");

					parent.unbind("keydown",toggleRadio);
					parent.keydown(toggleRadio);
				}).bind("mouseenter focus",function(e){
					me.addClass("over");
				}).bind("mouseleave blur",function(e){
					me.removeClass("over");
				}).focus(function(e){
					parent.unbind("keydown",toggleRadio)
					parent.keydown(toggleRadio);
				}).blur(function(e){
					parent.unbind("keydown",toggleRadio)
				});
			});


			var hasChecked
			radios.find("label input").each(function(){
				var me=$(this);

				me.removeAttr("tabindex");
				if(me.is(":checked")){
					hasChecked=true;
					var r=me.parent().parent();
					r.addClass("checked");
					r.attr("tabindex",parent.attr("tabindex"));
					parent.removeAttr("tabindex");

				}
			});


			if(!hasChecked){
				var onFocus=function(e){
					parent.removeAttr("tabindex");

					var r=radios.filter(".checked");
					if(r.length){
						r.focus();
					}else{
						r=radios.filter(":first");
						r[0].focus();
						r.addClass("checked");
					}
					r.find("input").attr("checked","checked");
					r.attr("tabindex",tabindex);

					parent.unbind("keydown",toggleRadio);
					parent.keydown(toggleRadio);
					parent.unbind("focus",onFocus);
				};

				parent.focus(onFocus);
			}

		});


		return $(this);
	};




	$.fn.enhanceCheckbox=function(){

		$(this).each(function(){
			var parent=$(this);
			var boxes=parent.find(".checkbox");
			var boxCount=boxes.length;
			var tabindex=parent.attr("tabindex");



			boxes.each(function(){
				$(this).attachCheckboxAbility();
			});

			boxes.find("label input").each(function(){
				var me=$(this);
				me.attr("tabindex",-1);
				if( me.is(":checked") ){
					me.parent().parent().addClass("checked");
				}else{
					me.parent().parent().removeClass("checked");
				}
			});

		});



	};

	$.fn.attachCheckboxAbility=function(){
		var me=$(this);

		var toggle=function(e){
			if(e.which==32){
				e.preventDefault();
				if( me.find("input").attr("checked") ){
					me.removeClass("checked");
					me.find("input").removeAttr("checked");
				}else{
					me.addClass("checked");
					me.find("input").attr("checked","checked");
				}
			}
		};

		me.click(function(e){
			e.preventDefault();
			if(me.find("input").attr("checked")){
				me.removeClass("checked");
				me.find("input").removeAttr("checked");
			}else{
				me.addClass("checked");
				me.find("input").attr("checked","checked");
			}
		}).mouseenter(function(e){
			me.addClass("over");
		}).mouseleave(function(e){
			me.removeClass("over");
		}).focus(function(e){
			me.addClass("over");
			me.keydown(toggle);
		}).blur(function(e){
			me.removeClass("over");
			me.unbind("keydown",toggle);
		});
	};

	$.fn.detachCheckboxAbility=function(){
		$(this).unbind();
	};






	$.fn.enhancePullDown=function(threshold){

		var pullDownSetAutoWidth=function(pd,maxWidth,width){
			if(pd.find(".pullDownSelector .pullDownSelectorSheet .scroll").length){
				if( width+61 > maxWidth ){
					width=maxWidth-61
				}
				pd.find(".pullDownSelectorBody .pullDownSelectorUnit").each(function(){
					$(this).width(width+20);
				});

				pd.width(width+58);
				pd.find(".selected").width(width+61);
				pd.find(".pullDownSelectorSheet .center .top").width(width+47);
				pd.find(".pullDownSelectorSheet .center").width(width+47);
				pd.find(".pullDownSelectorSheet").width(width+61);

			}else{
				if( width+58 > maxWidth ){
					width=maxWidth-58
				}
				pd.find(".pullDownSelectorBody .pullDownSelectorUnit").each(function(){
					$(this).width(width+44);
				});
				pd.width(width+58);
				pd.find(".selected").width(width+58);
				pd.find(".pullDownSelectorSheet .center .top").width(width+44);
				pd.find(".pullDownSelectorSheet .center").width(width+44);
				pd.find(".pullDownSelectorSheet").width(width+58);
			}
		};




		var pullDownSetFixedWidth=function(pd,fixedWidth){
			pd.find(".selected").width(fixedWidth);
			pd.find(".pullDownSelectorSheet .center .top").width(fixedWidth-14)
			if(pd.find(".pullDownSelector .pullDownSelectorSheet .scroll").length){
				pd.find(".pullDownSelectorBody .pullDownSelectorUnit").each(function(){
					$(this).width(fixedWidth-41);
				});
				pd.width(fixedWidth);
			}else{
				pd.find(".pullDownSelectorBody .pullDownSelectorUnit").each(function(){
					$(this).width(fixedWidth-14);
				});
				pd.width(fixedWidth)
			}
		};






		var pullDownGenerateAsset=function(pd,maxWidth,autoWidth){
			var scrollingIndex=0;
			var scrollingHeight=31;
			var scrollingThreshold=threshold==undefined?7:threshold;

			var select=pd.find("select");
			var options=pd.find("select option");

			select.attr("tabindex",-1);

			var index=options.index(select.find("option:selected"));

			var tabindex=pd.attr("tabindex");
			pd.attr("tabindex",-1);

			var selected=$('<div tabindex="'+tabindex+'" />').addClass("selected").append("<label></label>").appendTo(pd);

			var selector=$("<div />").addClass("pullDownSelector").appendTo(pd);
			var sheet=$("<div />").addClass("pullDownSelectorSheet").addClass("clearfix png").appendTo(selector);
			var bodyContainer=$("<div />").addClass("pullDownSelectorBodyContainer");
			var body=$("<div />").addClass("pullDownSelectorBody");


			pd.focus(function(e){
				focusCancelable=true
				if(selected[0])selected[0].focus()
				selected.find("label").addClass("over");
			});


			var hidePullDown=function(e){
				if(selector.hasClass("hidden"))return;

				selector.addClass("hidden");
				selected.click(showPullDown);
				selected.mouseleave(outSelected)
				pd.unbind("mousewheel",wheel);

				clearTimeout(waiter);
				pd.unbind("keydown",selectPullDown);
				sheet.unbind("mouseenter",clearWaitHidePullDown);
				sheet.unbind("mouseleave",hidePullDown);
			};

			var waiter;
			var waitHidePullDown=function(e){
				pd.unbind("mouseleave",waitHidePullDown);
				waiter=setTimeout(hidePullDown,100);
				sheet.mouseenter(clearWaitHidePullDown);
			};

			var clearWaitHidePullDown=function(e){

				clearTimeout(waiter);
				sheet.unbind("mouseenter",clearWaitHidePullDown);
				sheet.mouseleave(hidePullDown);
			};

			var showPullDown=function(e){
				if(!selector.hasClass("hidden"))return;

				selector.removeClass("hidden");
				selected.unbind("click",showPullDown);
				selected.unbind("mouseleave",outSelected)

				pd.mouseleave(waitHidePullDown);

				if(bar){
					pd.mousewheel(wheel);
				}

				var index=options.index(select.find("option:selected"));
				tmpIndex=index
				var i=0;
				$.each(body.find(".pullDownSelectorUnit"),function(){
					if(i==index){
						$(this).addClass("over");
					}else{
						$(this).removeClass("over");
					}
					i++;
				})

				if(scrollingIndex>index){
					step( scrollingIndex-index )
				}else if(index>=scrollingIndex+scrollingThreshold){
					step( scrollingIndex+scrollingThreshold-index-1 )
				}
			};



			var wheel=function(e,delta){
				e.preventDefault();
				e.stopPropagation();
				if(delta == 0) {
					return;
				}
				step(delta/Math.abs(delta));
			};

			var step=function(delta){

				scrollingIndex+=-parseInt(delta);
				if(scrollingIndex<0){
					scrollingIndex=0;
				}else if(scrollingIndex>scrollingMax){
					scrollingIndex=scrollingMax;
				}
				body.attr("style","margin-top:-"+(scrollingIndex*scrollingHeight)+"px;");
				if(bar)bar.css("top",parseInt(26+scrollingIndex*barDifY)+"px");
			};


			var focusCancelable;
			var blurCancelable;

			var tmpIndex;

			var overSelected=function(e){
				selected.find("label").addClass("over");
			};

			var outSelected=function(e){
				selected.find("label").removeClass("over");
			};

			selected.click(showPullDown).mouseenter(overSelected).mouseleave(outSelected).focus(function(e){
				blurCancelable=false;

				if(focusCancelable){
					focusCancelable=false;
					return;
				}
				selected.find("label").addClass("over");
				pd.keydown(selectPullDown)
				showPullDown(e);
			}).blur(function(e){
				focusCancelable=false
				if(blurCancelable){
					blurCancelable=false;
					return;
				}
				selected.find("label").removeClass("over");
				pd.unbind("keydown",selectPullDown);
				hidePullDown(e);
			}).mousedown(function(e){
				isDown=true;
			})

			var selectPullDown=function(e){
				if(e.which==38){//up
					e.preventDefault();
					e.stopPropagation();
					tmpIndex--;
					if(tmpIndex<0){
						tmpIndex=0;
					}else{
						if(tmpIndex<scrollingIndex){
							step(1)
						}
						body.find(".pullDownSelectorUnit:eq("+(tmpIndex+1)+")").removeClass("over");
						body.find(".pullDownSelectorUnit:eq("+(tmpIndex)+")").addClass("over");
						select.find("option:nth-child("+(tmpIndex+1)+")").attr("selected","selected");
						select.trigger("change");
					}
				}else if(e.which==40){//down
					e.preventDefault();
					e.stopPropagation();
					tmpIndex++;
					if(tmpIndex>options.length-1){
						tmpIndex=options.length-1;
					}else{
						if(tmpIndex>=scrollingIndex+scrollingThreshold){
							step(-1)
						}
						body.find(".pullDownSelectorUnit:eq("+(tmpIndex-1)+")").removeClass("over")
						body.find(".pullDownSelectorUnit:eq("+(tmpIndex)+")").addClass("over")
						select.find("option:nth-child("+(tmpIndex+1)+")").attr("selected","selected");
						select.trigger("change");
					}
				}
			};



			var len=options.length;
			var height=options.length*scrollingHeight+7;
			if(len>scrollingThreshold){
				height=scrollingThreshold*scrollingHeight+7;
				var h=parseInt((height-68)*scrollingThreshold/len);
				var scrollingMax=len-scrollingThreshold;
				var barDifY=(height-68-h)/scrollingMax;
				var module=$('<div class="scroll" style="height:'+(height-14)+'px"></div>');


				var over=function(e){
					$(this).addClass("over")
					$(this).bind("mouseleave",out)
				};

				var out=function(e){
					$(this).removeClass("over");
					$(this).unbind("mouseleave",out);
				};

				var isOver;
				var checkOver=function(e){
					isOver=true;
				};
				var checkOut=function(e){
					isOver=false;
				};
				var isOverSheet;
				var checkOverSheet=function(e){
					isOverSheet=true;
				};
				var checkOutSheet=function(e){
					isOverSheet=false;
				};

				var bar=$('<div class="bar" style="top:26px;height:'+h+'px"><span class="top"></span></div>').mousedown(function(e){
					var baseMouse=e.pageY;
					var baseBar=$(this).position().top;

					blurCancelable=true

					var drag=function(e){
						var y = baseBar+e.pageY-baseMouse;
						if(y<26){
							y=26;
						}else if(y>height-42-h){
							y=height-42-h;
						}
						scrollingIndex=parseInt((y-26)/barDifY+0.5);
						body.attr("style","margin-top:-"+ scrollingIndex * scrollingHeight+"px;")
						bar.css("top",parseInt(26+barDifY*scrollingIndex)+"px");
					};
					var up=function(e){
						blurCancelable=false

						$(document).unbind("mousemove",drag);
						$(document).unbind("mouseup",up);

						if(isOver){
							bar.bind("mouseleave",out);
						}else{
							bar.removeClass("over")
						}
						bar.unbind("mouseenter",checkOver)
						bar.unbind("mouseleave",checkOut);

						if(isOverSheet){
							sheet.bind("mouseleave",hidePullDown);
						}else{
							hidePullDown();
						}
						sheet.unbind("mouseenter",checkOverSheet)
						sheet.unbind("mouseleave",checkOutSheet);
					};

					isOver=true;
					isOverSheet=true;
					bar.mouseenter(checkOver).mouseleave(checkOut);
					sheet.mouseenter(checkOverSheet).mouseleave(checkOutSheet);
					$(this).unbind("mouseleave",out);
					sheet.unbind("mouseleave",hidePullDown);
					$(document).mousemove(drag).mouseup(up);
				}).mouseenter(over).appendTo(module);

				var scrollTimer
				var scrollUp=function(){
					blurCancelable=true
					scrollingIndex--;
					if(scrollingIndex<0)scrollingIndex=0;
					body.css("margin-top",-(scrollingIndex*scrollingHeight)+"px");
					bar.css("top",parseInt(26+scrollingIndex*barDifY)+"px");
					scrollTimer=setTimeout(scrollUp,250);
				};
				var scrollDown=function(){
					blurCancelable=true
					scrollingIndex++
					if(scrollingIndex>scrollingMax)scrollingIndex=scrollingMax
					body.css("margin-top",-(scrollingIndex*scrollingHeight)+"px");
					bar.css("top",parseInt(26+scrollingIndex*barDifY)+"px");
					scrollTimer=setTimeout(scrollDown,250);
				};

				var arrowUp=$('<div class="up bgOver"></div>').mousedown(scrollUp).mouseup(function(e){
					blurCancelable=false
					clearTimeout(scrollTimer)
				}).enhanceBGOver().appendTo(module);

				var arrowDown=$('<div class="down bgOver"></div>').mousedown(scrollDown).mouseup(function(e){
					blurCancelable=false
					clearTimeout(scrollTimer)
				}).enhanceBGOver().appendTo(module);

				sheet.mousedown(function(){
					blurCancelable=true
				}).append(module);



				if(scrollingIndex>index){
					step( scrollingIndex-index )
				}else if(index>=scrollingIndex+scrollingThreshold){
					step( scrollingIndex+scrollingThreshold-index-1 )
				}
			}

			bodyContainer.css("height",height-8);
			sheet.append('<div class="left png"><div class="top" style="height:'+height+'px"></div></div>');
			sheet.append('<div class="center"><div class="top" style="height:'+(height-8)+'px"></div></div>');
			sheet.append('<div class="right png"><div class="top" style="height:'+height+'px"></div></div>');
			sheet.find(".center .top").append(bodyContainer);

			bodyContainer.append(body)

			var index=1
			var w=0;



			$.each(options,function(){
				var unit=$("<div />").addClass("pullDownSelectorUnit");

				var i = index
				var l=$('<label />').text($(this).text());
				l.mouseenter(function(e){
					body.find(".pullDownSelectorUnit").eq(tmpIndex).removeClass("over");
					tmpIndex=i-1;
					unit.addClass("over");
				}).mousedown(function(e){
					e.stopPropagation();
					e.preventDefault();

					select.find("option:nth-child("+i+")").attr("selected","selected");
					selector.addClass("hidden");

					pd.unbind("keydown",selectPullDown);

					selected.unbind("click",hidePullDown);
					selected.click(showPullDown);

					select.trigger("change");

				}).appendTo(unit)



				unit.appendTo(body)

				if(l.width()>maxWidth-60){
					l.text(l.text()+"...");
					while(l.width()>maxWidth-60){
						var t=l.text()
						l.text(t.substring(0,t.length-4)+"...")
					}
				}

				l.css("float","none");

				if(l.width()>w){
					w=l.width()
				}


				if($(this).attr("selected")){
					unit.addClass("over")
				}

				index++
			});

			if(autoWidth){
				pullDownSetAutoWidth(pd,maxWidth,w)
			}else{
				pullDownSetFixedWidth(pd,maxWidth)
			}

			pd.find(".pullDownSelectorSheet .center").addClass("png");


			select.change(function(e){
				selected.find("label").text(body.find(".pullDownSelectorUnit:eq("+options.index(select.find("option:selected"))+")").text());
			});

			selected.find("label").text(body.find(".pullDownSelectorUnit:eq("+options.index(select.find("option:selected"))+")").text());

			selector.addClass("hidden")
		};










		var pullDownExpandedGenerateAsset=function(pd,maxWidth,autoWidth){
			var scrollingIndex=0;
			var scrollingHeight=31;


			var select=pd.find("select");
			var options=pd.find("select option");

			var scrollingThreshold=parseInt(select.attr("size"));
			var sheetHeight;
			var optionCount=options.length

			if(optionCount>scrollingThreshold){
				sheetHeight=scrollingThreshold*scrollingHeight+7;
			}else{
				sheetHeight=optionCount*scrollingHeight+7;
			}

			select.attr("tabindex",-1);

			var selectedIndex=options.index(select.find("option:selected"));

			var selector=$("<div />").addClass("pullDownSelector").appendTo(pd);
			var sheet=$("<div />").addClass("pullDownSelectorSheet").addClass("clearfix png").appendTo(selector);
			var bodyContainer=$("<div />").addClass("pullDownSelectorBodyContainer");
			var body=$("<div />").addClass("pullDownSelectorBody");

			selector.css("margin-top",0);
			pd.css("height",sheetHeight+"px");


			pd.focus(function(e){
				pd.keydown(selectPullDown)
			}).blur(function(e){
				pd.unbind("keydown",selectPullDown);
			}).click(function(e){
				pd.focus();
			});


			var wheel=function(e,delta){
				e.preventDefault();
				e.stopPropagation();
				step(delta/Math.abs(delta));
			};

			var step=function(delta){

				scrollingIndex+=-parseInt(delta);
				if(scrollingIndex<0){
					scrollingIndex=0;
				}else if(scrollingIndex>scrollingMax){
					scrollingIndex=scrollingMax;
				}

				body.attr("style","margin-top:-"+(scrollingIndex*scrollingHeight)+"px;");
				if(bar)bar.css("top",parseInt(26+scrollingIndex*barDifY)+"px");
			};

			var selectPullDown=function(e){
				if(e.which==38){//up
					e.preventDefault();
					e.stopPropagation();
					selectedIndex--;
					if(selectedIndex<0){
						selectedIndex=0;
					}else{
						if(selectedIndex<scrollingIndex){
							step(1)
						}
						body.find(".pullDownSelectorUnit:eq("+(selectedIndex+1)+")").removeClass("over");
						body.find(".pullDownSelectorUnit:eq("+(selectedIndex)+")").addClass("over");
						select.find("option:nth-child("+(selectedIndex+1)+")").attr("selected","selected");
						select.trigger("change");
					}
				}else if(e.which==40){//down
					e.preventDefault();
					e.stopPropagation();
					selectedIndex++;
					if(selectedIndex>options.length-1){
						selectedIndex=options.length-1;
					}else{
						if(selectedIndex>=scrollingIndex+scrollingThreshold){
							step(-1)
						}
						body.find(".pullDownSelectorUnit:eq("+(selectedIndex-1)+")").removeClass("over")
						body.find(".pullDownSelectorUnit:eq("+(selectedIndex)+")").addClass("over")
						select.find("option:nth-child("+(selectedIndex+1)+")").attr("selected","selected");
						select.trigger("change");
					}
				}
			};




			if(optionCount>scrollingThreshold){
				var h=parseInt((sheetHeight-68)*scrollingThreshold/optionCount);

				var scrollingMax=optionCount-scrollingThreshold;
				var barDifY=(sheetHeight-68-h)/scrollingMax;

				var module=$('<div class="scroll" style="height:'+(sheetHeight-14)+'px"></div>');

				var over=function(e){
					$(this).addClass("over")
					$(this).bind("mouseleave",out)
				};

				var out=function(e){
					$(this).removeClass("over");
					$(this).unbind("mouseleave",out);
				};

				var isOver;
				var checkOver=function(e){
					isOver=true;
				};
				var checkOut=function(e){
					isOver=false;
				};

				var bar=$('<div class="bar" style="top:26px;height:'+h+'px"><span class="top"></span></div>').mousedown(function(e){
					var baseMouse=e.pageY;
					var baseBar=$(this).position().top;


					var drag=function(e){
						var y = baseBar+e.pageY-baseMouse;
						if(y<26){
							y=26;
						}else if(y>sheetHeight-42-h){
							y=sheetHeight-42-h;
						}
						scrollingIndex=parseInt((y-26)/barDifY+0.5);
						body.attr("style","margin-top:-"+ scrollingIndex * scrollingHeight+"px;")
						bar.css("top",parseInt(26+barDifY*scrollingIndex)+"px");
					};
					var up=function(e){

						$(document).unbind("mousemove",drag);
						$(document).unbind("mouseup",up);

						if(isOver){
							bar.bind("mouseleave",out);
						}else{
							bar.removeClass("over")
						}
						bar.unbind("mouseenter",checkOver)
						bar.unbind("mouseleave",checkOut);
					};


					bar.mouseenter(checkOver).mouseleave(checkOut);
					$(this).unbind("mouseleave",out);
					$(document).mousemove(drag).mouseup(up);
				}).mouseenter(over).appendTo(module);

				var scrollTimer
				var scrollUp=function(){
					scrollingIndex--;
					if(scrollingIndex<0)scrollingIndex=0;
					body.css("margin-top",-(scrollingIndex*scrollingHeight)+"px");
					bar.css("top",parseInt(26+scrollingIndex*barDifY)+"px");
					scrollTimer=setTimeout(scrollUp,250);
				};
				var scrollDown=function(){
					scrollingIndex++
					if(scrollingIndex>scrollingMax)scrollingIndex=scrollingMax
					body.css("margin-top",-(scrollingIndex*scrollingHeight)+"px");
					bar.css("top",parseInt(26+scrollingIndex*barDifY)+"px");
					scrollTimer=setTimeout(scrollDown,250);
				};

				var arrowUp=$('<div class="up bgOver"></div>').mousedown(scrollUp).mouseup(function(e){
					clearTimeout(scrollTimer)
				}).enhanceBGOver().appendTo(module);

				var arrowDown=$('<div class="down bgOver"></div>').mousedown(scrollDown).mouseup(function(e){
					clearTimeout(scrollTimer)
				}).enhanceBGOver().appendTo(module);

				sheet.append(module);

				if(scrollingIndex>selectedIndex){
					step( scrollingIndex-selectedIndex )
				}else if(selectedIndex>=scrollingIndex+scrollingThreshold){
					step( scrollingIndex+scrollingThreshold-selectedIndex-1 )
				}

				pd.mousewheel(wheel);
			}

			bodyContainer.css("height",sheetHeight-8);
			sheet.append('<div class="left png"><div class="top" style="height:'+sheetHeight+'px"></div></div>');
			sheet.append('<div class="center"><div class="top" style="height:'+(sheetHeight-8)+'px"></div></div>');
			sheet.append('<div class="right png"><div class="top" style="height:'+sheetHeight+'px"></div></div>');
			sheet.find(".center .top").append(bodyContainer);

			bodyContainer.append(body)



			var index=1
			var w=0;



			$.each(options,function(){
				var unit=$("<div />").addClass("pullDownSelectorUnit");

				var i = index
				var l=$('<label />').text($(this).text());
				l.mousedown(function(e){
					e.stopPropagation();
					e.preventDefault();

					body.find(".pullDownSelectorUnit").eq(options.index(select.find("option:selected"))).removeClass("over")
					unit.addClass("over");

					selectedIndex=i-1;

					select.find("option:nth-child("+i+")").attr("selected","selected");

					select.trigger("change");

				}).appendTo(unit)

				unit.appendTo(body)
				if(l.width()>maxWidth-60){
					l.text(l.text()+"...");
					while(l.width()>maxWidth-60){
						var t=l.text()
						l.text(t.substring(0,t.length-4)+"...")
					}
				}

				l.css("float","none");

				if(l.width()>w){
					w=l.width()
				}


				if($(this).attr("selected")){
					unit.addClass("over")
				}

				index++
			});

			if(autoWidth){
				pullDownSetAutoWidth(pd,maxWidth,w)
			}else{
				pullDownSetFixedWidth(pd,maxWidth)
			}

			pd.find(".pullDownSelectorSheet .center").addClass("png");


			select.change(function(e){
				body.find(".pullDownSelectorUnit").removeClass("over")
				body.find(".pullDownSelectorUnit").eq(options.index(select.find("option:selected"))).addClass("over");
			});
		};














		var generatePullDown=function(pd){
			pullDownGenerateAsset(pd,500,true);
		}

		var generatePullDownFixedWidth=function(pd){
			pullDownGenerateAsset(pd,parseInt(pd.css("width")));
		}


		var generatePullDownExpanded=function(pd){
			pullDownExpandedGenerateAsset(pd,500,true);
		}


		var generatePullDownExpandedFixedWidth=function(pd){
			pullDownExpandedGenerateAsset(pd,parseInt(pd.css("width")));
		}






		return $(this).each(function(){
			var me=$(this);

			if(me.hasClass(".fixedWidth")||$.browser.opera){
				if(me.find("select").attr("size")>0){
					generatePullDownExpandedFixedWidth(me);
				}else{
					generatePullDownFixedWidth(me);
				}
			}else{
				if(me.find("select").attr("size")>0){
					generatePullDownExpanded(me);
				}else{
					generatePullDown(me);
				}
			}

		});













	};


$(document).ready(function(){

//	$(".textField").enhanceTextField()
//	$(".radiobuttons").enhanceRadioButton()
//	$(".checkboxes").enhanceCheckbox()
//	$(".pullDown").enhancePullDown()
//	$(".textarea").enhanceTextArea()


});
