var CGalleryApp = function(arParams){	
	this.ActNum = 0;
	this.fotoCount = arParams.allFotos.length;
	
	// переключает активную фотографию
	this.ShowOnMain = function(path, obj, number){		
		// удаляем выделение всех фотографий и назначаем активной выбранную		
		$(arParams.smalCont).find('.active').removeClass('active');
		$(obj).parent().addClass('active');
		this.ActNum = number;
		
		// перемещаем выбранную фотографию на место главного изображения
		$(arParams.bigCont).attr('src', path);
	}
	
	// показывает всплывающую галерею
	this.Show = function(e){		
		var DinPic = $(arParams.popup).find('img');		
		DinPic.attr('src', arParams.allFotos[this.ActNum]);				
		
		DinPic.bind('load', function(){ 
			var width = -DinPic.width()/2;
			var height = -(DinPic.height()+56)/2;
		
			$(arParams.mainCont).css({'margin-top': height, 'margin-left':width});		
			$(arParams.popup).css('visibility','visible');			
		});
		
		this.ShowCounter();
		this.BlockEvent(e);
		this.DelArrow();
	}
	
	// открывает следующую фотографию
	this.Next = function(e){
		this.ActNum++;
		
		if(this.ActNum > this.fotoCount-1){ this.ActNum = 0;}
		
		var DinPic = $(arParams.popup).find('img');		
		DinPic.attr('src', arParams.allFotos[this.ActNum]);
		
		var width = -DinPic.width()/2;
		var height = -(DinPic.height()+56)/2;
		
		this.ShowCounter();
		
		$(arParams.mainCont).css({'margin-top': height, 'margin-left':width});
		this.BlockEvent(e);
	}
	
	// открывает предыдущую фотографию
	this.Prev = function(e){		
		this.ActNum--;
		
		if((this.ActNum+1) <= 0 ){ this.ActNum = this.fotoCount-1;}
		
		var DinPic = $(arParams.popup).find('img');		
		DinPic.attr('src', arParams.allFotos[this.ActNum]);
		
		var width = -DinPic.width()/2;
		var height = -(DinPic.height()+56)/2;
		
		this.ShowCounter();
		
		$(arParams.mainCont).css({'margin-top': height, 'margin-left':width});
		this.BlockEvent(e);
	}
	
	// показывает счетчик
	this.ShowCounter = function(){
		$(arParams.curCont).html(parseInt(this.ActNum)+1);
		$(arParams.totCont).html(this.fotoCount);
	}
	
	// скрывает галерею
	this.Hide = function(){
		$(arParams.popup).css('visibility', 'hidden');		
		$(arParams.popup).find('img').attr('src', '');	
	}
	
	// блокировщик всплывающих событий
	this.BlockEvent = function(e){
		even = e || window.event;	
		if (even.stopPropagation) {
			even.stopPropagation();
		} else {				
			even.cancelBubble = true;
		}	
	}
	
	// удаляет стрелки
	this.DelArrow = function(){
		if(this.fotoCount <= 1)	{
			$('.zoom_left, .zoom_right, .zoom_right2, .zoom_left2').remove();	
		}
	}
}
