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

  //General
  $('button, label, li, input')
    .bind('mouseover focus', function(){ $(this).addClass('hover'); })
    .bind('mouseout blur', function(){ $(this).removeClass('hover'); });
  $('#content .wp-caption a').lightBox();

  //Home
  if($('body.page-template-page-home-php').length) {
    $('#home-select')
      .mouseenter(function(){ $(this).addClass('hover'); })
      .mouseleave(function(){ $(this).removeClass('hover'); })
      .click(function(){ $(this).toggleClass('hover'); });
    $('#home-select label')
      .mouseup(function(){
        $('#home-select label').removeClass('checked');
        $(this).addClass('checked');
        $(this).find('input').attr('checked', true);
        cid = $(this).find('input').val();
        $('#home-s1 .controller').removeClass('selected');
        $('#home-s1 .controller.c'+cid).addClass('selected');
      });
    Cufon.replace('body.page-template-page-home-php h1', {
      color: '-linear-gradient(#e9d9d0,#c1a291)',
      textShadow: '2px 2px #000'
    });
    Cufon.replace('#home-s2 h2', {
      textShadow: '1px 1px #000'
    });
    Cufon.replace('#home-videos h3, #home-s3 h3');

  //other pages
  } else {
    Cufon.replace('h1, h2:not(:has(a)), h3:not(:has(a)), caption, .thatcart-salesagreement label');
    Cufon.replace('h2 a, h3 a', { hover: true });
  }
  
  //macro library page
  if($('body.page-template-page-macros-php').length) {
    $('#v360-search-keywords').focus(function(){
      if($(this).val() == $(this).attr('title')) {
        $(this).val('').removeClass('blur');
      }
    }).blur(function(){
      if($(this).val() == '') {
        $(this).val($(this).attr('title')).addClass('blur');
      }
    }).addClass('blur');
    
    $('#search-macros').submit(function(){
      if($('#v360-search-keywords').val() == $('#v360-search-keywords').attr('title')) {
        $('#v360-search-keywords').val('');
      }
    });
  }

});

function switchVideo(videoID, autoPlay, link){
  params = (autoPlay ? '&autoplay=1' : '') + '&amp;hl=en_US&amp;fs=1?rel=0&amp;color1=0xc7d1dc&amp;color2=0xc7d1dc';
  jQuery('#home-video-1').html('').flash({
    src: 'http://www.youtube.com/v/'+videoID+params,
    width: 320,
    height: 205,
    wmode: 'opaque',
    allowFullScreen: 'true',
    allowscriptaccess: 'always'
  });
  if(link) {
    jQuery('#home-videos li, #home-videos li *').css({ opacity: 1 });
    jQuery(link).css({ opacity: .3 }).find('*').css({ opacity: .3 });
    jQuery('#home-videos .playing-arrow').remove();
    jQuery(link).after('<div class="playing-arrow"></div>');
  }
}
