(function($){  
	$.fn.extend({   
		
		shop: function(options) {

			//$("#bag_notify").fadeTo(0, 0); 
						
			var m_this = $(this);
			var shopProxy = new ShopProxy("<c:out value/>");
			var bagAnimated = false;
			
			// setup
			function setup() {
				if (m_this.data("__setup"))
					return;
				m_this.data("__setup", true);
				
				$("#bag_notify").fadeTo(0, 0)
				//$.styleDOMcomponent();
				$("select", m_this).each(function(){$(this).customSelect()});
				
				var currentHash = hash2JSON(jQuery.url.attr("anchor"));
				if (!isEmptyOrNull(currentHash)) {
					var currentView = currentHash.v;
					if (currentView == "detail") {
						$("#showcase").show();
						$("#productDetail").hide();
						$("#searchEngine").show();
						var p = currentHash.p;
						shopProxy.getShowCase().product(p, _displayProductDetail);
					} else if (currentView == "search") {
						$("#showcase").show();
						$("#searchResult").show();
						$("#searchEngine").show();
					} else if (currentView == "cart") {
    				$("#showcase").hide();
    				$("#cart #step1").show();
    				$("#cart #step2").hide();
    				$("#cart #step3").hide();
	    				
						shopProxy.getCart().list($("#cart").cart().displayCartStep1);

					} else if (currentView == "order") {
						$("#showcase").hide();
						$("#cart").show();
						
						$("#cart").cart().displayCartStep3(currentHash.codTrans,currentHash.errTrans);
						
					} else {
						errorpopup("view not supported");
					}
				
				} else {
					$("#showcase").show();
					$("#home").show();
					$("#productDetail").hide();
					$("#searchResult").hide();
					$("#searchEngine").show();
					
					shopProxy.getShowCase().dayProduct(displayProductOfDay);
					shopProxy.getShowCase().top10(displayProductTop10);
				}
			}

			// -----------------------------------------------------------------------------
				
				
			function displayProductOfDay(data) {					 

				if (!isEmptyOrNull(data)) {
					var prodOfDay = '';
					prodOfDay = prodOfDay + '<a class="prodlnk" href="#'+ qualifier2Hash({ 'brand' : data.brand.description, 'category' : data.category.description, 'product' : data.name }) + 'v=detail&p=' + data["kca:id"] + '"><img alt="'+data.name + '" src="/images/large/' +  data.brand.code + '/' + data.code + '.jpg" alt="'+data.name + '"/></a>';
					prodOfDay = prodOfDay + '<div id="lanciocont">';
					prodOfDay = prodOfDay + '<h3><a class="prodlnk" href="#'+ qualifier2Hash({ 'brand' : data.brand.description, 'category' : data.category.description, 'product' : data.name }) + 'v=detail&p=' + data["kca:id"] + '">' + data.name + '</a></h3>';
					prodOfDay = prodOfDay + '<p><a href="#'+ qualifier2Hash({ 'brand' : data.brand.description, 'category' : data.category.description }) + 'v=search&b='+ data.brand['kca:id']+ '&c='+data.category['kca:id'] + '"  class="catlnk">' + data.brand.description + '</a></p>';
					prodOfDay = prodOfDay + '<p class="prezzo">&euro; ' + data.priceB2C + '</p>';
					prodOfDay = prodOfDay + '</div>';
					$("#productOfDay").html(prodOfDay);
				}
				
				$("#productOfDay a.prodlnk").unbind('click');
				$("#productOfDay a.prodlnk").click(function () {
					shopProxy.getShowCase().product( hash2JSON($(this).attr("href")).p , _displayProductDetail);
				});
				
				$("#productOfDay a.catlnk").unbind('click');
				$("#productOfDay a.catlnk").click(function () {
					var brandcat = {"b" : hash2JSON($(this).attr("href")).b , "c" : hash2JSON($(this).attr("href")).c};
					$("#searchEngine").searchEngine().fillSearchMask(brandcat);
					return false;
				});
			}
			
			function displayProductTop10(data) {
				var list = '<ul>';
				$.each(data.data, function(i,aelement) {
					list = list + '<li>';
					list = list + '<a class="prodlnk prodimg" href="#'+ qualifier2Hash({ 'brand' : aelement.brand.description, 'category' : aelement.category.description, 'product' : aelement.name }) + 'v=detail&p=' + aelement["kca:id"] + '"><img src="/images/thumb/'+ aelement["brand"]["code"] +'/' + aelement["code"] + '.jpg"></a>';
					list = list + '<div class="descr_prodotto">';
					list = list + '<h2><a class="prodlnk" href="#'+ qualifier2Hash({ 'brand' : aelement.brand.description, 'category' : aelement.category.description, 'product' : aelement.name }) + 'v=detail&p=' + aelement["kca:id"] + '">' + aelement["name"] +'</a></h2>';
					list = list + '<p class="categoria"><a href="#'+ qualifier2Hash({ 'brand' : aelement.brand.description, 'category' : aelement.category.description }) + 'v=search&b='+ aelement["brand"]["kca:id"] + '&c='+aelement["category"]["kca:id"] + '" class="catlnk">'+ aelement["brand"]["description"] + '</a></p>';
					list = list + '<p class="prezzo">&#128; ' + aelement["priceB2C"] + '</p>';
					list = list + '</div>';
					list = list + '</li>';
				});
				list = list + '</ul>';

				$("#productTop10").append(list);
									
				$("#productTop10 li a.prodlnk").unbind('click');
				$("#productTop10 li a.prodlnk").click(function () {
					shopProxy.getShowCase().product( hash2JSON($(this).attr("href")).p , _displayProductDetail);
				});
				
				$("#productTop10 li a.catlnk").unbind('click');
				$("#productTop10 li a.catlnk").click(function () {
					var brandcat = {"b" : hash2JSON($(this).attr("href")).b , "c" : hash2JSON($(this).attr("href")).c};
					$("#searchEngine").searchEngine().fillSearchMask(brandcat);
//					return false;
				});
			}
			
			function _displayProductDetail (data) {
					
				$("#home").hide();
				$("#searchResult").hide();
				$("#productDetail").show();
					
				shopProxy.getShopTracker().track('dettaglio', data.brand.description, data.category.description, data.name);
 				
				$("#lanciofocusdett").html('<img src="/images/large/' + data.brand.code + '/' + data.code +'.jpg" alt="'+data.name + '"/>');
				$("#productDetail #description").html(data.name);
//				$("#productDetail #catlnkdett").html(data.brand.description + ' | ' + data.category.description);
				
				var searchLink = '';
				searchLink = searchLink + '<a class="catlnk1dett" href="#'+ qualifier2Hash({ 'brand' : data.brand.description }) + 'v=search&b=' + data.brand.id + '">' + data.brand.description + '</a>';
				searchLink = searchLink + ' | ';
				searchLink = searchLink + '<a class="catlnk2dett" href="#'+ qualifier2Hash({ 'brand' : data.brand.description, 'category' : data.category.description }) + 'v=search&b=' + data.brand.id + '&c=' + data.category.id + '">' + data.category.description + '</a>';
				$("#productDetail #searchlnk").html(searchLink);
				
				if( data.colour ){
					if(data.brand.description == 'CAMOMILLA') {
						$("#productDetail #colourDescription").html("Colore: " + data.colour.description);
					} else {
							$("#productDetail #colourDescription").html("Variante: " + data.colour.description);
					};
				};
				
				if(data.notes) {
					$("#productDetail #dimension").html('Dimensione: '+data.notes);
				}
 				else {
 					$("#productDetail #dimension").html('');
 				}
								
				$("#productDetail .catlnk1dett").unbind('click');
				$("#productDetail .catlnk1dett").click(function () {
					var brandcat = { "b" : data.brand['kca:id'] };
					$("#searchEngine").searchEngine().fillSearchMask(brandcat);
//					return false;
				});                                                 
				
				$("#productDetail .catlnk2dett").unbind('click');
				$("#productDetail .catlnk2dett").click(function () {
					var brandcat = { "b" : data.brand['kca:id'] , "c" : data.category['kca:id'] };
					$("#searchEngine").searchEngine().fillSearchMask(brandcat);
//					return false;
				}); 
				
				$("#productDetail #price").html(data.priceB2C);

				$("#productDetail #add").attr('href', '#v=add&p=' + data["kca:id"]);
				
				$("#productDetail #add").unbind('click');
				$("#productDetail #add").click(function () {
					
					  shopProxy.getShopTracker().track('aggiungicarrello');

					if (bagAnimated)
						return;

					bagAnimated = true;
					$("#bag_notify").animate({ "opacity": 1 }, 500, "linear", function() {
						setTimeout( function() {
							$("#bag_notify").animate({"opacity": 0}, 500); bagAnimated = false;}, 1000)
					});

					var idProduct = hash2JSON($(this).attr("href")).p;
					shopProxy.getCart().add(idProduct, 1, function(data) {
						$("#navi").navigation().fillNaviCartResume();
					});
					return false;
				});
			}
				
			this.displayProductDetail = function (data) {
				_displayProductDetail(data);
			}
				
			setup();
				
			return this;
		},
				
		searchEngine: function(options) {  

			var m_this = $(this);
			var shopProxy = new ShopProxy("<c:out value/>");
			
			// setup
			function setup() {
				if (m_this.data("__setup"))
					return;
				m_this.data("__setup", true);
				
				shopProxy.getSearchEngine().brandList(function(data) {
					fillBrandSelect(data);
					shopProxy.getSearchEngine().moodList(function(data) {
						fillMoodSelect(data);
						var currentHash = hash2JSON(jQuery.url.attr("anchor"));
						if (!isEmptyOrNull(currentHash)) {
							var currentView = currentHash.v;
							if (currentView == "search") {
								$("#searchEngine").searchEngine().fillSearchMask(currentHash);
							}
						}
					});
				});
				
				fillCategorySelect({data : []});
				fillColourSelect({data : []});
			
				$("#searchEngine").submit(function(){return false;});
			
				$("#searchEngine #search_radio_brand").click(function () {
					$("#content #ricercafrm").css('background', 'url(/consumer/res/shop/img/brandback.gif) no-repeat'); 
					$("#searchEngine #search_brand").removeAttr('disabled');
					if ($("#searchEngine #search_brand").val()!="") {
						$("#searchEngine #search_category").removeAttr('disabled');
						$("#searchEngine #search_colour").removeAttr('disabled');
					}	else {
						$("#searchEngine #search_category").attr('disabled', 'disabled');
						$("#searchEngine #search_colour").attr('disabled', 'disabled');
						$("#searchEngine #search_category").get(0).selectedIndex = 0;
						$("#searchEngine #search_colour").get(0).selectedIndex = 0;
					}	
						
					$("#searchEngine #search_mood").attr('disabled', 'disabled');
				});
				
				$("#searchEngine #search_radio_mood").click(function () {
					$("#content #ricercafrm").css('background', 'url(/consumer/res/shop/img/moodback.gif) no-repeat'); 
					$("#searchEngine #search_mood").removeAttr('disabled');
					$("#searchEngine #search_brand").attr('disabled', 'disabled');
					$("#searchEngine #search_category").attr('disabled', 'disabled');
					$("#searchEngine #search_colour").attr('disabled', 'disabled');
				});
				
				$("#searchEngine #search_reset").click(function () {
					$("#searchEngine #search_mood").removeAttr('disabled');
					$("#searchEngine #search_brand").removeAttr('disabled');
					$("#searchEngine #search_category").attr('disabled', 'disabled');
					$("#searchEngine #search_colour").attr('disabled', 'disabled');
					
					$("#searchEngine #search_mood").get(0).selectedIndex = 0;
					$("#searchEngine #search_brand").get(0).selectedIndex = 0;
					$("#searchEngine #search_category").get(0).selectedIndex = 0;
					$("#searchEngine #search_colour").get(0).selectedIndex = 0;
					$("#searchEngine #search_price").get(0).selectedIndex = 0;
					
					repaintSelects();
				});
			}

			$("#search_submit").unbind('click');
			$("#search_submit").click(function () {
				var queryHash = "v=search";
				var queryObj = {};
				
				if ($("#search_brand").val() != "") {
					queryHash = queryHash + "&b=" + $("#search_brand").val();
					queryObj.idBrand = $("#search_brand").val();
					
					if ($("#search_category").val() != "") {
						queryHash = queryHash + "&c=" + $("#search_category").val();
						queryObj.idCategory = $("#search_category").val();
					}
						
					if ($("#search_colour").val() != "") {
						queryHash = queryHash + "&cl=" + $("#search_colour").val();
						queryObj.idColour = $("#search_colour").val();
					}
				} else {
					if ($("#search_mood").val() != "") {
						queryHash = queryHash + "&m=" + $("#search_mood").val();
						queryObj.idMood = $("#search_mood").val();
					}
				}
				
				if ($("#search_price").val() != "") {
					queryHash = queryHash + "&pc=" + $("#search_price").val();
					queryObj.price = $("#search_price").val();
				}
				
				if ($("#search_text").val() != "") {
					queryHash = queryHash + "&t=" + $("#search_text").val();
					queryObj.text = $("#search_text").val();
				}
		
				queryHash = queryHash + "&o=0";
				queryObj.offset=0;
				queryHash = queryHash + "&l=10";
				queryObj.limit=10;
					
				document.location.hash = queryHash;
				
				// vuoto
				if ($("#search_brand").val() == "" &&
					$("#search_category").val() == "" &&
					$("#search_colour").val() == "" &&
					$("#search_mood").val() == "" &&
					$("#search_price").val() == "" &&
					$("#search_text").val() == "" ) {
					var arr = document.location.href.split("#");
					document.location = arr[0];
				}	else {
					// non vuoto
					shopProxy.getSearchEngine().search(queryObj, displaySearchResults);
				}
					
			});
				
			function fillBrandSelect(data) {
				$("#search_brand").empty();
				$("#search_brand").append('<option value="">Seleziona</option>');
				$.each(data.data, function(i,aelement) {
					$("#search_brand").append('<option value="' + aelement["kca:id"] + '">' + aelement["description"] + '</option>');
				});

				$("#search_brand").unbind("change");
				$("#search_brand").change(function () {
					
					$("#searchEngine #search_radio_brand").click();

					if (!isEmptyOrNull($(this).val())) { 
						$("#search_mood").get(0).selectedIndex = 0;
						
						shopProxy.getSearchEngine().categoryList($(this).val(), fillCategorySelect);
						shopProxy.getSearchEngine().colourList($(this).val(), fillColourSelect);
					} else {
						fillCategorySelect({data : []});
						fillColourSelect({data : []});
					}
				});
				repaintSelects();
			}  		

			function fillMoodSelect(data) {
				$("#search_mood").empty();
				$("#search_mood").append('<option value="">Seleziona</option>');
				$.each(data.data, function(i,aelement) {
					$("#search_mood").append('<option value="' + aelement["kca:id"] + '">' + aelement["description"] + '</option>');
				});
				
				$("#search_mood").unbind("change");
				$("#search_mood").change(function () {
					
					$("#searchEngine #search_radio_mood").click();
				
					if (!isEmptyOrNull($(this).val())) { 
						$("#search_brand").get(0).selectedIndex = 0;
						fillCategorySelect({data : []});
						fillColourSelect({data : []});
					}
				});
				repaintSelects();
			}
				
			function fillCategorySelect(data) {
				$("#search_category").empty();
				$("#search_category").append('<option value="">Seleziona</option>');
				$.each(data.data, function(i,aelement) {
					$("#search_category").append('<option value="' + aelement["kca:id"] + '">' + aelement["description"] + '</option>');
				});
				repaintSelects();
			}
				
			function fillColourSelect(data) {
				$("#search_colour").empty();
				$("#search_colour").append('<option value="">Seleziona</option>');
				$.each(data.data, function(i,aelement) {
					$("#search_colour").append('<option value="' + aelement["kca:id"] + '">' + aelement["description"] + '</option>');
				});
				repaintSelects();
			}
				
			function repaintSelects() {
				$("select").each(function() {
					$(this).customSelect();
				});
			}
								
			function displaySearchResults(data) {
				
				$("#home").hide();
				$("#productDetail").hide();
				$("#searchResult").show();
				
				var totalItem = data.total;
				
				$("#searchResult").empty();
				var list = [];	
				if (data.total > 0) {
					list.push( '<div id="listaprod"><ul>' );
					$.each(data.data, function(i,aelement) {
						var listElement = '';
						listElement = listElement + '<li>';
						listElement = listElement + '<a class="prodlnk prodimgsrc" href="#'+ qualifier2Hash({ 'brand' : aelement.brand.description, 'category' : aelement.category.description, 'product' : aelement.name }) + 'v=detail&p=' + aelement["kca:id"] + '"><img src="/images/thumb/'+ aelement["brand"]["code"] +'/' + aelement["code"] + '.jpg"></a>';
						listElement = listElement + '<div class="descr_prodotto">';
						listElement = listElement + '<h2><a class="prodlnk" href="#'+ qualifier2Hash({ 'brand' : aelement.brand.description, 'category' : aelement.category.description, 'product' : aelement.name }) + 'v=detail&p=' + aelement["kca:id"] + '">' + aelement["name"] +'</a></h2>';
						listElement = listElement + '<p class="categoria"><a href="#'+ qualifier2Hash({ 'brand' : aelement.brand.description, 'category' : aelement.category.description }) + 'v=search&b='+ aelement["brand"]['kca:id'] + '&c='+aelement["category"]['kca:id'] + '" class="catlnk">'+ aelement["brand"]["description"] + '</a></p>';
						listElement = listElement + '<p class="prezzo">&#128; ' + aelement["priceB2C"] + '<a href="#v=add&p=' + aelement["kca:id"] + '" class="addsearch"><img src="/consumer/res/shop/img/btn_aggiungi.gif"/></a></p>';
						listElement = listElement + '</div>';
						listElement = listElement + '</li>';
						
						list.push(listElement);
					});
				} else {
					list.push('<p id="noproducts">Nessun articolo corrisponde alla tua ricerca.</p>');
				}
			
				list.push('</ul></div>');
				$("#searchResult").append(list.join(""));
				
				var currentSearch = jQuery.url.attr("anchor").replace("#", "").substr(0,jQuery.url.attr("anchor").indexOf("&o=") );
		
				var pagination = '<div id="pagination0">';
				if ((data.offset - data.limit) >=0 ) { pagination = pagination + '<a href="#' + currentSearch + '&o=' + (data.offset - data.limit) + '&l=' + data.limit + '">&lt; prec.</a>'; }
				pagination = pagination + ' Pagina ' + (data.currentPage + 1) + ' di ' + data.totalPages + ' ';
				if ((data.offset + data.limit) < data.total) { pagination = pagination + '<a href="#' + currentSearch + '&o=' + (data.offset + data.limit) + '&l=' + data.limit + '">succ. &gt;</a>'; }
				pagination = pagination + '</div>';
				$("#searchResult").append(pagination);
			
				$("#searchResult li a.prodlnk").unbind('click');
				$("#searchResult li a.prodlnk").click(function () {
					shopProxy.getShowCase().product(hash2JSON($(this).attr("href")).p, $("#showcase").shop().displayProductDetail);
				});
				
				$("#searchResult li a.catlnk").unbind('click');
				$("#searchResult li a.catlnk").click(function () {
					var brandcat = {"b" : hash2JSON($(this).attr("href")).b , "c" : hash2JSON($(this).attr("href")).c};
					$("#searchEngine").searchEngine().fillSearchMask(brandcat);
					return false;
				}); 
				
				$("#searchResult #pagination0 a ").unbind("click");
  			$("#searchResult #pagination0 a ").click(function () {

  				document.location.hash = $(this).attr("href");
  				var currentSearchObj = hash2JSON($(this).attr("href"));
  				var queryObj = {};
  				
  				if(!isEmptyOrNull(currentSearchObj.b) ) {
    				queryObj.idBrand = currentSearchObj.b;
    				if(!isEmptyOrNull(currentSearchObj.c) ) {
    					queryObj.idCategory = currentSearchObj.c;
    				}
    				if(!isEmptyOrNull(currentSearchObj.cl) ) {
    					queryObj.idColour = currentSearchObj.cl;
    				}
  				} else {
  					if(!isEmptyOrNull(currentSearchObj.m) ) {
  						queryObj.idMood = currentSearchObj.m;
  					}
  				}
    			
					if(!isEmptyOrNull(currentSearchObj.pc) ) {
						queryObj.price = currentSearchObj.pc;
					}
					if(!isEmptyOrNull(currentSearchObj.t) ) {
						queryObj.text = currentSearchObj.t;
					}
					
					if(!isEmptyOrNull(currentSearchObj.o) ) {
						queryObj.offset = currentSearchObj.o;
					}
					queryObj.limit=10;

    			shopProxy.getSearchEngine().search(queryObj, displaySearchResults);
    			
    			return false;
  			});
							
				$("#searchResult a.addsearch").unbind('click');
				$("#searchResult a.addsearch").click(function () {
				//if (bagAnimated)
					//return;
				bagAnimated = true;
				$("#bag_notify").animate({ "opacity": 1	}, 500, "linear", function() {
					setTimeout( function(){ $("#bag_notify").animate({"opacity": 0}, 500); bagAnimated = false;} ,1000)
				});
									
				var idProduct = hash2JSON($(this).attr("href")).p;
					shopProxy.getCart().add(idProduct, 1, function(data) {
						$("#navi").navigation().fillNaviCartResume();
					});
					return false;
				});
			}
		
			function _fillSearchMask (searchParams) {
				
				if (!isEmptyOrNull(searchParams.pc)) {
					$("#search_price").val(searchParams.pc);
				}
				
				if (!isEmptyOrNull(searchParams.t)) {
					$("#search_text").val(searchParams.t);
				}  
				
				if (!isEmptyOrNull(searchParams.b)) {
					
					$("#search_brand").val(searchParams.b);
					$("#searchEngine #search_category").removeAttr('disabled');
					$("#searchEngine #search_colour").removeAttr('disabled');
					
					shopProxy.getSearchEngine().categoryList(searchParams.b, function(data) {
						fillCategorySelect(data);
						shopProxy.getSearchEngine().colourList(searchParams.b, function(data) {
							fillColourSelect(data);
							
							if (!isEmptyOrNull(searchParams.c)) {
								$("#search_category").val(searchParams.c);
							}
							
							if (!isEmptyOrNull(searchParams.cl)) {
								$("#search_colour").val(searchParams.cl);
							}
							
							$("#search_submit").click();
						});
					});				

				} else {
					if (!isEmptyOrNull(searchParams.m)) {
						$("#search_mood").val(searchParams.m);
						$("#search_mood").change();
					}
					
					$("#search_submit").click();
				}

			}
				
			this.fillSearchMask = function (searchParams) {
				_fillSearchMask(searchParams);
			}
			
			setup();
				
			return this;
		},
		
		navigation: function(options) {
		
			var m_this = $(this);
			var shopProxy = new ShopProxy("<c:out value/>");
			
			// setup
			function setup() {
				if (m_this.data("__setup"))
					return;
				m_this.data("__setup", true);

				_fillNaviMenu();
				_fillNaviCartResume();
				
				$(".cartlink").click(function () {
					shopProxy.getCart().list($("#cart").cart().displayCartStep1);
					return false;
				});
				$(".cartservicelnk").click(function () {
					shopProxy.getCart().list($("#cart").cart().displayCartStep1);
					return false;
				});
				
				
			}

			function _fillNaviMenu () {
				$("#sidebar #menusec").empty();
				$('#header .user_bar').empty();
				var navi = '';
				var userbar = '';
				shopProxy.getUser().userLogged(function(userData) {
					if (!isEmptyOrNull(userData.nickname)) {
						navi = navi + '<h3>Ciao <span>' + userData.nickname + '</span></h3>';
						navi = navi + '<ul><li><a href="/it/Consumer/Vanity-room/common/Il-mio-profilo.page">Il mio profilo</a></li><li><a class="trackinglnk" href="#">Tracking order</a></li></ul>';
						userbar = userbar + '<p>Ciao ' + userData.nickname + ' - <a href="/it/consumer/logout.page?targetURI=/it/consumer/index.page">Esci</a></p>';
				 	} else {
						//navi = navi + '<h3>Ciao <span>Ospite</span></h3>';
						navi = navi + '<h3><span>Ciao</span></h3>';
						navi = navi + '<p>Per procedere con l&#39;acquisto effettua <br/>il <a href="/it/consumer/login.page" class="loginlnk">login</a></p>';
						userbar = userbar + '<p><a href="#" class="loginlnk">Login</a>  - <a href="/it/consumer/shop-online/registrazione.page?targetURI=/it/consumer/shop-online.page">Registrati</a></p>';
					}
					
					$('#header .user_bar').html(userbar);
					$("#sidebar #menusec").html(navi);
					
					$(".loginlnk").unbind('click');
					$(".loginlnk").click(function () { 				
						_login();
						return false;
					});
					
					$(".trackinglnk").unbind('click');
					$(".trackinglnk").click(function () {
 						//shopProxy.getShopTracker().track('conferma','test','test');
						shopProxy.getTracking().list($("#tracking").tracking().showTrackingOrder);
 						return false;
					});
					
					
					
				});
			} 

  		this.fillNaviMenu = function () {
  			_fillNaviMenu();
  		}
			
  		function _fillNaviCartResume () {
			
				shopProxy.getCart().totQuantity(function(dataNum) { 
					if (dataNum.totalCartItems != 0) {
						$("#navi #cartResume #quantity").html( dataNum.totalCartItems + " prodotti");
						shopProxy.getCart().totAmount(function(dataTot) {
							$("#navi #cartResume #amount").html( "Totale: <br/> &#128; " + dataTot.totalAmount);
						});
					} else {
						$("#navi #cartResume #quantity").html("La tua shopping bag<br/> &egrave; vuota");
						$("#navi #cartResume #amount").empty();
					}
				});
  		}
    		
  		this.fillNaviCartResume = function () {
  			_fillNaviCartResume();
  		}
					
			function hideLoginBox() {
				$("#overlaylogin").hide();
				$("#list").hide();
				$("#login").hide();
				return false;
			};
				
			this.login = function (callback) {
  			_login(callback);
  		}
					
			function _login(callback) {
				$("#overlaylogin").css("height", $(window).height());
				var m_top = ($(window).height()/2)-(200)+$(document).scrollTop();
				var m_left = ($(window).width()/2)-(230);
				$("#login").css("top", m_top+"px").css("left", m_left+"px");
				$("#overlaylogin").fadeTo(0, 0.65);
				$("#overlaylogin").show();
				$("#login").show();
				$("#closelogin").click(function() {
					hideLoginBox();
					return false;
				});
					
				$("#login #loginbtn").unbind('click');
				$("#login #loginbtn").click(function () {
				
					if (!$("#loginnick").val()) {
						errorpopup("Inserisci lo Username");
						return false;
					}
					
					if (!$("#loginpwd").val()) {
						errorpopup("Inserisci la Password");
						return false;
					}
					
					shopProxy.getUser().login($("#loginnick").val(), $("#loginpwd").val(), function(userData) {
						
						if ( (!isEmptyOrNull(userData.error)) && (userData.error) ) {
							errorpopup("Username o Password errati.");
						} else {
							hideLoginBox();
							if(callback != null) {
								callback();
							}
							
							$("#navi").navigation().fillNaviMenu();
						}
					});
				});
			}
		
  		setup();
  		
  		return this;
		}

	});
	
})(jQuery); 