$(function(){

	$('[placeholder]').focus(function() {
		var input = $(this);
		if (input.val() == input.attr('placeholder')) {
			input.val('');
			input.removeClass('placeholder');
		}
	}).blur(function() {
		var input = $(this);
		if (input.val() == '' || input.val() == input.attr('placeholder')) {
			input.addClass('placeholder');
			input.val(input.attr('placeholder'));
		}
		}).blur();



		$( "#simpleSearch input[name=company_name]" ).autocomplete({
			minLength: 3,
			source: "company/company_autocomplete"
		})

		$( "#simpleSearch input[name=company_keyword]" ).autocomplete({
			minLength: 3,
			source: "company/keyword_autocomplete"
		})



		if($("#city_autocomplete").length > 0){
			
		$( "#city_autocomplete" ).autocomplete({
			source: "ajax/get_city",
			minLength: 2,
			focus: function( event, ui ) {
				$( "#city_autocomplete" ).val( ui.item.label );
				return false;
			},
			select: function( event, ui ) {
				$( "#city_autocomplete" ).val( ui.item.label );
				$( "#postal" ).val( ui.item.postal );
				$( "#city_id" ).val( ui.item.value );

				return false;
			}

		}).data( "autocomplete" )._renderItem = function( ul, item ) {
			return $( "<li></li>" )
			.data( "item.autocomplete", item )
			.append( "<a>" + item.label + " - " + item.postal + "</a>" )
			.appendTo( ul );
		};

	}
	if($('#kw_autocomplete').length > 0){

		$( "#kw_autocomplete" ).autocomplete({
			source: "ajax/search_keyword",
			minLength: 2/*
			,
			select: function( event, ui ) {
			log( ui.item ?
			"Selected: " + ui.item.value + " aka " + ui.item.id :
			"Nothing selected, input was " + this.value );
			}*/

		});		
		
	}

		if($('.fileupload').length > 0){

			$('.fileupload').fileupload();

			$.getJSON($('.fileupload form').prop('action'),$('.fileupload form').serialize(), function (files) {


				var fu = $('.fileupload').data('fileupload');
				fu._adjustMaxNumberOfFiles(-files.length);
				fu._renderDownload(files)
				.appendTo($('.fileupload .files'))
				.fadeIn(function () {
					// Fix for IE7 and lower:
					$(this).show();
				});

				$('.fileupload .files tbody').sortable(	{
					update: function(event, ui) { 
						console.log(
							ui
						)
					}
				});

			});

		}


		$( ".datepicker" ).datepicker({ dateFormat: 'yy-mm-dd' });
				

})

