var ProductGallery = Class.create (
{
	moving:false,
	visible:false,
	layerId:'productGalleryLayer',
	currentImage:'',
	fileW:'',
	fileH:'',
	pe:null,
	preImage:null,
	initialize: function()
	{

	},
	show : function (currentImage,fileW,fileH)
	{
		this.currentImage = currentImage;
		this.fileW=fileW;
		this.fileH=fileH;
		if (this.visible) return;
		this.visible = true;
		this.moving = true;
	/*
	//schovanie active-x komponentov v IE6, aby neboli stale zobrazene
	isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
	if (isIE6)
	{
		$$('#product_list_filter select').each(function(e) {e.style.visibility='hidden';});	
	}
	*/
	Effect.SlideDown(this.layerId,{ duration: 0.7, afterFinish: function() {
				  this.moving = false;
				  this.afterSlideDownFinish();
				  }.bind(this)});
	
	
	},
	hide : function ()
	{
		if (!this.visible) return;
		this.moving = true;

		
		Effect.Fade('productGalleryImage',{duration:0.3,afterFinish:function(){
						this.slideUp();						
					}.bind(this)});
		
	
	
	},
	slideUp: function()
	{
		Effect.SlideUp(this.layerId,{ duration: 0.7, afterFinish: function() {
						  this.visible = false;	
						  this.moving = false;	
							 /* //zobrazenie active-x komponentov v IE6, aby neboli stale zobrazene
							  isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
							  if (isIE6)
							  {
									$$('#product_list_filter select').each(function(e) {e.style.visibility='visible';});
							  }*/
						 this.callback();	  
						  }.bind(this)});
	},
	toogle :function ()
	{
		if (!this.moving && !this.visible)
		{
			this.show();
		}
		if (!this.moving && this.visible)
		{
			this.hide();
		}
	},
    afterSlideDownFinish: function()
	{
		this.showGalleryImage(this.currentImage,this.fileW,this.fileH);		
		Effect.Appear('productGalleryImage',{duration:0.5,afterFinish:function(){
											
					}.bind(this)});
	},
	callback: function()
	{
		
	},
	showGalleryImage:function(imageName,fileW,fileH)
	{
		
  		var extension_index = imageName.lastIndexOf('.');
		var suffix_index = imageName.lastIndexOf('.');
		if (Prototype.Browser.WebKit)
		{		
			this.preImage = null;
			this.preImage = new Image();
			this.preImage.src = imageName.substring(0,suffix_index) + imageName.substring(extension_index);
			this.fileW=fileW;
			this.fileH=fileH;
		
			this.pe = new PeriodicalExecuter(this.checkLoadingProcess.bind(this), 0.2);
		}
		else
		{
			$('productGalleryImage').src = imageName.substring(0,suffix_index) + imageName.substring(extension_index);
			$('productGalleryImage').width = this.fileW;
			$('productGalleryImage').height = this.fileH;
		}
		
	},
	
	checkLoadingProcess:function(imageName,fileW,fileH)
	{
			
		if(this.preImage.complete)
		{
			$('productGalleryImage').src = this.preImage.src;
			$('productGalleryImage').width = this.fileW;
			$('productGalleryImage').height = this.fileH;
			this.stopLoader();
			return;
		}
	
	},
	
	stopLoader:function()
	{
		if(this.pe)
		{
			this.pe.stop();
			this.pe = null;
		}
	}
	
});

var productGallery;
Event.observe(window, 'load', function() 
	{
		if ($('productGalleryLayer'))
		{
			productGallery = new ProductGallery();
		}
	}
);
