!function(a){var b=function(){return{init:function(b,c){this.cache={},this.children=[],this.options=a.extend({exclusions:!1,enableHtml:!1},c),this.$element=a(b),this.$label=a("#"+this.options.label),this.$value=a('input[name="'+this.options.valueHolder+'"]'),this.onChange=this.options.onChange||null;var d=this;if(this.$element.on("change",function(){d.fnHandlerOnChange(a(this))}),this.$element.data("children")){this.children=String(this.$element.data("children")).split(",");var e=this.children.shift();this.$element.val(e).trigger("change")}return this},updateLabel:function(){var b=[];a(this.options.selector+' option:selected:not([value=""])').each(function(){b.push(a(this).text())}),this.$label.val(b.length?b.join(" > "):_t("_not_selected_"))},addDropdown:function(b,c,d){if(b&&b.length){var e=this.options.selector.split(".");e.shift();var f=a("<option>").val("").text(_t("_select_")),g=a("<select>").addClass(e.join()).append(f),h=this.options.enableHtml;a.each(b,function(b,c){f=a("<option>").val(c.id),h?f.html(c.title):f.text(c.title),c.id==d&&f.prop("selected",!0),1==c.locked&&f.prop("disabled",!0),console.log(typeof c.data,c.data),"object"==typeof c.data&&f.data(c.data),g.append(f)}),c.after(g);var i=this;g.on("change",function(){i.fnHandlerOnChange(a(this))}),d&&g.trigger("change")}},fnHandlerOnChange:function(b){var c=b.val();if(c){b.nextAll().remove();var e=0;if(this.children&&this.children.length>0&&(e=this.children.shift()),this.cache[c])this.cache[c]!==!0&&this.addDropdown(this.cache[c],b,e);else{var f=a("<img>").attr({class:"spinner",src:intelli.config.ia_url+"templates/_common/img/preloader.gif"}).insertAfter(b),g=this,h={pid:c};this.options.exclusions&&(h.id=this.$element.data("id")),a.getJSON(this.options.url+"?fn=?",h,function(a){f.remove(),g.cache[c]=!0,a&&a.length>0&&(g.cache[c]=a,g.addDropdown(a,b,e))})}}else{var d=b.prev();d.length?(c=d.val(),d.nextAll().remove()):a(this.options.selector).not(":first").remove()}this.$value.val(c),this.onChange&&this.onChange(c),this.$label.length&&this.updateLabel()}}};a.fn.iaDropdown=function(c){if(this.length)return c.selector=this.selector,this.each(function(){var d=new b;d.init(this,c),a.data(this,"iadropdown",d)})}}(jQuery);