
var HomeNewProductsScrollable = {
		page: 1,
		size: 1,
		init: function()
		{
			$('#HomeNewProductsScrollableArrowLeft').bind("click", HomeNewProductsScrollable.on_click_arrow_left);
			$('#HomeNewProductsScrollableArrowRight').bind("click", HomeNewProductsScrollable.on_click_arrow_right);
			
			var scripts = document.getElementsByTagName('SCRIPT');
			for(var i = 0; i < scripts.length; i++)
			{
				s = scripts[i];
				if(s.src && s.src.indexOf('homenewproductsscrollable.js') > -1)
				{
					HomeNewProductsScrollable.path = s.src.replace(/homenewproductsscrollable\.js$/, '../');
					break;
				}
			}
		},

		on_click_arrow_left: function(event)
		{
			if (--HomeNewProductsScrollable.page < 1) {
				HomeNewProductsScrollable.page = HomeNewProductsScrollable.size;
			}
			
			$('#HomeNewProductsScrollablePage')[0].innerHTML = HomeNewProductsScrollable.page;
			
			HomeNewProductsScrollable.delete_items();
			HomeNewProductsScrollable.do_get_next();
		},

		on_click_arrow_right: function(event)
		{		
			if (++HomeNewProductsScrollable.page > HomeNewProductsScrollable.size) {
				HomeNewProductsScrollable.page = 1;
			}
			
			$('#HomeNewProductsScrollablePage')[0].innerHTML = HomeNewProductsScrollable.page;
			
			HomeNewProductsScrollable.delete_items();
			HomeNewProductsScrollable.do_get_next();
		},
		
		delete_items: function()
		{
			var itemList = $('#HomeNewProductsScrollable .ProductList li');
			
			itemList.each(function() {
				this.innerHTML = '<div class="AjaxLoader"></div>';
			})
			
			var x = 0;
		},
		
		do_get_next: function()
		{
			$.ajax({
				type: 'GET',
				dataType: 'html',
				url: HomeNewProductsScrollable.path+'homenewproductsscrollable.php?action=AjaxGetNext&page='+encodeURIComponent(HomeNewProductsScrollable.page),
				success: function(response) { HomeNewProductsScrollable.get_next_done(response); }
			});
			/*
			 * $.ajax({
				type: 'GET',
				dataType: 'xml',
				url: HomeNewProducts.path+'search.php?action=AjaxSearch&search_query='+encodeURIComponent($('#search_query').val()),
				success: function(response) { QuickSearch.search_done(response); }
			});
			 * */
		},
		
		get_next_done: function(response)
		{
			var ulProductList = $('#HomeNewProductsScrollable .ProductList');
			ulProductList[0].innerHTML = response;
		}
};

$(document).ready(function()
{
	HomeNewProductsScrollable.init();
});
