if(typeof Catalog=='undefined'){var Catalog = {};};
/********************* IMAGE SWITCHER ***********************/

Catalog.Scroller = Class.create();
Catalog.Scroller.prototype = {
    initialize: function()
    {
	this.onSwitcherClick = this.switchCategory.bindAsEventListener(this);
	this.onProductImageClick = this.productClick.bindAsEventListener(this);
	this.onProductCloseClick = this.productClose.bindAsEventListener(this);
	this.onProductImageLoad = this.productImageLoad.bindAsEventListener(this);
	this.onStopMoving = this.stopMoving.bindAsEventListener(this);
	this.onProductInfoShow = this.productInfoShow.bindAsEventListener(this);
	this.onMoving = this.moving.bindAsEventListener(this);
	this.options = Object.extend({
		
    	}, arguments[0] || {});
	this.container = $(this.options.container);
	this.options.categoryStatus = {};
	if (this.options.categories.length)
	for(var categoryIndex=0;categoryIndex<this.options.categories.length;categoryIndex++) if($(this.container.identify()+'-switcher-li-'+this.options.categories[categoryIndex]))
	{
		if ($(this.container.identify()+'-switcher-li-'+this.options.categories[categoryIndex]).hasClassName('active')) this.current_category_id = this.options.categories[categoryIndex];
		Event.observe($(this.container.identify()+'-switcher-li-'+this.options.categories[categoryIndex]), 'click', this.onSwitcherClick);
		this.options.categoryStatus[this.options.categories[categoryIndex]] = {loadedPages:{},currentPage:0,pages:{}};
	}
	Event.observe($(this.container.identify()+'-right-arrow'), 'click', this.onSwitcherClick);
	Event.observe($(this.container.identify()+'-left-arrow'), 'click', this.onSwitcherClick);
	this.switchCategory(true);
    },
    switchCategory: function(event)
    {
	if (this.processingStatus)
	    return false;
	var element = null;
	try
	{
	    element = Event.findElement(event, 'a');
	    if (element)
	    {
		if (element.identify()==this.container.identify()+'-left-arrow')
		{
		    if (this.processing(['left'])) return true;
/*		    this.stopProcessing(['left']);
		    return true;
		    if (this.options.categoryStatus[this.current_category_id].currentPage!=0)
		    {
			if (this.processing(['left'])) return true;
			this.options.categoryStatus[this.current_category_id].currentPage -= 1;
		    }
		    else
			return true;
*/
		}
		else if (element.identify()==this.container.identify()+'-right-arrow')
		{
		    if (this.processing(['right'])) return true;
/*		    this.stopProcessing(['right']);
		    return true;
		    if ((this.options.categoryStatus[this.current_category_id].currentPage+1)*this.options.categoryStatus[this.current_category_id].perPage<this.options.categoryStatus[this.current_category_id].total)
		    {
		        if (this.processing(['right'])) return true;
			this.options.categoryStatus[this.current_category_id].currentPage += 1;
		    }
		    else
			return true;
*/
		}
		else if (this.processing(['left','right'])) return true;
	    }
	    else if (this.processing(['left','right'])) return true;
	}catch(e){
	    if (this.processing(['left','right'])) return true;
	};
	var element = null;
	try
	{
	    element = Event.findElement(event, 'li');
	    if (element)
	    {
		for(var categoryIndex=0;categoryIndex<this.options.categories.length;categoryIndex++)
		    if (element.identify() == this.container.identify()+'-switcher-li-'+this.options.categories[categoryIndex])
			selected_category_id = this.options.categories[categoryIndex];
		if (selected_category_id == this.current_category_id)
		{
		    this.stopProcessing();
		    return true;
		}
	        $(this.container.identify()+'-switcher-li-'+this.current_category_id).removeClassName('active');
		this.options.categoryStatus[this.current_category_id].loadedPages = {};
		if (this.sourceContainer)
		{
		    this.sourceContainer.update('&nbsp;');
		    this.sourceContainer.setStyle({left:0,width:(this.options.categoryStatus[this.current_category_id].perPage*this.options.productContainerWidth) + 'px'});
		}
	        this.current_category_id = selected_category_id;
	    }
	}catch(e){};
	element = $(this.container.identify()+'-switcher-li-'+this.current_category_id);
	element.addClassName('active');

	var url = this.options.url;
	var hash = {};
	hash['cid'] = this.current_category_id;
	hash['sid'] = this.options.stores[this.current_category_id];
	hash['pnum'] = this.options.categoryStatus[this.current_category_id].currentPage;
	hash['imgW'] = this.options.imageWidth;
	hash['imgH'] = this.options.imageHeight;
	hash['imgBW'] = this.options.imageBigWidth;
	hash['imgBH'] = this.options.imageBigHeight;
	var urlOptions = [];
	for(key in hash)
	    urlOptions.push(key+'/'+hash[key]);
	url += urlOptions.join('/');
	hash['object'] = this;

/*	if (this.options.categoryStatus[this.current_category_id].loadedPages[this.options.categoryStatus[this.current_category_id].currentPage]==this.options.categoryStatus[this.current_category_id].currentPage)
	{
	    this.stopProcessing();
	}
	else */if (this.options.categoryStatus[this.current_category_id].pages[this.options.categoryStatus[this.current_category_id].currentPage])
	{
	    this.updateProductsContainer(this.options.categoryStatus[this.current_category_id].pages[this.options.categoryStatus[this.current_category_id].currentPage],hash);
	}
	else
	{
	    if (this.processingType.length>=2)
	    {
	        if (this.sourceContainer)
		    this.sourceContainer.hide();
		this.loadingContainer.show();
	    }
	    new Ajax.Request(url, {
		method: 'get',
		onSuccess: this.onRequestSuccess,
		onFailure: this.onRequestFailure,
		data: hash
	    });
	};
	return true;
    },
    onRequestSuccess: function(response)
    {
	try
	{
	    var responseData = response.responseText.evalJSON();
	    var responseOptions = response.request.options.data;
	    responseOptions['object'].options.categoryStatus[responseOptions['cid']].pages[responseOptions['pnum']] = responseData;
	    responseOptions['object'].options.categoryStatus[responseOptions['cid']].total = responseData.count;
	    responseOptions['object'].options.categoryStatus[responseOptions['cid']].perPage = responseData.perPage;
	    responseOptions['object'].options.categoryStatus[responseOptions['cid']].position = responseData.position;
	    responseOptions['object'].options.categoryStatus[responseOptions['cid']].loadedPages[responseOptions['pnum']] = responseOptions['pnum'];
	    var productsIds = [];
	    for(productId in responseData['products'])
		productsIds.push(productId);
	    responseOptions['object'].options.categoryStatus[responseOptions['cid']].productsIds = productsIds;
	    if (!responseOptions['object'].sourceContainer)
	    {
		responseOptions['object'].sourceContainer = new Element('div');
		responseOptions['object'].sourceContainer.setStyle({width:(responseOptions['object'].options.categoryStatus[responseOptions['cid']].total*responseOptions['object'].options.productContainerWidth) + 'px'});
		responseOptions['object'].sourceContainer.setStyle({position: 'relative',height:(responseOptions['object'].options.productContainerHeight) + 'px'});
		responseOptions['object'].sourceContainer.hide();
		$(responseOptions['object'].container.identify() + '-products').appendChild(responseOptions['object'].sourceContainer);
	    }
	    responseOptions['object'].updateProductsContainer(responseData,responseOptions);
	}catch(e){responseOptions['object'].stopProcessing();};
    },
    updateProductsContainer: function(responseData,responseOptions)
    {
	    this.sourceContainer.getElementsBySelector('.switcher-item').each(function showItem(element){$(element).setStyle({visibility:'visible'})});
	    responseOptions['object'].options.categoryStatus[responseOptions['cid']].loadedPages[responseOptions['pnum']] = responseOptions['pnum'];
	    var productsHtml = '';
	    var productsIds = {};
	    $(responseOptions['object'].container.identify() + '-products').setStyle({position:'relative',overflow:'hidden',width:(responseOptions['object'].options.categoryStatus[responseOptions['cid']].perPage*responseOptions['object'].options.productContainerWidth) + 'px',height:(responseOptions['object'].options.productContainerHeight) + 'px'});
	    if (responseOptions['object'].processingType.length>=2)
	    {
		responseOptions['object'].options.categoryStatus[responseOptions['cid']].position = 0;
		var length = responseOptions['object'].options.categoryStatus[responseOptions['cid']].productsIds.length>(responseOptions['object'].options.categoryStatus[responseOptions['cid']].perPage+1)?(responseOptions['object'].options.categoryStatus[responseOptions['cid']].perPage+1):responseOptions['object'].options.categoryStatus[responseOptions['cid']].productsIds.length;
		for(var i = 0;i<length;i++)
		{
		    productId = responseOptions['object'].options.categoryStatus[responseOptions['cid']].productsIds[i];
		    productsIds[productId] = responseData['products'][productId];
		    productsHtml += responseOptions['object'].getProductContentFromTemplate(responseData['products'][productId],responseOptions['object']);
		}
		productId = responseOptions['object'].options.categoryStatus[responseOptions['cid']].productsIds[responseOptions['object'].options.categoryStatus[responseOptions['cid']].productsIds.length-1];
		productsHtml = responseOptions['object'].getProductContentFromTemplate(responseData['products'][productId],responseOptions['object']) + productsHtml;
		productsIds[productId] = responseData['products'][productId];
		this.sourceContainer.setStyle({left:(-this.options.productContainerWidth) + 'px',width:((this.options.categoryStatus[this.current_category_id].perPage+2)*this.options.productContainerWidth) + 'px'});
		responseOptions['object'].sourceContainer.update(productsHtml);
	    }
	    else if (responseOptions['object'].processingType[0]=='right')
	    {
		responseOptions['object'].options.categoryStatus[responseOptions['cid']].position = responseOptions['object'].options.categoryStatus[responseOptions['cid']].productsIds.length>(parseInt(responseOptions['object'].options.categoryStatus[responseOptions['cid']].position) + 1)?
		   (parseInt(responseOptions['object'].options.categoryStatus[responseOptions['cid']].position) + 1)
		   :0;
		productNumber = (parseInt(responseOptions['object'].options.categoryStatus[responseOptions['cid']].perPage) + responseOptions['object'].options.categoryStatus[responseOptions['cid']].position)<responseOptions['object'].options.categoryStatus[responseOptions['cid']].productsIds.length?
		   responseOptions['object'].options.categoryStatus[responseOptions['cid']].position
		   :(responseOptions['object'].options.categoryStatus[responseOptions['cid']].position-responseOptions['object'].options.categoryStatus[responseOptions['cid']].productsIds.length);
		productId = responseOptions['object'].options.categoryStatus[responseOptions['cid']].productsIds[productNumber + parseInt(responseOptions['object'].options.categoryStatus[responseOptions['cid']].perPage)];
		productsHtml = responseOptions['object'].getProductContentFromTemplate(responseData['products'][productId],responseOptions['object']);
		productsIds[productId] = responseData['products'][productId];
		responseOptions['object'].sourceContainer.insert(productsHtml);
		if (responseOptions['object'].moveRight != true)
		{
		    var element = $(this.sourceContainer).childElements().first();
		    $(element).remove();
		    responseOptions['object'].sourceContainer.setStyle({left:(parseInt(responseOptions['object'].sourceContainer.getStyle('left')) + responseOptions['object'].options.productContainerWidth) + 'px'});
		}
		else
		{
		    for(productId3 in responseOptions['object'].options.categoryStatus[responseOptions['cid']].loadedProductsIds)
			productsIds[productId3] = responseData['products'][productId3];
		    this.doubleMove = false;
		}
	    }
	    else if (responseOptions['object'].processingType[0]=='left')
	    {
		responseOptions['object'].options.categoryStatus[responseOptions['cid']].position = 0<=(parseInt(responseOptions['object'].options.categoryStatus[responseOptions['cid']].position) - 1)?
		   (parseInt(responseOptions['object'].options.categoryStatus[responseOptions['cid']].position)-1)
		   :responseOptions['object'].options.categoryStatus[responseOptions['cid']].productsIds.length-1;
		productNumber = (responseOptions['object'].options.categoryStatus[responseOptions['cid']].position-1)>=0?
		   (responseOptions['object'].options.categoryStatus[responseOptions['cid']].position-1)
		   :responseOptions['object'].options.categoryStatus[responseOptions['cid']].productsIds.length-1;
		productId = responseOptions['object'].options.categoryStatus[responseOptions['cid']].productsIds[productNumber];
		productsHtml = responseOptions['object'].getProductContentFromTemplate(responseData['products'][productId],responseOptions['object']);
		productsIds[productId] = responseData['products'][productId];
		responseOptions['object'].sourceContainer.insert({'top':productsHtml});
		responseOptions['object'].sourceContainer.setStyle({left:(parseInt(responseOptions['object'].sourceContainer.getStyle('left')) - responseOptions['object'].options.productContainerWidth) + 'px'});
		if (responseOptions['object'].moveLeft != true)
		{
		    var element = $(this.sourceContainer).childElements().last();
		    $(element).remove();
		}
		else
		{
		    for(productId3 in responseOptions['object'].options.categoryStatus[responseOptions['cid']].loadedProductsIds)
			productsIds[productId3] = responseData['products'][productId3];
		    this.doubleMove = false;

		}
	    };
	    responseOptions['object'].options.categoryStatus[responseOptions['cid']].loadedProductsIds = productsIds;
	    for(productId2 in productsIds)
	    {
		img = new Element('img',{id:responseOptions['object'].container.identify()+'-product-image-loader-'+productId2});
		img.hide();
		document.body.appendChild(img);
		img.writeAttribute('src',$(responseOptions['object'].container.identify()+'-product-image-source-'+productId2).src);
		img = new Element('img',{id:responseOptions['object'].container.identify()+'-product-image-loader-big-'+productId2});
		img.hide();
		Event.observe($(img), 'load', responseOptions['object'].onProductImageLoad);
		document.body.appendChild(img);
		img.writeAttribute('src',this.options.categoryStatus[this.current_category_id].pages[0].products[productId2].imageBigUrl);
		Event.observe($(responseOptions['object'].container.identify()+'-product-image-source-'+productId2), 'click', responseOptions['object'].onProductImageClick);
//		Event.observe($(responseOptions['object'].container.identify()+'-product-close-'+productId2), 'click', responseOptions['object'].onProductCloseClick);
	    };
    },
    productImageLoad:function(event)
    {
	try
	{
	    element = event.target;
	    products = this.options.categoryStatus[this.current_category_id].loadedProductsIds;
	    show = true;
	    for(productId in products)
		if (element.identify() == this.container.identify()+'-product-image-loader-'+productId)
		    $(this.container.identify()+'-product-image-loader-big-'+productId).writeAttribute('loaded','loaded');
		else if (element.identify() == this.container.identify()+'-product-image-loader-big-'+productId)
		    $(this.container.identify()+'-product-image-loader-big-'+productId).writeAttribute('loaded','loaded');
	    for(productId2 in products)
		if ($(this.container.identify()+'-product-image-loader-'+productId2).readAttribute('loaded') != 'loaded' && $(this.container.identify()+'-product-image-loader-big-'+productId2).readAttribute('loaded') != 'loaded')
		    show = false;
	    if (show && this.doubleMove!=true)
	    {
		for(productId2 in products) {$(this.container.identify()+'-product-image-loader-'+productId2).remove();$(this.container.identify()+'-product-image-loader-big-'+productId2).remove();}
		this.stopProcessing();
	    };
	}catch(e){};
    },
    productClose:function(event)
    {
	try
	{
	    element = Event.findElement(event, 'span');
	    products = this.options.categoryStatus[this.current_category_id].pages[this.options.categoryStatus[this.current_category_id].currentPage].products;
	    for(productId in products)
		if (element.identify() == this.container.identify()+'-product-close-'+productId)
		    $(this.container.identify()+'-product-info-'+productId).hide();
	}catch(e){};
    },
    productClick:function(event)
    {
	try
	{
	    if (this.processingStatus)
		return this.processingStatus;
	    var products = $(this.container.identify()).getElementsBySelector( '#'+ this.container.identify()+'-products .prod-info');
	    for(var i=0;i<products.length;i++)
		$(products[i]).hide();
	    element = Event.findElement(event, 'p');
	    products = this.options.categoryStatus[this.current_category_id].pages[this.options.categoryStatus[this.current_category_id].currentPage].products;
	    total = this.options.categoryStatus[this.current_category_id].total;
	    var position = -1;
	    for(productId in products)
	    {
		position++;
		if (element.identify() == this.container.identify()+'-product-image-'+productId)
		{
//		    $(this.container.identify()+'-product-info-'+productId).show();
		    break;
		}
	    }
	    var url = this.options.url;
	    var hash = {};
	    hash['cid'] = this.current_category_id;
	    hash['sid'] = this.options.stores[this.current_category_id];
	    hash['pnum'] = this.options.categoryStatus[this.current_category_id].currentPage;
	    hash['imgBW'] = this.options.imageBigWidth;
	    hash['imgBH'] = this.options.imageBigHeight;
	    hash['imgW'] = this.options.imageWidth;
	    hash['imgH'] = this.options.imageHeight;
	    var urlOptions = [];
	    for(key in hash)
		urlOptions.push(key+'/'+hash[key]);
	    url += urlOptions.join('/');
	    hash['object'] = this;
	    this.options.categoryStatus[this.current_category_id].newPosition = position;
	    if (this.options.categoryStatus[this.current_category_id].newPosition==
		(this.options.categoryStatus[this.current_category_id].position+1==total?
		(2):
		(this.options.categoryStatus[this.current_category_id].position+3>=total?this.options.categoryStatus[this.current_category_id].position+3-total:this.options.categoryStatus[this.current_category_id].position+3)))
	    {
		this.processing(['right']);
		this.updateProductsContainer(this.options.categoryStatus[this.current_category_id].pages[this.options.categoryStatus[this.current_category_id].currentPage],hash);
	    }
	    else if (this.options.categoryStatus[this.current_category_id].newPosition==
		(this.options.categoryStatus[this.current_category_id].position+1==total?
		(0):
		(this.options.categoryStatus[this.current_category_id].position+1>=total?this.options.categoryStatus[this.current_category_id].position+1-total:this.options.categoryStatus[this.current_category_id].position+1)))
	    {
		this.processing(['left']);
		this.updateProductsContainer(this.options.categoryStatus[this.current_category_id].pages[this.options.categoryStatus[this.current_category_id].currentPage],hash);
	    }
	    else if (this.options.categoryStatus[this.current_category_id].newPosition==this.options.categoryStatus[this.current_category_id].position)
	    {
		this.processing(['left']);
		this.doubleMove = true;
		this.updateProductsContainer(this.options.categoryStatus[this.current_category_id].pages[this.options.categoryStatus[this.current_category_id].currentPage],hash);
		this.moveLeft = true;
		this.sourceContainer.setStyle({width:(parseInt(this.sourceContainer.getStyle('width')) + this.options.productContainerWidth) + 'px'});
		this.updateProductsContainer(this.options.categoryStatus[this.current_category_id].pages[this.options.categoryStatus[this.current_category_id].currentPage],hash);
	    }
	    else if (this.options.categoryStatus[this.current_category_id].newPosition==
		(this.options.categoryStatus[this.current_category_id].position+1==total?
		(3):
		(this.options.categoryStatus[this.current_category_id].position+4>=total?this.options.categoryStatus[this.current_category_id].position+4-total:this.options.categoryStatus[this.current_category_id].position+4)))
	    {
		this.doubleMove = true;
		this.processing(['right']);
		this.updateProductsContainer(this.options.categoryStatus[this.current_category_id].pages[this.options.categoryStatus[this.current_category_id].currentPage],hash);
		this.moveRight = true;
		this.sourceContainer.setStyle({/*left:(parseInt(this.sourceContainer.getStyle('left')) - this.options.productContainerWidth) + 'px',*/width:(parseInt(this.sourceContainer.getStyle('width')) + this.options.productContainerWidth) + 'px'});
		this.updateProductsContainer(this.options.categoryStatus[this.current_category_id].pages[this.options.categoryStatus[this.current_category_id].currentPage],hash);
	    }
	    else
	    {
		this.productInfoShow();
	    }
	}catch(e){};
    },
    productInfoShow:function()
    {
	try
	{
	    var products = $(this.container.identify()).getElementsBySelector( '#'+ this.container.identify()+'-products .prod-info');
	    for(var i=0;i<products.length;i++)
		$(products[i]).hide();
	    var total = this.options.categoryStatus[this.current_category_id].total;
	    var position = (this.options.categoryStatus[this.current_category_id].position+1==total?(1):
		(this.options.categoryStatus[this.current_category_id].position+2>=total?
			this.options.categoryStatus[this.current_category_id].position+2-total:this.options.categoryStatus[this.current_category_id].position+2));
	    var productId = this.options.categoryStatus[this.current_category_id].productsIds[position];
	    $(this.container.identify()+'-product-info-'+productId).show();
	    $(this.container.identify()+'-product-image-source-'+productId).writeAttribute('src',this.options.categoryStatus[this.current_category_id].pages[0].products[productId].imageBigUrl);
	}catch(e){};
    },
    onRequestFailure: function(transport)
    {
	responseOptions['object'].stopProcessing();
    },
    getProductContentFromTemplate: function(product,object)
    {
	return eval(this.options.productTemplate);
    },
    processing: function(type,showLoading)
    {
	showLoading = showLoading || false;
	if (this.processingStatus)
		return this.processingStatus;
	var products = $(this.container.identify()).getElementsBySelector( '#'+ this.container.identify()+'-products .prod-info');
	for(var i=0;i<products.length;i++)
	    $(products[i]).hide();
	if ('object'==typeof(type))for(var i=0;i<type.length;i++)
	{
	    if (!$(this.container.identify()+'-'+type[i]+'-arrow-img').readAttribute('realSrc'))
	    {
		$(this.container.identify()+'-'+type[i]+'-arrow-img').writeAttribute('realSrc',$(this.container.identify()+'-'+type[i]+'-arrow-img').readAttribute('src'));
		$(this.container.identify()+'-'+type[i]+'-arrow-img').writeAttribute('enabledSrc',$(this.container.identify()+'-'+type[i]+'-arrow-img').readAttribute('src'));
		$(this.container.identify()+'-'+type[i]+'-arrow-img').writeAttribute('disabledSrc',this.options.arrowsDisabledImages[type[i]]);
	    }
	    $(this.container.identify()+'-'+type[i]+'-arrow-img').writeAttribute('src',this.options.loadingImage);
	}
	else
	{
	    if (!$(this.container.identify()+'-'+type+'-arrow-img').readAttribute('realSrc'))
	    {
		$(this.container.identify()+'-'+type+'-arrow-img').writeAttribute('realSrc',$(this.container.identify()+'-'+type+'-arrow-img').readAttribute('src'));
		$(this.container.identify()+'-'+type+'-arrow-img').writeAttribute('disabledSrc',this.options.arrowsDisabledImages[type]);
	    }
	    $(this.container.identify()+'-'+type+'-arrow-img').writeAttribute('src',this.options.loadingImage);
	}
	this.processingType = type;
	this.processingStatus = true;
	if (!this.loadingContainer)
	{
	    $(this.container.identify() + '-products').update('');
	    this.loadingContainer = new Element('div');
	    this.loadingContainer.update(this.options.loading);
	    $(this.container.identify() + '-products').appendChild(this.loadingContainer);
	    this.loadingContainer.show();
	}
	if (showLoading && this.sourceContainer)
	    this.sourceContainer.hide();
	if (showLoading)
	    this.loadingContainer.show();
	return false;
    },
    stopProcessing: function()
    {
	if (!this.processingStatus)
	    return this.processingStatus;
	if (this.loadingContainer.visible())
	    this.loadingContainer.hide();
	if (!this.sourceContainer.visible())
	    this.sourceContainer.show();
/*	if (this.options.categoryStatus[this.current_category_id].currentPage==0)
	    $(this.container.identify()+'-'+'left'+'-arrow-img').writeAttribute('realSrc',$(this.container.identify()+'-'+'left'+'-arrow-img').readAttribute('disabledSrc'));
	else
	    $(this.container.identify()+'-'+'left'+'-arrow-img').writeAttribute('realSrc',$(this.container.identify()+'-'+'left'+'-arrow-img').readAttribute('enabledSrc'));
	if ((this.options.categoryStatus[this.current_category_id].currentPage+1)*this.options.categoryStatus[this.current_category_id].perPage<this.options.categoryStatus[this.current_category_id].total)
	    $(this.container.identify()+'-'+'right'+'-arrow-img').writeAttribute('realSrc',$(this.container.identify()+'-'+'right'+'-arrow-img').readAttribute('enabledSrc'));
	else
	    $(this.container.identify()+'-'+'right'+'-arrow-img').writeAttribute('realSrc',$(this.container.identify()+'-'+'right'+'-arrow-img').readAttribute('disabledSrc'));
*/	this.hideProduct();
	return true;
    },
    moving: function()
    {
	if (this.processingType.length>=2){this.stopMoving()}
	else if (this.processingType[0]=='right')
	{new Effect.Move(this.sourceContainer, {duration:this.options.duration, x: -(/*this.options.categoryStatus[this.current_category_id].perPage**/this.options.productContainerWidth*(this.moveRight==true?2:1)), afterFinishInternal:this.onStopMoving});}
	else if (this.processingType[0]=='left')
	{new Effect.Move(this.sourceContainer, {duration:this.options.duration, x: (/*this.options.categoryStatus[this.current_category_id].perPage**/this.options.productContainerWidth*(this.moveLeft==true?2:1)), afterFinishInternal:this.onStopMoving});};
    },
    stopMoving: function()
    {
	type = ['left','right'];
//	this.processingType = {};
	if ('object'==typeof(type))for(var i=0;i<type.length;i++)
	{
	    if ($(this.container.identify()+'-'+type[i]+'-arrow-img').readAttribute('realSrc'))
		$(this.container.identify()+'-'+type[i]+'-arrow-img').writeAttribute('src',$(this.container.identify()+'-'+type[i]+'-arrow-img').readAttribute('realSrc'));
	}
	else
	{
	    if ($(this.container.identify()+'-'+type+'-arrow-img').readAttribute('realSrc'))
		$(this.container.identify()+'-'+type+'-arrow-img').writeAttribute('realSrc',$(this.container.identify()+'-'+type+'-arrow-img').readAttribute('realSrc'));
	}
	if (this.processingType.length>=2){}
	else if (this.processingType[0]=='right'){};
	if (this.moveLeft == true)
	{
	    var element = $(this.sourceContainer).childElements().last();
	    $(element).remove();
	    this.sourceContainer.setStyle({width:(parseInt(this.sourceContainer.getStyle('width')) - this.options.productContainerWidth) + 'px'});	    
	}
	if (this.moveRight == true)
	{
	    var element = $(this.sourceContainer).childElements().first();
	    $(element).remove();
	    this.sourceContainer.setStyle({width:(parseInt(this.sourceContainer.getStyle('width')) - this.options.productContainerWidth) + 'px'});
	}
	var items = this.sourceContainer.getElementsBySelector('.switcher-item');
	items.first().setStyle({visibility:'hidden'});
	items.last().setStyle({visibility:'hidden'});
/*	var total = this.options.categoryStatus[this.current_category_id].total;
	var position = (this.options.categoryStatus[this.current_category_id].position+1==total?(1):
		(this.options.categoryStatus[this.current_category_id].position+2>=total?
			this.options.categoryStatus[this.current_category_id].position+2-total:this.options.categoryStatus[this.current_category_id].position+2));
	var productId = this.options.categoryStatus[this.current_category_id].productsIds[position];
	$(this.container.identify()+'-product-info-'+productId).show();*/
	this.sourceContainer.setStyle({left:(- this.options.productContainerWidth) + 'px'});
	this.productShow();
	this.moveRight = false;
	this.moveLeft = false;
	this.processingStatus = false;
    },
    productShow:function()
    {
	try
	{
	    var total = this.options.categoryStatus[this.current_category_id].total;
	    var position = (this.options.categoryStatus[this.current_category_id].position+1==total?(1):
		(this.options.categoryStatus[this.current_category_id].position+2>=total?
			this.options.categoryStatus[this.current_category_id].position+2-total:this.options.categoryStatus[this.current_category_id].position+2));
	    var productId = this.options.categoryStatus[this.current_category_id].productsIds[position];
/*	    if (this.options.categoryStatus[this.current_category_id].notStart)
	    {
*/	    new Effect.Scale($(this.container.identify()+'-product-image-source-'+productId), 120, {
		duration:   this.options.imageDuration,
		scaleFromCenter:true,
		scaleContent: false,
		afterFinishInternal:this.onProductInfoShow
	    });
/*	    }
	    else
	    {
		this.options.categoryStatus[this.current_category_id].notStart = true;
		new Effect.Scale($(this.container.identify()+'-product-image-source-'+productId), 120, {
		    duration:   this.options.imageDuration,
		    scaleFromCenter:true,
		    scaleContent: false
		});
	    }
*/	}catch(e){};
    },
    hideProduct: function()
    {
	if (this.options.categoryStatus[this.current_category_id].oldPosition || this.options.categoryStatus[this.current_category_id].oldPosition===0)
	{
	var total = this.options.categoryStatus[this.current_category_id].total;
	var position = (this.options.categoryStatus[this.current_category_id].oldPosition+1==total?(1):
		(this.options.categoryStatus[this.current_category_id].oldPosition+2>=total?
			this.options.categoryStatus[this.current_category_id].oldPosition+2-total:this.options.categoryStatus[this.current_category_id].oldPosition+2));
	var productId = this.options.categoryStatus[this.current_category_id].productsIds[position];
	this.options.categoryStatus[this.current_category_id].oldPosition = this.options.categoryStatus[this.current_category_id].position;
	if (productId)
	{
	    $(this.container.identify()+'-product-image-source-'+productId).writeAttribute('src',this.options.categoryStatus[this.current_category_id].pages[0].products[productId].imageUrl);
	    new Effect.Scale($(this.container.identify()+'-product-image-source-'+productId), 100, {
		scaleMode: {originalWidth: this.options.imageWidth,originalHeight: this.options.imageHeight},
		duration:   this.options.imageDuration,
		scaleFrom: 120,
		scaleFromCenter:true,
		scaleContent: false,
		afterFinishInternal:this.onMoving
	    });
	}
	else
	    this.moving();
	}
	else
	{
	    this.options.categoryStatus[this.current_category_id].oldPosition = this.options.categoryStatus[this.current_category_id].position;
	    this.moving();
	}
    }
};