var engine = {
// -------
	init: function() {
		this.prepareDocument();
		this.productActions();
		this.enableFancybox();
	},
// -------
	prepareDocument: function() {
		$('html').addClass('js');
	},
// -------
	productActions: function() {	
	
		$('a', '#product').click(function(e){
			var isVisible = $('article', '#product').toggle().is(":visible");
			$(this)
				.html(isVisible ? "Close" : "Information &raquo;");
			e.preventDefault();
		});
		$('#slider').slides({
			preload: true,
			effect: 'fade',
			play: 5000,
			pause: 2500,
			hoverPause: true
		});
 
 		var baseUrl = $('base').attr('href');

		$("input[name=q]").autocomplete({
				source: baseUrl + '/wp-content/plugins/products/ajax.php',
			    minLength: 2,				
				focus: function (event, ui) {
					$(event.target).val(ui.item.label);
					return false;
				},
				select: function (event, ui) {
					$(event.target).val(ui.item.label);
					window.location = ui.item.value;
					return false;
				}
			});		
	},
// -------
	enableFancybox: function() {
		$('a:has(img)', '.gallery-item')
		.attr('rel', 'gallery')
		.fancybox({
			'transitionIn': 'fade',
			'transitionOut': 'fade',
			'opacity': false,
			'overlayShow': true,
			'overlayColor': '#fff',
			'hideOnContentClick': true,
			'showCloseButton': false,
			'titleShow': false,
			'speedIn': 200,
			'speedOut': 200,
			'padding': 7
		});
	}
// -------
};

$(function() { engine.init(); });
