// переключатель страниц
pages = {
	length: 0, // длина массива данных
	current: 0, // текущая выделенная позиция
	position: 0, // текущая позиция
	cols_num: 3, // количество столбцов
	center: 0, // номер выделенной позиции, начало - единица
	data: Array(), // пункты переключателя страниц
	
	// инициализация
	init: function(data, dataNames){
		var count = 0;
		for (i = 0; i < data.length; i += dataNames.length){
			this.data[count] = Array();
			for (n = 0; n < dataNames.length; n++){
				this.data[count][dataNames[n]] = data[i + n];
			}
			count++;
		}
		for (i in this.data){
			this.length++;
		}
		this.center = parseInt(this.cols_num / 2) + 1;
	},
	// /инициализация
	
	// установка выделенного пункта
	set_current: function(current, position){
		if (current < 0){
			this.current = 0;
		}
		else if (current > this.length - 1){
			this.current = this.length - 1;
		}
		else{
			this.current = current;
		}
		if (position < 0){
			this.position = 0;
		}

		else if (position + this.cols_num > this.length){
			this.position = this.length - this.cols_num;
		}
		else{
			this.position = position;
		}
	},
	// /установка выделенного пункта
	
	// отображение
	show: function(){
		var str = '';
		str += '<table border="0" cellpadding="0" cellspacing="0">\n';
		str += '<tr align="center">\n';
		var begin_i = 0;
		var end_i = this.cols_num - 1;
		if (this.position < 0) {
				begin_i = 0;
				end_i = this.cols_num + begin_i - 1;
		}
		else if (this.position > this.length - this.cols_num) {
				begin_i = this.length - this.cols_num;
				end_i = this.cols_num + begin_i - 1;
		}
		else {
				begin_i = this.position;
				end_i = begin_i + this.cols_num - 1;
		}
		if (end_i >= this.length){
			end_i = this.length - 1;
		}
		if (end_i - begin_i > this.cols_num){
			end_i = begin_i + this.cols_num;
		}
		var count = 0;
		str += "	<td>" + this.get_previous_arrow() + "</td>\n";
		for (i in this.data){
			if (count >= begin_i && count <=end_i){
				var point = this.data[i];
				str += "	<td width='" + parseInt(100 / this.cols_num) + "%' align='center'>\n";
				str += "		<table border='0' cellpadding='0' cellspacing='1'>\n";
				str += "		<tr valign='top'>\n";
				var title = point['name'].replace('<br><br>', "\n").replace('<br>', "\n")
				if (count == this.current){
					str += "			<td align='center' width=190><div class='preview_good_main' style='width:174px'><img src='" + point['imageUrl'] + "' alt='" + title + "' title='" + title + "' width='170' height='101' hspace='1' vspace='1' class='img_back_1' border='0'></div>\n";
					//str += "			<br /><b>" + point['name'] + "</b></td>\n";
				}
				else{
					str += "			<td align='center' width=190><div style='border: 1px solid #FFFFFF; width:174px'><a href='javascript:pages.set_big_image_main(\"" +point['imageUrl1'] + "\",\"" + point['url'] + "\" ," + count + ");' class='preview_good_main' title='" + title + "'><img src='" + point['imageUrl'] + "' alt='" + title + "' width='170' height='101' hspace='1' vspace='1' class='img_back_1' border='0'></a></div>\n";
					//str += "			<br /><a href='" + point['url'] + "'><b>" + point['name'] + "</b></a></td>\n";
				}
				str += "		</tr>\n";
				str += "		</table>\n";
				str += "	</td>\n";
			}
			count++;
		}
		str += "	<td>" + this.get_next_arrow() + "</td>\n";
		str += "</tr>\n";
		str += "</table>\n";
		document.getElementById('pages_switch').innerHTML = str;
	},
	// /отображение
	
	// установка выделенного пункта и отображение
	show_current: function(current, position){
		this.set_current(current, position);
		this.show();
		
	},
	// /установка выделенного пункта и отображение

	// стрелка слева
	get_previous_arrow: function(){
		pos = this.position - 1;
		if (pos < 0 || this.length <= this.cols_num){
			return "<div style='visibility: hidden;'><img src='/img/arrow_left_main.jpg' alt='' width='13' height='19' border='0'></div>\n";
		}
		else{
			return "<a href='" + this.current + "#" + pos + "' onClick='pages.show_current(" + this.current + ", " + pos + "); return false;'><img src='/img/arrow_left_main.jpg' alt='' width='13' height='19' border='0'></a>\n";
		}
	},
	// /стрелка слева
	
	// стрелка справа
	get_next_arrow: function(){
		pos = this.position + 1;
		if (pos > this.length - (this.cols_num) || this.length <= this.cols_num){
			return "<div style='visibility: hidden;'><img src='/img/arrow_right_main.jpg' alt='' width='13' height='19' border='0'></div>\n";
		}
		else{
			return "<a href='#' onClick='pages.show_current(" + this.current + ", " + pos + "); return false;'><img src='/img/arrow_right_main.jpg' alt='' width='13' height='19' border='0'></a>\n";
		}
	},
	// /стрелка справа

    // отображение картинки
  set_big_image_main:function(ref, url, count){
	str = "<a href='" + url + "'><img src='" + ref + "' width=553 height=240 border=0 /></a>";
	document.getElementById('pages_switch_main').innerHTML = str;
    //this.current = count;
    pages.show_current(count, this.position);
}
// /отображение картинки

};
// переключатель страниц

