"use strict";

if (!Array.prototype.map) {
	Array.prototype.map = function (fun /*, thisp*/) {
		if (typeof fun !== "function") {
			throw new TypeError();
		}

		var len = this.length;
		var res = new Array(len);
		var thisp = arguments[1];

		for (var i = 0; i < len; i++) {
			if (i in this) {
				res[i] = fun.call(thisp, this[i], i, this);
			}
		}

		return res;
	};
}

$(document).ready(function () {
	$('#busqueda').autocomplete({
		source: function (request, response) {
			$.ajax({
				url: suggesturl,
				dataType: 'json',
				data: request,
				success: function (data) {
					response(data.map(function (value) {
						return {
							'label': '<img src="' + value.thumbsmall + '" />' + value.nombrecoleccion + '',
							'value': value.nombrecoleccion
						};
					}));
				}
			});
		},
		select: function (e, ui) {
			this.content = ui.item.value;
			$('#form_busqueda').submit();
		},
		minLength: 3
	}).width(300).watermark("Buscar...");

	$('#form_busqueda button').hide();

	$('#imagenes a').lightBox();
});

