/* ver 0.1a */

var photogallery = {
	//----- �?�����?.�?�?�?�����?�? �?�������? �����?�?�������� ----------------------------
  normal: function(large,preview) { jQuery(large).show(); },
	
	show: function(current_img) {
		var width = 0;
		var src = current_img.parentNode.href;
		var effect = this.normal;
		var cnfg = this.cfg;
		jQuery(this.cfg.small_image).removeClass("current_preview");
		jQuery(current_img).addClass("visited_preview current_preview");
			
		jQuery(cnfg.large_image).hide();
		jQuery(cnfg.large_image).attr({"src":src,"alt":src});
		jQuery(cnfg.large_image).fadeIn('slow');
			
		return false;
	},
  
	//----- �?���?���������?�� �?�?�����?���� --------------------------------------
	init: function(config) {

		this.cfg = config;
		this.List = jQuery(this.cfg.preview_all);					// ���?�� ���?�����?�? ���������?�����������?
		if (this.List.length > 0) this.show(jQuery(".preview",this.List)[0]);	// ���?�����? �����?������ �����?�?��������
		jQuery(this.cfg.small_image).click(function(){ return photogallery.show(this); });
		//jQuery(this.cfg.large_image).click(function(){ return photogallery.next(); });
		jQuery("#photogallery ul").hide();
		jQuery('.b-big_images').hover(function(){
			jQuery("#photogallery ul").stop(true, true).fadeIn('slow');
			photogallery.slideshow(false); // Не знаю так нужно или нет
			return false;

		},function(){
			jQuery("#photogallery ul").stop(true, true).fadeOut('slow');
			photogallery.slideshow(); // Не знаю так нужно или нет
			return false;
		})

		jQuery(this.cfg.small_image).eq(0).hide();

		photogallery.slideshow();
  },
  
	prev: function() {
		var src = jQuery(this.cfg.large_image)[0].src;
		for(var i=0; i < this.List.length; i++) if ( this.List[i].href == src ) {
	    if ( i == 0 ) i = this.List.length; // �� ���������?...
	    return this.show(jQuery(".preview",this.List)[i-1]);
		}
		return false;
	},
  
	next: function() {
		var src = jQuery(this.cfg.large_image)[0].src;
		for(var i=0; i < this.List.length; i++) if ( this.List[i].href == src ) {
	    if ( i+1 >= this.List.length ) i = -1; // �� �����?������...
	    return this.show(jQuery(".preview",this.List)[i+1]);
		}
		return false;
	},
	
	slideshow: function(callback) { // ������./���?����. �?���������� �?��������-�?���?
		if (this.slideshow_id) {
			window.clearInterval(this.slideshow_id);
			this.slideshow_id = null;
		  if (callback) callback(false);
		} else if (this.cfg.interval) {
		  this.next();
		  photogallery.prev();
		  this.slideshow_id = window.setInterval(function(){photogallery.next()},this.cfg.interval);
		  if (callback) callback(true);
		}
		return false;
 	}
}

