$.fn.jdrop=function(){$('body').append('<div class="jDrop" style="display:none"></div>');var setWidth=$('.jDrop').css('width');if(setWidth=='auto'){var widthMode="auto"}else{var widthMode="css";setWidth=setWidth.replace('px','');}
this.each(function(intIndex){$(this).after('<div class="jDrop" title="'+$(this).attr('name')+'"><div class="jSel"><span class="jSelOp">'+$(this).children('option:selected').includeHTML()+'</span></div><div class="jDropBut"></div><div class="jOpDrop"></div></div>').hide();if(widthMode=="auto"){var staticWidth=$(this).width()+20}
else{var staticWidth=setWidth-$(".jDropBut:eq("+intIndex+")").width()}
$(".jDrop:eq("+intIndex+")").children('.jSel').css({width:staticWidth+'px'})})
$('.jSel, .jDropBut').click(function(){if($('.jSel').index(this)!=-1){var jDropIndex=$('.jSel').index(this)}else{var jDropIndex=$('.jDropBut').index(this)}
var jDropOptions='';var count_items=0;$('select:eq('+jDropIndex+')').children('option').each(function(intIndex){jDropOptions=jDropOptions+'<div class="jOp" value="'+$(this).val()+'">'+$(this).includeHTML()+'</div>';count_items++;})
$('.jDrop:eq('+jDropIndex+')').children('.jOpDrop').html(jDropOptions);if(count_items>15){$('.jDrop:eq('+jDropIndex+')').children('.jOpDrop').css({"height":'200px'});$('.jDrop:eq('+jDropIndex+')').children('.jOpDrop').css({"overflow":'scroll'});width=$('.jDrop:eq('+jDropIndex+')').children('.jOpDrop').css("width");$('.jDrop:eq('+jDropIndex+')').children('.jOpDrop').css({"width":'200px'});}
$(".jDrop:eq("+jDropIndex+")").children('.jOpDrop').css({minWidth:$(".jDrop:eq("+jDropIndex+")").outerWidth()})
var jDropTop=$(this).parent().offset().top-$(this).parent().offsetParent().offset().top;var dropDownTop=jDropTop+$(this).parent().height()-1;var dropDownHeight=$('.jDrop:eq('+jDropIndex+') .jOpDrop').height();var winHeight=$(window).height();var docScrollTop=$(document).scrollTop();var dropDownYSpace=dropDownTop+dropDownHeight+$(this).parent().offsetParent().offset().top;var jDropLeft=$(this).parent().offset().left-$(this).parent().offsetParent().offset().left;var dropDownLeft=jDropLeft;var dropDownWidth=$('.jDrop:eq('+jDropIndex+') .jOpDrop').width();var jDropWidth=$(this).parent().outerWidth();var winWidth=$(window).width();var docScrollLeft=$(document).scrollLeft();var dropDownXSpace=dropDownLeft+dropDownWidth+$(this).parent().offsetParent().offset().left;if(dropDownYSpace>winHeight+docScrollTop){dropDownTop=jDropTop-dropDownHeight-1}
if(dropDownXSpace>winWidth+docScrollLeft){dropDownLeft=docScrollLeft+winWidth-dropDownWidth-$(this).parent().offsetParent().offset().left-3;}
$('.jDrop:eq('+jDropIndex+') .jOpDrop').css({top:dropDownTop,left:dropDownLeft})
$(this).parent().children('.jOpDrop').fadeIn(50,function(){$(this).parent().hover(function(){},function(){$(this).children('.jOpDrop').fadeOut()}),$(this).children('.jOp').hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')})
$(this).children('.jOp').click(function(){$("select[name='"+$(this).parent().parent().attr('title')+"']").val($(this).attr('value'))
$("select[name='"+$(this).parent().parent().attr('title')+"']").change();$(this).parent().parent().children('.jSel').children('.jSelOp').html($(this).html()).parent().parent().children('.jOpDrop').fadeOut()})})})};$.fn.includeHTML=function(){var thisHTML=$(this).attr('html');if(thisHTML){return thisHTML+$(this).text()}
else{return $(this).html()}};

