function recheck_height(grp)
{
	min_h=0;
	marg=0;
	switch(grp)
	{
		case 'oceanarium': min_h=770; marg=182+46; break;
		case 'marketplace': min_h=770; marg=148+89; break;
		case 'about': min_h=700; marg=167+117; break;
		case 'tranceforce': min_h=770; marg=181+119; break;
		case 'dino': min_h=770; marg=139+105; break;
		case 'horror': min_h=700; marg=140+81; break;
		default: min_h=700; marg=167+117; break;
	}
	if(document.getElementById('content_place'))
	{
		document.getElementById('content_place').style.height=(doc.clientHeight > min_h)?doc.clientHeight-marg+'px':min_h-marg+"px";
		windowResize=function(){
			document.getElementById('content_place').style.height=(doc.clientHeight > min_h)?doc.clientHeight-marg+'px':min_h-marg+"px";
			}
		window.onresize=function(){windowResize()}
	}	
}
function change_pic(url,w,h)
{
	if(url!=cur_img)
	{
		block=document.getElementById('big_fish');
		block.src='/usr/image/common/empty.gif';
		t_img=new Image;
		n_url=url.replace('/usr/image/','/usr/image/convert/custom/416x274/');
		t_img.src=n_url;
		t_img.onload=function()
		{
			block.src=n_url;
			cur_img=url;
		}
		big_img_w=w;
		big_img_h=h;
	}
	return false;
}
function stop_carousel()
{
	if(document.getElementById('carousel_flash'))
	{
		//pbstat=(mode)?"start":"stop";
		document.getElementById('carousel_flash').SetVariable("pbstatus","allstop");
		//alert('Уходим');
	}
}
function show_hide_menu(mode,step)
{
	/*if(document.getElementById('carousel_flash'))
	{
		pbstat=(mode)?"start":"stop";
		document.getElementById('carousel_flash').SetVariable("pbstatus",pbstat)
	}*/
	if(!document.getElementById('top_place') || !document.getElementById('hide_menu')) return false;
	tOut=20;
	a=0.7;
	block=document.getElementById('top_place');
	m=(mode)?-1:1;
	step=Math.abs(step);
	m_top=(block.style.top)?parseFloat(block.style.top):0;
	if((mode && Math.abs(m_top)<=100-step) || (!mode && Math.abs(m_top)>=step))
	{
		block.style.top=m_top+m*step+'px';
		//if(document.getElementById('page_content')) document.getElementById('page_content').style.paddingTop=100+m_top+m*step+'px';
		//if(document.getElementById('bottom_back') && document.getElementById('bottom_back').currentStyle)
		//{
			//el=document.getElementById('bottom_back');
			//el.style.marginTop=100+m_top+m*step;
		//}
		step-=m*a;
		bufferTout('show_hide_menu('+mode+','+step+')',tOut);
	}
	else
	{
		block.style.top=(mode)?'-100px':'0px';
		//if(document.getElementById('bottom_back') && document.getElementById('bottom_back').currentStyle)
		//{
			//el.style.marginTop=(mode)?'0px':'100px';
		//}
		//if(document.getElementById('page_content')) document.getElementById('page_content').style.paddingTop=(mode)?'0px':'100px';
		document.getElementById('hide_menu').onclick=function(){show_hide_menu(!mode,step)};
	}
}
function show_hide_menu_flash(mode,step)
{
	//stop_carousel();
	if(document.getElementById('carousel_flash'))
	{
		pbstat=(mode)?"start":"stop";
		document.getElementById('carousel_flash').SetVariable("pbstatus",pbstat)
	}
	if(!document.getElementById('top_place') || !document.getElementById('hide_menu')) return false;
	//tOut=20;
	//a=0.7;
	block=document.getElementById('top_place');
	m=(mode)?-1:1;
	step=Math.abs(step);
	m_top=(block.style.top)?parseFloat(block.style.top):0;
	/*if((mode && Math.abs(m_top)<=100-step) || (!mode && Math.abs(m_top)>=step))
	{
		block.style.top=m_top+m*step+'px';
		//if(document.getElementById('page_content')) document.getElementById('page_content').style.paddingTop=100+m_top+m*step+'px';
		if(document.getElementById('bottom_back') && document.getElementById('bottom_back').currentStyle)
		{
			//el=document.getElementById('bottom_back');
			//el.style.marginTop=100+m_top+m*step;
		}
		step-=m*a;
		bufferTout('show_hide_menu('+mode+','+step+')',tOut);
	}
	else
	{*/
		block.style.top=(mode)?'-100px':'0px';
		if(document.getElementById('bottom_back') && document.getElementById('bottom_back').currentStyle)
		{
			//el.style.marginTop=(mode)?'0px':'100px';
		}
		//if(document.getElementById('page_content')) document.getElementById('page_content').style.paddingTop=(mode)?'0px':'100px';
		document.getElementById('hide_menu').onclick=function(){show_hide_menu_flash(!mode,step)};
	/*}*/
}
function menu_focus(mode,obj)
{
	if(mode && obj.className.search(' selected')!=-1 || !document.getElementById('top_menu_line')) return false;
	block=document.getElementById('top_menu_line');
	var i=0;
	var defObj;
	for(i=0;i<block.childNodes.length;i++)
	{
		if(block.childNodes[i].className)
		{
			block.childNodes[i].className=block.childNodes[i].className.replace(/(\s?selected)|(\s?subselected)/gi,'');
		}
	}
	if(mode)
	{
		obj.className=obj.className.replace(/(\s?selected)|(\s?subselected)/gi,'')+' selected';
	}
	else
	{
		if(selectedPage!='page_')
		{
			defObj=document.getElementById('tsm_'+selectedPage);
			defObj.className=defObj.className.replace(/(\s?selected)|(\s?subselected)/gi,'')+' subselected';
		}
	}
}
function select_cat(id)
{
	if(document.getElementById('market_filter'))
	{
		countCat=0;
		cookieCat=getCookie('filter_last_cats_'+id);
		celcats=cookieCat.split(";");
		var inCatio=new Array;	
		for(i in filter_cats)
		{
			filter_cats[i]['selected']=(i==id);
			document.getElementById('group_'+i).className=document.getElementById('group_'+i).className.replace(/\s?selected/gi,'');
			if(i==id) document.getElementById('group_'+i).className+=' selected';
			for(j in filter_cats[i])
			{
				if(j!='selected')
				{
					wasSel=false;
					for(k in celcats)
					{
						wasSel=(celcats[k]==j);
						if(wasSel) break;
					}
					filter_cats[i][j]['checked']=wasSel;
	
					obj=document.getElementById('cat_'+j);
					obj.className=obj.className.replace(/\s?selected/gi,'');
					obj.className+=(wasSel)?' selected':'';
					if(i==id) inCatio.push(j);
					selM=false;
					for(k in inCatio)
					{
						if(j==inCatio[k])
						{
							selM=true;
							break;
						}
					}
					obj.parentNode.style.display=(selM)?"block":"none";
					if(i==id) countCat++;
				}
			}
			
		}
		if(countCat>0)
		{
			document.getElementById('filter_button_1').style.display='block';
			document.getElementById('filter_button_3').style.display='none';
			document.getElementById('filter_button_2').style.display='block';
		}
		else
		{
			document.getElementById('filter_button_1').style.display='none';
			document.getElementById('filter_button_3').style.display='none';
			document.getElementById('filter_button_2').style.display='none';
		}
		if(scrollers.textScr) scrollers.textScr.recheckScroller();
		sort_markets(false,true);
		//alert(scrollers.textScr);
	}
}
function check_filter_cat(id)
{
	for(i in filter_cats) if(filter_cats[i]['selected']) cat=i;
	filter_cats[cat][id]['checked']=!filter_cats[cat][id]['checked'];
	for(i in filter_cats[cat])
	{
		if(i!='selected')
		{
			obj=document.getElementById('cat_'+i);
			obj.className=obj.className.replace(/\s?selected/gi,'');
			if(filter_cats[cat][i]['checked']) obj.className+=' selected';
		}
	}
}
function validate_sort()
{
	for(i in filter_cats) if(filter_cats[i]['selected']) cat=i;
	for(i in filter_cats[cat])
	{
		if(i!='selected')
		{
			if(filter_cats[cat][i]['checked'])
			{
				sort_markets();
				return true;
			}
		}
	}
	alert('Выберите категорию.');
}
function sort_markets(allMode,notHideFilter)
{
	if(!allMode) allMode=false;
	if(!notHideFilter) notHideFilter=false;
	if(document.getElementById('market_filter'))
	{
		var selcats= new Array;
		for(i in filter_cats) if(filter_cats[i]['selected']) cat=i;
		var cookieText='';
		for(i in filter_cats[cat])
		{
			if(allMode && i!='selected')
			{
				filter_cats[cat][i]['checked']=(allMode==1);
				obj=document.getElementById('cat_'+i);
				obj.className=obj.className.replace(/\s?selected/gi,'');
				if(allMode==1) obj.className+=' selected';
				cookieText+=(allMode==1)?i+";":'';
			}
			if(i!='selected' && filter_cats[cat][i]['checked'])
			{
				selcats.push(i);
				cookieText+=i+";";
			}
		}
		var cnt=0;
		for(i in filter_markets)
		{
			marketselected=false;
			for(j in filter_markets[i])
			{	
				for(k in selcats)
				{
					//if(document.getElementById('DEBUG') && selcats[k]==filter_markets[i][j][0]) document.getElementById('DEBUG').innerHTML+='<br>'+();
					marketselected=(selcats[k]==filter_markets[i][j][0] && filter_markets[i][j]['cat']==cat);
					if(marketselected)
					{
						cnt++;
						break;
					}
				}
				if(marketselected) break;
			}
			if(marketselected)
			{
				if(!document.getElementById('market_'+i))
				{
					mrkt=document.createElement('div');
					mrkt.className="mess small";
					mrkt.id="market_"+i;
					mrkt_text="";
					mrkt_text+='	<div class="mess_top solidwhite"></div>';
					mrkt_text+='	<div class="round_corner"></div>';
					mrkt_text+='	<div class="news">';
					mrkt_text+='		<div class="sbck solidwhite"></div>';
					mrkt_text+='		<table class="text_place" cellpadding=0 border=0 cellspacing=0>';
					mrkt_text+='			<tr>';
					if(markets_list[i]['pages_img']!=null)
					{
					mrkt_text+='				<td class="image"><div class="img_place"><img src="'+markets_list[i]['pages_img'].replace('/usr/image/','/usr/image/convert/line/')+'"  alt="'+markets_list[i]['pages_name']+'"></div></td>';
					//alert(mrkt_text);
					}
					mrkt_text+='				<td class="body">';
					mrkt_text+='					<h3>'+markets_list[i]['pages_name']+'</h3>';
					mrkt_text+='					<div>'+markets_list[i]['pages_annotate']+'</div>';
					mrkt_text+='					<a class="readmore" href="'+markets_list[i]['pages_full_path']+'"><b>Подробнее</b></a>';
					mrkt_text+='				</td>';
					mrkt_text+='			</tr>';
					mrkt_text+='		</table>';
					mrkt_text+='		<div class="empty_br"></div>';
					mrkt_text+='	</div>';
					mrkt.innerHTML=mrkt_text;
					document.getElementById('marketLine').appendChild(mrkt);
				}				
			}
			else
			{
				if(document.getElementById('market_'+i)) document.getElementById('market_'+i).parentNode.removeChild(document.getElementById('market_'+i));
			}
			//if(document.getElementById('market_'+i)) document.getElementById('market_'+i).style.display = (marketselected)?'block':'none';
			
		}
		//if(document.getElementById('DEBUG')) document.getElementById('DEBUG').innerHTML+='<br>'+cnt;
		if(cnt>0 && !notHideFilter)
		{
			document.getElementById('filter_cat_list').style.display='none';
			filter_is_shown=false;
		}
		else
		{
			document.getElementById('filter_cat_list').style.display='block';
			filter_is_shown=true;	
		}
		if(scrollers.textScr) scrollers.textScr.recheckScroller();
		var current_date = new Date;
		var cookie_year = current_date.getFullYear();
		var cookie_month = current_date.getMonth();
		var cookie_day = current_date.getDate() + 1;
		var the_exp = cookie_day+"/" + cookie_month + "/" + cookie_year + " 00:00:00";
		
		setCookie("filter_last_cats_"+cat, cookieText, the_exp, "/");
	}
}