if (!isIE)
	var isIE = false;

	var imgBegin=0;
	var imgCount;
	


  // разбор get-запроса

 var tmp = new Array();      // два вспомагательных
 var tmp2 = new Array();     // массива
 var param = new Array();

 var get = location.search;  // строка GET запроса
 if(get != '')
 {
     tmp = (get.substr(1)).split('&');   // разделяем переменные
     for(var i=0; i < tmp.length; i++)
     {
         tmp2 = tmp[i].split('=');       // массив param будет содержать
         param[tmp2[0]] = tmp2[1];       // пары ключ(имя переменной)->значение
     }

  }

  //alert(get);
//alert(param['id']);

 //


function ieFix () {
	$('.menu li.level-1:last-child').addClass('last-child');
	$('.menu li.level-1:first-child').addClass('first-child');
	$('.photo-list :first-child.photo').addClass('first-child');
  //$('#current-lev-1').addClass('current');
	if ($('#cont').width() < 900) {
		$('#cont').width(900);		
	}
	if ($('#cont').width() > 1678) {
		$('#cont').width(1678);
	}
	$('#topmenu .level-1 ul').each(function(){
		var maxLiWidth = 0;
		var lis = $('li', this);
		lis.each(function() {
			if (maxLiWidth < $(this).width())
				maxLiWidth = $(this).width();
		});
		lis.width(maxLiWidth);
	});
}
function tableResize()
{	
	if ($('#cont').css('marginBottom') == '31px')
			return true;
	if (IsMediaType('print'))
		return true;
	if ($('#cont').width() > 1439) {
//		$('.contentPanel').width($('#cont').width() - (206*2) - 110);
		
		//$('.contentPanel table').width(728);
		var rightPanelWidth = $('#cont').width() - 206 - 968;

		$('#content2').css('marginLeft', '-'+rightPanelWidth+'px');
		$('.leftPanel').css('marginLeft', rightPanelWidth+'px');
		$('.contentPanel').css('marginLeft', (rightPanelWidth+251) + 'px');

		$('.rightPanel').width(rightPanelWidth);

		$('.rightPanel').css('marginLeft', '-' + (rightPanelWidth)+'px');
		if ($('.rightPanel').height() < $('#content').height()) {
			$('.rightPanel').height($('#content').height());
		} else {
			$('.rightPanel').height('auto');
		}

		$('.rightPanel').show();
	} else {
		$('#content2').css('marginLeft', 0);
		$('.leftPanel').css('marginLeft', 0);
		$('.contentPanel').css('marginLeft', 251 	);
		$('.rightPanel').hide();
	}
}
function divedUl(){
	this.lis = $('.dived-ul li');
	this.minUlWidth = 168;
}
divedUl.prototype.center = function() { 
	var textHeight = $('#text-ul-centred').height();
	var divedHeight = $('.dived-ul').height();
	$('.dived-ul').css('margin-top', (textHeight - divedHeight) / 2);
}
divedUl.prototype.resize = function() {
	var contWidth = $('.dived-ul').width();
	var columsCount = Math.floor(contWidth / this.minUlWidth);
	var l = (contWidth / this.minUlWidth) - Math.floor(contWidth / this.minUlWidth);
	$('.dived-ul').html('');
	var ul = document.createElement('ul');
	var ulCount = 1;
	$(ul).width(this.minUlWidth);
	var k = Math.floor(this.lis.length / columsCount);
	if (k < 2)
		k = 2;
	var s =this.lis.length % columsCount;
	j = 0;
	if (s !== 0 && ((columsCount % 2) !==0) ) {
		$(ul).append(this.lis[0]);
		j = 1;
	}
	for(var i = j; i<this.lis.length; i++){
		$(ul).append(this.lis[i]);
		if (((i+1 + j) % k) == 0) {
			$('.dived-ul').append(ul);
			ul = null;		
			ulCount++;
			ul = document.createElement('ul');
			$(ul).width(this.minUlWidth);
		}
	}
	if ((columsCount % 2) === 0) {
		$(ul).append(this.lis[this.lis.length-1]);
		$('.dived-ul').append(ul);
	}

	var newWidth = (contWidth / columsCount) - 10;
	if (newWidth > this.minUlWidth)
		$('.dived-ul ul').width( newWidth );
}


function MyOpen(adres, wid, hei)
{
  if (!wid) var width=800;
    else  var width=wid;
  if (!hei) var height=600;
    else  var height=hei;
  if (adres) window.open('javascript: \'<img style="position: absolute; top: 0px; left: 0px;" src="http://np-g.ru/' + adres + '" >\'','','toolbar=0,status=0,scrollbars=0,location=0,width=' + width + ',height=' + height + ',top=150,left=100');
}


function TurnImgRight()
{
  imgBegin++;
  photoResize();
//­ еҐа  $('.photolist-inner').css({'opacity': '0.3'});
}

function TurnImgLeft()
{
  imgBegin--;
  photoResize();
//­ еҐа  $('.photolist-inner').css({'opacity': '0.3'});
}



function photoResize()
{
	var contWidth = $('.photolist-inner').width() - 20;
//	$('.photo-list').css('border', '1px solid red');
	var photoWidth = 131;//165
	var photos = $('.photo-list .photo');
	var photoCount = (contWidth / photoWidth) - 0.3;

  var photoCountMy = Math.floor(photoCount +0);

//alert(photoCountMy + ' - ' + photoCount);

   $.post('AJimage.php', {begin: imgBegin, end: photoCountMy}, function(data){

      $('.photolist-inner').html(data);
//­ ег©      $('.photolist-inner').css({'opacity': '0'});
      // alert('OK');

     if (imgBegin == 0) $('.left-ctl').css({'visibility': 'hidden'});
        else $('.left-ctl').css({'visibility': 'visible'});

     // alert(imgCount + ' - '+ photoCountMy);
      if (imgBegin + photoCountMy < imgCount)
        {
          $('.right-ctl').css({'visibility': 'visible'});
        }
        else $('.right-ctl').css({'visibility': 'hidden'});





	   var photos = $('.photo-list .photo');
//var photoCountMy = (contWidth / photoWidth) + 0.2;
	   photoCount2 = Math.floor(photoCount);
    	k = Math.abs(photoCount - photoCount2);
//alert(photoCountMy + ' - ' + photoCount + ' - ' + photoCount2);

	   if (photoCount2 > photos.length)
	     	photoCount2 = photos.length;

	   var	marginLeft = (contWidth - (photoWidth * (photoCount2))) / (photoCount2 - 1);


      photos.css('margin-left', marginLeft);
	   $('.photo-list>div :first-child.photo').css('margin-left', 0);

  }); // k $.post('AJimage.php', {begin: imgBegin, end: photoCountMy}, function(data){


//	photos.css('margin-left', marginLeft);
//	$('.photo-list>div :first-child.photo').css('margin-left', 0);
}



var dLi = null;
$(document).ready(function(){
	if (isIE) {
		ieFix();
		$('#topmenu li').hover(function(){$(this).addClass('active');},
			function(){$(this).removeClass('active');});
	}
	photoResize();
	tableResize();

  if (!param['id'] && param['id']!='search')
	{  dLi = new divedUl();
	   dLi.resize();
	   dLi.center();
	}
	$('.menu .level-1').hover(function(){$(this).addClass('active')}, function(){$(this).removeClass('active')});

 // goTo(param['ancor']);

});
$(window).resize(function(){	
	if (isIE) {
		ieFix();
	}
  if (!param['id'] && param['id']!='search')
  {
	   dLi.resize();
	   dLi.center();
	}
	tableResize();
	photoResize();

});


/*function goTo(id) {
	var eloffset = $('#' + id).offset();
  	window.scrollTo(eloffset.left,eloffset.top);
}  */



