/* --------------------------------------------------*/ /* ---------- BEGIN DOCUMENT.READY() ------------*/ /* --------------------------------------------------*/ $(document).ready(function () { /* if a transcript is shown, scroll the navbar to its position in the navlist */ var path = window.location.search.split( "/" ); var id = "t"+path[path.length-1]; var el = document.getElementById(id); if( id.indexOf(".cha") != -1 ) { $("#nav").animate({scrollTop: $(el).offset().top - $("#top").height() - 15}); } /* if a hash is present (e.g., ?url=Eng-UK/Forrester/052.cha#l=24), jump to the requested Line (l) or Comment (c) */ var jumpToArray; if(jumpToArray = /((?:#)(\w)(=)(.+))/.exec(window.location)) { // if the hash is followed by the correct syntax jumpToArray[2].toLowerCase(); // ensure all letters are lowercase var pos = $('a[name="'+jumpToArray[4]+'"]'); // pos = the nearest anchor to the line/comment being requested switch(jumpToArray[2]) { // switch(letter following the hash) case "l" : var posAnchor = pos.offset().top - $("#top").height() - 5; break; case "c" : pos.parent().parent().show(); // show all of the comments for the utterance pos.parent().parent().prev().toggleClass("selected"); // set the utterance as Selected pos.parent().parent().prev().prev().prev().toggleClass("hasCommentfocus"); // change the add-comment image var posAnchor = pos.offset().top - $("#top").height() + 5; break; } $("html, body").animate({scrollTop: posAnchor}, 500); } /* set us up the linked utterances */ var utterances = $("span[name='utterance']"); // all spans where attribute "name" = "utterance" doc = utterances.get(); // get all of them into an array $(".hasComment, .addComment").click(function() { // on clicking the comment button var commClass = $(this).attr("class").slice(0,10); var utterance = $(this).nextAll("span[name='utterance']:first"); utterance.toggleClass("selected"); utterance.nextAll(".comment_set:first").slideToggle("slow"); // slide up/down the comments $(this).toggleClass(commClass+"focus"); movie.Stop(); }); /* Clicking "Log in to add a comment" opens the Login dropdown */ $(".logAdd").click(function(){ $("#loginButton").click(); }); /* --------------------------------------------------*/ /* ------------- COMMENT BUTTONS -----------------*/ /* --------------------------------------------------*/ if($("#newCommentBox").length > 0) { // ADD COMMENT BUTTON CLICKED $(".addCommentButton").click(function() { // stop the movie movie.Stop(); // set the values to the locus_beginning and locus_end $("#begin_time").val($(this).parent().prev().attr("id")); $("#end_time").val($(this).parent().prev().attr("class").match(/\d+/)); // select only the utterance's locus_end via RegEx // get the text for the selected utterance $("#newCommentUtt").html($(this).parent().prev().html()); $("#newCommentUtt .movControl").remove(); // height of the newCommentBox with extra pixels to account for border/padding/etc + the height of the selected utterance var boxHeight = 255+Number($("#newCommentUtt").height()); // show the New Comment box $("#newCommentBox").animate({"height": boxHeight}, 300); }); // TAG AUTOCOMPLETE $('#tags_input').click(function() { $('#tags_auto').focus(); }); var tagMap = {}; // array to hold the user-entered tags var i = 0; $('#tags_auto').keypress(function(e) { var char = e.which ? e.which : e.keyCode; // check browser compatibility: which vs. keyCode if (char == 13) { // if Enter is pressed e.preventDefault(); // prevent the default Enter behavior (form submit) if($('#tags_auto').val() != '') { // if the field is not blank var data = new Array(); // array to hold most recently entered tag data[0] = $('#tags_auto').val(); // data[0] = tag name data[1] = 0; // data[1] = 0 for a default "null" value add_tag(e, data, formatted = null); } return false; } }); function add_tag(event, data, formatted) { if(tagMap[data[0]] == undefined) { // if the recently-entered tag is not found in the full user-entered-tags array tagMap[data[0]] = data[1]; // set the tag equal to the default null value $("#tags_found").append(''+data[0]+'x<\/em><\/span> '); // add the tag to the list } $("#tags_auto").val(""); // clear the add-a-tag input resize_tags(); } $("#tags_auto").autocomplete("includes/ajax.auto.php", { width: 260, selectFirst: true, }).result(add_tag); $('.tags_remove').live('click', function(){ // to remove a tag $(this).parent().remove(); // remove the entire parent from the DOM delete tagMap[$(this).parent().attr('name')]; // and delete the tag from the user-entered-tags array resize_tags(); // resize the newCommentBox if the size has changed }); var tag_height = $("#tags_input").height(); // store the height of the Tags box function resize_tags() { if(tag_height != $("#tags_input").height()) { // if the height of the Tags box has changed var tag_diff = Number($("#tags_input").height()) - Number(tag_height); // store the change in height tag_height = $("#tags_input").height(); // store the new height of the Tags box $("#newCommentBox").animate({"height":Number($("#newCommentBox").height())+tag_diff}, 300); } } // CLOSE COMMENT BUTTON CLICKED $("#closeBox").click(function() { closeCommentBox(); }); function closeCommentBox() { $("#newCommentBox").animate({"height":"0"}, 200); // hide the New Comment box tagMap = {}; // clear the array of tags $("#comment").val(""); // clear the comment field $("#tags_found").html(""); // clear the tags field if($('#newCommentSuccessful').length > 0) $('#newCommentSuccessful').remove(); // remove the Success! alert } // NEW COMMENT SUBMITTED $('#newComment').validate({ errorPlacement: function(error, element) { error.insertBefore(element); }, submitHandler: function(form){ $('div#newCommentBox #submit').after('') var tranVal = $('#tran').val(); var begVal = $('#begin_time').val(); var endVal = $('#end_time').val(); var commVal = $('#comment').val(); $.ajax({ type: 'POST', url: 'includes/ajax.submit.php', data: ({ type: 'addComment', transcript_path: tranVal, locus_beginning: begVal, locus_end: endVal, newComment: commVal, tags: tagMap }), dataType: 'json', success: function(data){ $('#newCommentBox').animate({'height':'60'}, 300); $('#closeBox').after('
New comment added successfully!
'); $('#'+begVal).next().append(data.html); $('#'+data.id).hide().fadeIn('slow'); setTimeout(closeCommentBox, 1300); $('#loading').remove(); } }); return false; } }); } /* --------------------------------------------------*/ /* ---------- FORM SUBMISSIONS -------------------*/ /* --------------------------------------------------*/ // CUSTOM VALIDATION CLASSES jQuery.validator.addMethod("username", function(value, element) { return this.optional(element) || /^\w+$/.test(value); }, "Only letters and numbers allowed"); jQuery.validator.addMethod("name", function(value, element) { return this.optional(element) || /^[A-Z][a-zA-Z\s\'.-]*$/.test(value); // only allow letters, ', ., and - }, "Invalid name entered"); // EDIT PROFILE SUBMITTED $("#editForm").validate({ errorPlacement: function(error, element) { element.prev('.desc').remove(); error.insertBefore(element); }, submitHandler: function(form){ var curPassword = $("#editForm #curPassword").val(); var newPassword = $("#editForm #newPassword").val(); var firstname = $("#editForm #firstname").val(); var lastname = $("#editForm #lastname").val(); var email = $("#editForm #email").val(); $.ajax({ type: "POST", url: "/browser/includes/ajax.submit.php", data: ({type: "submitEdit", curPassword: curPassword, newPassword: newPassword, firstname: firstname, lastname: lastname, email: email}), dataType: "json", success: function(data) { if(data.success == false) alert(data.message); else if(data.success == true) { if(/(\.cha)/.test(document.referrer)) window.location = document.referrer; else window.location = window.location.protocol+"//"+window.location.host+window.location.pathname+"?user="+data.id; } } }); return false; } }); // REGISTRATION SUBMITTED var previousPage = null; //$("#registerButton").live('click', function() { previousPage = location.href; }); $("#registerForm").validate({ errorPlacement: function(error, element) { element.prev('.desc').remove(); error.insertBefore(element); }, submitHandler: function(form){ var username = $("#registerForm #username").val(); var password = $("#registerForm #password").val(); var firstname = $("#registerForm #firstname").val(); var lastname = $("#registerForm #lastname").val(); var email = $("#registerForm #email").val(); $.ajax({ type: "POST", url: "/browser/includes/ajax.submit.php", data: ({type: "submitRegistration", username: username, password: password, firstname: firstname, lastname: lastname, email: email}), dataType: "json", success: function(data) { alert(data.message); if(data.success == true) { if(/(\.cha)/.test(document.referrer)) window.location = document.referrer; else window.location = window.location.protocol+"//"+window.location.host+window.location.pathname+"?user="+data.id; } } }); return false; } }) // FORGOT PASSWORD SUBMITTED $("#forgotPassForm").validate({ submitHandler: function(form){ $('#forgotPassword').hide(); $('#forgotPassForm').append(''); var username = $("#forgotPassForm #forgotPassUsername").val(); $.post("/browser/includes/ajax.submit.php", {type: "forgotPassword", username: username}, function(data){ $('#forgotPassForm').append(data.message); $('#loading').remove(); $('#forgotPassword').show(); }, "json" ); return false; } }); // FORGOT USERNAME SUBMITTED $("#forgotUserForm").validate({ submitHandler: function(form){ $('#forgotUsername').hide(); $('#forgotUserForm').append(''); var email = $("#forgotUserForm #forgotUserEmail").val(); $.post("/browser/includes/ajax.submit.php", {type: "forgotUsername", email: email}, function(data){ $('#forgotUserForm').append(data.message); $('#loading').remove(); $('#forgotUsername').show(); }, "json" ); return false; } }); // SHOW LOG IN if($("#loginButton").css("display") == "inline"){ // if the user is not logged in $("#cancelLogin").click(function(){ // listen for clicks on the Cancel link if($("#loginDiv").css("display") == "block") { // if the login div is showing $("#loginDiv").slideUp('fast'); // hide the login div } }); $("#loginButton").unbind('click').click(function(e){ // unbind clicks from the login link $("#loginDiv").slideToggle('fast'); // show (or hide) the login div e.stopPropagation(); // stop the click event from trickling up $("#username").focus(); }); $("#loginDiv").unbind('click').click(function(e){ // unbind clicks from the login div e.stopPropagation(); // stop the click event from trickling up }); } // LOG IN SUBMITTED $("#top_login").validate({ errorPlacement: function(error, element) { element.after(error); element.focus(); }, submitHandler: function(form){ login(); } }); function login() { $('#login').hide(); $('#top_login').append(''); var username = $("#top_login #username").val(); var password = $("#top_login #password").val(); $.post("/browser/includes/ajax.submit.php", {type: "submitLogin", username: username, password: password}, function(data){ if (data.access != "true") { alert(data.message); $('#loading').remove(); $('#login').show(); } else location.reload(); }, "json" ); return false; } // LOG OUT SUBMITTED //$("#top_logout").live('click', function() { logout(); return false; }); function logout() { $.post("/browser/includes/ajax.submit.php", {type: "submitSignOut"}, function(data) { location.reload(); } ); } }); /* --------------------------------------------------*/ /* ---------- /END DOCUMENT.READY() -------------*/ /* --------------------------------------------------*/ /* --------------------------------------------------*/ /* ------------- MEDIA PLAYBACK -----------------*/ /* --------------------------------------------------*/ $(function (){ // Add "timeupdate" listener to "#mymovie". var vid = document.getElementById("mymovie"); vid.addEventListener("timeupdate", function(){ updatePosition(this.currentTime); }); // Listen for user to pause video. vid.addEventListener("pause", function(){ $( '.movControl' ).removeClass( 'playing' ); // Mark all bullets as not "playing". $( '.movControl' ).html("▶"); // Change all bullets to "play". }); // Click on the little 'play' character at end of utterance line. //$("body").on('click', ".movControl", $("body").on('click', 'span[name=utterance]', function(event) { var vid = document.getElementById("mymovie"); // If user clicked "stop" on a playing line, pause video, remove ".playing", change icon to "play". if($(this).children(".movControl").hasClass('playing')) { vid.pause(); } else { var newTime = $(this).attr("id"); vid.currentTime = newTime / 1000; vid.play(); } /* // If video currently paused, and click on highlighted line, then play video. if(( vid.paused ) && ($(this).children(".movControl").hasClass('playing'))) { vid.play(); } // Set media to clicked location and pause video else { var newTime = $(this).attr("id"); vid.currentTime = newTime / 1000; vid.pause(); } */ } ); // Listen for user to press "hotkeys". $( "body" ).on( 'keypress', function( event ) { // If user not in a text-editing field, process keypress. if(document.activeElement.type != "text" && document.activeElement.type != "textarea" && document.activeElement.type != "password") { handleKeypress(event.which); } }); getIntervals(); }); // Handle hotkeys for video playback control. function handleKeypress( keyCode ) { // If user presses 's' key, start/stop the playing. if((keyCode == 115) || (keyCode == 83)) { var vid = document.getElementById("mymovie"); if ( vid.paused ) { vid.play(); } else { vid.pause(); } } } // Create "intervals[]" from each using its id/class to get the begin/end times. // Needs to be called whenever a new chat file is loaded. var intervals = []; function getIntervals() { $( 'span[name=utterance]' ).each(function( index ) { //console.log( index + ", begin: " + $( this ).prop('id') + ", end: " + $( this ).prop('class')); intervals.push({"begin": $( this ).prop('id'), "end": $( this ).prop('class')}); }); //console.log(intervals); } // Set $ref as not playing. function notPlaying($ref) { $ref.removeClass('uttPlaying'); $ref.children(".movControl").html("▶"); // Show "play" icon. $ref.children(".movControl").removeClass("playing"); } // Set $ref as playing. function isPlaying($ref) { $ref.addClass('uttPlaying'); $ref.children(".movControl").html("■"); // Show "stop" icon. $ref.children(".movControl").addClass("playing"); } // Returns true if $elem is beyond the current scrolled view. function isScrolledOutOfView($elem) { var $window = $(window); var windowTop = $window.scrollTop(); var windowBottom = windowTop + $window.height(); var elemTop = $elem.offset().top; var elemBottom = elemTop + $elem.height(); return ((elemBottom > windowBottom) || (elemTop < windowTop)); } // Callback function for timeupdate event. function updatePosition( currentTime ) { var msTime = currentTime * 1000; for ( c = 0; c < intervals.length; c++ ) { if ((msTime >= intervals[c].begin) && (msTime < intervals[c].end)) { notPlaying($( 'span[name=utterance]' )); // Mark everything as "not playing". isPlaying($( '#' + intervals[c].begin )); // Mark line corresponding to currentTime as "playing". // Auto-scroll if playing line is out of view. if (isScrolledOutOfView($('.playing'))) { $('html, body').animate({ scrollTop: ($(".playing").offset().top - ($(window).height() / 2)) }, 500); } } //$( 'span[name=utterance]' ).removeClass('uttPlaying'); // No interval defined at currentTime. } } /* Copyright (c) 2009 Brandon Aaron (http://brandonaaron.net) * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers. * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix. * * Version: 3.0.2 * * Requires: 1.2.2+ */ (function(c){var a=["DOMMouseScroll","mousewheel"];c.event.special.mousewheel={setup:function(){if(this.addEventListener){for(var d=a.length;d;){this.addEventListener(a[--d],b,false)}}else{this.onmousewheel=b}},teardown:function(){if(this.removeEventListener){for(var d=a.length;d;){this.removeEventListener(a[--d],b,false)}}else{this.onmousewheel=null}}};c.fn.extend({mousewheel:function(d){return d?this.bind("mousewheel",d):this.trigger("mousewheel")},unmousewheel:function(d){return this.unbind("mousewheel",d)}});function b(f){var d=[].slice.call(arguments,1),g=0,e=true;f=c.event.fix(f||window.event);f.type="mousewheel";if(f.wheelDelta){g=f.wheelDelta/120}if(f.detail){g=-f.detail/3}d.unshift(f,g);return c.event.handle.apply(this,d)}})(jQuery);/* * jQuery Autocomplete plugin 1.1 * * Copyright (c) 2009 Jörn Zaefferer * * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * * Revision: $Id: jquery.autocomplete.js 15 2009-08-22 10:30:27Z joern.zaefferer $ */;(function($){$.fn.extend({autocomplete:function(urlOrData,options){var isUrl=typeof urlOrData=="string";options=$.extend({},$.Autocompleter.defaults,{url:isUrl?urlOrData:null,data:isUrl?null:urlOrData,delay:isUrl?$.Autocompleter.defaults.delay:10,max:options&&!options.scroll?10:150},options);options.highlight=options.highlight||function(value){return value;};options.formatMatch=options.formatMatch||options.formatItem;return this.each(function(){new $.Autocompleter(this,options);});},result:function(handler){return this.bind("result",handler);},search:function(handler){return this.trigger("search",[handler]);},flushCache:function(){return this.trigger("flushCache");},setOptions:function(options){return this.trigger("setOptions",[options]);},unautocomplete:function(){return this.trigger("unautocomplete");}});$.Autocompleter=function(input,options){var KEY={UP:38,DOWN:40,DEL:46,TAB:9,RETURN:13,ESC:27,COMMA:188,PAGEUP:33,PAGEDOWN:34,BACKSPACE:8};var $input=$(input).attr("autocomplete","off").addClass(options.inputClass);var timeout;var previousValue="";var cache=$.Autocompleter.Cache(options);var hasFocus=0;var lastKeyPressCode;var config={mouseDownOnSelect:false};var select=$.Autocompleter.Select(options,input,selectCurrent,config);var blockSubmit;$.browser.opera&&$(input.form).bind("submit.autocomplete",function(){if(blockSubmit){blockSubmit=false;return false;}});$input.bind(($.browser.opera?"keypress":"keydown")+".autocomplete",function(event){hasFocus=1;lastKeyPressCode=event.keyCode;switch(event.keyCode){case KEY.UP:event.preventDefault();if(select.visible()){select.prev();}else{onChange(0,true);}break;case KEY.DOWN:event.preventDefault();if(select.visible()){select.next();}else{onChange(0,true);}break;case KEY.PAGEUP:event.preventDefault();if(select.visible()){select.pageUp();}else{onChange(0,true);}break;case KEY.PAGEDOWN:event.preventDefault();if(select.visible()){select.pageDown();}else{onChange(0,true);}break;case options.multiple&&$.trim(options.multipleSeparator)==","&&KEY.COMMA:case KEY.TAB:case KEY.RETURN:if(selectCurrent()){event.preventDefault();blockSubmit=true;return false;}break;case KEY.ESC:select.hide();break;default:clearTimeout(timeout);timeout=setTimeout(onChange,options.delay);break;}}).focus(function(){hasFocus++;}).blur(function(){hasFocus=0;if(!config.mouseDownOnSelect){hideResults();}}).click(function(){if(hasFocus++>1&&!select.visible()){onChange(0,true);}}).bind("search",function(){var fn=(arguments.length>1)?arguments[1]:null;function findValueCallback(q,data){var result;if(data&&data.length){for(var i=0;i1){var seperator=options.multipleSeparator.length;var cursorAt=$(input).selection().start;var wordAt,progress=0;$.each(words,function(i,word){progress+=word.length;if(cursorAt<=progress){wordAt=i;return false;}progress+=seperator;});words[wordAt]=v;v=words.join(options.multipleSeparator);}v+=options.multipleSeparator;}$input.val(v);hideResultsNow();$input.trigger("result",[selected.data,selected.value]);return true;}function onChange(crap,skipPrevCheck){if(lastKeyPressCode==KEY.DEL){select.hide();return;}var currentValue=$input.val();if(!skipPrevCheck&¤tValue==previousValue)return;previousValue=currentValue;currentValue=lastWord(currentValue);if(currentValue.length>=options.minChars){$input.addClass(options.loadingClass);if(!options.matchCase)currentValue=currentValue.toLowerCase();request(currentValue,receiveData,hideResultsNow);}else{stopLoading();select.hide();}};function trimWords(value){if(!value)return[""];if(!options.multiple)return[$.trim(value)];return $.map(value.split(options.multipleSeparator),function(word){return $.trim(value).length?$.trim(word):null;});}function lastWord(value){if(!options.multiple)return value;var words=trimWords(value);if(words.length==1)return words[0];var cursorAt=$(input).selection().start;if(cursorAt==value.length){words=trimWords(value)}else{words=trimWords(value.replace(value.substring(cursorAt),""));}return words[words.length-1];}function autoFill(q,sValue){if(options.autoFill&&(lastWord($input.val()).toLowerCase()==q.toLowerCase())&&lastKeyPressCode!=KEY.BACKSPACE){$input.val($input.val()+sValue.substring(lastWord(previousValue).length));$(input).selection(previousValue.length,previousValue.length+sValue.length);}};function hideResults(){clearTimeout(timeout);timeout=setTimeout(hideResultsNow,200);};function hideResultsNow(){var wasVisible=select.visible();select.hide();clearTimeout(timeout);stopLoading();if(options.mustMatch){$input.search(function(result){if(!result){if(options.multiple){var words=trimWords($input.val()).slice(0,-1);$input.val(words.join(options.multipleSeparator)+(words.length?options.multipleSeparator:""));}else{$input.val("");$input.trigger("result",null);}}});}};function receiveData(q,data){if(data&&data.length&&hasFocus){stopLoading();select.display(data,q);autoFill(q,data[0].value);select.show();}else{hideResultsNow();}};function request(term,success,failure){if(!options.matchCase)term=term.toLowerCase();var data=cache.load(term);if(data&&data.length){success(term,data);}else if((typeof options.url=="string")&&(options.url.length>0)){var extraParams={timestamp:+new Date()};$.each(options.extraParams,function(key,param){extraParams[key]=typeof param=="function"?param():param;});$.ajax({mode:"abort",port:"autocomplete"+input.name,dataType:options.dataType,url:options.url,data:$.extend({q:lastWord(term),limit:options.max},extraParams),success:function(data){var parsed=options.parse&&options.parse(data)||parse(data);cache.add(term,parsed);success(term,parsed);}});}else{select.emptyList();failure(term);}};function parse(data){var parsed=[];var rows=data.split("\n");for(var i=0;i]*)("+term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi,"\\$1")+")(?![^<>]*>)(?![^&;]+;)","gi"),"$1");},scroll:true,scrollHeight:180};$.Autocompleter.Cache=function(options){var data={};var length=0;function matchSubset(s,sub){if(!options.matchCase)s=s.toLowerCase();var i=s.indexOf(sub);if(options.matchContains=="word"){i=s.toLowerCase().search("\\b"+sub.toLowerCase());}if(i==-1)return false;return i==0||options.matchContains;};function add(q,value){if(length>options.cacheLength){flush();}if(!data[q]){length++;}data[q]=value;}function populate(){if(!options.data)return false;var stMatchSets={},nullData=0;if(!options.url)options.cacheLength=1;stMatchSets[""]=[];for(var i=0,ol=options.data.length;i0){var c=data[k];$.each(c,function(i,x){if(matchSubset(x.value,q)){csub.push(x);}});}}return csub;}else if(data[q]){return data[q];}else if(options.matchSubset){for(var i=q.length-1;i>=options.minChars;i--){var c=data[q.substr(0,i)];if(c){var csub=[];$.each(c,function(i,x){if(matchSubset(x.value,q)){csub[csub.length]=x;}});return csub;}}}return null;}};};$.Autocompleter.Select=function(options,input,select,config){var CLASSES={ACTIVE:"ac_over"};var listItems,active=-1,data,term="",needsInit=true,element,list;function init(){if(!needsInit)return;element=$("
").hide().addClass(options.resultsClass).css("position","absolute").appendTo(document.body);list=$("
    ").appendTo(element).mouseover(function(event){if(target(event).nodeName&&target(event).nodeName.toUpperCase()=='LI'){active=$("li",list).removeClass(CLASSES.ACTIVE).index(target(event));$(target(event)).addClass(CLASSES.ACTIVE);}}).click(function(event){$(target(event)).addClass(CLASSES.ACTIVE);select();input.focus();return false;}).mousedown(function(){config.mouseDownOnSelect=true;}).mouseup(function(){config.mouseDownOnSelect=false;});if(options.width>0)element.css("width",options.width);needsInit=false;}function target(event){var element=event.target;while(element&&element.tagName!="LI")element=element.parentNode;if(!element)return[];return element;}function moveSelect(step){listItems.slice(active,active+1).removeClass(CLASSES.ACTIVE);movePosition(step);var activeItem=listItems.slice(active,active+1).addClass(CLASSES.ACTIVE);if(options.scroll){var offset=0;listItems.slice(0,active).each(function(){offset+=this.offsetHeight;});if((offset+activeItem[0].offsetHeight-list.scrollTop())>list[0].clientHeight){list.scrollTop(offset+activeItem[0].offsetHeight-list.innerHeight());}else if(offset=listItems.size()){active=0;}}function limitNumberOfItems(available){return options.max&&options.max").html(options.highlight(formatted,term)).addClass(i%2==0?"ac_even":"ac_odd").appendTo(list)[0];$.data(li,"ac_data",data[i]);}listItems=list.find("li");if(options.selectFirst){listItems.slice(0,1).addClass(CLASSES.ACTIVE);active=0;}if($.fn.bgiframe)list.bgiframe();}return{display:function(d,q){init();data=d;term=q;fillList();},next:function(){moveSelect(1);},prev:function(){moveSelect(-1);},pageUp:function(){if(active!=0&&active-8<0){moveSelect(-active);}else{moveSelect(-8);}},pageDown:function(){if(active!=listItems.size()-1&&active+8>listItems.size()){moveSelect(listItems.size()-1-active);}else{moveSelect(8);}},hide:function(){element&&element.hide();listItems&&listItems.removeClass(CLASSES.ACTIVE);active=-1;},visible:function(){return element&&element.is(":visible");},current:function(){return this.visible()&&(listItems.filter("."+CLASSES.ACTIVE)[0]||options.selectFirst&&listItems[0]);},show:function(){var offset=$(input).offset();element.css({width:typeof options.width=="string"||options.width>0?options.width:$(input).width(),top:offset.top+input.offsetHeight,left:offset.left}).show();if(options.scroll){list.scrollTop(0);list.css({maxHeight:options.scrollHeight,overflow:'auto'});if($.browser.msie&&typeof document.body.style.maxHeight==="undefined"){var listHeight=0;listItems.each(function(){listHeight+=this.offsetHeight;});var scrollbarsVisible=listHeight>options.scrollHeight;list.css('height',scrollbarsVisible?options.scrollHeight:listHeight);if(!scrollbarsVisible){listItems.width(list.width()-parseInt(listItems.css("padding-left"))-parseInt(listItems.css("padding-right")));}}}},selected:function(){var selected=listItems&&listItems.filter("."+CLASSES.ACTIVE).removeClass(CLASSES.ACTIVE);return selected&&selected.length&&$.data(selected[0],"ac_data");},emptyList:function(){list&&list.empty();},unbind:function(){element&&element.remove();}};};$.fn.selection=function(start,end){if(start!==undefined){return this.each(function(){if(this.createTextRange){var selRange=this.createTextRange();if(end===undefined||start==end){selRange.move("character",start);selRange.select();}else{selRange.collapse(true);selRange.moveStart("character",start);selRange.moveEnd("character",end);selRange.select();}}else if(this.setSelectionRange){this.setSelectionRange(start,end);}else if(this.selectionStart){this.selectionStart=start;this.selectionEnd=end;}});}var field=this[0];if(field.createTextRange){var range=document.selection.createRange(),orig=field.value,teststring="<->",textLength=range.text.length;range.text=teststring;var caretAt=field.value.indexOf(teststring);field.value=orig;this.selection(caretAt,caretAt+textLength);return{start:caretAt,end:caretAt+textLength}}else if(field.selectionStart!==undefined){return{start:field.selectionStart,end:field.selectionEnd}}};})(jQuery);