jQuery.fn.CRselectBox=jQuery.fn.sBox=function(){var _self=this;var _parent=_self.parent();var id=_self.attr("id");var width=_self.css("width");var wrapHtml='<div id="sBox-'+id+'" class="CRselectBox"></div>';var $wrapHtml=$(wrapHtml).appendTo(_parent);var selectedOptionValue=_self.find("option:selected").attr("value");var selectedOptionTxt=_self.find("option:selected").text();var name=_self.attr("name");var inputHtml='<input type="hidden" value="'+selectedOptionValue+'" name="'+name+'" id="'+id+'"/>';$(inputHtml).appendTo($wrapHtml);var inputTxtHtml='<input type="hidden" value="'+selectedOptionTxt+'" name="'+name+'_CRtext" id="'+id+'_CRtext"/>';$(inputTxtHtml).appendTo($wrapHtml);var aHtml='<a class="CRselectValue" href="#">'+selectedOptionTxt+'</a>';var caninput=_self.attr("ref")=='input'?true:false;if(caninput){aHtml='<input type="text" value="" id="'+id+'_hidtext" class="hidtext" style="display:none">'+aHtml;}
$(aHtml).appendTo($wrapHtml);var ulHtml='<ul class="CRselectBoxOptions"></ul>';var $ulHtml=$(ulHtml).appendTo($wrapHtml);var liHtml="";_self.find("option").each(function(){if($(this).attr("value")!=''){if($(this).attr("selected")){liHtml+='<li class="CRselectBoxItem" style="width:'+width+';"><a href="#" class="seled" rel="'+$(this).attr("value")+'">'+$(this).text()+'</a></li>';}else{liHtml+='<li class="CRselectBoxItem" style="width:'+width+';"><a href="#" rel="'+$(this).attr("value")+'">'+$(this).text()+'</a></li>';}}});$(liHtml).appendTo($ulHtml);$($wrapHtml,_parent).hover(function(){$(this).addClass("CRselectBoxHover");if(caninput){if($("#"+id+"_hidtext").val()!='')$(".CRselectValue",$wrapHtml).text($("#"+id+"_hidtext").val());}},function(){$(this).removeClass("CRselectBoxHover");});$(".CRselectValue",$wrapHtml).click(function(){$(this).blur();if(caninput){$(this).hide();$("#"+id+"_hidtext").show();}
$(".CRselectBoxOptions",$wrapHtml).show();return false;});$("#"+id+"_hidtext").change(function(){$("#"+id).val($(this).val());if($(this).val()!='')$(".CRselectValue",$wrapHtml).text($(this).val());$(".CRselectValue",$wrapHtml).show();$(this).hide();return false;});$(".CRselectBoxItem a",$wrapHtml).click(function(){$(this).blur();var value=$(this).attr("rel");var txt=$(this).text();$("#"+id).val(value);$("#"+id+"_CRtext").val(txt);$(".CRselectValue",$wrapHtml).text(txt);$(".CRselectBoxItem a",$wrapHtml).removeClass("seled");$(this).addClass("seled");$(".CRselectBoxOptions",$wrapHtml).hide();if(caninput){$(".CRselectValue",$wrapHtml).show();$("#"+id+"_hidtext").hide();$("#"+id+"_hidtext").val(txt);}
return false;});$(document).click(function(event){if($(event.target).attr("class")!="CRselectBox"){$(".CRselectBoxOptions",$wrapHtml).hide();}});_self.remove();return _self;}
