oCurrentDigestSelector = null;
oCurrentMenu = null;
oCurrentButton = null;
bLoadingDigest = false;
function setDigestSelector(oObject, oEvent)
	{
		if (bLoadingDigest)
			return false
		if (oCurrentDigestSelector)
			{
				oCurrentDigestSelector.className = '';
				oCurrentDigestSelector = null;
			}
		if (oObject)
			{
				oCurrentDigestSelector = oObject;
				oObject.className = 'selected';
				loadDigestPage(oObject.id);
			}
		$F.stopEvent(oEvent);
		return false;
	}

function loadDigestPage(sPageId)
	{
		bLoadingDigest = true;
		xHttp.cancelAll();
		var oRequest = xHttp.getRequest('/', 'get');
		oRequest.handler = function(oResult)
			{
				var oDiv = document.getElementById('divMainDigest');
				bLoadingDigest = false;
				if (oResult && oResult.responseData)
					{
						/*@cc_on @if (@_win32)
							oDiv.innerHTML = oResult.responseData;
						@else @*/
							oDiv.innerHTML = String(oResult.responseData);
						/*@end @*/
					}
			}
		oRequest.headers['X-Sub-Path'] = 'yes';
		oRequest.headers['X-Select-Id'] = sPageId;
		oRequest.execute();
	}

function setMenuOver(oObject, bFlag, oEvent)
	{
		var oTarget = oEvent.relatedTarget;
		if (oTarget && oObject !== oTarget && $F.contains(oObject, oTarget))
			{
				$F.stopEvent(oEvent);
				return false;
			}
 		if (bFlag)
 			{
 				if (oCurrentMenu )
 					{
						Animation.start({target : $F.getLastElementChild(oCurrentMenu) , onIterate : buttonAnimation, styleProperty : 'opacity', startValue : 1.0, finishValue : 0, easing : 1, time : 0.4});
						oCurrentMenu = null;
 					}
				if (oObject)
					{
						oCurrentMenu = oObject;
						Animation.start({target : $F.getLastElementChild(oObject) , onIterate : buttonAnimation, styleProperty : 'opacity', startValue : 0, finishValue : 1.0, easing : 1, time : 0.4});
					}
 			}
 		else if (oObject == oCurrentMenu)
 			{
				Animation.start({target : $F.getLastElementChild(oCurrentMenu) , onIterate : buttonAnimation, styleProperty : 'opacity', startValue : 1.0, finishValue : 0, easing : 1, time : 0.4});
				oCurrentMenu = null;
 			}
 		$F.stopEvent(oEvent);
	}

function setButtonOver(oObject, bFlag, oEvent)
	{
		if (bFlag === false && oCurrentButton === oObject || oCurrentButton)
			{
				if (!oEvent)
					oEvent = window.Event
				/*@cc_on @if (@_win32)
					if ($F.contains(oEvent.toElement))
						{
						}
				/*@else @*/
					if ($F.contains(oCurrentButton, oEvent.relatedTarget))
						{
							$F.stopEvent(oEvent);
							return false;
						}
				/*@end @*/

				oCurrentButton.className = 'image_btn';
				Animation.start({target : oCurrentButton , onIterate : buttonAnimation, styleProperty : 'opacity', startValue : 1.0, finishValue : 0.6, easing : 1, time : 0.4});
				oCurrentButton = null;
			}
		if (oObject && bFlag !== false)
			{
				oObject.className += ' image_btn_over';
				oCurrentButton = oObject;
				Animation.start({target : oObject , onIterate : buttonAnimation, styleProperty : 'opacity', startValue : 0.6, finishValue : 1.0, easing : 1, time : 0.4});
			}
		$F.stopEvent(oEvent);
	}

function buttonAnimation(oAnimation, nValue)
	{
		var
			oTarget = oAnimation.getTarget();
		try
			{
		/*@cc_on @if (@_win32)
			if (oTarget &&
					oTarget.filters(0)
					&& oTarget.filters(0).opacity !== undefined)
				oTarget.filters(0).opacity = nValue * 100;
		/*@else @*/
			oTarget.style.opacity = nValue;
		/*@end @*/
			}
		catch(e)
			{
			}
	}

function shutterAnimation(oAnimation, nValue)
	{
		var
			oTarget = oAnimation.getTarget(),
			oDiv = oAnimation.getData();
		/*@cc_on @if (@_win32)
			oTarget.filters(0).opacity = nValue * 100;
		/*@else @*/
			oTarget.style.opacity = nValue;
			oDiv.style.opacity = nValue * 5;
		/*@end @*/
	}

function toggleDialog(oDiv, oRoot, oEvent, bState)
	{
		$F.stopEvent(oEvent);
		if (oRoot)
			{
				var
					oCoords = $F.getGlobalXY(oRoot),
					oShutter = document.getElementById('divShutter');
				if (oDiv.style.visibility == 'visible' || bState === false)
					{
						Animation.start({
								target : oShutter , onIterate : shutterAnimation, startValue : 0.4, finishValue : 0, time : 0.1, data : oDiv,
								onStop : function(){
										oShutter.style.visibility = 'hidden';
										oShutter.style.display='none';
										oShutter.style.opacity = 0;
										oDiv.style.display = 'none';
										oDiv.style.opacity = 0;
									},
								onInit : function(){
										//oShutter.style.opacity = 0.3;
										//oDiv.style.opacity = 1;
									}
							});
					}
				else
					{
						
						Animation.start({
							target : oShutter,
							onIterate : shutterAnimation,
							startValue : 0,
							finishValue : 0.4,
							time : 0.1,
							data : oDiv,
							onInit : function()
								{
									$F.setGlobalXY(oDiv, oCoords.x - 35 - 19, oCoords.y - 18);
									oDiv.style.display = 'block';
									oShutter.style.display='block';
									oShutter.style.visibility='visible';
									oShutter.style.opacity = 0;
									oDiv.style.opacity = 0;
								}
							});
					}
			}
	}

var
	bLastSubmitSuccess = false;

function toggleOrderDialog(oRoot, oEvent, bState)
	{
		var
			oDiv = document.getElementById('divOrder'),
			oForm = document.getElementById('formOrder'),
			sName = $F.getCookie('uname'),
			sMail = $F.getCookie('umail'),
			sTel = $F.getCookie('utel');
		if (bLastSubmitSuccess)
			{
				oForm.reset();
				bLastSubmitSuccess = true;
			}
		if (sName)
			oForm.elements[1].value = sName;
		if (sMail)
			oForm.elements[2].value = sMail;
		if (sTel)
			oForm.elements[3].value = sTel;
		if (oDiv)
			toggleDialog(oDiv, oRoot, oEvent, bState);
	}

function toggleQuizDialog(oRoot, oEvent, bState)
	{
		var
			oDiv = document.getElementById('divQuiz'),
			oForm = document.getElementById('formQuiz'),
			sName = $F.getCookie('uname'),
			sMail = $F.getCookie('umail'),
			sTel = $F.getCookie('utel');
		if (oForm)
			{
				if (bLastSubmitSuccess)
					{
						oForm.reset();
						bLastSubmitSuccess = true;
					}
				if (sName)
					oForm.elements[1].value = sName;
				if (sMail)
					oForm.elements[2].value = sMail;
				if (sTel)
					oForm.elements[3].value = sTel;
				if (oDiv)
					toggleDialog(oDiv, oRoot, oEvent, bState);
			}
	}

function sendForm(sForm, sDiv)
	{
		var
			oDiv = document.getElementById(sDiv),
			oForm = document.getElementById(sForm);
		if (oForm)
			{
				var
					oName = oForm.elements[1],
					oMail = oForm.elements[2],
					oTel = oForm.elements[3];
				$F.setCookie('uname', oName.value);
				$F.setCookie('umail', oMail.value);
				$F.setCookie('utel', oTel.value);
				toggleDialog(oDiv, oDiv, null, false);
				oForm.submit();
			}
	}

function onResize()
	{
		var
			oCoords = $F.getGlobalXY(document.getElementById('linkOrder'));
		$F.setGlobalXY(document.getElementById('divOrder'), oCoords.x - 35 - 19, oCoords.y - 18);
			oCoords = $F.getGlobalXY(document.getElementById('linkQuiz'));
		$F.setGlobalXY(document.getElementById('divQuiz'), oCoords.x - 35 - 19, oCoords.y - 18);
	}		

function toggleAlertDialog(oEvent, bState)
	{
		$F.stopEvent(oEvent);
		var
			oDiv = document.getElementById('divAlert'),
			oShutter = document.getElementById('divShutter');

		if (oDiv.style.visibility == 'visible' || bState === false)
			{
				Animation.start({
						target : oShutter , onIterate : shutterAnimation, startValue : 0.4, finishValue : 0, time : 0.1, data : oDiv,
						onStop : function(){
								oShutter.style.visibility = 'hidden'
								oDiv.style.display = 'none';
								oDiv.style.opacity = 0;
							},
						onInit : function(){
								//oShutter.style.opacity = 0.3;
								//oDiv.style.opacity = 1;
							}
					});
			}
		else
			{
				Animation.start({
					target : oShutter,
					onIterate : shutterAnimation,
					startValue : 0,
					finishValue : 0.4,
					time : 0.1,
					data : oDiv,
					onInit : function()
						{
							oDiv.style.display = 'block';
							oShutter.style.visibility='visible';
							$F.setGlobalCenter(oDiv);
							oShutter.style.opacity = 0;
							oDiv.style.opacity = 0;
						}
					});
			}
	}

function showMessage(sText, sTitle)
	{
		var
			oContent = document.getElementById('divAlertContent'),
			oTitle = document.getElementById('spanAlertTitle');
		oContent.innerHTML = sText;
		oTitle.innerHTML = sTitle ? sTitle : 'Сообщение';
		toggleAlertDialog(null, true);
	}

$F.attachEvent(window, 'resize', onResize);

$F.onLoad(function()
	{
		var oFrame = document.getElementById('frameSubmit');
		$F.attachEvent(oFrame, 'load', function(){
			if (oFrame.contentWindow)
				{
					var oWindow = oFrame.contentWindow;
					if (oWindow.messageText)
						{
							bLastSubmitSuccess = oWindow.hasErrors ? false : true;
							showMessage(oWindow.messageText, oWindow.headerText);
						}
				}
		});
	});

_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='block';
				if (oThumb=document.getElementById('thumbimg_'+nId))
					oThumb.className='item_thumb_selected';
				oImg.style.display='inline';
				_current_image=nId;
			}
	}
	
function getObject(sMovie, sTarget, nWidth, nHeight, oVars)
	{
		var html, vars='', x, oObj;
		
		if (sTarget)
			oObj = document.getElementById(sTarget);
		if (oVars)
			for(x in oVars)
				{
					vars+='&'+x+'='+oVars[x];
				}
		html='<OBJECT id="oPlayer" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+(nWidth ? nWidth : '100%')+'" height="'+(nHeight ? nHeight : '100%')+'" align="middle">'
			+'<PARAM name="allowScriptAccess" value="sameDomain" />'
			+'<PARAM name="movie" value="'+sMovie+'" />'
			+'<PARAM name="quality" value="high" />'
			+'<PARAM name="bgcolor" value="#484848" />'
			+'<PARAM name="wmode" value="transparent" />'
			+'<PARAM name="flashVars" value="" />'
			+'<EMBED src="'+sMovie+'" quality="high" bgcolor="#484848" width="'+(nWidth ? nWidth : '100%')+'" height="'+(nHeight ? nHeight : '100%')+'" name="flash" align="middle" allowScriptAccess="sameDomain" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
			+'</OBJECT>';
/*		if (oObj)
			{
				alert(document.body.onload);
				document.body.onload = function()
					{
						oObj.innerHTML = html;
					}
			}
		else
		*/
			document.write(html);
	}

function getSearchField (oInput, sValue, sCssFilled, sCssEmpty)
	{
		var
			that = this,
			pbSaveOriginal = (oInput && oInput.value == sValue),
			psValue = sValue,
			poInput = oInput,
			psCssFilled = sCssFilled,
			psCssEmpty = sCssEmpty;
			
		function pOnFocus()
			{
				if (!pbSaveOriginal && poInput.value == psValue)
					{
						poInput.value = '';
						poInput.className = psCssFilled;
					}
			}
		
		function pOnBlur()
			{
				if (poInput.value == '' || poInput.value == psValue)
					{
						poInput.value = psValue;
						poInput.className = psCssEmpty;
					}
				else
					poInput.className = psCssFilled;
			}
		if (poInput)
			{
				$F.attachEvent(poInput, 'focus', function() {
							return pOnFocus()
						});
		
				$F.attachEvent(poInput, 'blur', function() {
							return pOnBlur()
						});
		
				$F.attachEvent(poInput, 'keydown', function() {
							//return pOnBlur()
						});
				pOnBlur();
			}
	}
