jQuery(document).ready(function($){

  $('#coda-nav-1 ul li').css('margin-right', '4px').filter('li:last').addClass('last').css('margin-right', '');
  $('#coda-slider-1').codaSlider({
    dynamicArrows: false,
    dynamicTabs: false,
    autoSlide: true,
    autoSlideInterval: 10000,
    firstPanelToLoad: 1,
  });

  $(".youtube_video").live('click', function() {
    $.fancybox({
      'padding'    : 0,
      'autoScale'    : false,
      'transitionIn'  : 'none',
      'transitionOut'  : 'none',
      'title'      : this.title,
      'width'      : 680,
      'height'    : 495,
      'href'      : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
      'type'      : 'swf'
    });
    return false;
  });

  $(".toggle-text").css({ cursor: 'pointer' });
  $(".toggle-text").click(function(){
    if($(this).parents("p").next(".the-text:visible").length > 0){
      $(this).parents("p").next(".the-text").slideUp()
    }else{
      $(this).parents("p").next(".the-text").slideDown()
    }
  });

  $("span.toggle-text").click();

  $("select.donate_amount").change(function(){

    if($(this).val() == "0")
    {
      $(this).parents("table").find("tr.donate_own_amount").show().find("input").focus();
    }
    else
    {
      $(this).parents("table").find("tr.donate_own_amount").hide().find("input").val($(this).val());
    }

  });

});

function newPopupWindow(url, title, w, h) {
  var features = "resizable=yes,toolbar=no,scrollbars=no,copyhistory=no,location=no,directories=no,status=no,menubar=no,width=" + w + ",height=" + h;
  popupWindow = window.open(url, title, features);
  popupWindow.focus();
}

function newImageWindow(prod_id,fence_id) {
  popupUrl    = "image.php@prod_id=" + prod_id + "&fence_id=" + fence_id;
  popupWindow = window.open(popupUrl,'image','resizable=yes,toolbar=no,scrollbars=yes,location=no,directories=no,status=no,menubar=no,width=550,height=700');
  popupWindow.focus();
}

function openTellAFriendWindow(prod_id,fence_id) {
  popupUrl    = "tell_a_friend.php@prod_id=" + prod_id + "&fence_id=" + fence_id;
  popupWindow = window.open(popupUrl,'tellAFriend','resizable=yes,toolbar=no,scrollbars=yes,location=no,directories=no,status=no,menubar=no,width=550,height=700');
  popupWindow.focus();
}

function validateAmount(amount){
  if(amount.value.match( /^[0-9]+(\.([0-9]+))?$/)){
    return true;
  }else{
    alert('You must enter a valid donation.');
    amount.focus();
    return false;
  }
}

function SelectAll(id) {
  document.getElementById(id).focus();
  document.getElementById(id).select();
}
