var cartOpen = false;

function navigate(position, action) {
  if(action == "index") $('html, body').animate({ scrollTop: ($(position).offset().top - 60) }, 1000, 'easeOutCubic'); 
  window.location = "http://" + window.location.host.toString() + "/" + position + "-redirect";
}       

function getAjaxElements() {
  $.get('home/render_footer', function(data) {
    $('#footer_order').html(data);
    $('#footer_order').animate({opacity:1.0}, 600);
    if(parseInt($('#mini-cart-amount').html()) > 0) {
      $('#checkout_link').html('<a href="/orders/' + $('#order_number').val() + '/edit"><img src="/images/nav/checkout_active.jpg"/></a>');
    }
    else {
      $('#checkout_link').html('<img src="/images/nav/checkout.jpg" />');
    }
    $('#checkout_link').animate({opacity:1.0}, 600);
    $(".search-input").each(function(i) {
      $(this).click(function() {
        $(this).find('#text_placeholder').hide();
        $(this).find('input').show();
        $("#subscriber_email").focus();
      });
    });
  });             
}
                                 
function toggleCart() {
  if(cartOpen) {
    $("#slide-arrow-open").show(); $("#slide-arrow-close").hide(); 
    $("#mini-cart-slide").animate({ width: "0px" }, 400, "easeOutCubic");      
  }
  else {
    $("#slide-arrow-open").hide(); $("#slide-arrow-close").show();       
    if(lineItems == 0)
      $("#mini-cart-slide").show().animate({ width: ($("#mini-cart-slide-content").width())+"px" }, 400, "easeOutCubic");
    else                                                                                                                                                                                                                                                                      
      $("#mini-cart-slide").show().animate({ width: lineItems*84+110+"px" }, 400, "easeOutCubic");
  }
  cartOpen = !cartOpen;    
}

function next(anchor) {
  $('html, body').animate({ scrollTop: ($(anchor).offset().top - 60) }, 1000, 'easeOutCubic'); 
}

function setSubscriberPlaceholder(result) {
  $('#text_placeholder').attr('src', result);
  $('#text_placeholder').show();
  $("#subscriber_email").blur();
  $("#subscriber_email").hide();
}   

function setPrice(name, price) {
  $('#'+name+'-price').html((parseFloat($('#'+name+'-qty').attr('value')) * price).toFixed(2));
  return false;
}

function forceNonSSL() {
  var l = document.location.toString();
  if(l.substring(0,5) == "https") document.location = l.replace("https", "http");
}

$(document).ready(function() {
  $(".info_email").each(function(i) {
    $(this).html("info@db"+"a-co.com");
    $(this).parent().attr("href", "mailto: info@db"+"a-co.com")
  });
  $(".sales_email").each(function(i) {
    $(this).html("sales@db"+"a-co.com");
    $(this).parent().attr("href", "mailto: sales@db"+"a-co.com")
  });
  $(".press_email").each(function(i) {
    $(this).html("press@db"+"a-co.com");
    $(this).parent().attr("href", "mailto: press@db"+"a-co.com")
  });
});