//
// Coded by Igor F.  igorf@euristica.ru
// Last edit: 15.07.09
//

$(document).ready(function() {

	function reDrawTable(firstItem, lastItem) {
		$("table#pricesTable tr").each(function() {
			$(this).find("td").show();
			$(this).find("td:lt("+ firstItem +")").hide();
			$(this).find("td:gt("+ lastItem  +")").hide();
			$(this).find("td:first").show();
		});
		
		$("table#pricesTable tr:last").each(function() {
			$(this).find("th").show();
			$(this).find("th:lt("+ firstItem +")").hide();
			$(this).find("th:gt("+ lastItem  +")").hide();
			$(this).find("th:first").show();
		});
		
		$("table#pricesTable tr.section:first th:first").attr("colspan", lastItem - firstItem + 2);
		
		$("div.pagenate").text( ((countCols > 0) ? firstItem : 0 ) +" - "+ ((lastItem > countCols) ? countCols : lastItem) + " из "+ countCols);
	}

	// prices scroll
	var countCols = $("table#pricesTable tr").eq(2).find("td").size() - 1;
	var countRows = $("table#pricesTable td").size() / ( countCols + 1 );

	var maxItems = 4;
	var firstItem = 1;
	var lastItem = firstItem + maxItems - 1;
	
	reDrawTable(firstItem, lastItem );
	
	$("div.toRight").click(function() {
		firstItem = ( (firstItem + 1) <= (countCols - maxItems + 1) ) ? ++firstItem : firstItem;
		lastItem = firstItem + maxItems - 1;
		reDrawTable(firstItem, lastItem);
	});
	
	$("div.toLeft").click(function() {
		firstItem = ( (firstItem - 1) > 0 ) ? --firstItem : firstItem;
		lastItem = firstItem + maxItems - 1;
		reDrawTable(firstItem, lastItem);
	});

	$("form#contactform select#point option").click(function() {
		var ind = $("form#contactform select#point option").index(this);
		$("form#contactform input#pointid").val( pointID[ind] );
	});

})