﻿/* 
	Main Class to manage the top/Bottom products grids
	We need one instance for the top part ans one for the bottom part
*/

var SearchProductsTopBottom = new Class({
	initialize: function(options){
		if (!options) options = '';
		this.viewMode = !options.viewMode ? 'onmodel': options.viewMode;
		if (Cookie.read('PRODUCT_VISUALIZATION')) {
			this.viewMode = Cookie.read('PRODUCT_VISUALIZATION');
		}
		this.filterSet = !options.filterSet ? false: options.filterSet;
		this.line = !options.line ? 'top': options.line;
		this.newSearch = true;
		this.currentItem = 4;
		this.itemPerLine = 7;
		this.itemPreloadedPerLine = 9;
		this.lineBoxes = new Array();
		this.moveComplete = true;
		this.moveBoxComplete = 0;
		this.savedFilter = null;
		this.savedTop = null;
		this.savedBottom = null;
		if (collection_param = this.getUrlParam('collection'))
			this.savedFilter = "collection_"+collection_param;
		var topbottomCookie = Cookie.read('TOP_BOTTOM_SEARCH_STATE');
		if (topbottomCookie) {
			var cookieParams = topbottomCookie.split('/');
			this.savedFilter = cookieParams[0];
			this.savedTop = cookieParams[1];
			this.savedBottom = cookieParams[2];
			if (this.line == 'top') {
				this.currentItem = this.savedTop;
			} else if (this.line == 'bottom') {
				this.currentItem = this.savedBottom;
			}
			var serviceUrl = "/"+ locale +"/shop/services/SearchProductsTopBottom?newSearch="+ this.newSearch +"&category="+ this.line +"s"+ this.getFilterParam() +"&gender="+this.getGender()+"&rangeStart=1&rangeLength="+ (this.itemPerLine.toInt() + this.itemPreloadedPerLine.toInt());
		} else {
			var serviceUrl = "/"+ locale +"/shop/services/SearchProductsTopBottom?newSearch="+ this.newSearch +"&category="+ this.line +"s"+ this.getFilterParam() +"&gender="+this.getGender()+"&rangeStart=1&rangeLength="+ (this.itemPerLine.toInt() + this.itemPreloadedPerLine.toInt());
		}
		var jsonRequest = new Request.JSON({url: serviceUrl, onComplete: function(search){
			this.total_items = search.METADATA.TOTAL_ITEMS;
			if (this.total_items < this.currentItem) this.currentItem = 1;
			this.products = search.PRODUCTS;
			this.setProducts();
			this.setPaging();
			if (this.line == 'top') {
				if(!this.filterSet){
					this.filterSet = true;
					this.setFilters();
					this.setButtonsOnOff();
					this.setPageTag();
				}
			}
			$('topbottom-top').getElement('span.number-'+ this.line +'s').set('text', this.total_items);
			$('topbottom-top').getElement('span.number-'+ this.line +'s').set('text', this.total_items);
		}.bind(this)}).get();
	},
	getPreloadedItemsCount: function () {
		return $('topbottom-allproduct-'+ this.line).getElements('div.position4').length;
	},
	getLoadedItemsCount: function(){
		return $('topbottom-allproduct-'+ this.line).getElements('table.productPreviewBoxes tr td').length;
	},
	getMovableItemsCount: function(){
		var count = -1;
		if ($('topbottom-allproduct-'+ this.line).getElements('div.position-4')[0]) count++;
		if ($('topbottom-allproduct-'+ this.line).getElement('div.position-3')) count++;
		if ($('topbottom-allproduct-'+ this.line).getElement('div.position-2')) count++;
		if ($('topbottom-allproduct-'+ this.line).getElement('div.position-1')) count++;
		if ($('topbottom-allproduct-'+ this.line).getElement('div.position0')) count++;
		if ($('topbottom-allproduct-'+ this.line).getElement('div.position1')) count++;
		if ($('topbottom-allproduct-'+ this.line).getElement('div.position2')) count++;
		if ($('topbottom-allproduct-'+ this.line).getElement('div.position3')) count++;
		if ($('topbottom-allproduct-'+ this.line).getElements('div.position4')[0]) count++;
		return count;
	},
	getRangeStart: function(){
		return $('topbottom-allproduct-'+ this.line).getElements('div.productPreviewBox').length + 1;
	},
	getFilterParam: function(){
		var filterParam = '';
		if (this.savedFilter) {
			filterParam += '&'+ this.savedFilter.replace('_', '=');
		}
		return filterParam;
	},
	getGender: function(){
		var url = window.location.href;
		if (url.indexOf('women') != -1) {
			return 'women';
		}
		else
			return "men";
	},
	getUrlParam: function(name){
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#;]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null )
	    return "";
	  else
	    return results[1];
	},
	setProducts: function(){
		this.products.each(function(product, index){
			var cellElement = new Element('td');
			cellElement.inject($('topbottom-allproduct-'+ this.line).getElement('table.productPreviewBoxes tr'));
			var boxElement = new Element('div', {'class': 'productPreviewBox', html: '<div class="specialFeatureLabel" style="display:none;"><img src="/en/images/shop/features/new.png" alt="new" /></div><div class="productImage"><a href="#"><img style="visibility: visible; opacity: 0.9; display: none;" src="#" class="front onmodel" alt=""><img style="visibility: visible; opacity: 0.9; display: none;" src="#" class="front productonly" alt=""><img style="visibility: visible; opacity: 0.9; display: none;" src="#" class="back onmodel" alt=""><img style="visibility: visible; opacity: 0.9; display: none;" src="#" class="back productonly" alt=""></a></div><div class="productDetails"><h2 class="productNameLabel typeface-js"><a href="#"></a></h2><span class="promotionLabel" style="display: none;"></span><span class="priceLabel"><span class="newprice" style="display: none;"></span><span class="oldprice" style="display: none;"></span><span class="price"></span></span><a href="#" class="flipButton"></a></div><div class="collectionLogo"><img src="#" alt="LEVI\'S"></div>'});
			boxElement.inject(cellElement);
			if (!this.lineBoxes[index] && this.lineBoxes[index] != 0) {
				var box = new ProductPreviewBox(boxElement, {'productImageView': this.viewMode});
				box.update(this.products[index]);
				boxElement.set('title', this.products[index].NAME);
				box.setProductImage('front', this.viewMode);
				boxElement.getElements('.typeface-js').each(function(item){
					reintinilazeTypeFace(item);
				});
				this.lineBoxes.push(index);
			}
			var globalIndex = index - this.currentItem + 1;
			if (globalIndex < -3) {
				boxElement.addClass('position-4');
			} else if (globalIndex < 0) {
				boxElement.addClass('position'+ globalIndex);				
			} else if (globalIndex == 0) {
				boxElement.addClass('position0').addClass('productPreviewBoxFocus');
			} else if (globalIndex <= 3) {
				boxElement.addClass('position'+ globalIndex);
			} else if (globalIndex > 3) {
				boxElement.addClass('position4');
			}			
			boxElement.addEvent('click', function(){
				if (boxElement.hasClass('position0')) {
					document.location = boxElement.getElement('h2.productNameLabel a').get('href');
				} else {
					this.moveTo(boxElement);
				}
				return false;
			}.bind(this));
		}.bind(this));
	},
	setOtherProducts: function(){
		var jsonRequest = new Request.JSON({url: "/"+ locale +"/shop/services/SearchProductsTopBottom?newSearch="+ this.newSearch +"&category="+ this.line +"s"+ this.getFilterParam() +"&gender="+this.getGender()+ "&rangeStart="+ this.getRangeStart() +"&rangeLength="+ (this.itemPerLine.toInt() + this.itemPreloadedPerLine.toInt()), onComplete: function(search){
			var loadedItemsCount = this.getLoadedItemsCount();
			search.PRODUCTS.each(function(product, index){
				this.products = this.products.concat(product);
				var cellElement = new Element('td');
				cellElement.inject($('topbottom-allproduct-'+ this.line).getElement('table.productPreviewBoxes tr'));
				var boxElement = new Element('div', {'class': 'productPreviewBox position4', html: '<div class="specialFeatureLabel" style="display:none;"><img src="en/images/shop/features/new.png" alt="new" /></div><div class="productImage"><a href="#"><img style="visibility: visible; opacity: 0.9; display: none;" src="#" class="front onmodel" alt=""><img style="visibility: visible; opacity: 0.9; display: none;" src="#" class="front productonly" alt=""><img style="visibility: visible; opacity: 0.9; display: none;" src="#" class="back onmodel" alt=""><img style="visibility: visible; opacity: 0.9; display: none;" src="#" class="back productonly" alt=""></a></div><div class="productDetails"><h2 class="productNameLabel typeface-js"><a href="#"></a></h2><span class="promotionLabel" style="display: none;"></span><span class="priceLabel"><span class="newprice" style="display: none;"></span><span class="oldprice" style="display: none;"></span><span class="price"></span></span><a href="#" class="flipButton"></a></div><div class="collectionLogo"><img src="#" alt="LEVI\'S"></div>'});
				boxElement.inject(cellElement);
				var newIndex = index + loadedItemsCount;
				if (!this.lineBoxes[newIndex] && this.lineBoxes[newIndex] != 0) {
					var box = new ProductPreviewBox(boxElement, {'productImageView': this.viewMode});
					box.update(this.products[newIndex]);
					box.setProductImage('front', this.viewMode);
					boxElement.getElements('.typeface-js').each(function(item){
						reintinilazeTypeFace(item);
					});
					this.lineBoxes.push(newIndex);
				}
				boxElement.addEvent('click', function(){
					if (boxElement.hasClass('position0')) {
						document.location = boxElement.getElement('h2.productNameLabel a').get('href');
					} else {
						this.moveTo(boxElement);
					}
					return false;
				}.bind(this));
			}.bind(this));
		}.bind(this)}).get();
	},
	setPaging: function(){
		$('next'+ this.line).addEvent('click', function(){
			if (this.moveComplete) this.moveRight();
			return false;
		}.bind(this));
		$('previous'+ this.line).addEvent('click', function(){
			if (this.moveComplete) this.moveLeft();
			return false;
		}.bind(this));
	},
	moveTo: function(box) {
		if (!box.hasClass('position0') && this.moveComplete) {
			var position = null;
			var classNames = box.get('class').split(' ');
			classNames.each(function(className, index){
				if (className.indexOf('position') != -1) position = className.substring(8).toInt();
			});
			if (position < 0) {
				this.moveLeft(Math.abs(position));
			} else if (position > 0) {
				this.moveRight(Math.abs(position));
			}
		}
	},
	moveRight: function(count) {
		if ($('topbottom-allproduct-'+ this.line).getElement('div.position1')) {
			this.moveComplete = false;
			this.movableItems = this.getMovableItemsCount();
			this.currentItem++;
			this.moveBox({'boxClassName': 'position-3', 'boxNewClassName': 'position-4', 'width': 90, 'left': -91});
			this.moveBox({'boxClassName': 'position-2', 'boxNewClassName': 'position-3', 'width': 90, 'left': 0});
			this.moveBox({'boxClassName': 'position-1', 'boxNewClassName': 'position-2', 'width': 90, 'left': 91});
			this.moveBox({'boxClassName': 'position0', 'boxNewClassName': 'position-1', 'width': 90, 'left': 182});
			this.moveBox({'boxClassName': 'position1', 'boxNewClassName': 'position0', 'width': 180, 'left': 273, 'orientation': 'right', 'count': count});
			this.moveBox({'boxClassName': 'position2', 'boxNewClassName': 'position1', 'width': 90, 'left': 454});
			this.moveBox({'boxClassName': 'position3', 'boxNewClassName': 'position2', 'width': 90, 'left': 545});
			this.moveBox({'boxClassName': 'position4', 'boxNewClassName': 'position3', 'width': 90, 'left': 636});
		}
	},
	moveLeft: function(count) {
		if ($('topbottom-allproduct-'+ this.line).getElement('div.position-1')) {
			this.moveComplete = false;
			this.movableItems = this.getMovableItemsCount();
			this.currentItem--;
			this.moveBox({'boxClassName': 'position-4', 'boxNewClassName': 'position-3', 'width': 90, 'left': 0});
			this.moveBox({'boxClassName': 'position-3', 'boxNewClassName': 'position-2', 'width': 90, 'left': 91});
			this.moveBox({'boxClassName': 'position-2', 'boxNewClassName': 'position-1', 'width': 90, 'left': 182});
			this.moveBox({'boxClassName': 'position-1', 'boxNewClassName': 'position0', 'width': 180, 'left': 273, 'orientation': 'left', 'count': count});
			this.moveBox({'boxClassName': 'position0', 'boxNewClassName': 'position1', 'width': 90, 'left': 454});
			this.moveBox({'boxClassName': 'position1', 'boxNewClassName': 'position2', 'width': 90, 'left': 545});
			this.moveBox({'boxClassName': 'position2', 'boxNewClassName': 'position3', 'width': 90, 'left': 636});
			this.moveBox({'boxClassName': 'position3', 'boxNewClassName': 'position4', 'width': 90, 'left': 727});
		}
	},
	moveBox: function(options){
		if (options.boxClassName == 'position4') {
			var elements = $('topbottom-allproduct-'+ this.line).getElements('div.' + options.boxClassName);
			if (elements) var ele = elements[0];
		} else if (options.boxClassName == 'position-4') {
			var elements = $('topbottom-allproduct-'+ this.line).getElements('div.' + options.boxClassName);
			if (elements) var ele = elements[elements.length-1];
		} else {
			var ele = $('topbottom-allproduct-'+ this.line).getElement('div.' + options.boxClassName);
		}
		if (ele) {
			ele.setStyle('display', 'block');
			if (options.boxNewClassName == 'position0') {
				ele.getElement('div.collectionLogo').morph({width: 35, height: 35});
			} else {
				ele.getElement('div.productDetails').setStyle('display', 'none');
				ele.getElement('div.collectionLogo').morph({width: 20, height: 20});
				ele.removeClass('productPreviewBoxFocus');
			}
			var myEffect = new Fx.Morph(ele, {
				duration: 400,
				onComplete: function() {
					ele.removeClass(options.boxClassName).addClass(options.boxNewClassName);
					if (options.boxNewClassName == 'position0') {
						ele.getElement('div.productDetails').setStyle('display', 'block');
						ele.addClass('productPreviewBoxFocus');
						this.setCookie();
						if (options.orientation == 'left') {
							if (options.count && options.count > 1) {
								var timer = setTimeout(function() {
									this.moveLeft(options.count - 1);
								}.bind(this), 200);
							}
						} else if (options.orientation == 'right') {
							if (options.count && options.count > 1) {
								var timer = setTimeout(function() {
									this.moveRight(options.count - 1);
								}.bind(this), 200);
							}
							if (this.getPreloadedItemsCount() && this.getPreloadedItemsCount() <= 3 && this.getLoadedItemsCount() < this.total_items) {
								this.newSearch = false;
								this.setOtherProducts();
							}
						}
					}
					this.moveBoxComplete++;
					if (this.moveBoxComplete == this.movableItems) {
						this.moveBoxComplete = 0;
						var timer = setTimeout(function() {
							this.moveComplete = true;
						}.bind(this), 300);
					}
				}.bind(this)
			});
			(function () {
				myEffect.start({
					'width': options.width,
					'height': options.width,
					'left': options.left
				});
			}).delay(10);
		}
	},
	reload: function(line){
		var effectIn = new Fx.Morph($('topbottom-allproduct-'+ line), {
			duration: 500
		});
		var effectOut = new Fx.Morph($('topbottom-allproduct-'+ line), {
			duration: 500,
			onComplete: function() {
				$('topbottom-allproduct-'+ line).set('html', '<table class="productPreviewBoxes"><tbody><tr></tr></tbody></table>');
				effectIn.start({opacity: 1, left: 0});
				var search = new SearchProductsTopBottom({'line': line, 'filterSet': true, 'viewMode': this.viewMode});
			}
		});
		effectOut.start({opacity: 0, left: 726});
	},
	setFilters: function(){
		if ($('topbottom-top').getElement('a.filters')) {
			$('topbottom-top').getElement('a.filters').addEvent('click', function(){
				if ($('filters').getStyle('display') == 'none') {
					var showFX = new Fx.Morph('filters', {duration: 'normal', transition: Fx.Transitions.Sine.easeOut});
					showFX.start({
						'height': 105
					});
					$('filters').setStyle('display', 'block');
					$('topbottom-top').getElement('a.filters').addClass('filters-open');
				} else {
					var hideFX = new Fx.Morph('filters', {duration: 'normal', transition: Fx.Transitions.Sine.easeOut, onComplete: function() {
						$('filters').setStyle('display', 'none');
						$('topbottom-top').getElement('a.filters').removeClass('filters-open');
					}});
					hideFX.start({
						'height': 0
					});
				}
				var myAccordion = new Accordion($('filters'), 'a.button', 'ul.filters-level1', {'show': 0, 'display': -1, 'alwaysHide': true, 
					'onActive': function(toggler, element) {
						if (toggler.getParent('li')) toggler.getParent('li').morph({paddingTop:5, paddingBottom:10}).addClass('opened');
					},
					'onBackground': function(toggler, element){
						if (toggler.getParent('li')) toggler.getParent('li').morph({paddingTop:0, paddingBottom:0}).removeClass('opened');
					}
				});
				this.setFiltersDisabled();
				$('filters').getElements('a.filter').each(function(filter, index){
					if (filter.getParent('li').get('class') == this.savedFilter) {
						filter.addClass('selected');
					}
					filter.addEvent('click', function(){
						if (!filter.hasClass('selected')) {
							$('filters').getElements('a.filter').removeClass('selected');
							filter.addClass('selected');
							filter.getParent('li').getParent('li').getElement('a.filterall').removeClass('selected');
							this.setCookie({'filter': filter.getParent('li').get('class'), 'top': 4, 'bottom': 4});
							//window.location.reload();
							this.reload('top');
							this.reload('bottom');
							this.setFilterTag(filter);
						}
						return false;
					}.bind(this));
				}.bind(this));
				$('filters').getElements('a.filterall').each(function(filterall, index){
					if (!this.savedFilter) filterall.addClass('selected');
					filterall.addEvent('click', function(){
						if (!filterall.hasClass('selected')) {
							filterall.addClass('selected');
							var className = filterall.getParent('li').get('class');
							var splitedClassName = className.split('_');
							$('filters').getElements('#'+ splitedClassName[0] +' li a').each(function(filter, index){
								if (!filter.hasClass('filterall')) {
									filter.removeClass('selected');
								}
							}.bind(this));
							this.setCookie({'filter': null, 'top': 4, 'bottom': 4});
							//window.location.reload();
							this.reload('top');
							this.reload('bottom');
							this.setFilterTag(filterall);
						}
						return false;
					}.bind(this));
				}.bind(this));
				return false;
			}.bind(this));
		}
	},
	setFiltersDisabled: function() {
		$('filters').getElement('li.product').addClass('button-disabled').setStyle('display', 'none');
		$('filters').getElement('li.colors').addClass('button-disabled').setStyle('display', 'none');
		$('filters').getElement('li.sizes').addClass('button-disabled').setStyle('display', 'none');
		$('filters').getElement('li.fits').addClass('button-disabled').setStyle('display', 'none');
		$('filters').getElements('li.button-disabled').each(function(button, index){
			button.getElement('ul').setStyle('display','none');
			button.getElement('a.button').removeEvents('click');
		});
	},
	setButtonsOnOff: function () {
		if (this.viewMode == 'productonly') {
			$('topbottom-top').getElement('a.productonly img').set('src', '/common/images/shop/utils/picto-product-on.gif');
			$('topbottom-top').getElement('a.onmodel img').set('src', '/common/images/shop/utils/picto-model.gif');
		} else if (this.viewMode == 'onmodel') {
			$('topbottom-top').getElement('a.onmodel img').set('src', '/common/images/shop/utils/picto-model-on.gif');
			$('topbottom-top').getElement('a.productonly img').set('src', '/common/images/shop/utils/picto-product.gif');
		}
	},
	setCookie: function(options) {
		if (!options) options = '';
		var tosaveFilter = '';
		var tosaveTop = 1;
		var tosaveBottom = 1;
		if (!options.filter) {
			if ($('filters')) {
				$('filters').getElements('a.filter').each(function(filter, index){
					if (filter.hasClass('selected')) tosaveFilter = filter.getParent('li').get('class');
				});
			}
		} else {
			tosaveFilter = options.filter;
		}
		if (!options.top) {
			$('topbottom-allproduct-top').getElements('div.productPreviewBox').each(function(box, index){
				if (box.hasClass('productPreviewBoxFocus')) tosaveTop = index + 1;
			});
		} else {
			tosaveTop = options.top;
		}
		if (!options.bottom) {
			$('topbottom-allproduct-bottom').getElements('div.productPreviewBox').each(function(box, index){
				if (box.hasClass('productPreviewBoxFocus')) tosaveBottom = index + 1;
			});
		} else {
			tosaveBottom = options.bottom;
		}
		var topbottomCookie = Cookie.write('TOP_BOTTOM_SEARCH_STATE', tosaveFilter +'/'+ tosaveTop +'/'+ tosaveBottom,{path:'/'});
	},
	setPageTag: function() {
		var tag = new Tag();
		tag.set({'pageName': 'shop product finder '+ this.getGender() +' top-bottom', 'channel': 'shop', 'prop1': 'shop:product finder', 'prop2': 'shop:product finder:'+ this.getGender(), 'prop10': locale});
		tag.send();
	},
	setFilterTag: function(filter) {
		var tag = new Tag();
		var className = filter.getParent('li').get('class');
		var keyvalue = className.split('_');
		var prop8 = '';
		for (var i = 0; i < keyvalue.length; i++) {
			if (i == 1) prop8 += ':';
			else if (i > 1) prop8 += '_';
			prop8 += keyvalue[i];
		}
		tag.set({'prop8': prop8});
		tag.sendClick();
	}
});

var boxWidth = 180;
var morphDuration = 200;
/*
	specific ProductPreviewBox class for this page
*/
var ProductPreviewBox = new Class({
	initialize: function(object, options){
		if (!options) options = '';
		this.box = object;
		this.productImageView = !options.productImageView ? 'productonly': options.productImageView;
		this.productImageSide = 'front';
		this.flipBtn = this.box.getElement('a.flipButton');
		this.box.getElements('div.productImage img').setStyles({opacity: 0.9});
		if (this.flipBtn) {
			this.flipBtn.addEvent('click', function(){
				this.flip();
				return false;
			}.bind(this));
		}
	},
	go: function(){
		document.location = this.box.getElement('h2.productNameLabel a').get('href');
	},
	flip: function(){
		this.hide(function () {
			this.productImageSide = (this.productImageSide == 'front') ? 'back': 'front';
			this.show();
		}.bind(this));
	},
	show: function(options){
		if (!options) {
			this.setProductImage(this.productImageSide, this.productImageView);
		} else if (options.productImageSide == 'locked') {
			this.setProductImage(this.productImageSide, options.productImageView);
		} else {
			this.setProductImage(options.productImageSide, options.productImageView);
		}
		this.box.set('morph', {onComplete: function() {this.box.getElements('div.productDetails').morph({opacity: 1});this.box.getElements('div.collectionLogo').morph({opacity: 1});}.bind(this)});
		this.box.morph({width: boxWidth, marginLeft: 0});
		this.box.getElements('div.productImage img').morph({opacity: 0.9});
	},
	hide: function(callback){
		this.box.getElements('div.productImage img').morph({opacity: 0});
		this.box.getElements('div.productDetails').setStyles({opacity: 0});
		this.box.getElements('div.collectionLogo').setStyles({opacity: 0});
		if (!callback) {
			var options = {duration:morphDuration}
		} else {
			var options = {duration:morphDuration, onComplete: callback}
		}
		this.box.set('morph', options);
		this.box.morph({width: 0, marginLeft: boxWidth/2});
	},
	update: function(product){
		this.box.getElement('div.specialFeatureLabel').setStyle('display', 'none');
		this.box.getElement('h2.productNameLabel a').set('text', product.NAME);
		this.box.getElement('h2.productNameLabel a').set('href', product.LINK);
		if (!product.PROMOTION) {
			this.box.getElement('span.priceLabel span.price').set('text', product.PRICE).setStyle('display', 'block');
			this.box.getElement('span.promotionLabel').setStyle('display', 'none');
			this.box.getElement('span.priceLabel span.newprice').setStyle('display', 'none');
			this.box.getElement('span.priceLabel span.oldprice').setStyle('display', 'none');
		} else {
			this.box.getElement('span.priceLabel span.price').setStyle('display', 'none');
			this.box.getElement('span.promotionLabel').set('text', product.PROMOTION.PROMOTION_AMOUNT).setStyle('display', 'block');
			this.box.getElement('span.priceLabel span.newprice').set('text', product.PROMOTION.REDUCED_PRICE).setStyle('display', 'block');
			this.box.getElement('span.priceLabel span.oldprice').set('text', product.PRICE).setStyle('display', 'block');
		}
		this.box.getElement('img.front.onmodel').set('src', product.FRONT_ONMODEL_IMAGE);
		this.box.getElement('img.front.productonly').set('src', product.FRONT_PRODUCTONLY_IMAGE);
		this.box.getElement('img.back.onmodel').set('src', product.BACK_ONMODEL_IMAGE);
		this.box.getElement('img.back.productonly').set('src', product.BACK_PRODUCTONLY_IMAGE);
		this.box.getElement('div.collectionLogo img').set('src', '/common/images/shop/collections/' + product.COLLECTION.CODE + '-small.gif');
	},
	setProductImage: function(imageSide, imageView){
		this.productImageSide = imageSide;
		this.productImageView = imageView;
		this.box.getElements('div.productImage img').setStyle('display', 'none');
		this.box.getElements('div.productImage img.'+ this.productImageSide +'.'+ this.productImageView).setStyle('display', 'inline');
	}
});

window.addEvent('domready', function(){
	var searchTop = new SearchProductsTopBottom({'line': 'top', 'viewMode': 'onmodel'});
	var searchBottom = new SearchProductsTopBottom({'line': 'bottom', 'viewMode': 'onmodel'});
	
	$('topbottom-top').getElement('a.productonly').addEvent('click', function(){
		searchTop.viewMode = 'productonly';
		searchBottom.viewMode = 'productonly';
		$('topbottom-top').getElement('a.productonly img').set('src', '/common/images/shop/utils/picto-product-on.gif');
		$('topbottom-top').getElement('a.onmodel img').set('src', '/common/images/shop/utils/picto-model.gif');
		$('topbottom-center').set('tween', {duration: 'long'});
		$('topbottom-center').fade('out');
		setTimeout((function(){
			$('topbottom-center').getElements('div.productPreviewBox div.productImage img').setStyle('display', 'none');
			$('topbottom-center').getElements('div.productImage img.front.productonly').setStyle('display', 'inline');
			$('topbottom-center').fade('in');
		}),1000);
		var viewCookie = Cookie.write('PRODUCT_VISUALIZATION', 'productonly',{path:'/'});
		var tag = new Tag();
		tag.set({'pageName': 'shop product finder view', 'linkTrackVars': 'eVar1,prop8', 'evar1': 'view:ProductOnly', 'prop8': 'view:ProductOnly','name':'eshop product finder view'});
		tag.sendClick();
		return false;	});
	$('topbottom-center').getElement('a.buy-link').addEvent('mouseover',function(){
		this.setProperty('href','/'+locale+'/shop/outfits/my-outfit.html?top='+searchTop.products[searchTop.currentItem-1].PRODUCTID +'&bottom='+searchBottom.products[searchBottom.currentItem-1].PRODUCTID);
	});
	$('topbottom-top').getElement('a.onmodel').addEvent('click', function(){
		searchTop.viewMode = 'onmodel';
		searchBottom.viewMode = 'onmodel';
		$('topbottom-top').getElement('a.productonly img').set('src', '/common/images/shop/utils/picto-product.gif');
		$('topbottom-top').getElement('a.onmodel img').set('src', '/common/images/shop/utils/picto-model-on.gif');
		$('topbottom-center').set('tween', {duration: 'long'});
		$('topbottom-center').fade(0);
		setTimeout((function(){
			$('topbottom-center').getElements('div.productPreviewBox div.productImage img').setStyle('display', 'none');
			$('topbottom-center').getElements('div.productImage img.front.onmodel').setStyle('display', 'inline');
			$('topbottom-center').fade('in');
		}),1000);
		var viewCookie = Cookie.write('PRODUCT_VISUALIZATION', 'onmodel',{path:'/'});
		var tag = new Tag();
		tag.set({'pageName': 'shop product finder view', 'linkTrackVars': 'eVar1,prop8', 'evar1': 'view:OnModel', 'prop8': 'view:OnModel','name':'eshop product finder view'});
		tag.sendClick();
		return false;
	});
	$('display-mode').getElement('a').addEvent('click', function(){
		var tag = new Tag();
		tag.set({'prop17': 'display:Grid'});
		tag.send();
	});
});

