// *** Shopping Cart scripts
var hideC=null;
var showC=null;
var holdC=null;
var holdHide=false;
var holdShow=false;
var Delay=300;

function showCart(flag) {
    if (holdC) clearTimeout(holdC);
    if (!holdHide) {
        if (showC) clearTimeout(showC);
        showC=setTimeout("$('mini-cart').addClassName('showCart')", Delay);
    }
    if (flag) {
        hideC=setTimeout("$('mini-cart').removeClassName('showCart')", 5000);
    }
}

function hideCart() {
    if (showC) clearTimeout(showC);

    if (holdHide) {
        if (holdC) clearTimeout(holdC);
        holdC=setTimeout("clearHold()", Delay);
    }

    if (!holdShow) {
        if (hideC) clearTimeout(hideC);
        hideC=setTimeout("$('mini-cart').removeClassName('showCart')", Delay);
    }
}

function toogleCart() {
    if (!holdShow) {
        holdHide = false;
        holdShow = true;
        $('mini-cart').addClassName('showCart');
    } else {
        holdHide = true;
        holdShow = false;
        $('mini-cart').removeClassName('showCart');
    }
}

function clearHold() {
    holdHide = false;
}

function holdCart(flag) {
    if (flag) {
        if (hideC) clearTimeout(hideC);
        if (showC) clearTimeout(showC);
        if (holdC) clearTimeout(holdC);
        holdHide = false;
        holdShow = true;
    } else {
        holdHide = true;
        holdShow = false;
    }
}


// *** Nav Menu scripts
function toggleMenu(el, over)
{
    if (over) {
        Element.addClassName(el, 'over');
    }
    else {
        Element.removeClassName(el, 'over');
    }
}

function toggleSubMenu(el, over)
{
    if (Element.childElements(el)) {
    var uL = Element.childElements(el)[1];
    var iS = true;
    }
    if (over) {
        Element.addClassName(el, 'over');
    }
    else {
        //  setTimeout(function(){
            Element.removeClassName(el, 'over');
        //}, 1000); 
    }
}

// *** Custom Fade effects scripts
// fadein: cFade.go('window_overlay', 1, 70, 0.2);
// fadeout: cFade.go('window_overlay', 0, 0, 0.3);
var cFade=function(){
    return{
        go:function(id, flag, target, speed){
            this.elem = document.getElementById(id);
            clearInterval(this.si);
            if(this.elem) {
                if(flag) {
                    this.elem.style.opacity = 0;
                    this.elem.style.filter = 'alpha(opacity=0)';
                    this.elem.style.display = 'block';
                } else {
                    if(!this.elem.style.opacity) {
                        this.elem.style.opacity = 1;
                        this.elem.style.filter = 'alpha(opacity=100)';
                    }
                }
                this.target = target ? target : flag ? 100 : 0;
                this.flag = flag || -1;
                this.speed = speed || 0.05;
                this.alpha = this.elem.style.opacity ? parseFloat(this.elem.style.opacity) * 100 : 0;
                this.si = setInterval(function(){cFade.tween()}, 20);
            }
        },
        tween:function(){
            if(this.alpha == this.target){
                clearInterval(this.si);
                if(parseFloat(this.elem.style.opacity) <= 0) {
                    this.elem.style.display = 'none';
                    this.elem.style.opacity = 0;
                    this.elem.style.filter = 'alpha(opacity=0)';
                } else {
                    this.elem.style.display = 'block';
                    this.elem.style.opacity = this.target / 100;
                    this.elem.style.filter = 'alpha(opacity=' + this.target + ')';
                }
            } else {
                var value = Math.round(this.alpha + ((this.target - this.alpha) * this.speed)) + (1 * this.flag);
                this.elem.style.opacity = value / 100;
                this.elem.style.filter = 'alpha(opacity=' + value + ')';
                this.alpha = value;
            }
        }
    }
}();

// *** Popup Window scripts
function showWindow(el, content, styles, withClose, isAjax) {
    if (!$('window_overlay')) {
        var overlay = new Element('div',{id:'window_overlay'});
        overlay.update('&nbsp;');
        document.body.appendChild(overlay);
    }
    if ($('window_overlay')) {
        cFade.go('window_overlay', 1, 70, 0.2);
    }

    var windowDiv = new Element('div',{id:el,style:styles});
    windowDiv.className = 'window';
    if(isAjax) {
        var url = content;
        content = '';
        windowDiv.addClassName('window-preload');
    }
    windowDiv.innerHTML = '<div class="window-inner"><div id="'+el+'-content">'+content+'</div>';
    if(withClose) windowDiv.innerHTML += '<span class="window-close" onclick="hideWindow(\''+el+'\');">&nbsp;</span>';
    windowDiv.innerHTML += '</div>';
    document.body.appendChild(windowDiv);
    windowDiv.style.display = 'block';
}

function hideWindow(el) {
    if ($(el)) $(el).remove();
    if ($('window_overlay')) {
        cFade.go('window_overlay', 0, 0, 0.2);
        window.setTimeout('removeOverlay()', 100);
    }
}
function removeOverlay() {
    if ($('window_overlay')) {
        $('window_overlay').style.display = 'none';
        $('window_overlay').stopObserving('click');
        $('window_overlay').remove();
    }
}


// *** Home Promo scripts
function showAbout() {
    if ($('promolink-featured')) $('promolink-featured').removeClassName('active');
    if ($('promolink-about')) $('promolink-about').addClassName('active');
    if ($('home-promo-text')) $('home-promo-text').show();
    autoCircle = false;
}
function hideAbout() {
    if ($('promolink-about')) $('promolink-about').removeClassName('active');
    if ($('promolink-featured')) $('promolink-featured').addClassName('active');
    if ($('home-promo-text')) $('home-promo-text').hide();
}

function userPromoOnmouse() {
    onmousetimer = window.setTimeout('stopCarusel()', 500);
    hideAbout();
}

function userPromoOnmouseOut() {
    window.clearTimeout(onmousetimer);
}

function stopCarusel() {
    autoCircle = false;
}

function circlePromos() {
    if (autoCircle) {
        highlightPromo(curPromo);
        var itemsEl = $('promoItems-'+curPromo).childElements();

        if (itemsEl && itemsEl.length) {
            if (!promoItems[curPromo]) {
                promoItems[curPromo] = new Array();
                var itemsLength = itemsEl.length;
                for (var index = 0; index < itemsLength; ++index) {
                      var tmp = itemsEl[index].id.split('-');
                      promoItems[curPromo].push(tmp[2]);
                }
            }
            circlePromoItems(curPromo);
        } else {
            curPromo = getNextArrVal(promoCategories, curPromo);
            window.setTimeout('circlePromos()', 2000);
        }
    } else {
    }
}

function circlePromoItems(category) {
    if (autoCircle && promoItems[curPromo]) {
        if (!curPromoItem) {
            curPromoItem = promoItems[curPromo].first();
        }
        highlightPromoItem(category, curPromoItem);
        if (curPromoItem != promoItems[curPromo].last()) {
            curPromoItem = getNextArrVal(promoItems[curPromo], curPromoItem);
            window.setTimeout('circlePromoItems('+category+')', 2500);
        } else {
            curPromoItem = null;
            curPromo = getNextArrVal(promoCategories, curPromo);
            window.setTimeout('circlePromos()', 2500);
        }
    }
}

function getNextArrVal(arr, curVal) {
    if (curVal == arr.last()) {
        return arr.first();
    }

    for (var index = 0; index < arr.length; ++index) {
        if (arr[index] == curVal) {
            return arr[index+1]? arr[index+1] : false;
        }
    }
}

function setCookie(c_name,value,expiredays) {
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name) {
    if (document.cookie.length>0)   {
        c_start=document.cookie.indexOf(c_name + "=");
        if (c_start!=-1)    {
            c_start=c_start + c_name.length+1;
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1)
                c_end=document.cookie.length;
            return unescape(document.cookie.substring(c_start,c_end));
        }
    }
    return "";
}

function highlightPromo(category) {
    if(noSwitch) return false;
    loadPromo(category);
    switchTimer = setTimeout('switchPromoCategory('+category+')', delay);
}

function loadPromo(category) {
    if (inProgress[category]) {
        return;
    }

    if (result[category]) {
        return;
    }

    result[category] = new Array;
    inProgress[category] = true;

    new Ajax.Request (
        ajaxUrl,
        {
            parameters: {
               promo_category_id: category
            },
            onComplete: function(transport) {
                var categoryItems = eval('('+transport.responseText+')');
                result[category] = categoryItems;
                inProgress[category] = false;

                if (prevCategory==category) {
                   switchTimer = setTimeout('switchPromoCategory('+category+')', delay);
                }
                return;
            },
            onFailure: function(transport) {
                $('home-promo-content-'+prevCategory).show();
                $('home-promo-content-'+prevCategory).style.opacity = 1;
                $('home-promo-content-'+prevCategory).style.filter = 'alpha(opacity=100)';
            },
            evalScripts: true
        }
    );
}

function nolightPromo() {
    if (switchTimer) {
        clearTimeout(switchTimer);
    }
}

function switchPromoCategory(category) {
    setCookie(cookieCategoryName, category);

    $('pThumb'+prevCategory).className = '';
    $('pThumb'+category).className = 'hover';

    if (prevCategory!=category) {
        $('home-promo-content-'+prevCategory).hide();

        $('pThumb'+prevCategory).className = '';

        // $('promoSwitchBlock-'+category).show();
        cFade.go('promoSwitchBlock-'+category, 1, 100, 0.2);

        // $('home-promo-content-'+category).show();
        // cFade.go('home-promo-content-'+category, 1, 100, 0.2);

        $('home-promo-content-'+category).style.display = 'block';
        $('home-promo-content-'+category).style.opacity = 1;
        $('home-promo-content-'+category).style.filter = 'alpha(opacity=100)';

        var elem = $('home-promo-content-'+category);
        // console.debug(elem.id+' | '+elem.style.display+' | '+elem.style.opacity+' | '+elem.style.filter);

        var showFirst = false;
        var names = $$('#home-promo-content-'+category+' .promo-product-name');
        names.each(function(el) {
            if(el.style.display != 'none') showFirst = true;
        })
        $('home-promo-content-'+category).down('.promo-product-name').style.display='block';

        prevCategory = category;
    }

    if (typeof(item) != 'undefined') {
        if (result[category][item]) {
            switchPromoItem(category, item);
        }
    }
}

function highlightPromoItem(category, item) {
    if(noSwitch) return false;
    if (prev[category]['item'] == item) {
        return;
    }
    switchItemTimer = setTimeout('switchPromoItem('+category+', '+item+')', delay);
}

function nolightPromoItem() {
    if (switchItemTimer) {
        clearTimeout(switchItemTimer);
    }
}

function switchPromoItem(category, item) {
    setCookie(cookieCategoryName, category);
    setCookie(cookieItemName, item);

    loadPromo(category);

    if (itemProgressHolder) {
        return;
    }
    itemProgressHolder = true;
    refreshCount++;

    if (inProgress[category]) {
        if (refreshCount < refreshLimit) {
            progressHolderTimer = setTimeout('switchPromoItem('+category+', '+item+')', 1000);
            itemProgressHolder = false;
            return;
        } else {
            if (progressHolderTimer) {
                clearTimeout(progressHolderTimer);
            }
            $('home-promo-content-'+prevCategory).style.display = 'block';
            $('home-promo-content-'+prevCategory).style.opacity = 1;
            $('home-promo-content-'+prevCategory).style.filter = 'alpha(opacity=100)';
            itemProgressHolder = false;
            return;
        }
    }

    if (!prev[category]) {
        prev[category] = new Array;
    }

    if (!prev[category]['item']) {
        prev[category]['item'] = false;
    }

    if (prev[category]['item'] == item) {
        itemProgressHolder = false;
        return;
    }

    // $('promoSwitchBlock-'+category).hide();
    $('promoSwitchBlock-'+category).style.display = 'none';
    $('promoSwitchBlock-'+category).style.opacity = 0;
    $('promoSwitchBlock-'+category).style.filter = 'alpha(opacity=0)';

    if (prev[category]['item']) {
        $('promoItem-'+category+'-'+prev[category]['item']).removeClassName('active');
    }
    if (prev[category]['item'] != item) {
        $('promoName-'+category+'-'+prev[category]['item']).hide();
    }

    $('promoItem-'+category+'-'+item).addClassName('active');
    $('promoItemContainer-'+category).innerHTML = result[category][item];

    var names = $$('#promoSwitchBlock-'+category+' .promo-product-name');
    names.each(function(el) { el.style.display = 'none'; })
    $('promoName-'+category+'-'+item).show();

    // $('promoSwitchBlock-'+category).show();
    cFade.go('promoSwitchBlock-'+category, 1, 100, 0.2);

    prevCategory = category;
    prev[category]['item'] = item;
    refreshCount = 0;
    itemProgressHolder = false;
}

function stopPromo() {
    autoCircle = false;
}
function stopSwitch() {
    autoCircle = false;
}


// *** Product Listing scripts
function getQty(prodId, numeric) {
    var qty = $('qty_'+prodId);
    if (qty.value == '' || qty.value == this.defaultValue || qty.value < 1) {
        return (numeric? 1 : '');
    }
    return (numeric ? qty.value : 'qty/'+qty.value+'/');
}

function initHintsListing() {
    if($('prod-list')) {
        var hints = $$('#prod-list div.add-to');
        hints.each(function(el) {
            var bo_id = el.id;
            bo_id = bo_id.replace('add-to-box-','');
            var bo_qty = $('bo-qty-'+bo_id).value;
            var button = el.down('.btn-addtocart');
            if(bo_qty > 0) {
                if($('bo-attention-'+bo_id)) {
                    button.observe('mouseover', function(e){
                        if(parseInt($('qty_'+bo_id).value) > parseInt($('bo-qty-'+bo_id).value)) showHint('bo-attention-'+bo_id);
                    });
                    button.observe('mouseout', function(e){
                        hideHint('bo-attention-'+bo_id);
                    });
                }
            } else {
                if($('bo-backorder-'+bo_id)) {
                    button.observe('mouseover', function(e){
                        showHint('bo-backorder-'+bo_id);
                    });
                    button.observe('mouseout', function(e){
                        hideHint('bo-backorder-'+bo_id);
                    });
                }
            }
        })
    }
}

function initHintsDetails(id) {
    el = $('add-box');
    if(el){
        // var hints = $$('#prod-list div.add-to');
        var bo_qty = $('bo-qty').value;
        var button = el.down('.btn-addtocart');
        var ie = (document.all && !window.opera && window.XMLHttpRequest);
        if(bo_qty > 0) {
            if($('bo-attention')) {
                button.observe('mouseover', function(e){
                    if(parseInt($('qty_'+id).value) > parseInt($('bo-qty').value)) showHint('bo-attention');
                });
                button.observe('mouseout', function(e){
                    hideHint('bo-attention');
                });
                if(ie) $('bo-attention').style.left = '73px';
            }
        } else {
            if($('bo-backorder')) {
                button.observe('mouseover', function(e){
                    showHint('bo-backorder');
                });
                button.observe('mouseout', function(e){
                    hideHint('bo-backorder');
                });
                if(ie) $('bo-backorder').style.left = '73px';
            }
        }
    }
}

function showHint(el) {
    cFade.go(el, 1, 100, 0.3);
}

function hideHint(el) {
    if($(el) && $(el).style.display == 'block') cFade.go(el, 0, 0, 0.3);
}


// *** buttons 
Event.observe(window, 'load', function(){
    $$('.btn').each(function(el){
        Event.observe(el, 'mousedown', function(){
            el.addClassName('b-active');
        });
        Event.observe(el, 'mouseup', function(){
            el.removeClassName('b-active');
        });
    });
});


// *** ajax add to cart
function updateMinicart(url,showAdded) {
    // new Ajax.Request(url, {
    new Ajax.Request(url+'?ms=' + new Date().getTime(), {
        method: 'get',
        onSuccess: function(transport) {
            var mCart = transport.responseText.match(/<ul\s+id="mCart"[^>]*>[\S\s]*?<\/ul>/gi);
            mCart = mCart[0].replace(/(<ul\s+id="mCart"[^>]*>)/gi,'').replace(/(<\/ul>)/gi,'');
            $('mCart').update(mCart);

            var cartQty = $('cart-qty');
            var topLink = $('cartHeader');
            var cartHead = $('cart-amount');
            if(cartQty && cartQty.value > 0) {
                if(topLink) topLink.update('<a href="'+originalCartUrl+'">Shopping Cart <span>('+cartQty.value+')</span></a>'); 
                if(cartHead) cartHead.update(cartQty.value > 1 ? ': '+cartQty.value+' items' : ': 1 item');
            } else {
                if(topLink) topLink.update('Shopping Cart <span>(0)</span>'); 
                if(cartHead) cartHead.update('');
            }

            if(showAdded) {
                var addedHtml = transport.responseText.match(/<div\s+id="addedHtml"[^>]*>[\S\s]*?<\/div>/gi);
                if(addedHtml) {
                    addedHtml = addedHtml[0].replace(/(<div\s+id="addedHtml"[^>]*>)/gi, '').replace(/(<\/div>)/gi, '');
                    showLastAdded(addedHtml);
                }
            } else {
                showCart(true);
            }
            // console.debug(addedHtml);
            // alert(addedHtml);
        }
    });
}

function delItem(id) {
    var row = $('cart-row-'+id);
    if(row.hasClassName('to-delete')) {
        row.removeClassName('to-delete');
        row.down('.cart-qty').value = row.down('.cart-qty-ini').value;
    } else {
        row.addClassName('to-delete');
        row.down('.cart-qty').value = 0;
    }
    updateTotal();
}
function updateTotal() {
    var cartTotal = 0.00;
    $$('#cart-sidebar .cart-row').each(function(el) {
        var rowPrice = el.down('.cart-qty').value;
        if(parseInt(el.down('.cart-qty').value) > 0) {
            cartTotal += parseFloat(el.down('.cart-qty').value) * parseFloat(el.down('.price').innerHTML.replace('$',''));
        }
    });
    cartTotal = cartTotal.toFixed(2);
    $('cart-total-price').innerHTML = '<span class="price">$'+cartTotal+'<'+'/span>';

    var el = $('upd-load'); 
    el.setAttribute('class', '');
    if(parseFloat(cartTotal) != parseFloat($('cart-total-ini').value)) {
        el.addClassName('upd-save');
    } else {
        el.removeClassName('upd-save');
    }
}

function updateCartForm() {
    holdCart(true);
    var updForm = $('minicartform');
    var el = $('upd-load'); 

    if(!updProgress) {
        if(updTimeout) clearTimeout(updTimeout);
        updProgress = true;
        el.setAttribute('class', '');
        el.addClassName('upd-load').show().setStyle({opacity: 1});
        el.style.filter = 'alpha(opacity=100)';
        updForm.request({
            onSuccess: function(){
                if ($('product-view-tier-prices')) {
                   updateTierBlock(prodId);
                } else if (typeof isOnProductList != 'undefined') {
                    updateProductListTierBlocks();
                }
                if(updTimeout) clearTimeout(updTimeout);
                updProgress = false;
                el.setAttribute('class', '');
                el.addClassName('upd-success');
                setTimeout("updateMinicart(cartUrl,0)", 100);
            },
            onFailure: function(){
                el.hide();
                updForm.submit();
            }
        });
    }
}

function addToCart(url, id) {
    var parent = $('add-to-box-'+id);
    var qtyBox = parent.down('.qty-box');
    var hint = $('add-hint-'+id);

    if(!listProgress){
        listProgress = true;
        qtyBox.addClassName('add-load');
        $$('.add-hint').invoke('hide');
        if(hintTimeout) clearTimeout(hintTimeout);
        new Ajax.Request(url+'?ms=' + new Date().getTime(), {
            method: 'get',
            onComplete: function(transport) {
                if (typeof isOnProductList != 'undefined') {
                    updateProductListTierBlocks();
                }
                if(hintTimeout) clearTimeout(hintTimeout);
                listProgress = false;
                qtyBox.removeClassName('add-load');
                $$('.add-hint').invoke('hide');
                hint.innerHTML = 'Product added to your cart.';
                hint.addClassName('add-success').show().setStyle({opacity: 1});
                hint.style.filter = 'alpha(opacity=100)';
                hintId = 'add-hint-'+id;
                hintTimeout = setTimeout("cFade.go(hintId, 0, 0, 0.05)", 3000);
                updateMinicart(miniCartUrl,1);
                showPixel(id);
            },
            onFailure: function(){
                setLocation(url);
            }
        });
    } else {
        hint.removeClassName('add-success');
        hint.removeClassName('add-error');
        hint.innerHTML = 'Please wait while loading...';
        if(hintTimeout) clearTimeout(hintTimeout);
        hint.show();
        hint.style.opacity = 1;
        hint.style.filter = 'alpha(opacity=100)';
    }
    return false;
}

function addToCartMini(url, id, parent) {
    var miniParent = $(parent);
    var hint = $('add-mini-'+id);
    if(!miniProgress){
        miniProgress = true;
        hint.removeClassName('mini-success');
        $$('#'+parent+' .add-mini').invoke('hide');
        hint.show().setStyle({opacity: 1});
        hint.style.filter = 'alpha(opacity=100)';
        if(miniTimeout) clearTimeout(miniTimeout);
        new Ajax.Request(url+'?ms=' + new Date().getTime(), {
            method: 'get',
            onComplete: function(transport) {
                if ($('product-view-tier-prices')) {
                   updateTierBlock(prodId);
                } else if (typeof isOnProductList != 'undefined') {
                    updateProductListTierBlocks();
                }
                if(miniTimeout) clearTimeout(miniTimeout);
                miniProgress = false;
                hint.addClassName('mini-success').show().setStyle({opacity: 1});
                hint.style.filter = 'alpha(opacity=100)';
                miniId = 'add-mini-'+id;
                miniTimeout = setTimeout("cFade.go(miniId, 0, 0, 0.05)", 2500);
                updateMinicart(miniUrl,1);
                showPixel(id);
            },
            onFailure: function(){
                hint.hide();
                setLocation(url);
            }
        });
    }
    return false;
}


// *** added to cart drop out box
var addedTimeout = false;
var addedHold = false;
var addedClosed = false;
function showLastAdded(addedContent) {
    var addedBox = '';
    if(!$('addedBox')) {
        addedBox = new Element('div',{id:'addedBox'});
        addedBox.addClassName('added-box');
        document.body.appendChild(addedBox);
    }
    addedBox = $('addedBox');
    addedBox.update(addedContent);

    if(addedTimeout) clearTimeout(addedTimeout);
    addedBox.style.top = '-1000px';
    addedBox.show();
    addedBox.style.opacity = 1;
    addedBox.style.filter = 'alpha(opacity=100)';

    var boxHeight = -1*(addedBox.offsetHeight+20);
    addedBox.style.top = boxHeight+'px';
    move(addedBox, boxHeight, 0, circEaseInOut, 1000);

    var close = addedBox.down('.add-close');
    Event.observe(close, 'click', function(){
        if(addedTimeout) clearTimeout(addedTimeout);
        // addedBox.hide();
        // cFade.go('addedBox', 0, 0, 0.2)
        move(addedBox, 0, boxHeight, circEaseInOut, 300);
        addedClosed = true;
    });

    if(addedHold) {
        holdLastAdded(1);
    } else {
        hideLastAdded();
    }

    Event.observe(addedBox, 'mouseover', function(){
        holdLastAdded(1);
    });
    Event.observe(addedBox, 'mouseout', function(){
        if(addedClosed) {
            holdLastAdded(0);
        } else {
            holdLastAdded(0);
            hideLastAdded();
        }
    });
}
function holdLastAdded(flag) {
    if (flag) {
        if(addedTimeout) clearTimeout(addedTimeout);
        addedHold = true;
    } else {
        addedHold = false;
    }
}
function hideLastAdded() {
    if(addedTimeout) clearTimeout(addedTimeout);
    // addedTimeout = setTimeout("cFade.go('addedBox', 0, 0, 0.1)", 3000);
    addedTimeout = setTimeout(function() {
        var addedBox = $('addedBox');
        var boxHeight = -1*(addedBox.offsetHeight+20);
        move(addedBox, 0, boxHeight, circEaseInOut, 500);
    }, 4000);
}

function showPixel(id) {
    var pixel = $('pixel');
    if(!pixel) {
        pixel = new Element('div',{id:'pixel'});
        document.body.appendChild(pixel);
    }
    pixel.update('<iframe src="'+window.location.protocol+'//pixel.fetchback.com/serve/fb/pdj?cat=&amp;name=landing&amp;sid=1645&amp;abandon_products='+id+'" scrolling="no" width="1" height="1" marginheight="0" marginwidth="0" frameborder="0" style="margin:0;padding:0;width:1px;height:1px;border:0;"></iframe>');
}


// *** animations
// http://javascript.info/tutorial/animation#the-basics-of-the-animation
// http://jqueryui.com/demos/effect/easing.html
function animate(opts) {
    var start = new Date;
    var id = setInterval(function() {
        var timePassed = new Date - start;
        var progress = timePassed / opts.duration;
        if (progress > 1) progress = 1;
        var delta = opts.delta(progress);
        opts.step(delta);
        if (progress == 1) {
            clearInterval(id)
        }
    }, opts.delay || 10)
}

function move(element, start, end, delta, duration) {
    var to = (end - start);
    animate({
        delay: 10,
        duration: duration || 1000,
        delta: delta,
        step: function(delta) {
            element.style.top = start + to * delta + "px"; 
        }
    })
}
function linear(progress) {
    return progress;
}
function quad(progress) {
    return Math.pow(progress, 2);
}
function circ(progress) {
    return 1 - Math.sin(Math.acos(progress));
}
function back(progress, x) {
    return Math.pow(progress, 2) * ((x + 1) * progress - x);
}
function bounce(progress) {
    for(var a = 0, b = 1, result; 1; a += b, b /= 2) {
        if (progress >= (7 - 4 * a) / 11) {
            return -Math.pow((11 - 6 * a - 11 * progress) / 4, 2) + Math.pow(b, 2);
        }
    }
}
function elastic(progress, x) {
    return Math.pow(2, 10 * (progress-1)) * Math.cos(20*Math.PI*x/3*progress);
}
function makeEaseIn(delta) {
    return function(progress) {
        return delta(1*progress) / 1;
    }
}
function makeEaseOut(delta) { 
    return function(progress) {
        return 1 - delta(1 - progress);
    }
}
function makeEaseInOut(delta) {  
    return function(progress) {
        if (progress < .5){
            return delta(2*progress) / 2
        } else {
            return (2 - delta(2*(1-progress))) / 2
        }
    }
}
var circEaseIn = makeEaseIn(circ);
var circEaseOut = makeEaseOut(circ);
var circEaseInOut = makeEaseInOut(circ);


// Event.observe(window, 'load', function(){
// });



function showTier(id) {
    var el = $(id);
    if(el) {
        el.up('li.product-item').style.zIndex = '999';
    }
}
function hideTier(id) {
    var el = $(id);
    if(el) {
        el.up('li.product-item').style.zIndex = '5';
    }
}
