jQuery.noConflict();
jQuery(document).ready(function () {

    if (location.href.indexOf("/store/os/shoppingcart.aspx") > -1)
        jQuery('#title').html("Shopping <span>Bag</span>");

    if (location.href.indexOf("/store/os/myaccount.aspx") > -1)
        jQuery('#title').html("My <span>Account</span>");

    if (location.href.indexOf("/store/os/trackorder.aspx") > -1 || location.href.indexOf("/store/os/customerorderlist.aspx") > -1)
        jQuery('#title').html("<span>Track</span> Your <span>Order</span>");

    if (location.href.indexOf("/store/os/giftcertificate.aspx") > -1)
        jQuery('#title').html("<span>Gift</span> Certificates");

    if (location.href.indexOf("/the-technology.html") > -1)
        jQuery("a[rel^='prettyPhoto']").prettyPhoto({ theme: 'light_square', animationSpeed: 'fast', show_title: false, allow_resize: false, modal: false });

    if (location.href.indexOf("/FAQs.html") > -1 || location.href.indexOf("/clinical-results.html") > -1 || location.href.indexOf("/customer-care.html") > -1)
        jQuery("#accordion").accordion();

    if (location.href.indexOf("/store/storelocator.aspx") > -1)
        jQuery('select').selectbox();

    setMiniCart();

    jQuery('input.autohint, textarea.autohint').focus(function () {
        autoHint(jQuery(this), true);
    });

    jQuery('input.autohint, textarea.autohint').blur(function () {
        autoHint(jQuery(this), false);
    });
    var b = false;
    jQuery('#header UL.menu LI').hover(function () {
        jQuery('.sub-menu').stop(true, true);
        if (jQuery(this).find('.sub-menu').size() > 0) {
            jQuery(this).find('.sub-menu').slideDown();
        }
    }, function () {
        jQuery('.sub-menu').stop(true, true);
        if (jQuery(this).find('.sub-menu').size() > 0) {
            jQuery(this).find('.sub-menu').slideUp();
        }
    });

    jQuery('#header .bag').hover(function () {
        jQuery('#header .bags').stop(true, true);
        jQuery('#header .bags').slideDown();
    }, function () {
        jQuery('#header .bags').stop(true, true);
        jQuery('#header .bags').slideUp();
    });

});

function setMiniCart() {
    jQuery.ajax({
        url: '/store/minicart.aspx',
        cache: false,
        success: function (html) {
            jQuery('#bags').html(html);
            render_cart_header("CartItemsLBGet", "CartTotalLBGet");
        }
    });
}

function OnResponseEnd() {
    render_cart_header("CartItemsLBGet", "CartTotalLBGet");
    setMiniCart();
    jQuery('#header .bags').slideDown();
}

function removeItem(rid) {
    jQuery.ajax({
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        url: '/store/MiniCart.aspx/RemoveItem',
        data: '{rid:"' + rid + '"}',
        dataType: 'json',
        success: function (msg) {
            setMiniCart();
        },
        error: function (e) { alert('error: ' + e.responseText); }
    });
}

function autoHint(obj, flag){
    if (flag) {
        if (jQuery(obj).val() == jQuery(obj).attr('title')){
            jQuery(obj).val('');
            jQuery(obj).addClass('edit');
        }
    } else {
        if (jQuery(obj).val() == ''){
            jQuery(obj).val(jQuery(obj).attr('title'));
            jQuery(obj).removeClass('edit');
        }
    }
}

function initPopup(obj, close) {
    jQuery(obj).show();
    jQuery(close).click(function () {
        jQuery(obj).empty();
        jQuery(obj).hide();
        jQuery('.overlay').hide();
    });
}

function siteSearch(v) {
    var values = v.split(" ");
    var s1 = "luxury toothpaste touch-ups instant stain remover am pm duo lemonade smile fresh mint watermelon green apple 30 70 count touch up";
    var s2 = "sets kits discover travel jet set kit extras lip treatment vacation gloss pack sampler";
    var url;

    for (var i = 0; i < values.length; i++) {
        if (s1.indexOf(values[i].toLowerCase()) > -1)
            url = "/keep-your-teeth-white.html";
        else if (s2.indexOf(values[i].toLowerCase()) > -1)
            url = "/sets-kits-and-extras.html";
        else
            url = "/whiten-your-teeth.html";
    }
    
    window.location.href = url;
}
