jQuery(document).ready(function () {
	var bSubmenuShow = false;
	resizeWindow(false);
	jQuery('td.sidebar div.content > ul').css('display','none');
	jQuery('td.sidebar div.content > a').click(function () {
		if (jQuery(this).hasClass('active'))
		{
			jQuery('td.sidebar div.content a.active').attr('id','menulink').removeClass('active').next('ul').hide('slow');
		}
		else
		{
			
			jQuery('td.sidebar div.content a.active').attr('id','menulink').removeClass('active').next('ul').hide('slow');
			jQuery(this).addClass('active').attr('id','menulinkact').next('ul').show('display');
			
		}
		return false;
	});
	jQuery('#menubat1,#menubat2,#menubat3').click(function () {
		bSubmenuShow = true;
		jQuery('#links_menubat1,#links_menubat2,#links_menubat3').stop().css('opacity','1').css('display','none');
		jQuery('#info div.info').css('display','block');
		if (jQuery.browser.opera)
		{
			jQuery('#links_' + jQuery(this).attr('id')).css('display','block');
		}
		else
		{
			jQuery('#links_' + jQuery(this).attr('id')).fadeIn('slow');
		}
		jQuery('#menubat1,#menubat2,#menubat3').removeClass('active');
		jQuery(this).addClass('active');
		return false;

	})
	.hover(function () {
		if (jQuery('#menubat1,#menubat2,#menubat3').hasClass('active'))
		{
			bSubmenuShow = true;
		}
		},function () {
		bSubmenuShow = false;
		if ((jQuery.browser.msie) && (jQuery.browser.version == '6.0'))
		{
		}
		else
		{
		}
		hideSubmenu();
	});
	jQuery('#info div.info').hover(function () {
		bSubmenuShow = true;
	},function () {
		bSubmenuShow = false;
		hideSubmenu();
	});

	// а�Аб���ЕаЛб�
	
	var nTizerWidth = 0;
	var nTizerPosition = 0;
	var nTizerCount = jQuery('li.tizer').length;
	var nMaxTizer = jQuery('td.itizer').length;
	var nMinTizer = 0;
	var nBaseTizerCount = nMaxTizer;

	function getWindowWidth()
	{
		var windowWidth,windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		return windowWidth;
	}
	function resizeWindow(bIgnore) {

		nWindowWidth = getWindowWidth();
		// а��ЛаИ б�Иб�ИаНаА аОаКаНаА б�ЖаЕ 1000px
		if (nWindowWidth < 1000)
		{
			var nRasporkaWidth = 1000;
			
		}
		// а��ЛаИ аБаОаЛб��Е 1260 аПаИб�КаЕаЛаЕаЙ
		else if (nWindowWidth > 1280)
		{
			nRasporkaWidth = 1260;
			
		}
		// а�НаАб�Е 
		else
		{
			nRasporkaWidth = Math.max(1000,Math.ceil(nWindowWidth * 0.983));
			
		}
		if (nWindowWidth <= 1024)
		{
			nWidth = 805;
		}

		else if (nWindowWidth > 1280 )
		{
			nWidth = jQuery('#middle').width() * 0.8;
		}
		else
		{
			nWidth = nWindowWidth * 0.789;
		}
    //nWidth=nWidth+6;
		//s
		outputInfo(nWindowWidth,nRasporkaWidth,nWidth);
		jQuery('.stretching').css('width',nRasporkaWidth);

		//
		// 
		jQuery('#karusel').css('width',nWidth + 'px');
		jQuery('div.info').css('width',nWidth + 'px');
		// аЈаИб�ИаНаА б�АаБаЛаИб��
		nTizerCount = jQuery('td.itizer').length;
		nTizerWidth = Math.ceil((nWidth - 22) / 3);
		jQuery('#tizerous').css('width',(nTizerWidth * nTizerCount + (nTizerCount - 1) * 10) + 10+'px');
		jQuery('td.itizer').css('width',nTizerWidth +'px');
		//

		if (bIgnore)
		{
			animateTizers();
		}
		
	}
	function animateTizers() 
	{

		jQuery('#tizerous').animate({
			'margin-left' : -1 * (nTizerWidth * (nTizerPosition - nMinTizer) + (nTizerPosition - nMinTizer) * 10) + 'px'
		},300);
	}
	resizeWindow(false);
	jQuery(window).resize(resizeWindow);
	jQuery('#tizers_left').click(function () {
		
		if (nTizerPosition > nMinTizer)
		{
			nTizerPosition--;

		}
		else
		{
			nTizerPosition--;
			
			var nPos = nBaseTizerCount - (Math.abs(nTizerPosition) % nBaseTizerCount); // Выравненая позиция
			var new_td = jQuery('#tizerous td.itizer:eq(' + (nPos + (-1 * nMinTizer) - 1) +')').clone();
			jQuery('#tizerous tr:eq(0)').prepend('<td width="10"><!-- --></td>').prepend(new_td);
			jQuery('#tizerous').css('margin-left',-1 * (nTizerWidth + 10) + 'px');
			resizeWindow(false);
			nMinTizer--;
			
		}
		animateTizers();
		return false;
	});
	jQuery('#tizers_right').click(function () {
		if (nTizerPosition + 3 < nMaxTizer)
		{
			nTizerPosition++;

		}
		else
		{
			
			var nPos = (Math.abs(nTizerPosition + 3) % nBaseTizerCount); // Выравненая позиция
			nTizerPosition++;
			var new_td = jQuery('#tizerous td.itizer:eq(' + (nPos + (-1 * nMinTizer)) +')').clone();
			
			jQuery('#tizerous tr:eq(0)').append(new_td).append('<td width="10"><!-- --></td>');
			resizeWindow(false);
			nMaxTizer++;
		}
			animateTizers();
		return false;
	});
	function hideSubmenu()
	{
		window.setTimeout(function () {
			if (!bSubmenuShow)
			{
				jQuery('#info div.info').css('display','none');
				jQuery('#menubat1,#menubat2,#menubat3').removeClass('active');
			}
			},100);
	}
	function outputInfo(nWindowWidth,nRasporkaWidth,nWidth)
	{ 
	jQuery('#debug').html('WindowWidth = ' + nWindowWidth + 'Rasporka = ' + nRasporkaWidth + 'Karusel width=' + nWidth  );
	//<div id="debug" style="color:red;position:absolute;left:10;top:10;width:200;height:100"><!-- --></div>
	}
	
});
