function updateOuterFrame(outer_frame)
{
  $("#outer_frame_" + outer_frame).click();
  updateOnClick();
}

function updateSize(size)
{
  $("#size_" + size).click();
  updateOnClick();  
}

function updateFeaturedPhoto(){
  var frame_style = $('[name=frame_style]:checked').val()
  var outer_frame = $('[name=outer_frame]:checked').val()
  
  $("#featured_photo").attr('src', "/assets/kidsunlimitedphotoboard/images/" + frame_style + "-" + outer_frame + "_photo.jpg");
}

function showPhoto(id, style){
  //$("#featured_photo").attr('src', "/assets/kidsunlimitedphotoboard/images/" + style + "-None_photo.jpg");
  //$("#featured_photo").attr('src', "/assets/kidsunlimitedphotoboard/images/" + id + "_frame_with_photo.jpg");
  $("#frame_style_" + style).click();
  updateFeaturedPhoto();
  // $("#frame_link").attr('href', "/products/show/" + id);
  // $("#frame_link_2").attr('href', "/products/show/" + id);

  return false;
}

function updatePrices(productData)
{
  var frame_style = $('[name=frame_style]:checked').val();
  var outer_frame = $('[name=outer_frame]:checked').val()
  var giving_level = $('[name=giving_level]:checked').val()
  var size = $('[name=size]:checked').val()
  
  key = size + '-' + frame_style + '-' + outer_frame + '-Bronze'
  $('#bronze_price').html(productData[key] && productData[key].price)
  $('#bronze_donation').html(productData[key] && productData[key].donation)

  key = size + '-' + frame_style + '-' + outer_frame + '-Silver'
  $('#silver_price').html(productData[key] && productData[key].price)
  $('#silver_donation').html(productData[key] && productData[key].donation)

  key = size + '-' + frame_style + '-' + outer_frame + '-Gold'
  $('#gold_price').html(productData[key] && productData[key].price)
  $('#gold_donation').html(productData[key] && productData[key].donation)
  
  key = size + '-' + frame_style + '-' + outer_frame + '-' + giving_level
  if(productData[key]){
    $("#frame_link").attr('href', "/products/show/" + productData[key].id);
    $("#frame_link_2").attr('href', "/products/show/" + productData[key].id);
  } else {
  }
}

function updateOnClick()
{
  updatePrices(productData);
  updateFeaturedPhoto();
}

$(document).ready(function() {
  productData = $.getJSON("/products/json", function(json){ productData = json })

  // $('.frame_style_radio').click(function(e){
  //   console.log('clicked frame style e');
  //   console.log($(this).val())
  // })

  $('input[type="radio"]').click(function(e){
    updateOnClick();
  });  
  
  updatePrices(productData);
});
