var Autocompleter={};Autocompleter.Base=new Class({options:{minLength:1,useSelection:true,markQuery:true,inheritWidth:true,maxChoices:10,injectChoice:null,onSelect:Class.empty,onShow:Class.empty,onHide:Class.empty,customTarget:null,className:"autocompleter-choices",zIndex:10002,observerOptions:{},fxOptions:{},overflown:[]},initialize:function(b,a){if(a){this.setOptions(a)}this.element=$(b);this.build();this.observer=new Observer(this.element,this.prefetch.bind(this),$merge({delay:100},this.options.observerOptions));this.value=this.observer.value;this.queryValue=null},build:function(){if($(this.options.customTarget)){this.choices=this.options.customTarget}else{this.choices=new Element("ul",{"class":this.options.className,styles:{zIndex:this.options.zIndex}}).injectTop(document.body);this.fix=new OverlayFix(this.choices)}this.fx=this.choices.effect("opacity",$merge({wait:false,duration:200},this.options.fxOptions)).addEvent("onStart",function(){if(this.fx.now){return}this.choices.setStyle("display","");this.fix.show()}.bind(this)).addEvent("onComplete",function(){if(this.fx.now){return}this.choices.setStyle("display","none");this.fix.hide()}.bind(this)).set(0);this.element.setProperty("autocomplete","off").addEvent((Browser.Engine.trident||Browser.Engine.webkit)?"keydown":"keypress",this.onCommand.bindWithEvent(this)).addEvent("mousedown",this.onCommand.bindWithEvent(this,[true])).addEvent("focus",this.toggleFocus.bind(this,[true])).addEvent("blur",this.toggleFocus.bind(this,[false])).addEvent("trash",this.destroy.bind(this))},destroy:function(){this.choices.remove()},toggleFocus:function(a){this.focussed=a;if(!a){this.hideChoices()}},onCommand:function(b,a){if(a&&this.focussed){this.prefetch()}if(b.key&&!b.shift){switch(b.key){case"enter":case"tab":if(this.selected&&this.visible){this.choiceSelect(this.selected);b.stop()}return;case"up":case"down":if(this.observer.value!=(this.value||this.queryValue)){this.prefetch()}else{if(this.queryValue===null){break}else{if(!this.visible){this.showChoices()}else{this.choiceOver((b.key=="up")?this.selected.getPrevious()||this.choices.getLast():this.selected.getNext()||this.choices.getFirst());this.setSelection()}}}b.stop();return;case"esc":this.hideChoices();return}}this.value=false},setSelection:function(){if(!this.options.useSelection){return}var d=this.queryValue.length;if(this.element.value.indexOf(this.queryValue)!=0){return}var b=this.selected.inputValue.substr(d);if(document.getSelection){this.element.value=this.queryValue+b;this.element.selectionStart=d;this.element.selectionEnd=this.element.value.length}else{if(document.selection){var a=document.selection.createRange();a.text=b;a.move("character",-b.length);a.findText(b);a.select()}}this.value=this.observer.value=this.element.value},hideChoices:function(){if(!this.visible){return}this.visible=this.value=false;this.observer.clear();this.fx.start(0);this.fireEvent("onHide",[this.element,this.choices])},showChoices:function(){if(this.visible||!this.choices.getFirst()){return}this.visible=true;var a=this.element.getCoordinates(this.options.overflown);this.choices.setStyles({left:a.left,top:a.bottom});if(this.options.inheritWidth){this.choices.setStyle("width",a.width)}this.fx.start(1);this.choiceOver(this.choices.getFirst());this.fireEvent("onShow",[this.element,this.choices])},prefetch:function(){if(this.element.value.length<this.options.minLength){this.hideChoices()}else{if(this.element.value==this.queryValue){this.showChoices()}else{this.query()}}},updateChoices:function(a){this.choices.empty();this.selected=null;if(!a||!a.length){return}if(this.options.maxChoices<a.length){a.length=this.options.maxChoices}a.each(this.options.injectChoice||function(b,d){var e=new Element("li").setHTML(this.markQueryValue(b));e.inputValue=b;this.addChoiceEvents(e).injectInside(this.choices)},this);this.showChoices()},choiceOver:function(a){if(this.selected){this.selected.removeClass("autocompleter-selected")}this.selected=a.addClass("autocompleter-selected")},choiceSelect:function(a){this.observer.value=this.element.value=a.inputValue;this.hideChoices();this.fireEvent("onSelect",[this.element],1)},markQueryValue:function(a){return(this.options.markQuery&&this.queryValue)?a.replace(new RegExp("^("+this.queryValue.escapeRegExp()+")","i"),'<span class="autocompleter-queried">$1</span>'):a},addChoiceEvents:function(a){return a.addEvents({mouseover:this.choiceOver.bind(this,a),mousedown:this.choiceSelect.bind(this,a)})}});Autocompleter.Base.implement(new Events);Autocompleter.Base.implement(new Options);Autocompleter.Local=new Class({Extends:Autocompleter.Base,options:{minLength:0,filterTokens:null},initialize:function(b,d,a){this.parent(b,a);this.tokens=d;if(this.options.filterTokens){this.filterTokens=this.options.filterTokens.bind(this)}},query:function(){this.hideChoices();this.queryValue=this.element.value;this.updateChoices(this.filterTokens())},filterTokens:function(a){var b=new RegExp("^"+this.queryValue.escapeRegExp(),"i");return this.tokens.filter(function(d){return b.test(d)})}});Autocompleter.Ajax={};Autocompleter.Ajax.Base=new Class({Extends:Autocompleter.Base,Implements:[Events,Options],options:{postVar:"value",postData:{},ajaxOptions:{},onRequest:Class.empty,onComplete:Class.empty},initialize:function(d,b,a){this.parent(d,a);var a=$merge({sendJson:false,url:b,autoCancel:true,onComplete:this.queryResponse.bind(this),onFailure:this.queryResponse.bind(this,[false])},this.options.ajaxOptions);this.ajax=new Request.JSON(a)},query:function(){var a=$extend({},this.options.postData);a[this.options.postVar]=this.element.value;pageTracker._trackEvent("Search","Autosearch",this.element.value);this.fireEvent("onRequest",[this.element,this.ajax]);this.ajax.get(a)},queryResponse:function(a){this.value=this.queryValue=this.element.value;this.selected=false;this.hideChoices();this.fireEvent(a?"onComplete":"onFailure",[this.element,this.ajax],20)}});Autocompleter.Ajax.Json=new Class({Extends:Autocompleter.Ajax.Base,queryResponse:function(a){this.parent(a);var b=JSON.decode(a||false);if(!b||!b.length){return}this.updateChoices(b)}});Autocompleter.Ajax.Xhtml=new Class({Extends:Autocompleter.Ajax.Base,options:{parseChoices:null},queryResponse:function(a){this.parent(a);if(!a){return}this.choices.setHTML(a).getChildren().each(this.options.parseChoices||this.parseChoices,this);this.showChoices()},parseChoices:function(a){var b=a.innerHTML;a.inputValue=b;a.setHTML(this.markQueryValue(b))}});var OverlayFix=new Class({initialize:function(a){this.element=$(a);if(Browser.Engine.trident&&!Browser.Engine.version==5){this.element.addEvent("trash",this.destroy.bind(this));this.fix=new Element("iframe",{properties:{frameborder:"0",scrolling:"no",src:"javascript:false;"},styles:{position:"absolute",border:"none",display:"none",filter:"progid:DXImageTransform.Microsoft.Alpha(opacity=0)"}}).injectAfter(this.element)}},show:function(){if(this.fix){this.fix.setStyles($extend(this.element.getCoordinates(),{display:"",zIndex:(this.element.getStyle("zIndex")||1)-1}))}return this},hide:function(){if(this.fix){this.fix.setStyle("display","none")}return this},destroy:function(){this.fix.remove()}});var Observer=new Class({options:{periodical:false,delay:300},initialize:function(d,a,b){if(b){this.setOptions(b)}this.addEvent("onFired",a);this.element=$(d);this.listener=this.fired.bind(this);this.value=this.element.get("value");if(this.options.periodical){this.timer=this.listener.periodical(this.options.periodical)}else{this.element.addEvent("keyup",this.listener)}},fired:function(){var a=this.element.get("value");if(this.value==a){return}this.clear();this.value=a;this.timeout=this.fireEvent.delay(this.options.delay,this,["onFired",[a]])},clear:function(){$clear(this.timeout);return this}});Observer.implement(new Options);Observer.implement(new Events);VinesSearchAC={};VinesSearchAC.Base=new Class({Extends:Autocompleter.Ajax.Base,options:{postVar:"q",maxChoices:20,ajaxOptions:{method:"get"},allow_create:false,ignore_no_image:false,callBackEvent:false},initialize:function(d,b,a){if(!$(d)){return}$(d).addEvent("click",function(){$(d).focus();$(d).select()});if(a){this.setOptions(a)}this.parent(d,b)},get_data_from_choice:function(b,a){if(!b){return}try{var d=b.getChildren()}catch(f){return}this.val="";this.idName=a;d.each(function(e){if(e.id==this.idName){this.val=e.innerHTML}}.bind(this));return this.val},get_ct_ob:function(d){var a=this.get_data_from_choice(d,"object_id");var b=this.get_data_from_choice(d,"content_type_id");return b+"-"+a},are_there_results:function(a){try{var b=a.getChildren()}catch(d){return false}if(b[0].id=="no-results"){return false}else{return true}},format_one_choice:function(b,e,h,j,g,f,d){if(!f){arr=h.split("/");var a=arr[2];arr=a.split("-");g=arr[1];f=arr[0]}str="";if(Browser.Engine.trident4){str+='<div style="zoom:1;">'}str+='<div id="object_id" style="display:none">'+g+"</div>";str+='<div id="content_type_id"style="display:none">'+f+"</div>";str+='<div id="content_type_name" style="display:none">'+b+"</div>";str+='<div id="name" style="display:none">'+e+"</div>";str+='<div id="name_url"style="display:none">'+h+"</div>";str+='<div id="image_url" style="display:none">'+j+"</div>";if(j){str+='<img src="'+j+'" class="fl">'}str+='<div class="object-text">';str+='    <div id="'+h+'-search-loading" class="pt-5 fr dn">';str+='	    <img src="'+MEDIA_URL+'vine/img/icons/loader-rating.gif"/><input type="hidden" name="q" id="ac-sub-'+f+"-"+g+'"  value="'+f+"-"+g+'" />   ';str+="    </div>";str+='	<span class="bold">'+e+"</span><br/>";str+='	<span class="f-11 mgray">'+b+"</span>";if(d){str+='&nbsp;<span class="f-10 black">(alias match)</span>'}str+="    <br/>";str+="</div>";if(Browser.Engine.trident4){str+="</div>"}return str},format_no_choice:function(){str='<div id="no-results" style="margin-left:40px;line-height:12px;" class="mt-4">';str+='	<span class="bold">Sorry no results.</span><br/>';str+="</div>";return str},format_create_new:function(a){str='<div id="object_id" style="display:none">0</div>';str+='<div id="content_type_id"style="display:none">0</div>';str+='<div id="content_type_name" style="display:none"></div>';str+='<div id="name" style="display:none">'+a+"</div>";str+='<div id="name_url"style="display:none"></div>';str+='<div id="image_url" style="display:none"></div>';str+='<div id="create-new" style="margin-left:40px;line-height:12px;" class="mt-4">';str+='	<span id="'+a+'" class="bold">Create "'+a+'"</span><br/>';str+="</div>";return str},format_choices:function(d){var b=[];if(this.options.allow_create){b.include(this.format_create_new(this.element.value))}var a=true;if(d){d.each(function(f,g){if(typeof(f)=="string"){b.include(f)}else{if(this.options.ignore_no_image==false||(this.options.ignore_no_image==true&&f.image_url!=undefined)){b.include(this.format_one_choice(f.content_type,f.name,f.url,f.image_url,f.pk,f.content_type_id,f.alias_match));a=false}}}.bind(this))}if(a){b.include(this.format_no_choice())}return b},queryResponse:function(a){this.parent(a);choices=this.format_choices(a);this.value=this.queryValue=this.element.value;this.updateChoices(choices)},setSelection:function(){this.value=this.observer.value=this.element.value},build:function(){if($(this.options.customTarget)){this.choices=this.options.customTarget}else{this.choices=new Element("ul",{"class":this.options.className,styles:{zIndex:this.options.zIndex}}).injectTop(document.body);this.fix=new OverlayFix(this.choices)}this.fx=this.choices.effect("opacity",$merge({wait:false,duration:200},this.options.fxOptions)).addEvent("onStart",function(){if(this.fx.now){return}this.choices.setStyle("display","");this.fix.show()}.bind(this)).addEvent("onComplete",function(){if(this.fx.now){return}}.bind(this)).set(0);this.element.setProperty("autocomplete","off").addEvent((Browser.Engine.trident||Browser.Engine.webkit)?"keydown":"keypress",this.onCommand.bindWithEvent(this)).addEvent("mousedown",this.onCommand.bindWithEvent(this,[true])).addEvent("focus",this.toggleFocus.bind(this,[true])).addEvent("blur",this.toggleFocus.bind(this,[false])).addEvent("trash",this.destroy.bind(this))},choiceSelect:function(d){if(this.options.callBackEvent){arg={};arg.object_id=this.get_data_from_choice(d,"object_id");arg.content_type_id=this.get_data_from_choice(d,"content_type_id");arg.name=this.get_data_from_choice(d,"name");arg.name_url=this.get_data_from_choice(d,"name_url");arg.image_url=this.get_data_from_choice(d,"image_url");this.element.fireEvent(this.options.callBackEvent,arg);this.fireEvent(this.options.callBackEvent,arg);this.hideChoices();this.element.value=""}else{var a=this.get_data_from_choice(d,"object_id");var f=this.get_data_from_choice(d,"content_type_id");var b=this.get_data_from_choice(d,"name");var e=this.element.value+":"+b+":"+f+":"+a;pageTracker._trackEvent("Search","Selection",e);var g=this.get_data_from_choice(d,"name_url");document.location.href=g}}});VinesSearchAC.BaseWithAds=new Class({Extends:VinesSearchAC.Base,initialize:function(d,b,a){this.adHtml="";var e=$(d);if(e){e.addEvent("adReceived",this.injectAd.bind(this))}this.parent(d,b,a)},injectAd:function(a,b){this.adHtml='<div class="js-search-ad"><img src="'+a+'"/></div>';this.adUrl=b},format_choices:function(a){search_slot=3;if(this.adHtml){first=a.filter(function(d,b){return b<(search_slot-1)});second=a.filter(function(d,b){return b>=search_slot});a=first.extend([this.adHtml]).extend(second)}return this.parent(a)},choiceSelect:function(b){var a=b.getChildren();if(a.length==1&&a[0].hasClass("js-search-ad")){window.open(this.adUrl,"_blank")}else{this.parent(b)}}});VinesSearchAC.WithSubMenus=new Class({Extends:VinesSearchAC.Base,options:{subs:{},url2:"",build_animation_duration:200,allow_select_main_menu:true,subMenuClass:"VinesSearchAC.SubMenu"},initialize:function(e,d,b){this.options.subs={};this.sub_menu_focused=false;if(!$(e+"-selected")){var a=new Element("input");a.id=e+"-selected";a.setProperty("type","hidden").injectAfter(e)}this.parent(e,d,b)},get_sub_menu:function(b){var a=this.get_ct_ob(b);var d="ac-sub-"+a;if(this.options.subs[d]){return this.options.subs[d]}else{return false}},choiceSelect:function(a){if(!this.are_there_results(a)){this.hideChoices();a.fireEvent("hide_sub_menu");return}if(this.options.allow_select_main_menu==false){if(this.options.allow_create&&this.get_data_from_choice(a,"object_id")==0){}else{return}}arg={};arg.object_id=this.get_data_from_choice(a,"object_id");arg.content_type_id=this.get_data_from_choice(a,"content_type_id");arg.name=this.get_data_from_choice(a,"name");arg.name_url=this.get_data_from_choice(a,"name_url");arg.image_url=this.get_data_from_choice(a,"image_url");this.element.fireEvent(this.options.callBackEvent,arg);this.hideChoices();a.fireEvent("hide_sub_menu")},onCommand:function(d,b){var a=this.get_sub_menu(this.selected);if(b&&this.focussed){this.prefetch()}if(d.key&&!d.shift){switch(d.key){case"enter":case"tab":if(this.sub_menu_focused==true&&a){if(a.selected&&a.visible){a.choiceSelect(a.selected);d.stop()}return}else{if(this.selected&&this.visible){this.choiceSelect(this.selected);d.stop()}return}case"up":case"down":if(this.observer.value!=(this.value||this.queryValue)){this.prefetch()}else{if(this.queryValue===null){break}else{if(!this.visible){this.showChoices()}else{if(this.sub_menu_focused==true&&a){a.choiceOver((d.key=="up")?a.selected.getPrevious()||a.choices.getLast():a.selected.getNext()||a.choices.getFirst());a.setSelection()}else{this.choiceOver((d.key=="up")?this.selected.getPrevious()||this.choices.getLast():this.selected.getNext()||this.choices.getFirst());this.setSelection()}}}}d.stop();return;case"esc":this.hideChoices();return;case"left":case"right":if(d.key=="left"){this.sub_menu_focused=false;if(a){a.hideChoices()}}else{this.sub_menu_focused=true;if(a){a.showChoices();a.choices.getFirst();if(a.selected){a.selected.addClass("autocompleter-selected")}}}d.stop();return}}this.value=false},choiceOver:function(el){if(this.selected==el){return}if(this.selected){this.selected.fireEvent("hide_sub_menu")}if(this.selected){this.selected.removeClass("autocompleter-selected")}this.selected=el.addClass("autocompleter-selected");if(!this.are_there_results(this.selected)){return}if(this.get_data_from_choice(this.selected,"object_id")==0){return}var name_url=this.get_data_from_choice(this.selected,"name_url");if($(name_url+"-search-loading")){$(name_url+"-search-loading").removeClass("dn")}var ct_ob=this.get_ct_ob(this.selected);var choice_ac_id="ac-sub-"+ct_ob;if($(choice_ac_id)&&!$(choice_ac_id).hasClass("ready")){$(choice_ac_id).addClass("ready");c=eval(this.options.subMenuClass);var ac=new c(choice_ac_id,this,this.options.url2);$(el).addEvent("mouseover",function(){this.showChoices()}.bind(ac));$(el).addEvent("show_sub_menu",function(){this.showChoices()}.bind(ac));$(el).addEvent("hide_sub_menu",function(){this.hideChoices();this.ignoreAjaxCall()}.bind(ac));$(el).addEvent("focus",function(){this.showChoices()}.bind(ac));$(el).addEvent("blur",function(){this.hideChoices()}.bind(ac));this.addEvent("onHide",function(){this.hideChoices()}.bind(ac));ac.observer.fireEvent("onFired");this.options.subs[choice_ac_id]=ac}else{$(el).fireEvent("show_sub_menu")}}});VinesSearchAC.WithSubMenus.implement(new Options);VinesSearchAC.SubMenu=new Class({Extends:VinesSearchAC.Base,options:{parentSelected:null,parentMenu:null,build_animation_duration:0},initialize:function(d,b,a){this.options.parentMenu=b;this.options.parentSelected=b.selected;this.parent(d,a)},ignoreAjaxCall:function(){this.ajax.addEvent("onComplete",this.hideChoices.bind(this));this.hideChoices()},showChoices:function(){var f=this.get_data_from_choice(this.options.parentSelected,"name_url");if($(f+"-search-loading")){$(f+"-search-loading").addClass("dn")}if(this.options.parentMenu.selected!==this.options.parentSelected){return}if(this.visible||!this.choices.getFirst()){return}this.visible=true;if(this.get_data_from_choice(this.choices.getFirst(),"object_id")==0){return}var g=this.options.parentSelected.getCoordinates();var e=g.left.toInt()+100;var d=g.top.toInt();var b=this.options.parentSelected.getStyle("width");e=e+"px";d=d+"px";var a=this.choices;a.setStyles({left:e,top:d,width:b,"z-index":10003});this.fx.start(1);this.choiceOver(this.choices.getFirst());this.selected.removeClass("autocompleter-selected");this.fireEvent("onShow",[this.element,this.choices])},choiceSelect:function(a){arg={};arg.object_id=this.get_data_from_choice(a,"object_id");arg.content_type_id=this.get_data_from_choice(a,"content_type_id");arg.name=this.get_data_from_choice(a,"name");arg.name_url=this.get_data_from_choice(a,"name_url");arg.image_url=this.get_data_from_choice(a,"image_url");try{this.options.parentMenu.element.fireEvent(this.options.parentMenu.options.callBackEvent,arg);this.options.parentMenu.hideChoices()}catch(b){}this.hideChoices()}});VinesACWidgets={};function StartVinesAutoCompleteWidget(b,a){if($(b.id).hasClass("ready")&&VinesACWidgets[b.id]){return}VinesACWidgets[b.id]=new VinesAutoCompleteWidget(b,a)}VinesAutoCompleteWidget=new Class({options:{ct_ids:"",content_objects:[],content_type_id:null,object_id:null,disable_delete:false,disable_add:false,name:null,search_input:null,input_name:"assoc",input_values_with_ct:true,single_value:false},initialize:function(f,d){this.setOptions(d);var b=(Math.round((Math.random()*9)+1));var g=new Element("input",{styles:{border:"none","padding-top":"2px",background:"none"},id:b});g.inject(f);this.options.search_input=g;this.create({content_type_id:this.options.content_type_id,object_id:this.options.object_id,name:this.options.name,disable_delete:this.options.disable_delete});var h=this.options.content_objects;h.each(function(k,j){this.create(k)}.bind(this));if(this.options.disable_add){g.setProperty("disabled","true")}else{f.addEvent("click",function(){this.focus()}.bind(g));var a="Fire"+g.id;var e=new VinesSearchAC.Base(g.id,"/autosearch/?ct_ids="+this.options.ct_ids,{callBackEvent:a});$(g).addEvent(a,function(j,k){j.disable_delete=false;this.create(j,k)}.bind(this))}$(g).addEvent((Browser.Engine.trident||Browser.Engine.webkit)?"keydown":"keypress",this.onCommand.bindWithEvent(this));f.addClass("ready")},onCommand:function(d,a){if(d.key&&!d.shift){switch(d.key){case"backspace":search_input=this.options.search_input;if(search_input.value==""){var b=search_input.getPrevious();if(b&&!b.hasClass("disable_delete")){this.removeNode(b)}}}}},create:function(n,g){if(n.content_type_id==null||n.object_id==null||n.name==null){return}var l=n.object_id;var f=n.content_type_id;var b=n.name;var d=n.disable_delete;var m=f+"-"+l;if(this.options.content_objects.contains(m)&&$("text-complete-object"+m)){$("text-complete-object"+m).effect("background-color",{duration:600,transition:Fx.Transitions.linear}).start("#FFFF33","#FFFFff").chain(function(){$("text-complete-object"+m).setStyle("background-color","transparent")});return false}this.options.content_objects.extend([m]);var k=new Element("span");k.setProperty("id","text-complete-object"+m).setHTML(b).addClass("text-complete-object").addClass("dib").injectBefore(this.options.search_input).setProperty("content_type_id",f).setProperty("object_id",l);if(d){k.addClass("disable_delete")}else{var j=new Element("a");j.addEvent("click",function(){this.removeNode(j.parentNode)}.bind(this));j.addClass("red");j.setHTML(" (x)");j.inject(k)}var h=new Element("input");h.type="hidden";if(this.options.input_values_with_ct){h.value=f+"-"+l}else{h.value=l}h.name=this.options.input_name;h.inject(k);if(this.options.single_value){this.options.search_input.addClass("dn");this.options.search_input.setProperty("disabled","true")}},removeNode:function(a){var d=a.getProperty("content_type_id");var b=a.getProperty("object_id");a.remove();this.removeContentObjectElement(d+"-"+b);if(this.options.single_value&&(this.options.content_objects.length==0)){this.options.search_input.removeProperty("disabled");this.options.search_input.removeClass("dn")}},removeContentObjectElement:function(a){if(!this.options.content_objects.contains(a)){return false}for(i=0;i<this.options.content_objects.length;i++){if(this.options.content_objects[i]==a){this.options.content_objects.splice(i,1);return}}}});VinesAutoCompleteWidget.implement(new Events);VinesAutoCompleteWidget.implement(new Options);