(function ($) {

  Drupal.behaviors.featuredContent = {
    attach: function (context) {
      // show manual or filter fieldset depending on type selection
      var type = $('#edit-featured-content-block-type');
      if (type) {
        showHideFeaturedBlockSettings(type);
      }
      $('#edit-featured-content-block-type').bind('change', {}, onchangeFeaturedBlockSettings);
    
      // show style select list depending on display selection
      var display = $('#edit-featured-content-block-display');
      if (display) {
        showHideFeaturedBlockStyleSettings(display);
      }
      $('#edit-featured-content-block-display').bind('change', {}, onchangeFeaturedBlockStyleSettings);
    
      // show read more fields depending on more selection
      var more = $('#edit-featured-content-block-more-display');
      if (more) {
        showHideFeaturedBlockMoreSettings(more);
      }
      $('#edit-featured-content-block-more-display').bind('change', {}, onchangeFeaturedBlockMoreSettings);
    
      // show rss fields depending on rss selection
      var rss = $('#edit-featured-content-block-rss-display');
      if (rss) {
        showHideFeaturedBlockRSSSettings(rss);
      }
      $('#edit-featured-content-block-rss-display').bind('change', {}, onchangeFeaturedBlockRSSSettings);
    }
  };

  function onchangeFeaturedBlockSettings(event) {
    showHideFeaturedBlockSettings($(this));
  }

  function showHideFeaturedBlockSettings(select) {
    var choice = select.attr('value');
    if (choice == 'manual') {
      $('fieldset.featured-content-block-filter').hide();
      $('fieldset.featured-content-block-cck').hide();
      $('fieldset.featured-content-block-manual').show();
    }
    else if (choice == 'filter') {
      $('fieldset.featured-content-block-manual').hide();
      $('fieldset.featured-content-block-cck').hide();
      $('fieldset.featured-content-block-filter').show();
    }
    else if (choice == 'cck') {
      $('fieldset.featured-content-block-manual').hide();
      $('fieldset.featured-content-block-filter').hide();
      $('fieldset.featured-content-block-cck').show();
    }
  }

  function onchangeFeaturedBlockStyleSettings(event) {
    showHideFeaturedBlockStyleSettings($(this));
  }

  function showHideFeaturedBlockStyleSettings(select) {
    var choice = select.attr('value');
    if (choice == 'links') {
      $('.form-item-featured-content-block-style').show();
    }
    else {
      $('.form-item-featured-content-block-style').hide();
    }
  }

  function onchangeFeaturedBlockMoreSettings(event) {
    showHideFeaturedBlockMoreSettings($(this));
  }

  function showHideFeaturedBlockMoreSettings(select) {
    var choice = select.attr('value');
    if (choice == 'custom') {
      $('fieldset#edit-more').show();
      $('.form-item-featured-content-block-more-text').show();
      $('.form-item-featured-content-block-more-url').show();
      $('.form-item-featured-content-block-more-num').hide();
      $('.form-item-featured-content-block-more-style').hide();
      $('.form-item-featured-content-block-more-title').hide();
      $('.form-item-featured-content-block-more-header').hide();
      $('.form-item-featured-content-block-more-footer').hide();
    }
    else if (choice == 'none') {
      $('fieldset#edit-more').hide();
    }
    else if (choice == 'links') {
      $('fieldset#edit-more').show();
      $('.form-item-featured-content-block-more-text').show();
      $('.form-item-featured-content-block-more-url').hide();
      $('.form-item-featured-content-block-more-num').show();
      $('.form-item-featured-content-block-more-style').show();
      $('.form-item-featured-content-block-more-title').show();
      $('.form-item-featured-content-block-more-header').show();
      $('.form-item-featured-content-block-more-footer').show();
    }
    else {
      $('fieldset#edit-more').show();
      $('.form-item-featured-content-block-more-text').show();
      $('.form-item-featured-content-block-more-url').hide();
      $('.form-item-featured-content-block-more-num').show();
      $('.form-item-featured-content-block-more-style').hide();
      $('.form-item-featured-content-block-more-title').show();
      $('.form-item-featured-content-block-more-header').show();
      $('.form-item-featured-content-block-more-footer').show();
    }
  }

  function onchangeFeaturedBlockRSSSettings(event) {
    showHideFeaturedBlockRSSSettings($(this));
  }

  function showHideFeaturedBlockRSSSettings(checkbox) {
    if (checkbox.attr('checked')) {
      $('fieldset#edit-rss').show();
    }
    else {
      $('fieldset#edit-rss').hide();
    }
  }

})(jQuery);
;

/**
 * @file
 * Adds some show/hide to the admin form to make the UXP easier.
 *
 */
(function($){
  Drupal.behaviors.video = {
    attach: function (context, settings) {
      //lets see if we have any jmedia movies
      if($.fn.media) {
        $('.jmedia').media();
      }
	
      video_hide_all_options();
      $("input[name='video_convertor']").change(function() {
        video_hide_all_options();
      });

      // change metadata options
      video_hide_all__metadata_options();
      $("input[name='video_metadata']").change(function() {
        video_hide_all__metadata_options();
      });

      $('.video_select').each(function() {
        var ext = $(this).attr('rel');
        $('select', this).change(function() {
          if($(this).val() == 'video_play_flv') {
            $('#flv_player_'+ext).show();
          } else {
            $('#flv_player_'+ext).hide();
          }
          if($(this).val() == 'video_play_html5') {
            $('#html5_player_'+ext).show();
          } else {
            $('#html5_player_'+ext).hide();
          }
        });
        if($('select', this).val() == 'video_play_flv')
          $('#flv_player_'+ext).show();
        
        if($('select', this).val() == 'video_play_html5')
          $('#html5_player_'+ext).show();
        else
          $('#html5_player_'+ext).hide();
      });
	
      if(settings.video) {
        $.fn.media.defaults.flvPlayer = settings.video.flvplayer;

      }
	
      //lets setup our colorbox videos
      $('.video-box').each(function() {
        var url = $(this).attr('href');
        var data = $(this).metadata();
        var width = data.width;
        var height= data.height;
        var player = settings.video.player; //player can be either jwplayer or flowplayer.
        $(this).colorbox({
          html: '<a id="video-overlay" href="'+url+'" style="height:'+height+'; width:'+width+'; display: block;"></a>',
          onComplete:function() {
            if(player == 'flowplayer') {
              flowplayer("video-overlay", settings.video.flvplayer, {
                clip: {
                  autoPlay: settings.video.autoplay,
                  autoBuffering: settings.video.autobuffer
                }
              });
            } else {
              $('#video-overlay').media({
                flashvars: {
                  autostart: settings.video.autoplay
                },
                width:width,
                height:height
              });
            }
          }
        });
      });
    }
  };


  function video_hide_all_options() {
    $("input[name='video_convertor']").each(function() {
      var id = $(this).val();
      $('#'+id).hide();
      if ($(this).is(':checked')) {
        $('#' + id).show();
      }
    });
  }

  function videoftp_thumbnail_change() {
    // Add handlers for the video thumbnail radio buttons to update the large thumbnail onchange.
    $(".video-thumbnails input").each(function() {
      var path = $(this).val();
      if($(this).is(':checked')) {
        var holder = $(this).attr('rel');
        $('.'+holder+' img').attr('src', settings.basePath + path);
      }
    });

  }

  function video_hide_all__metadata_options() {
    $("input[name='video_metadata']").each(function() {
      var id = $(this).val();
      $('#'+id).hide();
      if ($(this).is(':checked')) {
        $('#' + id).show();
      }
    });
  }
})(jQuery);;

