// Site-depend JavaScript.

jQuery.noConflict();

var ajax_loader = '<img src="/images/ajax_loader.gif">';
var ajax_loader_small = '<img src="/images/ajax_loader_sm.gif">';

function AjaxDesync () {

	var arList = new Array();

	var iNumber = 0;

	var iExecRequestNumber = 0;

	this.AppendRequest = function (sLink, func) {
		iNumber = iNumber + 1;
		//alert(sLink);
		arList[iNumber] = { 'link'	: sLink, 'func' : func };
		if (!iExecRequestNumber) {
			execRequestList();
		}
	}

	var execRequestList = function () {
		iExecRequestNumber = iExecRequestNumber + 1
		if (arList[iExecRequestNumber] == undefined) {
			iExecRequestNumber = 0;
			iNumber = 0;
			delete arList;
			arList = new Array();
			return;
		}
		jQuery.get(arList[iExecRequestNumber]['link'], function (data) {
			if (arList[iExecRequestNumber]['func'] != undefined)	{
				arList[iExecRequestNumber]['func'](data);
				delete arList[iExecRequestNumber];
			}
			execRequestList();
		});
	}
}

var dAjax = new AjaxDesync();

function sformAlert () {
	if (!document.sform_offer_list.name.value.length) {
		alert('Вы не ввели название выборки');
		return false;
	}
	return true;
}
// Получение списка предложений в соответствии с их флагом (отмечен/неотмечен)
function getOfferList (strXPath, checked, sAttrId) {
	var sId = '';
	jQuery(strXPath +
		(checked ? ':checked' : ':not(:checked)')).each(function () {
		sId = sId + jQuery(this).attr(sAttrId) + ',';
	});
	if (!sId.length) {
		return '';
	}
	return sId.substr(0, sId.length - 1);
}

function getTreeOfferParamList () {
	if (jQuery('#list_offer').length) {
		jQuery('body').append('<div id="tree_pol" style="width:' + jQuery('body').width() + 'px"> </div>');
		jQuery('#list_offer').html(ajax_loader);
		//alert(jQuery('#current_page_result').val() + '?by_ajax=1&offer_rows=' + jQuery('#town_id').val());
		dAjax.AppendRequest(jQuery('#current_page_result').val() + '?by_ajax=1&offer_rows=' + jQuery('#town_id').val(), function (data) {
			jQuery('#list_offer').html(data);
			jQuery('#tree_pol').remove();
		});
/*
		jQuery.get(jQuery('#current_page_result').val() + '?by_ajax=1&offer_rows=' + jQuery('#town_id').val(), function (data) {
			jQuery('#list_offer').html(data);
			jQuery('#tree_pol').remove();
		});
*/
	}
}

function changeOfferList (sId, func) {
	//jQuery.get(jQuery('#script_set').val() + 'offer/tree_set/?by_ajax=1&offers=' + sId, getTreeOfferParamList());
	dAjax.AppendRequest(jQuery('#script_set').val() + 'offer/tree_set/?by_ajax=1&offers=' + sId, (func == undefined) ? function () {} : function () { func() } );
}

jQuery(document).ready(function() {
	/*
	jQuery('#map_canvas').css({
		'height' : parseInt(jQuery('#map_canvas').prev('img').eq(0).attr('height')) + 'px',
		'width' : parseInt(jQuery('#map_canvas').prev('img').eq(0).attr('width')) + 'px',
		'margin-top' : '-' + parseInt(jQuery('#map_canvas').prev('img').eq(0).attr('height')) + 'px'
	});
	*/
	jQuery('#list_history table th :checkbox').click(function () {
		jQuery('#list_history table td :checkbox').attr('checked', jQuery(this).attr('checked'));
	});
	jQuery('#list_history table td :checkbox').click(function () {
		var sId = getOfferList('#list_history table td :checkbox', false, 'rel');
		jQuery('#list_history table th :checkbox').attr('checked', !sId.length);
	});
	jQuery('#button_append_offer').click(function() {
		var sAct = jQuery(this).attr('checked') ? 'append' : 'remove';
		//jQuery.get(jQuery(this).attr('rel2') + 'offer_list/' + sAct + '/?by_ajax=1&offers=' + jQuery(this).attr('rel1'));
		dAjax.AppendRequest(jQuery(this).attr('rel2') + 'offer_list/' + sAct + '/?by_ajax=1&offers=' + jQuery(this).attr('rel1'));

		function getOpenerListObject (sElem) {
			if (window.opener && window.opener.document) {
				var el = window.opener.document.getElementById(sElem);
				if (el) {
					return el;
				}
				return null;
			}
			return null;
		}

		function getOpenerListObjectValue (sElem) {
			var obj = getOpenerListObject(sElem);
			if (obj) {
				return obj.value;
			}
			return null;
		}

		var OpList = getOpenerListObject('list_of_offers');
		if (OpList) {
			var iId = jQuery(this).attr('rel1');
			var checked = jQuery(this).attr('checked');
			jQuery(OpList).find(':checkbox[rel="' + iId + '"]').each(function () {
				jQuery(this).attr('checked', checked);
			});
			if (checked) {
				var map = getOpenerListObject('map_canvas');
				var iNumber = getOpenerListObjectValue('number[' + iId + ']');
				var x = getOpenerListObjectValue('coord_x[' + iId + ']');
				var y = getOpenerListObjectValue('coord_y[' + iId + ']');
				var color = getOpenerListObjectValue('color[' + iId + ']');
				var text_color = getOpenerListObjectValue('text_color[' + iId + ']');
				var link = getOpenerListObjectValue('link[' + iId + ']');
				jQuery(map).append('<a href="' + link + '" id="ofp_' + iId + '" target="_blank">' + iNumber + '</a>');
				var ofp = getOpenerListObject('ofp_' + iId);
				jQuery(ofp).css({
					'color' : '#' + text_color,
					'background-color' : '#' + color,
					'top' : parseInt(y) + 'px',
					'left' : parseInt(x) + 'px',
					'border' : '1px solid #' + text_color
				});
			} else {
				var img = getOpenerListObject('ofp_' + jQuery(this).attr('rel1'));
				jQuery(img).remove();
			}
		}

	});
	jQuery('#delete_history').click(function () {
		var sId = getOfferList('#list_history table td :checkbox', true, 'rel');
		if (sId.length && confirm('Вы действительно хотите удалить выбранные элементы?')) {
			document.location.href = jQuery('#delete_history').attr('rel') + '?delete=' + sId;
		}
	});
	jQuery('#see_history').click(function () {
		var sId = getOfferList('#list_history table td :checkbox', true, 'rel');
		if (sId.length) {
			document.location.href = jQuery('#delete_history').attr('rel') + '?list=' + sId;
		}
	});
	jQuery('#append_sel_offers_to_list').click(function () {
		var sIdApp = getOfferList('#format_list_container .format_list ul :checkbox', true, 'rel'),
			sIdRem = getOfferList('#format_list_container .format_list ul :checkbox', false, 'rel');
		offerSetUnset(sIdApp, true, function () { });
		offerSetUnset(sIdRem, false, function () { alert('Список выборки успешно изменен'); });
	});

	setFormatListLinksParam();
	jQuery('#drop_sel_offers').click(function () {
		jQuery('#format_list_container .format_list :checkbox').attr('checked', false);
		paintCurrentOffers('#format_list_container li li :checkbox');
	});
	// расширенные параметры города
	jQuery('div.fl_pl > div.town > :checkbox').click(function () {
		jQuery(this).parents('div').eq(0).children('.ptown_link').eq(0).css(
			'display',
			jQuery(this).attr('checked') ? 'inline-block' : 'none'
		);
	});
	jQuery('#logo').each(function () {
		var sPath = jQuery('#id_flash').val();
		if (!sPath) {
			return;
		}
		var so = new SWFObject(sPath,"mymovie","354","550","9.0.0", "#FFFFFF");
		so.addParam("wmode", "transparent");
		if (so) {
			so.write("animation");
		}
	});
	jQuery('#sparam_check_all').click(function () {
		jQuery('#sparam_format_list :checkbox').attr('checked', 'checked');
		return false;
	});
	jQuery('#sparam_type_check_all').click(function () {
		jQuery('#sparam_type_list :checkbox').attr('checked', 'checked');
		return false;
	});
	jQuery('#sparam_townlist :radio').click(function () {
		jQuery('#sparam_townlist label').removeClass('checked');
		jQuery(this).next().addClass('checked');
	});
	jQuery('#search_res_formats :radio').click(function () {
		jQuery('#search_param_result_td').html('');
		jQuery('#search_res_formats label').removeClass('checked');
		jQuery(this).parent().parent().addClass('checked');
		jQuery('#result_format_title').html(jQuery(this).prev().val());
		getSearchResultByParam(jQuery(this).val());
	});

	prepareSearchResultByParamCheckbox();

	jQuery('#someid').each(function () {
		jQuery(this).parents('form').submit(function () {
			if (!jQuery('#someid').val().length) {
				alert('Введите номер носителя');
				return false;
			}
			if (jQuery('#sparam_townlist :checked').length) {
				jQuery('#town_id_for_number').val(jQuery('#sparam_townlist :checked').val());
				return true;
			}
			alert('Выберите город!');
			return false;
		});
	});
	
	jQuery('div.a-prog-choice input[name="town_id"]').click(function () {
		jQuery('div.a-prog-choice input[name="town_id"]').next().removeClass('checked');
		jQuery(this).next().addClass('checked');
		jQuery('#tree_content').html('');
		jQuery.each(jQuery.browser, function(i) {
  			if(jQuery.browser.msie){
     			jQuery('#tree_content').height(100);
  			}
		});
		jQuery('#tree_content').css('background', 'url(/images/ajax-loader.gif) 50% 0% no-repeat');
		jQuery.get(jQuery('#current_page_result').val() + '?town_id=' + jQuery(this).val() + '&by_ajax=1', function (data) {
			jQuery('#tree_content').css('background', 'none');
			jQuery('#tree_content').html(data);
			setFormatListLinksParam();
		});
	});
	

});

function setFormatListLinksParam () {
	jQuery('#format_list_container .format_list a').click(function() {
		var parentLi = jQuery(this).parents('span').eq(0).parents('li').eq(0),
			listUl = parentLi.children('ul').eq(0);
		parentLi.toggleClass('closed');
		var vis = false;
		if (listUl.length) {
			listUl.css('display', (listUl.css('display') == 'block') ? 'none' : 'block');
			if (listUl.css('display') == 'block') {
				vis = true;
			}
		} else {
			vis = true;
			parentLi.append(ajax_loader_small);
			var link = jQuery('#current_page_result').val() + '?by_ajax=1&town_id=' +
				jQuery('#town_id').val() + '&format_id=' + jQuery(this).attr('rel');
			//alert(link);
			//jQuery.get(link, function (data) {
			dAjax.AppendRequest(link, function (data) {
				if (data.length) {
					parentLi.children(':checkbox').eq(0).css('visibility', 'visible');
				}
				parentLi.append(data);
				parentLi.children('ul').eq(0).find(':checkbox').click(function () {
					var sel = true;
					parentLi.children('ul').eq(0).find(':checkbox').each(function () {
						sel = sel & jQuery(this).attr('checked');
					});
					parentLi.children(':checkbox').eq(0).attr('checked', sel);
					paintOffers([jQuery(this).attr('rel')], jQuery(this).attr('checked'));
					changeOfferList(
						getOfferList('#format_list_container li li :checkbox', true, 'rel'),
						getTreeOfferParamList
					);
				});
				parentLi.children('img').remove();
			});
		}
		jQuery(this).attr('class', vis ? 'opened' : 'closed');
	});
	jQuery('#format_list_container > ul > li > :checkbox:visible').each(function () {
		var num = jQuery(this).next().children('a').eq(0).attr('rel');
		var sNotAct = getOfferList('#list_format_' + num + ' :checkbox', false, 'rel');
		var objCh = jQuery(this);
		objCh.attr('checked', !sNotAct.length);
		jQuery('#list_format_' + num + ' :checkbox').click(function () {
			var sna = getOfferList('#list_format_' + num + ' :checkbox', false, 'rel');
			objCh.attr('checked', !sna.length);
			paintOffers([jQuery(this).attr('rel')], jQuery(this).attr('checked'));
			changeOfferList(
				getOfferList('#format_list_container li li :checkbox', true, 'rel'),
				getTreeOfferParamList
			);
		});
	});
	jQuery('#format_list_container > ul > li > :checkbox').click(function () {
		jQuery(this).parents('li').eq(0).find('ul').eq(0).find(':checkbox').attr('checked', jQuery(this).attr('checked'));
		paintCurrentOffers('#format_list_container li li :checkbox');
		changeOfferList(
			getOfferList('#format_list_container li li :checkbox', true, 'rel'),
			getTreeOfferParamList
		);
	});
}


function prepareSearchResultByParamCheckbox () {
	jQuery('#format_list_container').each(function () {
		paintCurrentOffers('#format_list_container li li :checkbox');
		getTreeOfferParamList();
	});
	jQuery('#offer_list_check').click(function () {
		if(!jQuery.browser.msie) {
			s_checked = jQuery('#offer_list_check').attr('checked');
			if(confirm((s_checked ? "Отметить предложения" : "Снять отметку с предложений")+" на всех страницах (это может занять продолжительное время) ?")) {
				var iTown = jQuery('#town_id').val();
				var iFormat = jQuery('#search_res_formats input[name="format"][checked]').val();
				var iFilter = jQuery("#filter_select_type").val();
				var iFilterVal = jQuery("#filter_select_value").val();
				
				if(s_checked) {
					jQuery.get("/aprog/offer/set/", {by_ajax:1,offers:'all',town:iTown,format:iFormat,filter:iFilter,filter_val:iFilterVal}, function(data){window.location = '?town_id='+iTown+'&filter='+iFilter+'&filter_val='+iFilterVal+'&format='+iFormat;});
				} else {
					jQuery.get("/aprog/offer/unset/", {by_ajax:1,offers:'all',town:iTown,format:iFormat,filter:iFilter,filter_val:iFilterVal}, function(data){window.location = '?town_id='+iTown+'&filter='+iFilter+'&filter_val='+iFilterVal+'&format='+iFormat;});
				}
				//window.location.reload(true);
				return;
			}
		}
		jQuery('#list_of_offers td :checkbox').attr('checked', jQuery('#offer_list_check').attr('checked'));
		paintCurrentOffers('#list_of_offers td :checkbox', true);
		getTreeOfferParamList();
	});
	jQuery('#list_of_offers td :checkbox').click(function () {
		paintOffers([jQuery(this).attr('rel')], jQuery(this).attr('checked'));
		offerSetUnset(jQuery(this).attr('rel'), jQuery(this).attr('checked'));
		var sNotAct = getOfferList('#list_of_offers td :checkbox', false, 'rel');
		jQuery('#offer_list_check').attr('checked', !sNotAct.length);
	});

	jQuery('#list_of_offers th :checkbox').each(function() {
		var sNotAct = getOfferList('#list_of_offers td :checkbox', false, 'rel');
		jQuery('#offer_list_check').attr('checked', !sNotAct.length);
		paintCurrentOffers('#list_of_offers td :checkbox', true);
	});
	jQuery('input.select_offer').each(function () {
		paintOffers(['sel_off_' + jQuery(this).attr('rel')], true);
	});
	jQuery('#filter_select_type').change(function () {
		if (jQuery(this).val() == 0) {
			jQuery('#filter_select_value').html('<option value="0"> </option>');
			return;
		}
		var iTown = jQuery('#town_id').val();
		var link = jQuery('#ajax_link').val();
		var iFormat = jQuery('#search_res_formats :checked[name="format"]').val();
		jQuery('#filter_select_value').html('<option value="0"> </option>');
		jQuery.get(link + '&town=' + iTown + '&format=' + iFormat + '&filter=' + jQuery(this).val(), function (data) {
			jQuery('#filter_select_value').html(data);
		});
	});
	jQuery('#filter_submit_button').click(function () {
		var iTown = jQuery('#town_id').val();
		var link = jQuery('#ajax_link').val();
		var iFormat = jQuery('#search_res_formats input[name="format"]').val();
		var iFilter = jQuery("#filter_select_type").val();
		var iFilterVal = jQuery("#filter_select_value").val();
		setSearchParamPreloader();
		//document.body.innerHTML = document.body.innerHTML + '<span>' + link + '&town=' + iTown + '&format=' + iFormat + '&filter=' + iFilter + '&filter_val=' + iFilterVal + '</span>';
		jQuery.get(link + '&town=' + iTown + '&format=' + iFormat + '&filter=' + iFilter + '&filter_val=' + iFilterVal, function (data) {
			jQuery('#search_content > table.map_res_holder').css('width', 'auto');
			jQuery('#search_content').html(data);
			prepareSearchResultByParamCheckbox();
		});
	});
	jQuery('div.a-prog-choice input[name="town_id"]').click(function () {
		jQuery('div.a-prog-choice input[name="town_id"]').next().removeClass('checked');
		jQuery(this).next().addClass('checked');
		jQuery('#tree_content').html('');
		jQuery.each(jQuery.browser, function(i) {
  			if(jQuery.browser.msie){
     			jQuery('#tree_content').height(100);
  			}
		});
		jQuery('#tree_content').css('background', 'url(/images/ajax-loader.gif) 50% 0% no-repeat');
		jQuery.get(jQuery('#current_page_result').val() + '?town_id=' + jQuery(this).val() + '&by_ajax=1', function (data) {
			jQuery('#tree_content').css('background', 'none');
			jQuery('#tree_content').html(data);
			setFormatListLinksParam();
		});
	});
}

function setSearchParamPreloader () {
	jQuery('#search_param_result_td').html('');
	jQuery('#search_content > table.map_res_holder td.map_cell').css('width', jQuery('#map_canvas > img').width());
	jQuery('#search_content > table.map_res_holder').css('width', '100%');
	jQuery('#search_param_result_td').append('<div style="text-align:center;width:100%;height:' + jQuery('#search_param_result_td').height() + 'px">' + ajax_loader + '</div>');
}

function getSearchResultByParam (iFormat) {
	var iTown = jQuery('#town_id').val();
	var link = jQuery('#ajax_link').val();
	setSearchParamPreloader();
	jQuery.get(link + '&town=' + iTown + '&format=' + iFormat, function (data) {
		jQuery('#search_content').html(data);
		jQuery('input.select_offer').each(function () {
			paintOffers(['sel_off_' + jQuery(this).attr('rel')], true);
		});
		prepareSearchResultByParamCheckbox();
	});
}

function prepareStyleTownInfo (town_id) {
	jQuery('#ptown_' + town_id + ' div > ul > li > :checkbox').each(function() {
		jQuery(this).click(function () {
			var checked = jQuery(this).attr('checked');
			jQuery(this).next('ul').children('li').each(function () {
				jQuery(this).children(':checkbox').each(function () {
					jQuery(this).attr('checked', checked);
				});
			});
		});
	});
	jQuery('#ptown_' + town_id + ' div > ul > li > ul > li > :checkbox').each(function() {
		jQuery(this).click(function () {
			var ch = true;
			if (!jQuery(this).attr('checked')) {
				var all_not_ch = true;
				jQuery(this).parents('ul').eq(0).children('li').each(function () {
					jQuery(this).children(':checkbox').each(function () {
						if (jQuery(this).attr('checked')) {
							all_not_ch = false;
						}
					});
				});
				ch = !all_not_ch;
			}
			jQuery(this).parents('ul').eq(0).parent('li').eq(0).children(':checkbox').eq(0).attr('checked', ch);
		});
	});
	//div = jQuery('#map_obertka_' + town_id);
	div = jQuery('#map_list_link_' + town_id);

	var iIndex = 1;
	var max_x = 0, max_y = 0;

	jQuery('#sector_' + town_id + ' .sect').each(function () {
		var coord = jQuery(this).val();
		var arCoord = coord.split(',');
		if (max_x < parseInt(arCoord[2])) {
			max_x = parseInt(arCoord[2]);
		}
		if (max_y < parseInt(arCoord[3])) {
			max_y = parseInt(arCoord[3]);
		}

		var h = parseInt(arCoord[3]) - parseInt(arCoord[1]),
			w = parseInt(arCoord[2]) - parseInt(arCoord[0])

		var sName = jQuery(this).attr('name');
		sName = sName.substr(4);
		sName = sName.replace(/\]/g, '');
		sName = sName.replace(/\[/g, '_');
		var strClass = parseInt(jQuery('#sect_select' + sName).val()) ? 'class="select" ' : '';
		div.append('<a ' + strClass + ' style="width:' + w + 'px;height:' + h + 'px" href="JavaScript:void(0);" onclick="return putOnButtonMap(this, ' + town_id + ')" title="Добавить сектор в выборку" rel="' + iIndex + '"> </a>');
		var obj = div.children('a[href="#' + iIndex + '_' + town_id + '"]').eq(0);

		obj.css('width', w + 'px');
		obj.css('height', h + 'px');

		obj.width(w);
		obj.height(h);

		iIndex = iIndex + 1;
	});
	div.css('width', max_x + 'px');
	div.css('height', max_y + 'px');
	div.css('margin-top', '-' + (max_y + 2) + 'px');
}
function putOnButtonMap (obj, parent) {
	jQuery(obj).toggleClass('select');
	//alert(jQuery('#sect_select_' + parent + '_' + jQuery(obj).attr('rel')).val());
	//jQuery('#sect_select_' + parent + '_' + jQuery(obj).attr('rel')).val((jQuery(obj).attr('class') == '') ? 0 : 1)
	//alert(jQuery('#sect_select_' + parent + '_' + jQuery(obj).attr('rel')).val());
	jQuery(obj).attr('title', (jQuery(obj).attr('class') == '') ?
		'Добавить сектор в выборку' : 'Убрать сектор из выборки');
	return false;
}
function seeTownInfo (town_id, link) {
	var dta = jQuery('#ptown_' + town_id).html();
	if (dta.length < 30) {
		//jQuery.get(link + town_id + '/', function (data) {
		dAjax.AppendRequest(link + town_id + '/', function (data) {
			jQuery('#ptown_' + town_id).html(data);
			prepareStyleTownInfo(town_id);
			setSliders();
			jQuery('#ptown_' + town_id).css('display', 'block');
			jQuery('#ptown_' + town_id + ' .slider').addClass('opened');
		});
	} else {
		jQuery('#ptown_' + town_id).css('display', 'block');
	}
}
function offerSetUnset (strId, bType, func) {
	if (!strId.length || !jQuery('#script_set').length) {
		if (func != undefined) {
			func();
		}
	} else {
		//jQuery.get(
		dAjax.AppendRequest(
			jQuery('#script_set').val() +
			'offer/' + (bType ? 'set' : 'unset') + '/?by_ajax=1&' +
			(jQuery('#list_history').length ? 'offers_personal' : 'offers') +
			'=' + strId, (func == undefined) ? function () {} : function (data) { /*alert(data);*/ func(); }
		);
	}
}
function paintCurrentOffers (nodeId, appendInMemory) {
	function paintCirrentOffersPart (sId, bType, appendInMemory) {
		if (sId.length) {
			//if (jQuery('#map_print_link').attr('href') != undefined) {
				paintOffers(sId.split(','), bType);
			//}
			if (appendInMemory) {
				offerSetUnset(sId, bType);
			}
		}
	}
	var sSet = getOfferList(nodeId, true, 'rel'),
		sUnset = getOfferList(nodeId, false, 'rel');

	paintCirrentOffersPart(sSet, true, appendInMemory);
	paintCirrentOffersPart(sUnset, false, appendInMemory);
}
function paintOffers(arId, bType) {
	for (var i = 0; i < arId.length; i++) {
		if (bType) {
			if (!jQuery('#ofp_' + arId[i]).length) {
				putOfferOnMap(arId[i]);
			}
		} else {
			clearOfferFromMap(arId[i]);
		}
	}
	if(jQuery('#map_canvas a').length > 20) {
		jQuery('#export_link_pdf').css('display', 'none');
	} else {
		jQuery('#export_link_pdf').css('display', 'inline');
	}
}
function clearOfferFromMap (iId) {
	jQuery('#ofp_' + iId).remove();
}
function putOfferOnMap (iId) {
	putOfferPoint(
		document.getElementById('number[' + iId + ']').value,
		document.getElementById('coord_x[' + iId + ']').value,
		document.getElementById('coord_y[' + iId + ']').value,
		document.getElementById('color[' + iId + ']').value,
		document.getElementById('text_color[' + iId + ']').value,
		document.getElementById('link[' + iId + ']').value,
		iId
	);
}
function putOfferPoint (iNumber, x, y, color, text_color, link, iId) {
	jQuery('#map_canvas').append('<a href="' + link + '" id="ofp_' + iId + '" target="_blank">' + iNumber + '</a>');
	jQuery('#ofp_' + iId).css({
		'color' : '#' + text_color,
		'background-color' : '#' + color,
		'top' : parseInt(y) + 'px',
		'left' : parseInt(x) + 'px',
		'border' : '1px solid #' + text_color
	});
}
function changeTownParamList (id1, id2) {
	jQuery('#' + id2).css('display', 'none');
	jQuery('#' + id1).css('display', 'block');
}
function closeTownParamList (id_town) {
	jQuery('#ptown_' + id_town).css('display', 'none');
	setTownMemoryFromParam(id_town);
}
function getTownIdFromDOM (obj, id_town) {
	var sHref = obj.attr('href');
	var arHref = sHref.split('_');
	return '#sect_select_' + id_town + '_' + obj.attr('rel');//arHref[0].substr(arHref[0].indexOf('#') + 1);
}
function setTownParamFromMemory (id_town) {
	/*
	jQuery('#ptown_' + id_town + ' ul :checkbox').each(function () {
		jQuery(this).attr('checked',
			parseInt(jQuery('#ptown_' + id_town + ' ul input[rel="' + this.id + '"]').val())
		);
	});
	
	jQuery('#map_obertka_' + id_town + ' span  a').each(function () {
		console.log(jQuery(getTownIdFromDOM(jQuery(this), id_town)).val());
		jQuery(this).attr('class',
			parseInt(jQuery(getTownIdFromDOM(jQuery(this), id_town)).val()) ? 'select' : ''
		);
	});
	*/
	jQuery('#map_obertka_' + id_town + ' a').removeClass('select');
	jQuery('#map_obertka_' + id_town + ' a').attr('title', 'TITLE!');
	setTownMemoryFromParam(id_town);
}
function setTownMemoryFromParam (id_town) {
	/*
	jQuery('#ptown_' + id_town + ' ul :checkbox').each(function () {
		jQuery('#ptown_' + id_town + ' ul input[rel="' + this.id + '"]').val(jQuery(this).attr('checked') ? '1' : '0');
	});
	*/
	jQuery('#map_obertka_' + id_town + ' a').each(function () {
		
		jQuery(getTownIdFromDOM(jQuery(this), id_town)).val(
			(jQuery(this).attr('class') == 'select') ? 1 : 0
		);
	});
}
function closeTownParamListWithoutConfirm (id_town) {
	jQuery('#ptown_' + id_town).css('display', 'none');
	setTownParamFromMemory(id_town);
}
function setSliders () {
	jQuery('.slider-title a').each(function()
		{
			jQuery(this).parents('.slider').removeClass('opened');
			jQuery(this).click
				(
					function(e)
					{
						e.preventDefault();
						jQuery(this).parents('.slider').hasClass('opened') ?
						jQuery(this).parents('.slider').removeClass('opened') :
						jQuery(this).parents('.slider').addClass('opened');
					}
				)
		})
}
jQuery(document).ready(function(){
	setSliders();
})
function closeTownInfoPopup (town_id) {
	jQuery('#ptown_' + town_id).css('display', 'none');
}