function R24Sugg(){function e(e){var t=e.extra_info.split("||");return 4!=t.length?"":'
Nessun suggerimento disponibile per '+e+'
';$(h).append(t)}var o,u=location.protocol,c=u+"//r24api.ilsole24ore.com",g="r24extra_mix",p="",v="",h="",d="",_=!1,m="",y="";this.init=function(e){m=e.inner_input_selector,y=e.outer_input_selector,v="#"+e.sugg_modal_id,h=v+" #"+e.sugg_list_id,c=e.r24SuggSrvUrl,g=e.r24SuggSrvProfile,p=e.form_selector;var t=this;$(v).find(".close").on("click",function(e){$(".tools-left .tool-container .search-tool .search-input").val("")}),$(v).keydown(function(e){if(40==e.keyCode){""===d?d=0:d+1<$(h+" li a").length&&d++;var n=$(h+" li a:eq("+d+")");return $(h+" li a").removeClass("active"),n.addClass("active"),n.hasClass("sugg_query_a")?t.selectR24Query(n):_=!1,!1}if(38==e.keyCode){""===d?d=0:d>0&&d--;var n=$(h+" li a:eq("+d+")");return $(h+" li a").removeClass("active"),n.addClass("active"),n.hasClass("sugg_query_a")?t.selectR24Query(n):_=!1,!1}if(13==e.keyCode){if(""===d||_)$(p+" input[name=searchFilter]").val(""),$(p+" input[name=channelFilter]").val(""),$(p).submit();else{var n=$(h+" li a:eq("+d+")");window.location=n.attr("href")}return!1}27===e.keyCode&&($(v).modal("hide"),$(".tools-left .tool-container .search-tool .search-input").val(""))}),$(v+" button").click(function(e){return $(p+" input[name=searchFilter]").val(""),$(p+" input[name=channelFilter]").val(""),$(p).submit(),!1}),$(v).on("click",".sugg_query_a",function(){return t.selectR24Query($(this)),$(p+" input[name=searchFilter]").val(""),$(p+" input[name=channelFilter]").val(""),$(p).submit(),!1});var t=this;$(document).delegate(y+","+m,"input",function(e){for(s=0;s<$(y+","+m).size();s++){var n=$(y+","+m).eq(s);n.is(":focus")||(n.val($(this).val()),t.update_sugg(this))}}),$(document).delegate(y,"input",function(e){$(v).modal("show"),$innerInput=$(v+" "+m),$innerInput.focus();var t=$(this).getCursorPosition();navigator.userAgent.indexOf("MSIE 9")>-1&&(t+=1),$innerInput[0].setSelectionRange(t,t)}),void 0!=e.modal_envelope_html&&$("#modal-search-wrapper").load(e.modal_envelope_html,function(){})},this.selectR24Query=function(e){for(_=!0,$chosenSuggText=$(e).find(".value").text(),f=0;f<$(y).size();f++)$(y).eq(f).val($chosenSuggText)},this.update_sugg=function(e){var t=$(e).val();if(clearTimeout(o),t.length>=2){var n=c+"/autocomp?callback=?&profilo="+g+"&output=json&q=";o=setTimeout(function(){$.getJSON(n+t,function(e){$(h).empty(),l(t,e),d=""}).done(function(){}).fail(function(){$(h).empty(),update_with_no_result(t)}).always(function(){})},200)}}}!function(e,t){e.fn.getCursorPosition=function(){var t=e(this).get(0),n=0;if("selectionStart"in t)n=t.selectionStart;else if("selection"in document){t.focus();var i=document.selection.createRange(),a=document.selection.createRange().text.length;i.moveStart("character",-t.value.length),n=i.text.length-a}return n}}(jQuery);