var stores_featured = [];
var stores_featured_i = 0;

var stores_page = 1;
var category_id = 0;
	
$(document).ready(function(){
	$("#stores").click(function () {
      $("#hidden").slideToggle(300);
      $(this).toggleClass("active");

    });
    
/*
	//search autocomplete
	$('.search-bar').autocomplete('/ajax/autocomplete.php', {
		minChars: 3,
		delay: 30,
		maxItemsToShow: 10,
		autoFill:true,
		onItemSelect:submit_search
	});
*/
	
	function submit_search() {
		var url = $('#dl-bar-search').attr('action') + $('.search-bar').val().replace(/ |\%20/g,'+');
		window.location = url;
	}
	
	$('.search-button').click(function(){
		submit_search();
		return false;
	});
	
	$('#dl-bar-search').submit(function(){
		submit_search();
		return false;
	});
	
	
	
	$('.stores-featured').each(function(){
		stores_featured.push($(this).attr('id'));
	});
	
	$('#featured-right').click(function(){
		move_stores_featured(1);
		return false;
	});
	$('#featured-left').click(function(){
		move_stores_featured(-1);
		return false;
	});
	
	function move_stores_featured(dir) {
		if (stores_featured[stores_featured_i + dir]) {
			$('#'+stores_featured[stores_featured_i]).hide();
			stores_featured_i += dir;
			$('#'+stores_featured[stores_featured_i]).show();
		} else {
			$('#'+stores_featured[stores_featured_i]).hide();
			stores_featured_i = (dir == 1) ? 0 : stores_featured.length - 1;
			$('#'+stores_featured[stores_featured_i]).show();
		}
	}
	
	
	$('#stores-right').live('click', function(){
		stores_page ++;
		load_stores();
		return false;
	});
	$('#stores-left').live('click', function(){
		stores_page --;
		load_stores();
		return false;
	});
	
	
	$('#top a.ajax').click(function(){
		$this = $(this);
		$('#top a').removeClass('selected');
		$this.addClass('selected');
		category_id = $this.attr('href').replace('#','');
		stores_page = 1;
		
		load_stores();
		return false;
	});
	
	function load_stores() {
		$('#store-links').html('<img src="/images/ajax-loader.gif" alt="Loading..." />');
		$('#store-links').load('/ajax/store-links.php?category_id=' + category_id + '&menu-page=' + stores_page)
	}
});

