$(document).ready(function(){
    $("form").submit(function() {
      return false;
    });
	$("#cse_search").autocomplete(
		"/sng.nsf/FormSearch?OpenAgent&count=10",{
		delay:10,
		minChars:2,
		matchSubset:1,
		matchContains:1,
		cacheLength:10,
		onItemSelect:selectItem,
		onFindValue:findValue,
		formatItem:formatItem,
		autoFill:false,
width: 243,
scrollHeight: 250
	}); 

		$("#cse_search").focus(function(){
			if(this.value==this.defaultValue) this.value='';
		}).blur(function(){
			if(this.value=='') this.value=this.defaultValue;
		});

	$('#navi-main').mainNavigator({
		data: [
		{title: '\u0413\u0430\u043B\u0435\u0440\u0435\u044F', css: 'red2', gaq: 'Gallery'},		
		{title: '\u0422\u0435\u0440\u0440\u0430\u0441\u0430', css: 'blue', gaq: 'Terrace'},
		{title: '\u041E\u043F\u0435\u0440\u0430\u0446\u0438\u043E\u043D\u043D\u044B\u0439 \u0437\u0430\u043B', css: 'brown', gaq: 'Operations Room'},
		{title: '\u041A\u0430\u0431\u0438\u043D\u0435\u0442', css: 'red', gaq: 'Cabinet'},
		{title: '\u0425\u043E\u043B\u043B \u0431\u0430\u043D\u043A\u0430', css: 'green', gaq: 'Main Building Lobby'},	
		{title: '\u0422\u0435\u0440\u0440\u0430\u0441\u0430', css: 'night', gaq: 'Terrace-Night'}
		],
		cssChange: true,
		alreadyCreated: 0
	});
document.getElementById( "cse_search" ).setAttribute( "autocomplete","off" );
document.getElementById( "cse_search" ).setAttribute( "value","\u041F\u043E\u0438\u0441\u043A" );
});

function Left(str, n){
   if (n <= 0)
         return "";
   else if (n > String(str).length)
         return str;
   else
         return String(str).substring(0,n);
}

function findValue(li) {
if( li == null ) return alert("No match!");

// if coming from an AJAX call, let's use the CityId as the value
if( !!li.extra ) var sValue = li.extra[0];

// otherwise, let's just display the value in the text box
else var sValue = li.selectValue;

//alert("The value you selected was: " + sValue);
}

function selectItem(li) {
findValue(li);
}

function formatItem(row) {
var gaqtmp="onclick=\"_gaq.push(['_trackEvent', 'search', '"+$("#cse_search").val()+"', '"+row[1]+"']);\"";
return "<a href=\"" + row[1] + "\""+gaqtmp+" >"+Left(row[0],41)+"\u2026</a>";
}

function lookupAjax(){
var oSuggest = $("#cse_search")[0].autocompleter;
oSuggest.findValue();
return false;
}

function lookupLocal(){
var oSuggest = $("#cse_search")[0].autocompleter;
oSuggest.findValue();
return false;
} 
