(function($) {  // Compliant with jquery.noConflict()
$(document).ready(function() {
    // footer rollover effect 
    $("ul.nav li.head").mouseover(function() {
        $(this).addClass("hover");
    });
    $("ul.nav li.head").mouseout(function() {
        $(this).removeClass("hover");
    });

    // hide email addresses from spambots
    $("a.email").each(function(){
        $(this).attr("href", "mailto:" + $(this).html().replace("(at)","@").replace("(dot)",".")); 
        $(this).html($(this).html().replace("(at)","@").replace("(dot)","."));
    });

    // if no flightdeck, remove shadow and set minimum content height of 450px
    if ($("div#standard").length == 0) {
        $(".shadow").hide();
        $(".documentContent").css("min-height", "450px");
    }
    // detect browser version
    //alert($('#os').html("Your browser is running on: <b>" + $.client.os + "</b>" + $('#browser').html("Your browser is: <b>" + $.client.browser + "</b>"));
});
})(jQuery);

$(function() {	
		$("#find").autocomplete(
			{ 
				minLength: 2, 
				source: function(request, response) { 
					$.post(
								baseUrl+"ajax/getCategoriesAutocomplete/"+Math.round(new Date().getTime() / 1000) , 
								{ term: request.term }, 
								function(data) { 
									response(data); 
									$('.ui-autocomplete').css('z-index','1000');
								}, 
								"json"
							); 
					} 
			}
		);
		/*
		$("#location").autocomplete(
			{ 
				minLength: 2, 
				source: function(request, response) { 
					$.post(
								baseUrl+"ajax/getLocationAutocomplete/"+Math.round(new Date().getTime() / 1000) , 
								{ term: request.term }, 
								function(data) { 
									response(data); 
									$('.ui-autocomplete').css('z-index','1000');
								}, 
								"json"
							); 
					} 
			}
		);
		*/
		
		$('#location').autocomplete(
			{
				minLength: 3, 
				source: function( request, response ) {
					$.ajax({
						url: baseUrl+"ajax/getLocationAutocomplete/"+Math.round(new Date().getTime() / 1000) , 
						dataType: "json",
						traditional: true,
						type: "post",
						autoFocus: true,
						data: {
							term: request.term
						},
						success: function( data ) {
							response( $.map( data, function( item ) {
								return {
									//label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
									//value: item.name + (item.adminName1 ? ", " + item.adminName1 : "")
									label: item.city + ", " + item.region_name + ", " + item.country,
									value: item.city + ", " + item.region
								}
							}));
							$('.ui-autocomplete').css('z-index','1000');
						}
					});
				},
				open: function() {
					$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
				},
				close: function() {
					$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
				}
			}
		);
		
});
