// Product Detail Page Scripts

// When the medium image is clicked, we create a new window and add the content to it.
$('.mediumImg').click(function() {
    var destUrl = $(this).attr('href'); // the URL to the large image file.
    var newWindow = window.open('', 'largeImageWindow','width=720,height=500,scrollbars=1,resizable=1'); // Open the window.
    
    newWindow.document.write('<div style="text-align:center;"><img src="' + destUrl + '" alt="" /><div><a href="javascript:close();"><img src="/btn_close.gif" title="Close Window" title="Close Window" /></div></div>'); // Add the content to the window.
    
    // Style the window contents:
    $(newWindow.document).find('head').append('<title>' + destUrl + '</title>')
    $(newWindow.document).find('body').css({'margin':'0px','padding':'0px','border':'0px'});
    $(newWindow.document).find('img').css({'border':'0px', 'margin':'5px 0'});
    
    return false;
});

$(document).ready(function() {
  $('.lowdown div.head').append('<img src="/lowdown-corner.gif" alt="" />');
  
  var ourPrice = $('.productPrice').text();
  var newPrice = ourPrice.replace(',', '');
  fixedPrice = parseFloat(newPrice);
  $('.productPrice').text('$' + fixedPrice.toFixed(2))
  
  $('.additionalProducts .container div.item:last').css('border-bottom','0px');

  if ( typeof(splitIsActive) !== "undefined" && splitIsActive === true ) {
    var paymentPrice = 0;
    paymentPrice = (fixedPrice * (1 + priceIncrease/100)) / numberOfPayments;
    // Round it to neareast .01
    paymentPrice = Math.round(paymentPrice * 100) / 100;
    $.get('/SplitPayment.html', function(html) {
      html = html.replace(/\{NUM\_PAYMENTS\}/g, numberOfPayments).replace(/\{PAYMENT\_PRICE\}/g, '<span class="price">$'+paymentPrice.toFixed(2)+'</span>');
      $(".detailBox .prices").after(html);
      //$("#splitPaymentTable td").append('<strong>'+numberOfPayments+' payments of <span>$'+paymentPrice.toFixed(2)+'</span>');
      $("form .addToCart").css('margin-top', '-28px');
      /*
      for ( i = 0; i < numberOfPayments; i++ ) {
        // Show line-by-line payment?
        $("#splitPaymentTable").append('<tr><td>'+(i+1)+'</td><td>$'+paymentPrice.toFixed(2)+'</td></tr>');
      }
      */
    });
  }
    
});
