// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require fancybox
//= require jquery_ujs
//= require hexcmsadmin
//= require_tree .

//= require_self

function spinner_show() {
    $('#spinner').show();
    $('body').addClass('curWait');
}
function spinner_hide() {
    $('body').removeClass('curWait');
    $('#spinner').hide();
}

/* FLASHES */

var Flash = {
  // last used ID for flash boxes
  last_flash_id: 0,
  
  // draw a flash box
  flash: function(type, msg) {
    var str = '';
    str = '<div class=" margin-auto w400" style="display:none;" id="flash_message_'+this.last_flash_id+'"><div class="bbox">';
      str += '<div class="bbox-inner">';
  
        str += '<div class="float-right"><a href="#" class="box_close_link">X</a></div>';
        
        str += '<div class="float-left"><div class="flash flash_'+type+'">' + msg + '</div></div>';
        str += '<div class="clear"></div>';
  
      str += '</div>';
    str += '</div></div>';
    
    $('#flashes').append(str);
    $('#flashes #flash_message_'+this.last_flash_id).slideDown();
    this.last_flash_id += 1;
  }
}

function flash_notice(msg) { Flash.flash('notice', msg); }
function flash_warning(msg) { Flash.flash('notice', msg); }
function flash_error(msg) { Flash.flash('notice', msg); }

jQuery(document).ready(function() {
  // fancybox init
  $('a[rel=fancybox]').fancybox({
    'overlayColor'  : '#000',
    'titlePosition' : 'over'
  });
  
  if($.fn.tokenInput) {
    
    // tokenizer settings
    // prePopulate needs json with current values
    $('.tokenized_articles').tokenInput('/feeds/article_tokens.json', {
      theme: 'facebook-mine',
      crossDomain: false,
      minChars: 2,
      preventDuplicates: true
    });
    
    // storage_files
    $('.tokenized_storage_files').tokenInput('/feeds/storage_file_tokens.json', {
      theme: 'facebook-mine',
      crossDomain: false,
      minChars: 2,
      preventDuplicates: true
    });
    
    // tokenizer settings
    // prePopulate needs json with current values
    $('.tokenized_author').tokenInput('/feeds/author_tokens.json', {
      theme: 'facebook-mine',
      crossDomain: false,
      minChars: 2,
      preventDuplicates: true,
      tokenLimit: 1
    });
  };
  
  // BOXES
  $('a.box_close_link').live('click', function(a) {
    a.preventDefault();
    $(this).parents('.bbox').parent().slideUp('slow', function () { $(this).remove(); });
  });
  // flash_error('test flash');
  var subtitle_upcaser = new Upcaser('span.header-subtitle');
  
});

jQuery(window).load(function () {
  $('#spinner').hide();
});
