var proxy = {
    site: "www.pidelorapido.com",
    ready: false,
    map: false,
    console: false,
    isDebug: true,
    start: false,
    ticket: {},
    product: {},
    Conf: {},
    debug: function(msg) {
        if (proxy.console && window.console) console.debug(msg);
        else if (document.getElementById("proxy_debug")) document.getElementById("proxy_debug").innerHTML += '<p style="margin:0">' + msg + '</p>';
    },
    init: function(site) {
      
        proxy.Conf = site;
        proxy.site += proxy.Conf.Host;
        if (!proxy.Conf.ProcessServerSide) visitLink();
    }
}

if(proxy.isDebug){proxy.start = new Date();proxy.debug("body start..."+ proxy.start);}
function visitLink(){
    // has map?
    if (document.body.getAttribute('title') == "toolbar") return;
    proxy.debug("process links...");
    if(jQuery("map")&&!proxy.map){      
       jQuery("area[href]:not(.proxy_ignore)").each(function(i){
          if(!jQuery(this).attr('proxy_ignore')){
            if(jQuery(this).attr('href').indexOf(window.location.host )<0){
                 jQuery(this).attr("href",jQuery(this).attr("href").replace('http://','http://'+window.location.host+"/" ));
              }else{
                 jQuery(this).attr("href",jQuery(this).attr("href").replace(window.location.host,proxy.site ));
              }              
              jQuery(this).addClass("proxy_ignore");
          }
       });
    }
    
      //form
      jQuery("form[action]:not(.proxy_ignore)").each(function(i){
          if(!jQuery(this).attr('proxy_ignore')){
            if(jQuery(this).attr('action').indexOf(window.location.host )<0){
                 jQuery(this).attr("action",jQuery(this).attr("action").replace('http://','http://'+window.location.host+"/" ));
              }else{
                 jQuery(this).attr("action",jQuery(this).attr("action").replace(window.location.host,proxy.site ));
              }              
              jQuery(this).addClass("proxy_ignore");
          }
       });
       
    
     jQuery("a[href]:not(.proxy_ignore)").each(function(i){
          if(!jQuery(this).attr('proxy_ignore')){
           if(jQuery(this).attr('href').indexOf("javascript") >= 0){//pass javascript links
             }else if(jQuery(this).attr("href").indexOf('http://') == 0)
              if(jQuery(this).attr('href').indexOf(window.location.host )<0){
                 jQuery(this).attr("href",jQuery(this).attr("href").replace('http://','http://'+window.location.host+"/" ));
              }else{
                 jQuery(this).attr("href",jQuery(this).attr("href").replace(window.location.host,proxy.site ));
              }
           else if(jQuery(this).attr("href").indexOf('/') == 0)
              jQuery(this).attr("href",'http://'+proxy.site+jQuery(this).attr("href"));
           else 
              jQuery(this).attr("href", 'http://'+proxy.site+'/'+jQuery(this).attr("href"));
              
           jQuery(this).attr("proxy_ignore",1);
         }
     });
  
     jQuery("img[src]:not(.proxy_ignore)").each(function(i){
           var img = jQuery(this);
           if(img.attr("src").indexOf('/' ) == 0)
              img.attr("src", 'http://'+proxy.site+img.attr("src"));
           else if(img.attr("src").indexOf('http')<0){ 
             img.attr("src", 'http://'+proxy.site+"/"+img.attr("src"));
           }else if(img.attr("src").indexOf(window.location.host)>0) {
             img.attr("src",img.attr("src").replace(window.location.host,proxy.site));
           }
        jQuery(this).addClass("proxy_ignore");
     });
  
    if (!proxy.ready){
     window.setTimeout("visitLink();",500);
    }
};

(function($) {
    $.fn.hookCart = function() {
        if ($(this).attr("isdisabled") == "true") {
            window.setTimeout("jQuery('.button_add_to_bag').hookCart();", 1000);
            return;
        }
        $(this).attr("onclick", "").attr("id", "pr_add").unbind().click(function() {
            $.pr_cart.add(proxy.ticket);
            return false;
        });
    };

    $.isDebug = function() {
        return eval(jQuery.cookie("debug"));
    };
    $.showdebug = function() {
        var content = '<strong>Name:</strong> ' + proxy.ticket.Name + '<br />';
        content += '<strong>Product Category:</strong> ' + proxy.ticket.ProductCategory + '<br />';
        content += '<strong>Product Price:</strong> $' + proxy.ticket.ProductPrice + '<br />';
        content += '<strong>Shipping Price:</strong> $' + proxy.ticket.ShippingPrice + '<br />';
        content += '<strong>Shipping Weight:</strong> ' + proxy.ticket.ShippingWeight + '<br />';
        content += '<strong>Description:</strong> ' + proxy.ticket.Description + '<br />';
        prBox2('Product debug information', content);
    };
    $.getItemTip = function() {
        var s = proxy.ticket.ShippingPrice;
        if(s <=0) s= 0;
        var tip = "<p style='text-align:left;width:150px;margin:0;' ><b>Precio cotizado</b>: " + formatCurrency("$", proxy.ticket.ProductPrice) + "<br />";
        tip += "<b>Shipping cotizado</b>: " + formatCurrency("$", s) + "<br />";
        tip += "<b>Peso cotizado</b>: " + proxy.ticket.ShippingWeight + (proxy.ticket.ShippingWeight > 1 ? " libras" : " libra") + "<br /><br />";
        tip += $.PriceInfo; //  tip += "<b>Incluye Todo</b>: fletes, seguro, impuestos de importación, trámites aduanales y entrega en tu casa u oficina.";
        return tip;
    };
    
    $.pr_init = function() {
        if (window.location.href.indexOf("www.hollisterco.com") >= 0) {
            serverHostname = "www.hollisterco.com";
        }
        if ($.isDebug()) {
            // show dialog
            $(".pidelorapido_shopping").append('<a href="javascript:void(0);" class="debug_view">View Debug Info</a><span class="debug_split">|</span><a href="javascript:void(0);" class="debug_off">Turn Off</a>');
            $(".pidelorapido").before('<div id="pr_debug" class="content"></div>');
            $(".debug_view").click(function() { $.showdebug(); });
            $(".debug_off").click(function() {
                $.cookie("debug", "false", { path: "/" });
                $(".debug_view").hide();
                $(".debug_split").hide();
                $(this).hide();
            });
        }

        if (!proxy.Conf.ProcessServerSide) visitLink();

       if(typeof $.tipsy != 'undefined') $("img.pr_item_tip").tipsy({ fade: true, gravity: 'n', title: $.getItemTip() });
        $("a").each(function() {
            if ($(this).attr("href") && $(this).attr("href").indexOf('http://') == 0)
                if ($(this).attr('href').indexOf(window.location.host) < 0)
                $(this).attr("href", $(this).attr("href").replace('http://', 'http://' + window.location.host + "/"));
            if ($(this).attr("href") && $(this).attr("href").indexOf('https://') == 0)
                if ($(this).attr('href').indexOf(window.location.host) < 0)
                $(this).attr("href", $(this).attr("href").replace('https://', 'https://' + window.location.host + "/"));
        });

        $(".pidelorapido_remove").each(function() {
            $(this).remove();
        });

        $('input[name="AddToCart"]').unbind().attr("onclick", "").click(function() {
            $.pr_cart.add(proxy.ticket);
            return false;
        });
        $('img[name="addtocart"]').parent().attr("href", "javascript:void(0);").unbind().attr("onclick", "").click(function() {
            $.pr_cart.add(proxy.ticket);
            return false;
        });

        $('a#itemdets_submit_img').unbind().attr("onclick", "").attr("href", "javascript:void(0);").click(function() {
            $.pr_cart.add(proxy.ticket);
            return false;
        });

        proxy.ready = true;
        // 
        if (proxy.ticket.ProductPrice < 1 && $(".buyBox .enterZip").length > 0) {
            $(".pidelorapido_add").unbind("click").addClass("empty").attr("onclick", "");
            $(".pidelorapido_final").text("0.00");
        }
        // extraction
        if (proxy.Conf.ExtractServerSide) return;
        if ($("#sisterSiteContainer"))
            $("#sisterSiteContainer").remove();
        if (window.location.href.indexOf('productDisplay') > 0) {
            $(".Type11A").each(function(i) {
                if ($(this).text() && $(this).text().indexOf('$') > 0) {
                    $("#proxy_price").html($('#selectedItemLink').text() + " " + $(this).text().substring($(this).text().indexOf('$')).split(' ')[0] + ' <a>Agregar a Carreta</a>');
                    return false;
                }
            });
        } else if (window.location.href.indexOf('product.do') > 0) {
        $.watchProduct();
        } else if (window.location.href.indexOf('Product.aspx') > 0) {
            $(".final .zmp").each(function(i) {
                if ($(this).text() && $(this).text().indexOf('$') >= 0) {
                    $("#proxy_price").html($("#bcaBreadcrumbBottom dd:has(a):last").text() + " " + $(this).text().substring($(this).text().indexOf('$')) + ' <a>Agregar a Carreta</a>');
                    return false;
                }
            });
        } else if (window.location.href.indexOf('nplm=') > 0) {
            $("#proxy_price").html($("#breadcrumb li:has(a):last").text() + " " + $('#price').text() + ' <a>Agregar a Carreta</a>');
        }
    }
})(jQuery);

 


 