/**
 * @author Wolf
 * xajax.inc.php line 816: $html .= "\t<script type=\"text/javascript\" src=\"" . $sJsURI . "/xajax_js/shortcuts.js \"></script>\n";	
 */

// IntelliSearch Shortucts (Up & Down)
function Shortcuts(value, InputEvent){
	// If Up or Down Key
    if (InputEvent.keyCode == 40 || InputEvent.keyCode == 38) {
        $('#intelliSearchResult a')[0].focus(); // Focus on First SearchResult
        navigate(); // Up & Down Key Events
    }
    else {
        xajax_intelliSearch(value); // Search by Ajax
    }
}

function navigate(){
	// Any SearchResult
    for (var i = 0, SearchResults = $('#intelliSearchResult a'); i < SearchResults.length; i++) {
        
		// KeyUp Event - Bind i
        $(SearchResults[i]).bind('keyup', {index: i}, function(event){
            if (event.data.index != "undefined") {
                if (event.keyCode == 40) { // If Key Down
                    if (event.data.index < (SearchResults.length-1)) {
                        SearchResults[event.data.index + 1].focus(); // Focus Next Link
                    }
                }
                else 
                    if (event.keyCode == 38) { // If Key Up
                        if (event.data.index > 0) 
                            SearchResults[event.data.index - 1].focus(); // Focus previous Link
                    }
            }
        });
		// Stop Scrolling by Up & Down
        $(SearchResults[i]).keydown(function(event){
			if (event.keyCode == 40 || event.keyCode == 38) {
				event.preventDefault();
			}
        });
    }
}

function closeSearch() {
	$('#intelliSearchResult').hide();
}

