$(function()
{
	$('input[id^="auto_"]').each(function()
	{
		var type = $('#type_' + this.id).val();
		//var field = $('#' + this.id + '_field').val();
		var field = this.id.split('_')[1]; //hotfix
		
		var autoField = new intelli.autofield(
        {
            id: this.id,
            container: 'con_' + this.id,
            url: 'controller.php?plugin=locations&file=get-auto',
            searchField: field, //hotfix
            limit: 30,
            type: type
        });

        autoField.init();
		
		if(type == 'listings')
		{
			var pos = $("#auto_listing").position();
			var wid = $("#auto_listing").width();
			$('#con_auto_listing').css({ 'left' : pos.left, 'top' : pos.top + 20 }).width(wid);
		}
		if(type == 'locations')
		{
			var pos = $("#auto_location").position();
			var wid = $("#auto_location").width();
			$('#con_auto_location').css({ 'left' : pos.left, 'top' : pos.top + 20 }).width(wid);
		}
		if(type == 'categories')
		{
			var pos = $("#auto_category").position();
			var wid = $("#auto_category").width();
			$('#con_auto_category').css('left', pos.left).width(wid);
		}
	});
	
	 $("#listing_location_search").submit(function(){
      if (($("#auto_listing").val() != "") && ($("#auto_listing").val() != "ex: real estate, computer, music")) {
        return true;
      }
       $("#suggestions").show();
      return false;
    });
    
    $("#close").click(function()
    {
    	$("div.someclass").css("display", "none");
    });

	$(".autosearch").focus(function ()
	{
		if($(this).val() == $(this).attr("fade_text"))
		{
			$(this).val('');
		}
	}).blur(function ()
	{
		if($(this).val() == '')
		{
			$(this).val($(this).attr("fade_text"));
		}
	});
	
});

