$pCurCategory = null;
$oCurrentSubMenu = null;
$oCurrentSel = null;
$sCurrentSel = '';
$bIsCatalog = false;

function markSubmenu(oSub, bFlag)
	{
		if (oSub)
			{
				var nIndex = oSub.className.indexOf('over');
				if (nIndex != -1)
					{
						oSub.className = oSub.className.substring(0, nIndex);
						$oCurrentSubMenu = null;
					}
				else
					{
						if (bFlag && $oCurrentSubMenu)
							markSubmenu($oCurrentSubMenu, true);
						oSub.className += ' over';
						$oCurrentSubMenu = oSub;
					}
			}
	}

function pageClick($oItem, $oEvent)
	{
			$F.stopEvent($oEvent)
			if ($bIsCatalog)
				loadCatalogPage($oItem.href);
			else	
				window.location.href = $oItem.href
	}

function itemClick($oItem, $oEvent)
	{
			if ($sCurrentSel)
				$oCurrentSel = document.getElementById($sCurrentSel);
			
			if ($oCurrentSel)
				{
					$sCurrentSel = "";
					$oCurrentSel.className="cItm";
					$oCurrentSel=null;
				}
			$oCurrentSel = $F.getParent($oItem);
			$oCurrentSel.className = "cItm lv3sel"
			$F.stopEvent($oEvent)
			if ($bIsCatalog)
				loadCatalogPage($oItem.href);
			else	
				window.location.href = $oItem.href
	}

bLoadingDigest = false

function catalogPanelAnimation($oAnimation, $nValue)
	{
		
		var
			$oTarget = $oAnimation.getTarget();
		/*@cc_on @if (@_win32)
			$oTarget.filters(0).opacity = $nValue * 100;
		/*@else @*/
			$oTarget.style.opacity = $nValue;
		/*@end @*/
	}

function loadCatalogPage($sCatalogUrl, $bForceReload)
	{
		var $oDiv = document.getElementById('divCatalogPanel');
		if ($oDiv || $bForceReload)
			{
				bLoadingDigest = true;
				xHttp.cancelAll();
				var $oRequest = xHttp.getRequest('/', 'get');
				$oRequest.handler = function(oResult)
					{
						
						bLoadingDigest = false;
						/*@cc_on @if (@_win32)
						$oDiv.filters[0].apply();
						$oDiv.innerHTML = String(oResult.responseData);
						$oDiv.filters[0].play();
						@else @*/
						if (oResult && oResult.responseData)
							{
								Animation.start({
										target : $oDiv,
										onIterate : catalogPanelAnimation,
										startValue : 1,
										finishValue : 0,
										time : 0.1,
										onStop : function(){
												//$oDiv.innerHTML = oResult.responseData;
												$oDiv.innerHTML = String(oResult.responseData);
												var oTitle = document.getElementById("hTitle");
												if (oTitle && oTitle.title)
														document.title = oTitle.title;
		
											},
										onInit : function(){
												//oShutter.style.opacity = 0.3;
												//$oDiv.style.opacity = 1;
											}
									}, {
										target : $oDiv,
										onIterate : catalogPanelAnimation,
										startValue : 0,
										finishValue : 1,
										time : 0.1,
										onStop : function(){
												/*@cc_on @if (@_win32)
													$oDiv.filters(0).opacity = 100;
												/*@else @*/
													$oDiv.style.opacity = 1;
												/*@end @*/
											},
										onInit : function(){
											}
									}
									);
							}
						/*@end @*/
					}
				$oRequest.headers['X-Sub-Path'] = 'yes';
				$oRequest.headers['X-Cat-Id'] = $sCatalogUrl;
				$oRequest.execute();
			}
		else
			{
				window.location.href = $sCatalogUrl;
			}
	}

function toggleMenu(oItem)
	{
		var oItems = $F.getLastElementChild(oItem)
		var aImgs = oItem.getElementsByTagName("img"), oImg;
		var nIndex = oItem.className.indexOf('c_Sel');
		var bSelected = true;
		if (nIndex != -1)
			{
				oItem.className = oItem.className.substring(0, nIndex);
				bSelected = false
				oItems.style.display = 'none';
			}
		else
			{
				oItem.className += ' c_Sel';
				oItems.style.display = 'block';
			}

		if (aImgs.length)
			{
				oImg = aImgs[0];
				if (bSelected)
					oImg.src="/i/lmenu-open.gif"
				else
					oImg.src="/i/lmenu-close.gif"
			}
	}

_current_image=0;
function swapImage(nId)
	{
		if (nId==_current_image)
			return false;
		var oImg, oCaption, oThumb;
		if (_current_image != undefined && (oImg=document.getElementById('srcimg_'+_current_image)))
			{
				if (oCaption=document.getElementById('capimg_'+_current_image))
					oCaption.style.display='none';
				if (oThumb=document.getElementById('thumbimg_'+_current_image))
					oThumb.className='item_thumb';
				oImg.style.display='none';
				_current_image=undefined;
			}
		if (nId != undefined && (oImg=document.getElementById('srcimg_'+nId)))
			{
				if (oCaption=document.getElementById('capimg_'+nId))
					oCaption.style.display='inline';
				if (oThumb=document.getElementById('thumbimg_'+nId))
					oThumb.className='item_thumb_selected';
				oImg.style.display='inline';
				_current_image=nId;
			}
	}


function doBookmark()
	{
		var sTitle = "ООО \"Инсист\"",
		sUrl = "http://www.insist.spb.ru/"; 
		if (window.sidebar)
			window.sidebar.addPanel(sTitle, sUrl, "");
		else if (window.opera && window.print)
			{
				var elem = document.createElement('a');
				elem.setAttribute('href',sUrl);
				elem.setAttribute('title',sTitle);
				elem.setAttribute('rel','sidebar');
				elem.click();
			}
		else if(document.all)
			window.external.AddFavorite(sUrl, sTitle);
		else
			alert("Попробуйте добавить в избранное вручную!");
		return false;
	}

function chn(o1, o2)
	{
		var st=o2.style, v = o1.value;
		switch(o1.tagName)
			{
				case 'SELECT':
						st.visibility=((o1.selectedIndex==0)?'visible':'hidden')
					break;
				case 'TEXTAREA':
						st.visibility=((v==''||v==' ')?'visible':'hidden')
					break;
				default:
					switch(o1.type)
						{
							case 'checkbox':
								break;
							case 'radio':
								break;
							default:
								st.visibility=((v==''||v==' ')?'visible':'hidden')
						}
			}
		st=v=undefined;
	}

function setCategory($_oCur, $_sMenu)
	{
		if ($pCurCategory)
			{
				var $oCurrent = document.getElementById($pCurCategory);
				if ($oCurrent)
					{
						var $sMenu = $oCurrent.getAttribute("cmenu");
						var $oMenu = document.getElementById($sMenu);
						$oMenu.style.display = "none";
						$oCurrent.className = "";
					}
				$pCurCategory = '';
			}
		var $oMenu = document.getElementById($_sMenu);
		if ($oMenu)
			{
				$oMenu.style.display = "block";
				$pCurCategory = $_oCur.id;
				$U.setCookie('scat', $_oCur.id);
				//$oMenu.style.backgroundImage="url(" + $_sMenu + ")";
				//$oMenu.style.borderColor = $_sColor
				$_oCur.className = "cur";
			}
	}