/*
Phil Renaud the mad scientist behind this.
phil@rhinointernet.com
http://rhinointernet.com
asdf
*/



$(document).ready(function(){
   if ($('.buyProductForm').length) {
      newcart();
   }; //if buyProductForm exists
   if ($('#productfinder').length) {
      productnamesearch();
   };
});








/*==( Cart in a fancybox. )======================================================*/

function newcart(){



//   $('body').append('<div class="hideme"><div id="popuppy"></div></div>');
$('table.buyProductForm').wrap('<div class="hideme"><div id="popuppy"></div></div>');


$('div.productDetails').find('h1').prependTo('#popuppy');

$('.orderbuttoncontainer').append('<a href="#popuppy" class="fancyboxbutton">Order Sample</a>');
$('#popuppy').find('h1').css({'textTransform': 'uppercase', 'fontSize': '15px', 'color': '#922931', 'textAlign': 'center', 'marginBottom': '20px'});

$('#popuppy').append('<p style="font-size: 10px; color: #999; margin-top: 15px;">Sample purchases are non-returnable. Orders received by 5:00PM (PST) will ship within two business days.</p>');


   $(".fancyboxbutton").fancybox({
   	'titleShow'		: false,
   	'transitionIn'	: 'fade',
   	'padding': 40, 
   	'overlayOpacity' : 0.5,
   	'overlayColor' : '#000',
   	'transitionOut'	: 'fade',
   	'autoDimensions' : false,
   	'width' : 400
   });

}; //newcart

var timerID;
function productnamesearch(){

   $('#productfinder select').live('change', function ()
   {
      if ($(this).val() != 0) {
         $(this).addClass('selected');
      } else {
         $(this).removeClass('selected');
      }
   });

   $('.searchproductname').live('click', function ()
   {
      if ($(this).val() == 'Enter Product Name') {
         $(this).val('');
         $(this).addClass('selected');
      }
   }).live('blur', function ()
   {
      if ($(this).val() == '') {
         $(this).val('Enter Product Name');
         $(this).removeClass('selected');
      }
   }).live('keyup', function (event)
   {
      $(this).css('font-weight', 'bold');
      clearTimeout(timerID);
      timerID = setTimeout(function ()
      {
         $('#productfinder input[value=Find Products]').click();
      }, 500);
   });


}


