/*=规格选择联动=
*(c) www.v5shop.com.cn
* 2010-1-21
*/
	  
var priceControl={
		  base:188.00,
		  _format:{"decimals":2,"dec_point":".","thousands_sep":"","fonttend_decimal_type":0,"fonttend_decimal_remain":2,"sign":"\uffe5"},
		  format:function(num){
			var part;
			if(!num)return;
			var num = num.toFloat();
				num = num.round(this._format.decimals)+'';
				var p =num.indexOf('.');
				if(p<0){
					p = num.length;
					part = '';
				}else{
					part = num.substr(p+1);
				}
				while(part.length<this._format.decimals){
						part+='0';
					}
				var c=[];
				while(p>0){
					if(p>2){
						c.unshift(num.substr(p-=3,3));
					}else{
						c.unshift(num.substr(0,p));
						break;
					}
				}
				if(!part){
					this._format.dec_point='';
				}
				return (this._format.sign||"")+c.join(this._format.thousands_sep)+this._format.dec_point+part;
		}
   };

String.implement({
  toFormElements:function(){
		if(!this.contains('=')&&!this.contains('&'))return new Element('input',{type:'hidden'});
		var elements=[];
		var queryStringHash=this.split('&');
		$A(queryStringHash).each(function(item){
			if(item.contains('=')){
				item=$A(item.split('='));
				elements.push(new Element('input',{type:'hidden',name:item[0],value:item[1]}));
			}else{
			  elements.push(new Element('input',{type:'hidden',name:item}));
			}
		});
		return new Elements(elements);
		}
});
Number.implement({
	   interzone:function(min,max){
			 var _v=this.toFloat();
			 if(!_v)_v=0;
			 return _v>=min&&_v<=max;
		 }
	  });
var keyCodeFix=[48,49,50,51,52,53,54,55,56,57,96,97,98,99,100,101,102,103,104,105,8,9,46,37,39];









 window.addEvent('domready',function(){
         var picThumbnailItems=$$('#goods-viewer .goods-detail-pic-thumbnail td a');        
         if(!picThumbnailItems.length)return;
         var goodsPicPanel = $E('#goods-viewer .goods-detail-pic');
         var goodsDetailPic = $E('#goods-viewer .goods-detail-pic img');
         
         
         var picscroll=$E('#goods-viewer .picscroll');
         var scrollARROW=picscroll.getElements('.scrollarrow');
         var picsContainer=$E('.pics',picscroll).scrollTo(0,0);
             picsContainer.store('selected',picThumbnailItems[0]);
        
        
         if(picsContainer.getSize().x<picsContainer.getScrollSize().x){
               scrollARROW.setStyle('visibility','visible').addEvent('click',function(){
                     var scrollArrow=this;
                     var to=eval("picsContainer.scrollLeft"+(scrollArrow.hasClass('toleft')?"-":"+")+"picsContainer.offsetWidth");
                     picsContainer.retrieve('fxscroll',new Fx.Scroll(picsContainer,{'link':'cancel'})).start(to);
               });
         };
     
        picThumbnailItems.each(function(item){
             var _img = new Image();
             _img.src = JSON.decode(item.get('imginfo'))['small'];
        });
        
        picThumbnailItems.addEvents({
			'click':function(e){
				e.stop();
				this.fireEvent('selected');
			},
			'mouseenter':function(){
				if(this.getParent('td').hasClass('current'))return;
				var imgInfo = JSON.decode(this.get('imgInfo'));
				goodsDetailPic.src = imgInfo['small'];
			},
			'mouseleave':function(){
				if(this.getParent('td').hasClass('current'))return;
				picsContainer.retrieve('selected').fireEvent('selected','noclick');
			},
			'selected':function(noclick){
				var _td = this.getParent('td');
				if(_td.hasClass('current')&&!noclick)return;
				picsContainer.retrieve('selected').fireEvent('unselect');
				 _td.addClass('current');
				var imgInfo = JSON.decode(this.get('imgInfo'));
				goodsDetailPic.src = imgInfo['small'];
				goodsDetailPic.set('jqimg',imgInfo['big']);
				picsContainer.store('selected',this);
			},
			'unselect':function(){
				this.getParent('td').removeClass('current');
			},
			'focus':function(){
				this.blur();
			}
        });      
              
        picThumbnailItems[0].fireEvent('selected');
               
             
        
        });











void function() {

    var buyBtn = $empty;
    var notifyBtn = $empty;
    var setbuyBtnTip = $empty;
    var popAloneSpec = $empty;

    window.addEvent('domready',
    function() {
		//初始化参数
        buyBtn = $E('#goods-viewer .btn-buy').store('tip:text', '看看能不能买');
        notifyBtn = $E('#goods-viewer .btn-notify').store('tip:text', '对不起,您当前选择的商品缺货.');
		//加入购物车的Tip提示
		new Tips(buyBtn, {
            showDelay: 0,
            hideDelay: 0,
            className: 'cantbuy',
            onShow: function(tip) {
                if (!this.textElement || !$E('.tip-text', tip) || !$E('.tip-text', tip).getText()) {
                    buyBtn.setStyle('cursor', 'pointer');
                    return tip.setStyle('visibility', 'hidden');
                } else {
                    buyBtn.setStyle('cursor', 'not-allowed');
                }
                tip.setStyle('visibility', 'visible');
            }
        });
		//缺货通知的Tip提示
        new Tips(notifyBtn, {
            className: 'cantbuy',
            showDelay: 0,
            hideDelay: 0
        });
		//缺货通知的点击事件
        notifyBtn.addEvent('click',
        function(e) {
            location.href = spath + "productreg.aspx?id="+$(this).id;
        });
        notifyBtn.addEvents({
            'onhide': function() {
                $(this).getPrevious('.btn-fastbuy').setStyle('visibility', 'visible');
            }
        });
		
		/*快速购买*/
        var fastbuyBtn = $E('#goods-viewer .btn-fastbuy');
        if (fastbuyBtn) {
            fastbuyBtn.store('tip:text', '').addEvent('click',
            function(e) {
                e.stop();
                this.blur();
                if (this.retrieve('tip:text')) return false;
                var form = $('fastbuy-form');
                form.empty().adopt($(this.form).toQueryString().toFormElements());
                form.adopt(new Element('input', {
                    name: 'isfastbuy',
                    value: 1,
                    type: 'hidden'
                }));
                if (!form.retrieve('events', {})['submit']) return form.submit();
                form.fireEvent('submit', e);

            });

            new Tips(fastbuyBtn, {
                showDelay: 0,
                hideDelay: 0,
                className: 'cantbuy',
                onShow: function(tip) {
                    if (!this.textElement || !$E('.tip-text', tip) || !$E('.tip-text', tip).getText()) {
                        fastbuyBtn.setStyle('cursor', 'pointer');
                        return tip.setStyle('visibility', 'hidden');
                    } else {
                        fastbuyBtn.setStyle('cursor', 'not-allowed');
                    }
                    tip.setStyle('visibility', 'visible');
                }
            });
        }
		
		setbuyBtnTip = function() {
            var spec_item_nocheck = [];
            $ES('#goods-spec .spec-item em').each(function(em) {
                if (!em.hasClass('check')) spec_item_nocheck.include(em.getText());

            });
            if (spec_item_nocheck.length > 0) {
                $$(buyBtn, fastbuyBtn).store('tip:text', '请选择：' + spec_item_nocheck.join(','));
            } else {
                $$(buyBtn, fastbuyBtn).store('tip:text', '');
            }
            return arguments.callee;
        } ();
		
		popAloneSpec = function() {
            $$('#goods-spec tr.spec-item', '#goods-spec div.spec-item .content').each(function(si) {
                var specs = si.getElements('a[specid]');
                if (specs.length > 1) return false;
                if (specs[0].hasClass('selected') || specs[0].hasClass('lock')) return false;
                specs[0].fireEvent('click');

            });
            return arguments.callee;
        } ();

        $E('#goods-viewer .btnBar').setStyle('visibility', 'visible');
	});
	
	var getSpecText = function(el) {
        if ($E('img', el)) return $E('img', el).alt || $E('img', el).title;
        return $E('span', el).get('text');
    };



    var specItems = $ES('#goods-spec .spec-item em');
    var referencePoint = {
        bn: $('goodsBn'),
        weight: $('goodsWeight'),
        marketPrice: $E('#goods-viewer .mktprice1'),
        price: $E('#goods-viewer .price1'),
        discount: $E('#goods-viewer .discount'),
        store: $E('#goods-viewer .buyinfo .store'),
        specTip: $E('#goods-spec .spec-tip'),
        update: function(v, html) {
            return referencePoint[v] ? referencePoint[v].setHTML(html) : false;
        }
    };
    var RPSV = $H(referencePoint).getValues();
    RPSV.each(function(el) {
        if (el && $type(el) == 'element') el.retrieve('defaultInnerHTML', el.get('html'));
    });

    var referencePointDef = function() {
        RPSV.each(function(el) {
            if (el && $type(el) == 'element') el.setHTML(el.retrieve('defaultInnerHTML'));
        });
        if ($E('#goods-viewer .mprice')) $E('#goods-viewer .mprice').hide();
        updatepic();
        buyBtn.show();
        notifyBtn.hide();
    };
	
	/*var PRODUCT_HASH=new Hash(
{
"249":
{
	"bn":"G49B7AF2072AF8-1",
	"price":238,
	"mktprice":258,
	"store":99,
	"weight":"0.000",
	"mprice":{"1":238,"2":238,"3":238},
	"spec_private_value_id":["12367746031","12367746084"]
},
"250":{"bn":"G49B7AF2072AF8-2","price":188,"mktprice":258,"store":98,"weight":"0.000","mprice":{"1":188,"2":188,"3":188},"spec_private_value_id":["12367746052","12367746084"]},"251":{"bn":"G49B7AF2072AF8-3","price":188,"mktprice":258,"store":99,"weight":"0.000","mprice":{"1":188,"2":188,"3":188},"spec_private_value_id":["12367746063","12367746084"]},"252":{"bn":"G49B7AF2072AF8-4","price":238,"mktprice":258,"store":99,"weight":"0.000","mprice":{"1":238,"2":238,"3":238},"spec_private_value_id":["12367746031","12367746085"]},"253":{"bn":"G49B7AF2072AF8-5","price":188,"mktprice":258,"store":99,"weight":"0.000","mprice":{"1":188,"2":188,"3":188},"spec_private_value_id":["12367746063","12367746085"]},"254":{"bn":"G49B7AF2072AF8-6","price":238,"mktprice":258,"store":99,"weight":"0.000","mprice":{"1":238,"2":238,"3":238},"spec_private_value_id":["12367746031","12367746096"]},"255":{"bn":"G49B7AF2072AF8-7","price":188,"mktprice":258,"store":98,"weight":"0.000","mprice":{"1":188,"2":188,"3":188},"spec_private_value_id":["12367746052","12367746096"]}});*/
	var PRODUCT_SPECV_ARR=[];
		PRODUCT_HASH.each(function(v){
		   PRODUCT_SPECV_ARR.push(v['spec_private_value_id']);
		});
	

    var updatepicRequest = new Request.HTML({
        url: '?product-goodspics.html',
        update: $E('#goods-viewer .goodspic'),
        autoCancel: true,
        onRequest: function() {}
    });
	
	 /*相册联动*/
    var updatepic = function(vids) {
        if(!vids)return $$('.goods-detail-pic-thumbnail td[img_id]').each(Element.show);
		vids = vids.split(',');
		
		var pointer = false;
		$$('.goods-detail-pic-thumbnail td[img_id]').each(function(i){
			if(vids.contains(i.get('img_id'))){
				i.style.display = '';
				if(!pointer){
				   i.getElement('a').fireEvent('click',{stop:$empty});
				   pointer = true;
				}
			}else{
				i.style.display = 'none';
			}
		});
    };

    /*其他联动*/
    var updateReference = function(specSelected, specvidarr) {
        var fix = (specvidarr.length == specItems.length);
        setbuyBtnTip();
        var productIntersection = [];
        /*当前已选择规格的商品交集*/
        var specTip = [];
        var picsId = [];
        if (specSelected) {
            specSelected.each(function(s) {
                productIntersection.combine(SPEC_HASH[s.get('specvid')]['product_id']);
                specTip.include("<font color=red>\"" + getSpecText(s) + "\"</font>");
                picsId.combine(SPEC_HASH[s.get('specvid')]['images']);
            });
        }

        if (!productIntersection || !productIntersection.length) return referencePointDef();

        var price = [];
        productIntersection.each(function(pid) {
            var product = PRODUCT_HASH[pid];
            /*if(storeCount.toInt()>9999){
                      storeCount='9999+';
                    }else{
                      storeCount=storeCount.toInt()+product['store'].toInt();
                    }*/

            price.include(product['price']).clean();

        });

        /*相册联动*/
        updatepic(picsId.clean().join(','));

        /*库存联动
                referencePoint.update('store',storeCount.toInt()>9999?'9999+':storeCount);*/

        /*价格联动*/
        if (price.length > 1) {
            price.sort(function(p1, p2) {
                p1 = p1.toInt();
                p2 = p2.toInt();
                if (p1 > p2) return 1;
                if (p1 == p2) return 0;
                return - 1;
            });
            referencePoint.update('price', priceControl.format(price[0]) + '-' + priceControl.format(price[price.length - 1]));
        } else {
            referencePoint.update('price', priceControl.format(price[0]));
        }

        /*规格选择提示联动*/
        referencePoint.update('specTip', '<em>您已选择：</em><span>' + specTip.join("、") + '</span>');

        var product_hiddenInput = $E('#goods-spec input[name^=goods[product_id]').set('disabled', !fix);
        var mprice = $E('#goods-viewer .mprice');

        /*定位到货品*/
        if (fix) {
            var fixProductID = null;
            PRODUCT_HASH.each(function(v, k) {
                if ($A(v['spec_private_value_id']).combine(specvidarr).length == specvidarr.length) {
                    fixProductID = k;
                }
            });
            if (fixProductID) {
                var fixProduct = PRODUCT_HASH[fixProductID];
                referencePoint.update('weight', fixProduct['weight']);
                referencePoint.update('bn', fixProduct['bn']);
                referencePoint.update('store', fixProduct['store'] || 0);
                referencePoint.update('price', priceControl.format(fixProduct['price']));
                referencePoint.update('marketPrice', priceControl.format(fixProduct['mktprice']));
                product_hiddenInput.set('value', fixProductID);

                /*库存联动*/
                if (referencePoint['store'] && (referencePoint['store'].getText().toInt() < 1)) {

                    buyBtn.hide();
                    notifyBtn.setStyle('display', 'inline');
                    notifyBtn.getPrevious('.btn-fastbuy') ? notifyBtn.getPrevious('.btn-fastbuy').setStyle('visibility', 'hidden') : $empty();
                    return;
                }
				
				referencePoint.update('store', fixProduct['store']);
				
                //if (buynum = $E('#goods-viewer .buyinfo input[type=text]')) {
                //    buynum.fireEvent('keyup');
                //}

                /*优惠联动*/
                if (referencePoint['discount'] && referencePoint['marketPrice']) {
                    var dcType = {
                        T1: '节省',
                        T2: '优惠',
                        T3: '折'
                    };

                    var _discount = referencePoint['discount'];
                    var _discountValue = _discount.get('text');
                    var fdt = priceControl._format.sign;


                    var _priceValue = fixProduct['price'];

                    var _priceMarketValue = fixProduct['mktprice'];

                    var _priceDiff = _priceMarketValue - _priceValue;				

                    if (! (_priceDiff > 0)) return;
                    if (_discountValue.test(dcType.T2, 'i')) {
                        referencePoint.update('discount', '优惠：' + (_priceDiff / _priceMarketValue * 100).toFixed(1) + '%');
                    } else if (_discountValue.test(dcType.T3, 'i')) {
                        referencePoint.update('discount', ((1 - _priceDiff / _priceMarketValue) * 10).toFixed(1).replace('.', '') + '折');
                    } else {
                        referencePoint.update('discount', '节省：' + priceControl.format(_priceDiff));
                    }

                }

                /*会员价联动*/
                if (mprice) {
                    mprice.getElements('.mlvprice').each(function(lvp) {
                        lvp.set('text', priceControl.format(fixProduct['mprice'][lvp.get('mlv')]));
                    });
                    mprice.show();
                }
            }

        } else {
            if (mprice) mprice.hide();
        }
		if($type(buyBtn)!="function")
        	buyBtn.show();
		if($type(notifyBtn)!="function")
	        notifyBtn.hide();

    };
	
	var specSelections = $$('#goods-spec .spec-item a[specvid]');
    specSelections.addEvent('click',
    function(e) {
        e ? e.stop() : e;
        this.blur();
        var specid = this.get('specid');
        var specvid = this.get('specvid');
        var prt = this.getParent('li.content') || this.getParent('ul');

        if (this.hasClass('lock')) return (function() {
            if (selected = this.getParent('ul').getElement('a.selected')) {
                selected.fireEvent('click');
            }
        }).call(this);
        if (this.hasClass('selected')) {
            this.removeClass('selected');
            if (prt.hasClass('content')) {
                var handle = prt.retrieve('handle');
                $E('span', handle).set('text', '请选择').removeClass('select');
                handle.removeClass('curr');
                prt.removeClass('content-curr');
            }
			
//		alert(specid);
            specSelectedCall(0, specid, this);
            return;
        }

        var tempsel = prt.retrieve('ts', this);
        if (tempsel != this) {
            tempsel.removeClass('selected')
        }
        prt.store('ts', this.addClass('selected'));

        if (prt.hasClass('content')) {
            var handle = prt.retrieve('handle');
            $E('span', handle).set('text', getSpecText(this)).addClass('select');
            handle.removeClass('curr');
            prt.removeClass('content-curr');
        }

        specSelectedCall(specvid, specid, this);

        if (e && e.fireFromProductsList) return;
        popAloneSpec();

    });

    void
    function() {
        /*下拉方式的规格选择*/
        var specHandles = $$('#goods-spec .spec-item .handle');
        var specContents = $$('#goods-spec .spec-item .content');

        var tempSlipIndex = 0;
        var tempCurrentIndex = -1;

        specHandles.each(function(handle, index) {
            var content = specContents[index];
            var contentPadding = content.getPadding();
            content.store('handle', handle);
            handle.addEvent('click',
            function(e) {
                if (tempCurrentIndex >= 0 && tempCurrentIndex != index) {
                    specHandles[tempCurrentIndex].removeClass('curr');
                    specContents[tempCurrentIndex].removeClass('content-curr');
                }
                tempCurrentIndex = index;
                this.toggleClass('curr');
                content.toggleClass('content-curr');
                content.setStyles({
                    'top': this.getCis().bottom - 4,
                    'left': specHandles[0].getPosition().x - 3,
                    'width': this.getParent('.goods-spec').getSize().x - (contentPadding.x + contentPadding.y + 14)
                });

            });

        });

    } ();
    /*规格点击时call此函数*/
    var specSelectedCall = function(specvid, specid, spec) {

        var specSelected = $$('#goods-spec .spec-item a.selected');

        var selectedSpecvids = [];
        specSelected.each(function(s) {
            var _specvid = s.get('specvid');
            selectedSpecvids.include(_specvid);
        });

        /*设置 spec-item 状态*/
        var em = (spec.getParent('li.content') && spec.getParent('li.content').retrieve('handle') || spec.getParent('.spec-item')).getElement('em');
        em[spec.hasClass('selected') ? 'addClass': 'removeClass']('check');

        /*隐藏|显示无交集规格值*/

        var usefulSpecvArr = [];

        PRODUCT_SPECV_ARR.each(function(item) {

            if ($A(item).combine(selectedSpecvids).length == item.length) {
                usefulSpecvArr.combine(item);
            }

        });

        specSelections.each(function(s) {
            if (usefulSpecvArr.indexOf(s.get('specvid')) > -1) {
                s.removeClass('lock')
            } else {
                s.addClass('lock');
            }
        });

        if (specSelected.length == 1) {
            var aspec = specSelected[0];
            (aspec.getParent('li.content') || aspec.getParent('ul')).getElements('a[specvid]').removeClass('lock');
        }

        updateReference(specSelected, selectedSpecvids);

    };

    var fixProductHidden = $E('#goods-spec input[name^=goods[product_id]');
    var gpList = $('goods-products-list').addEvents({

        pop: function() {
            this.setStyles({
                width: $E('#goods-viewer .hightline').getSize().x,
                top: $E('#goods-viewer .hightline').getPosition().y,
                left: $E('#goods-viewer .hightline').getPosition().x,
                visibility: 'visible'
            });
            if (this.getSize().y > 300) {
                this.setStyles({
                    height: 300,
                    'overflow-y': 'auto'
                });
            }
            this.getElements('tbody tr').each(function(tr) {
                var fixProductId = fixProductHidden.disabled ? false: fixProductHidden.value;
                if (tr.get('productid') == fixProductId) {
                    tr.addClass('selected');
                } else {
                    tr.removeClass('selected');
                }
            });

            $(document.body).addEvent('click',
            function(e) {
                this.fireEvent('unvisible');
                $(document.body).removeEvent('click', arguments.callee);
            }.bind(this));

        },
        unvisible: function() {
            this.setStyles({
                top: -20000,
                visibility: 'hidden'
            });
        }
    });

    gpList.getElements('tbody tr').addEvents({

        mouseenter: function() {
            this.addClass('mouseover');
        },
        mouseleave: function() {
            this.removeClass('mouseover');
            this.fireEvent('mouseup');
        },
        mousedown: function() {
            this.addClass('mousedown');
        },
        mouseup: function() {
            this.removeClass('mousedown');
        },
        click: function() {
            this.fireEvent('ischecked');

        },
        ischecked: function() {
            var productId = this.get('productId');
            var productMap = PRODUCT_HASH[productId];
            var specIDarr = productMap['spec_private_value_id'];
            $$('#goods-spec .spec-item a.selected').fireEvent('click');
            specIDarr.each(function(s) {
                var specEl = $E('#goods-spec .spec-item a[specvid=' + s + ']');
                if (!specEl) return;
                specEl.fireEvent('click', {
                    stop: $empty,
                    fireFromProductsList: true
                });
            });

        }

    });

} ();



/* 迷你购物车 www.v5shop.com.cn  */
 window.addEvent('domready',function(){
     var miniCart={
           'show':function(target){
               var dialog  = this.dialog =$pick($('mini-cart-dialog'),new Element('div',{'class':'dialog mini-cart-dialog','id':'mini-cart-dialog'}).setStyles({width:300}).inject(document.body));
			   
                  var result = $E('#template-modal .dialog').get('html');
				  result = result.replace("[title]", '正在加入购物车');
				  result = result.replace("[content]", '正在加入购物车...');
                this.dialog.setStyles({
                         top:target.getPosition().y+target.getSize().y,
                         left:target.getPosition().x
                    }).set('html',result
                  
				  /*.substitute({
                      
                      title:'正在加入购物车',
                      content:'正在加入购物车...'
                  })*/
                  
               ).show();
               
               
               
               document.addEvent('click',function(){
                  dialog.remove();
                  document.removeEvent('click',arguments.callee);
               });
           
           },
           'load':function(){
              var params=Array.flatten(arguments).link({
                  'remoteURL':String.type,
                  'options':Object.type
              });
              params.options.data = params.options.data?params.options.data.toQueryString()+'&mini_cart=true':'&mini_cart=true';
              var opts=params=$extend({
                 url:params.remoteURL,
                 method:'post',
                 onRequest:function(){
                     this.dialog.getElement('.title').set('html','正在加入购物车');
                 }.bind(this),
                 onSuccess:function(re){
                     this.dialog.getElement('.title').set('html','<img src="../../template/public/images/products/icon-success.gif" />成功加入购物车');
                     this.dialog.getElement('.dialog-content').set('html',re);
                     $$('.cart-number').set('text',Cookie.get('S[CART_COUNT]')||0);
                 }.bind(this),
                 onFailure:function(xhr){
                     this.dialog.remove();
                     MessageBox.error("加入购物车失败.<br /><ul><li>可能库存不足.</li><li>或提交信息不完整.</li></ul>");
                 }.bind(this)
              },params.options||{});
              if(!params.url)return false;
              miniCart.show(opts.target);
              new Request(opts).send();
           }
     };
     
        

   if(formtocart=$E('form[target=_dialog_minicart]')){
       formtocart.addEvent('submit',function(e){
           
           e.stop();
           miniCart.load([{
               url:this.action,
               method:this.method,
               data:this,
               target:this.getElement('input[value=加入购物车]')
           }]);
       
       });
   };
   /*for  goods which has specs*/
   if(btnbuy=$E('#goods-viewer form[target=_dialog_minicart] .btn-buy')){
      
      btnbuy.removeEvents('click').addEvent('click',function(e){
          e.stop();
          if(this.retrieve('tip:text'))return false;
          this.blur();
          this.form.fireEvent('submit',e);
      
      });
   
   };
   
   if(linktocart=$$('a[target=_dialog_minicart]')){
       if(linktocart.length){
            linktocart.addEvent('click',function(e){
                 e.stop();
                 miniCart.load([{url:this.href,target:this}]);
            });
         
       }
   };
});