$(document).ready(function() {

	if ($(window).width() <= 974) $("#doc4").attr("id",'doc');

	$("#link_rss").click(function(event) {
		event.preventDefault();
		$("#window_rss").toggle();
	});
	
	$("#link_login").click(function(event) {
		event.preventDefault();
		$("#window_login").toggle();
		$("#username").focus();
	});

	/*$(".filmbox").autocomplete( {
		source: "/ajax/film.php",
		select: function(event, ui) {
			document.location = "/film/" + ui.item.u;
		}
	} );*/

	$.fn.setup = function() {
		return this.focus(function() {
			if( this.value == this.defaultValue ) { this.value = ""; }
		}).blur(function() {
			if( !this.value.length ) { this.value = this.defaultValue; }
		});
	};
	
	$(".filmfinder").setup().autocomplete('/ajax/film.php', {
		dataType: "json",
		extraParams: { mode:"ac" },
		width: 300,
		scroll: false,
		max: 10,
		cacheLength: 10,
		parse: function(data) {
			return $.map(data, function(row) {
				return { data: row, value: row.value, result: row.value }
			});
		},
		formatItem: function(item) {
			return item.value;
		}
	}).result(function(e, item) {
		return document.location = "/film/" + item.u;
	});

});
