
function product(id, name, url, image, price, parentId){
  this.id = id;
  this.name = name;
  this.image = image;
  this.price = price;
  this.highestRound=1;
  this.display = function(){
    return "<div><img src='"+image+"' alt='"+name+"' class='prod"+id+"' style='cursor: default;' /><br /><a href='"+url+"' class='productHeading' target='_blank'>"+name+",</a> <span class='price'>$"+price+"</span></div>";
  }
}

function resetHighestRounds(){
  $.each(products, function(key, value){
    eval('value.highestRound = '+$('.prod'+value.id).size());
  });
}

function getNextRoundEltId(id, highestRound){
  var match;
  var pos;
  switch(highestRound){
    case 2:
      match = Math.ceil(id/2);
      pos = ((Math.ceil(id/2) + 1) %2) + 1;
      break;
    case 3:
      match = Math.ceil(id/4);
      pos = ((Math.ceil(id/4) + 1) %2) + 1;
      break;
    case 4:
      match = Math.ceil(id/8);
      pos = ((Math.ceil(id/8) + 1) %2) + 1;
      break;
    case 5:
      match = Math.ceil(id/16);
      pos = ((Math.ceil(id/8) + 1) %2) + 1;
      break;

    default:
      break;
  }
  
  return 'div[id|=R'+(highestRound) +'-P'+match+']';
}

$('#first_name').focus(function(){
  if($(this).val() == 'First Name'){
    $(this).val('');
  }
});

$('#first_name').focusout(function(){
  if($(this).val() == ''){
    $(this).val('First Name');
  }
});

$('#last_name').focus(function(){
  if($(this).val() == 'Last Name'){
    $(this).val('');
  }
});

$('#last_name').focusout(function(){
  if($(this).val() == ''){
    $(this).val('Last Name');
  }
});

var settings = {
      tl: { radius: 20 },
      tr: { radius: 20 },
      bl: { radius: 20 },
      br: { radius: 20 },
      antiAlias: true
    }
curvyCorners(settings, document.getElementById('content'));

var products = new Array();
products[0] = prod1 = new product(1, "Mexican Blown Glass Shot Glasses", "http://worldofgood.ebay.com/RUBYMexican-Blown-Glass-Art-6-Shot-Glasses-by-Novica/380191107494/item", "images/shotglasses.jpg", '29.99', 'R1-P1');
products[1] = prod2 = new product(2, "Oil Drum Art Wall Hanging", "http://worldofgood.ebay.com/Sunflower-Tree-Oil-Drum-Wall-Hanging-Fair-Trade-Winds/270515375352/item", "images/drumart.jpg", '32.95', 'R1-P1');
products[2] = prod3 = new product(3, "Crochet Raffia Tote Bag", "http://worldofgood.ebay.com/Mad-Imports-Ile-St-Marie-Crochet-Raffia-Tote-Bag/270490639693/item", "images/raffiaBag.jpg", '79.95', 'R1-P2');
products[3] = prod4 = new product(4, "Recycled Glass Rings", "http://worldofgood.ebay.com/Recycled-Glass-Rings/170404857423/item", "images/rings.jpg", '32.50', 'R1-P2');
products[4] = prod5 = new product(5, "Stainless Steel Bottle", "http://worldofgood.ebay.com/Blue-Q-Cool-It-Igloo-Stainless-Steel-Bottle-20oz-Eskimo/370326811749/item", "images/bottle.jpg", '17.99', 'R1-P1');
products[5] = prod6 = new product(6, "Set of 4 Organic Herb", "http://worldofgood.ebay.com/Set-of-4-Organic-Herb-Kits/250531897243/item", "images/herbkit.jpg", '38.00', 'R1-P1');
products[6] = prod7 = new product(7, "Fair Trade Satchel", "http://worldofgood.ebay.com/108-Malas-Block-Printed-Fair-Trade-Kaya-Yellow-Satchel/260535609936/item", "images/satchel.jpg", '29.99', 'R1-P2');
products[7] = prod8 = new product(8, "San Antonio Scarf", "http://worldofgood.ebay.com/San-Antonio-Scarf---Gold/400055528063/item", "images/scarf.jpg", '25.99', 'R1-P2');
products[8] = prod9 = new product(9, "Eco-Friendly T-Shirt", "http://worldofgood.ebay.com/REUSE-T-SHIRT-Certified-Green-Eco-Friendly-Product/300397936424/item", "images/tshirts.jpg", '13.00', 'R1-P1');
products[9] = prod10 = new product(10, "Organic Hemp Shoes", "http://worldofgood.ebay.com/Organic-Hemp-Shoes/230363779089/item", "images/shoes.jpg", '33.54', 'R1-P1');
products[10] = prod11 = new product(11, "Cotton Napkin Set", "http://worldofgood.ebay.com/OliveAqua-Cotton-Napkins-Set4---Fair-Trade-Winds/270518236025/item", "images/napkins.jpg", '18.00', 'R1-P2');
products[11] = prod12 = new product(12, "Wooden Coaster Set", "http://worldofgood.ebay.com/Wooden-Coasters-Set8--Fiesta-Flowers--Fair-Trade-Winds/280463915431/item", "images/coasters.jpg", '20.00', 'R1-P2');
products[12] = prod13 = new product(13, "Recycled Record Earrings", "http://worldofgood.ebay.com/Surf-City---Recycled-Record-Earrings/150263313344/item", "images/record-earrings.jpg", '30.00', 'R1-P1');
products[13] = prod14 = new product(14, "Copper and Bronze Cuff", "http://worldofgood.ebay.com/Silver-Scroll-Copper-and-Bronze-Cuff---Chile/150412559441/item", "images/cuff.jpg", '53.99', 'R1-P1');
products[14] = prod15 = new product(15, "Fair Trade Tie Top", "http://worldofgood.ebay.com/Mata-Traders-Fair-Trade-Tie-Top/260505926302/item", "images/shirt.jpg", '48.00', 'R1-P2');
products[15] = prod16 = new product(16, "Aromatherapy Oil Set", "http://worldofgood.ebay.com/Organic-Aromatherapy-Body-Oil-Revitalize/120304688171/item", "images/Aromatherapy.jpg", '37.50', 'R1-P2');

$('td').attr('valign', 'middle').attr('align', 'middle');
$('td').each(function(){
  $(this).append('<input type="hidden" name="' + $(this).attr('id')+'" />');
});

$('div#R1-P1').html(prod1.display());
$('div#R1-P2').html(prod2.display());
$('div#R1-P3').html(prod3.display());
$('div#R1-P4').html(prod4.display());
$('div#R1-P5').html(prod5.display());
$('div#R1-P6').html(prod6.display());
$('div#R1-P7').html(prod7.display());
$('div#R1-P8').html(prod8.display());
$('div#R1-P9').html(prod9.display());
$('div#R1-P10').html(prod10.display());
$('div#R1-P11').html(prod11.display());
$('div#R1-P12').html(prod12.display());
$('div#R1-P13').html(prod13.display());
$('div#R1-P14').html(prod14.display());
$('div#R1-P15').html(prod15.display());
$('div#R1-P16').html(prod16.display());

$('div#R2-P1').html(prod1.display());
$('div#R2-P2').html(prod3.display());
$('div#R2-P3').html(prod6.display());
$('div#R2-P4').html(prod7.display());
$('div#R2-P5').html(prod9.display());
$('div#R2-P6').html(prod12.display());
$('div#R2-P7').html(prod14.display());
$('div#R2-P8').html(prod15.display());
$('div#R3-P1').html(prod3.display());
$('div#R3-P2').html(prod7.display());
$('div#R3-P3').html(prod9.display());
$('div#R3-P4').html(prod14.display());
$('div#R4-P1').html(prod3.display());
$('div#R4-P2').html(prod14.display());
$('div#R5-P1').html(prod3.display());
