var load_product = function(item_id) {
//	$('#scroll_area > a').hide();
	$('#hidingPlace').append($('#scroll_area > a'));
	/*$('#scroll_area > a').each(function () {
		$('#hidingPlace').append(this);												 
	});*/
	//TODO: reset active item and load appropriate thumbs
	activeItem = Number(item_id);
	var thumbs = getThumbs(activeItem);
	loadThumbs(thumbs);
	item_name = itemsArray[item_id];
	$.get('product/' + item_name + '.html', function(data, status) {
		document.getElementById('container').innerHTML = data;
		initLightbox();
	});
};

var nextThumbnail = function () {
	$('#hidingPlace').append($('#scroll_area > a'));
	if (activeItem == total) {
		//start over
		activeItem=0;
	}	else {
		//increment
		activeItem++;
	}
	var thumbs = getThumbs(activeItem);
	loadThumbs(thumbs);
};

var prevThumbnail = function () {
	$('#hidingPlace').append($('#scroll_area > a'));
	if (activeItem == 0) {
		//go to top
		activeItem=total;							
	} else {
		//normal decrement
		activeItem--;
	}
	var thumbs = getThumbs(activeItem);
	loadThumbs(thumbs);
};

var getThumbs = function (firstItem) {
	var items;
	if (firstItem == total) {
		items = [total, 0, 1];
	} else if (firstItem == total - 1) {
		items = [total - 1, total, 0];
	} else {
		items = [firstItem, firstItem + 1, firstItem + 2]
	}
	return items;
}
var loadThumbs = function (thumbs) {
	for (x in thumbs) {
		$('#scroll_area').append($('#a_item'+thumbs[x]));
	}
}
var nextThumb = nextThumbnail;
var prevThumb = prevThumbnail;