function Gallery(){

	this.search_query = '';
	
	this.current_period = '';
	this.current_category = '';
	this.current_recnum = 0;
	
	this.gallery_name = '';
	
	this.categories_list_id = '';
	this.categoriy_item_id = '';
	
	this.timeperiods_list_id = '';
	this.timeperiod_item_id = '';
	
	this.gallery_body_id = '';
	
	this.left_pager_id = '';
	this.right_pager_id = '';
	
	this.ajax_action = '';
	
	this.left_pager_status = false;
	this.right_pager_status = false;
	
	this.isStarted = false;
}

	Gallery.prototype.start = function()
	{
		this.isStarted = true;
		this.setLeftPagerStatus(this.left_pager_status);
		this.setRightPagerStatus(this.right_pager_status);
	}

	Gallery.prototype.getCurrentPeriod = function(){
		return this.current_period;
	}
	
	Gallery.prototype.setSearchQuery = function(query) {
		this.search_query = query;
	}
	
	Gallery.prototype.init = function()
	{
		this.categories_list_id = '';
		this.categoriy_item_id = '';
		
		this.timeperiods_list_id = '';
		this.timeperiod_item_id = '';
		
		this.gallery_body_id = '';
		
		this.left_pager_id = '';
		this.right_pager_id = '';
		
		this.ajax_action = '';
	}



	Gallery.prototype.setCurrentCategory = function(id)
	{
		$('div > a', '#' + this.categories_list_id).each(function(){
			$(this).attr('class', 'none');
		});
		$('#'+this.categoriy_item_id+id).attr('class', "active");
		this.current_category = id;
		this.current_recnum = 0;
		this.updatePicturesRow();
	}

	Gallery.prototype.setTimePeriod = function(id)
	{
		$('a', '#'+this.timeperiods_list_id).each(function(){
			$(this).attr('class', "none");
		});
		$('#'+this.timeperiod_item_id+id).attr('class', "active");
		this.current_period = id;
		this.current_recnum = 0;
		this.updatePicturesRow();
	}
	
	Gallery.prototype.update = function()
	{
		this.updatePicturesRow();
	}
	
	Gallery.prototype.updatePicturesRow = function()
	{
		var obj = this;
		var url = "?controller=gallery&action="
			+obj.ajax_action
			+"&id_period="
			+obj.current_period
			+"&id_category="
			+obj.current_category
			+"&search_query="
			+( (obj.search_query != undefined && obj.search_query.length > 0) ? (obj.search_query) : "")
			+"&recnum="+obj.current_recnum;
		
		ajax(url, 'GET', '', 
			function(){
				
			}, 
			function(html){
				$('#' + obj.gallery_body_id).html(html);
			}
		);
	}
	
	Gallery.prototype.setLeftPagerStatus = function(status)
	{
		this.left_pager_status = status;
		if( !this.isStarted )
		{
			return;
		}
		var obj = this;
		if( status == false )
		{
			if( $('#' + this.left_pager_id).attr('src') != this.template_root + 'img/icons/ar-left-noac.gif')
			{
				$('#' + this.left_pager_id).attr('src', this.template_root + 'img/icons/ar-left-noac.gif');
			}
			$('#' + this.left_pager_id).unbind('click');
			$('#' + this.left_pager_id).attr('style', '');
		}
		else
		{

			if( $('#' + this.left_pager_id).attr('src') != this.template_root + 'img/icons/ar-left-ac.gif')
			{
				$('#' + this.left_pager_id).attr('src', this.template_root + 'img/icons/ar-left-ac.gif');
			}
			$('#' + this.left_pager_id).unbind('click');
			$('#' + this.left_pager_id).click(
				function(){
					eval(obj.gallery_name+'.descRecnum();');
				}
			);
			$('#' + this.left_pager_id).attr('style', 'cursor: pointer; cursor: hand;');
		}
	}
	
	Gallery.prototype.setRightPagerStatus = function(status)
	{
		this.right_pager_status = status;
		if( !this.isStarted )
		{
			return;
		}
		var obj = this;
		if( status == false )
		{
			if( $('#' + this.right_pager_id).attr('src') != this.template_root + 'img/icons/ar-right-noac.gif')
			{
				$('#' + this.right_pager_id).attr('src', this.template_root + 'img/icons/ar-right-noac.gif');
			}
			$('#' + this.right_pager_id).unbind('click');
			$('#' + this.right_pager_id).attr('style', '');
		}
		else
		{
			if( $('#' + this.right_pager_id).attr('src') != this.template_root + 'img/icons/ar-right-ac.gif')
			{
				$('#' + this.right_pager_id).attr('src', this.template_root + 'img/icons/ar-right-ac.gif');
			}
			$('#' + this.right_pager_id).unbind('click');
			$('#' + this.right_pager_id).click(
				function(){
					eval(obj.gallery_name+'.incRecnum();');
				}
			);
///			alert( $('#' + this.right_pager_id).click );
//			$('#' + this.right_pager_id).attr('onclick', this.gallery_name+'.descRecnum();');
			$('#' + this.right_pager_id).attr('style', 'cursor: pointer; cursor: hand;');
		}
	}
	
	Gallery.prototype.disablePagers = function ()
	{
		this.setLeftPagerStatus(false);
		this.setRightPagerStatus(false);
	}
	
	Gallery.prototype.descRecnum = function()
	{
		this.current_recnum--;
		if( this.current_recnum < 0 ) {
			this.current_recnum = 0;
		} else {
			this.updatePicturesRow();
		}
	}
	
	Gallery.prototype.incRecnum = function()
	{
		this.current_recnum++;
		if( this.current_recnum <	 0 ) {
			this.current_recnum = 0;
		} else {
			this.updatePicturesRow();
		}
	}
	
	Gallery.prototype.initGallery = function()
	{
		this.init();
		
	}
	

