$(function(){
  $('a.colorbox').colorbox({
    href: $(this).attr('href'),
    close:"",
    opacity:0.5,
    width:768,
    height:550,
    scrolling:false
  });
});

$(document).ready(function(){
  wh = $(window).height()
  box = $('#flash-messages')
  bh = box.height()
  box.css({'position': 'fixed', 'top': wh})
  box.show().animate({ 'top': wh-bh-25}, 300).delay(5000).animate({ 'top': wh }, 300, function(){ $('#flash-messages').hide() })
  box = $('#dialog-messages')
  bh = box.height()
  box.css({'position': 'fixed', 'top': wh})
  box.show().animate({ 'top': Math.floor((wh/2)-(bh/2))}, 300).delay(5000).animate({ 'top': wh }, 300, function(){ $('#dialog-messages').hide() })
});

function remove_fields(element){
  $(element).prev("input[type=hidden]").val("1");
  $(element).closest('.shipping_fields').hide();
}

function add_fields(link, association, content){
  var new_id = new Date().getTime();
  var regexp = new RegExp("new_" + association, "g")
  $(link).parent().before(content.replace(regexp, new_id));
}

Number.prototype.formatMoney = function(c, d, t){
  if(c == null && d == null && t == null){
    c = 2;
    d = ',';
    t = '';
  }
  var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
  return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};


