try 
{
  document.execCommand("BackgroundImageCache", false, true);
} 
catch(err) 
{
}

addHandler(window, "load", onloadFunctions);

function onloadFunctions()
{
	initProductGallery();
}

function initProductGallery()
{
	if (domElement = _('.productgallery')[0])
	{
		new productGallery(domElement);
	}
}

function productGallery(domElement)
{
	this.init = function()
	{
		this.smallPictures = new Array();
		this.biggerPictures = new Array();
		
		this.gallery = domElement;
		var urlList = new Array();
		var pictureList = _('.productgallery_big', domElement);
		for (i = 0; i < pictureList.length; i++)
		{
			this.biggerPictures.push(new productGalleryBiggerImage(pictureList[i], this));
		}
		
		this.currentBigPicture = _('.productgallery_big.productgallery_first', domElement)[0];
		var pictureList = _('.productgallery_small', domElement);
		for (i = 0; i < pictureList.length; i++)
		{
			this.smallPictures.push(new productGalleryImage(pictureList[i], this));
		}
	}
	this.swapBigPicture = function(container, imageObject)
	{
		var pictureId = 'bigger_'+container.id;
		var currentBigPicture = this.currentBigPicture;		
		var newBigPicture = document.getElementById(pictureId);
		
		if (currentBigPicture != newBigPicture)
		{		
			currentBigPicture.style.zIndex = '1';
			newBigPicture.style.zIndex = '10';
		
			var parameters = {end: 1, step: 0.05};
			artWebEffectsManager.startEffect('opacity', newBigPicture, parameters);
			
			var parameters = {end: 0, step: 0.05};
			artWebEffectsManager.startEffect('opacity', currentBigPicture, parameters);
			
			this.currentBigPicture = newBigPicture;
		}
		for (var i=0; i<self.smallPictures.length; i++)
		{
			if (self.smallPictures[i] != imageObject)
			{
				self.smallPictures[i].container.className = 'productgallery_small';
			}
		}
	}
	var self = this;
	this.init();
}
function productGalleryBiggerImage(container, productGalleryObject)
{
	this.init = function()
	{
		this.container = container;
		this.productGalleryObject = productGalleryObject;
		
		if (container.className != 'productgallery_big productgallery_first')
		{
			opacityHandler.setOpacity(container, 0);
			container.style.display = 'block';
		}
		addHandler(this.container, 'click', this.click);
	}
	this.click = function(event)
	{
		preventDefaultAction(event);
	}
	var self = this;
	this.init();
}
function productGalleryImage(container, productGalleryObject)
{
	this.init = function()
	{
		this.container = container;
		this.productGalleryObject = productGalleryObject;
		addHandler(this.container, 'click', this.click);
		addHandler(this.container, 'mouseover', this.mouseoverHandler);
		addHandler(this.container, 'mouseout', this.mouseoutHandler);
	}
	this.mouseoverHandler = function()
	{
		self.container.className = 'productgallery_small productgallery_small_hovered';
		self.productGalleryObject.swapBigPicture(self.container, self);
	}
	this.click = function(event)
	{
		preventDefaultAction(event);
	}
	var self = this;
	this.init();
}
