function openMe(id,left)                                
{
	var tmp = document.getElementById(id);
	if (tmp)
	{
		tmp.style.display = "";
		tmp.style.position = "absolute";
		tmp.zIndex = 99;
		tmp.style.left = ((myWidth - tmp.offsetWidth) >> 1) + "px";
		tmp.style.top = "54px";

		var tmp2 = document.getElementById(id + "_bg");
		if (tmp2 && navigator.appName.indexOf("Microsoft")!=-1)
		{
			tmp2.style.display = "";
			tmp2.style.position = "absolute";
			tmp2.zIndex = 55;
			tmp2.style.left = tmp.style.left;
			tmp2.style.top = tmp.style.top;
			tmp2.style.width = tmp.offsetWidth + "px";
			tmp2.style.height = tmp.offsetHeight + "px";
		}
	}
	return false;
}

function closeMe(id)
{
	var tmp = document.getElementById(id);
	if (tmp) tmp.style.display = "none";
	tmp = document.getElementById(id + "_bg");
	if (tmp) tmp.style.display = "none";
}
function winOpen(href,win)
{
	window.open(href,win,'scrollbars=yes,width=580,height=610,left=' + (myLeft + (myWndWidth - 580) >> 1) + ',top=' + (myTop + (myWndHeight - 610) >> 1)).focus();
	return false;
}
function open_print(elem)
{
	window.open(elem.href,"_print",'scrollbars=yes,width=680,height=500,left=10,top=10').focus();
	return false;
}
function open_order(elem)
{
	window.open(elem.href,"_order",'scrollbars=yes,width=590,height=470,left=10,top=10').focus();
	return false;
}
function toggle_citylist(id)
{
	refs = document.getElementsByTagName("a");

	for (x = 0; x < refs.length; x++) if (refs[x].id) if (refs[x].id.substr(0,3) == "aa_")
	{
		y = refs[x].id.substr(3);
		if (y == id)
		{
			if (refs[x].style.display == "none")
			{
				refs[x].style.display = "";
				document.getElementById("ca_" + y).style.display = "none";
			}
			else
			{
				refs[x].style.display = "none";
				document.getElementById("ca_" + y).style.display = "";
			}
		}
		else
		{
			refs[x].style.display = "";
			document.getElementById("ca_" + y).style.display = "none";
		}
	}
	return false;
}

var cml_id = "cl_fav";
function openCmlist(el)
{
	var id = "cl_" + el.id.substr(3);
	if (cml_id == id)
	{
		var tmp = document.getElementById(id);
		if (tmp) tmp.style.display = "none";
		tmp = document.getElementById("cl_fav");
		if (tmp) tmp.style.display = "";
		cml_id = "cl_fav";
	}
	else
	{
		var tmp = document.getElementById(cml_id);
		if (tmp) tmp.style.display = "none";
		tmp = document.getElementById(id);
		if (tmp) tmp.style.display = "";
		tmp = document.getElementById("cc_" + cml_id.substr(3));
		if (tmp) tmp.className = "wpgen";
		cml_id = id;
	}
}

function wpSel(el)
{
	if ("cl_" + el.id.substr(3) != cml_id) el.className = "wpsel";
}

function wpGen(el)
{
	if ("cl_" + el.id.substr(3) != cml_id) el.className = "wpgen";
}

function rollMB(i,to)
{
	var els = $("#mb_over > div");

	if (els.length > i)
	{
		$(els.get(i > 0 ? i - 1 : els.length - 1)).fadeOut(800);
		$(els.get(i)).fadeIn(800);

		i++;
		window.setTimeout("rollMB(" + (i >= els.length ? 0 : i) + "," + to + ")",to);

/*	// увеличиваем счетчик просмотров показанного баннера
	$("<script src=/ad.js.php?id="+bannersList[next][0]+"></script>").appendTo("#body");
}*/
	}
}

var MTt = false;
var MTto = 0;
function rollMT()
{
	$("#mt_next").click();
//	MTt = window.setTimeout(rollMT,MTto);
}

function bind_events()
{
	$("#mt_next").bind("click", function(){
		
//		unbind_events();

		if (MTt)
			window.clearTimeout(MTt);
		MTt = window.setTimeout(rollMT,MTto);

		tmp = $("#mt_cont > table");
		ws = ifScreenIsWide();
		if (tmp.get(ws ? 4 : 3))
		{
			hide = $(tmp.get(0));
			hide.clone(true).appendTo("#mt_cont");
			hc = $(tmp.get(ws ? 4 : 3));
			hc.css('width','0');
			hc.css('overflow','hidden');
					
			hide.animate({
				marginLeft: '-' + hide.attr('width') + 'px'
			},	function(){
				hide.remove();
//				bind_events()
			}
			);
			hc.animate({
				width: hc.attr('width') + 'px'
			});

		}
		else
		{
//			bind_events();
		}
	
		return false;
	});
	$("#mt_prev").bind("click", function(){
		
//		unbind_events();

		if (MTt)
			window.clearTimeout(MTt);
		MTt = window.setTimeout(rollMT,MTto);

		tmp = $("#mt_cont > table");
		ws = ifScreenIsWide();
		if (tmp.get(ws ? 4 : 3))
		{
			hide = $('#mt_cont > table:last');
			tmp = $('#mt_cont > table:first');
			hide.clone(true).css({marginLeft: '-' + hide.attr('width') + 'px'}).prependTo("#mt_cont");
			show = $('#mt_cont > table:first');		
				
			show.animate({
				marginLeft: '0px'
			},function(){
				hide.remove();
//				bind_events()
			}
			);
		}
		else
		{
//			bind_events();
		}
	
		return false;
	});
}

function unbind_events()
{
	$("#mt_next").unbind('click');
	$("#mt_prev").unbind('click');
	
	$("#mt_next").bind('click',function(){
		return false;
	});
	
	$("#mt_prev").bind('click',function(){
		return false;
	});
}

function checkWideScreen()
{
	if (ifScreenIsWide())
	{
		wideScreen();
	}
	else
	{
		narrowScreen();
	}
}

var wd = (navigator.appName.indexOf("Microsoft")!=-1 ? 80 : 94);

function wideScreen()
{
//	$("#mt_cont").parent().css("width","1182px");
	$("#mt_cont").parent().css("width",myWidth > 1280  ? (1280 - wd) + "px" : (myWidth - wd) + "px");
	$(document).find("table.mtr").each(function(i) {
		$(this).attr("width",Math.ceil((myWidth > 1280  ? (1280 - wd) : (myWidth - wd - 14)) / 3));
		$(this).css("width",(Math.ceil((myWidth > 1280  ? (1280 - wd) : (myWidth - wd - 14)) / 3)) + "px");
	});
	$("#papa").attr("width",myWidth > 1280 ? "1280" : "100%");
}

function narrowScreen()
{
//	$("#mt_cont").parent().css("width","888px");
	$("#mt_cont").parent().css("width",myWidth < 1002 ? (1002 - wd) + "px" : (myWidth - wd) + "px");
	$(document).find("table.mtr").each(function(i) {
		$(this).attr("width",Math.ceil((myWidth < 1002  ? (1002 - wd) : (myWidth - wd - 14)) / 3));
		$(this).css("width",(Math.ceil((myWidth < 1002  ? (1002 - wd) : (myWidth - wd - 14)) / 3)) + "px");
//window.status = window.defaultStatus = myWidth + " :: " + (Math.ceil((myWidth < 1002  ? 922 : (myWidth - 80 - 14)) / 3));
	});
	$("#papa").attr("width",myWidth < 1002 ? "1002" : "100%");
}

function ifScreenIsWide()
{
	return getWindowSize() >= 1257;
}

var myWidth = 0, myHeight = 0;
var myWndWidth = 0, myWndHeight = 0;
var myLeft = 0, myTop = 0;
function getWindowSize() {
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
    myWndWidth = window.screen.width;
    myWndHeight = window.screen.height;
    myLeft = window.scrollX;
    myTop = window.scrollY;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
    myWndWidth = document.documentElement.scrollWidth;
    myWndHeight = document.documentElement.scrollHeight;
    myLeft = document.documentElement.scrollLeft;
    myTop = document.documentElement.scrollTop;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
    myWndWidth = document.body.scrollWidth;
    myWndHeight = document.body.scrollHeight;
    myLeft = document.body.scrollLeft;
    myTop = document.body.scrollTop;
  }
  return myWidth
}

function reShowRC(id)
{
	var tmp = document.getElementById("rclist");
	if (tmp) for (var x = 0; x < tmp.childNodes.length; x++) if (tmp.childNodes[x] && tmp.childNodes[x].tagName == "DIV")
	{
		var cnt = 0;
		for (var y = 0; y < tmp.childNodes[x].childNodes.length; y++) if (tmp.childNodes[x].childNodes[y] && tmp.childNodes[x].childNodes[y].tagName == "A" && tmp.childNodes[x].childNodes[y].getAttribute("types"))
		{
			if (!id || tmp.childNodes[x].childNodes[y].getAttribute("types").indexOf("|" + id + "|") >= 0)
			{
				tmp.childNodes[x].childNodes[y].style.display = "";
				if (tmp.childNodes[x].childNodes[y].previousSibling && tmp.childNodes[x].childNodes[y].previousSibling.tagName == "SPAN") tmp.childNodes[x].childNodes[y].previousSibling.style.display = (cnt ? "" : "none");
				cnt++;
			}
			else
			{
				tmp.childNodes[x].childNodes[y].style.display = "none";
				if (tmp.childNodes[x].childNodes[y].previousSibling && tmp.childNodes[x].childNodes[y].previousSibling.tagName == "SPAN") tmp.childNodes[x].childNodes[y].previousSibling.style.display = "none";
			}
		}
		tmp.childNodes[x].style.display = (cnt ? "" : "none");
	}
}
