String.prototype.trim = function() {
  return this.replace(/^\s+|\s+$/g,"");
}

$(function() {
  // Activate 'learn more' links and faq's
  /*$('.learnmore').each(function(){
    var more = $(this), link = $('<p><a href="javascript:;">Learn More</a></p>').click(function(){$(this).slideToggle(function(){more.slideToggle()})});
    $(this).hide().before(link);
  });*/
  $('dl.faq dt, dl.faq dd, dl.aboutus dt, dl.aboutus dd').filter('dt').addClass('link').click(function(){$(this).next('dd').slideToggle('fast');}).end().filter('dd').hide().end().filter('dl.faq dt:first').trigger('click');

  // Create email links from req'd elements
  $('span.eml').each(function(){
    var eml = $(this).text().split(/(at|dot)/);
    if (eml.length == 5) {
      var address = eml[0].trim()+"@"+eml[2].trim()+'.'+eml[4].trim();
      $(this).html('<a href="mailto:'+address+'">'+address+'</a>');
    }
  });

  if ($('body').is('#employment')) {
    // Set up tinymce
    var mceOpts = mceExtend(mceBase/*,mceSkinned*/);
    $('#message').tinymce(mceOpts);

    $("span.resumelbl label").each(function(){
			var type = $(this).attr('for');
			$(this).prepend('<input type="radio" name="resumetype" value="'+type+'" />').click(function(){
        $("input",$(this)).attr('checked',true);
        $(".resumefld:not([name^='"+type+"'])").parent().slideUp('fast',function(){ $(".resumefld[name^='"+type+"']").parent().slideDown('fast'); });
			});
		});
		$("label[for='message']").click();

  }
});


// Define tinymce defaults
var mceBase = {
  // Location of TinyMCE script
  script_url : '/includes/tinymce/jscripts/tiny_mce/tiny_mce.js',

  // General options
  theme : "advanced",
  /*width: "100%",*/
  height: "250",
  plugins : "safari,advlink,inlinepopups,paste,fullscreen",

  // Theme options
  theme_advanced_buttons1 : "undo,redo,|,justifyleft,justifycenter,|,bold,italic,bullist,|,copy,paste,pastetext,pasteword,|,link,unlink,|,formatselect,removeformat,|,fullscreen",
  theme_advanced_buttons2 : "",
  theme_advanced_buttons3 : "",
  theme_advanced_buttons4 : "",

  theme_advanced_blockformats: "p,h1,h2,h3,h4",

  theme_advanced_toolbar_location : "top",
  theme_advanced_toolbar_align : "left",
  theme_advanced_statusbar_location : "bottom",
  theme_advanced_resizing : true,
  /*theme_advanced_resizing_min_height : 200,*/
  theme_advanced_resize_horizontal : false,

  // Preview options
  plugin_preview_width: "800",
  plugin_preview_height: "600",
  plugin_preview_pageurl: "/includes/tinymce/jscripts/tiny_mce/plugins/preview/example.html",

  valid_elements: "@[title],a[name|href|title],strong/b,em/i,"
+ "#p,-ol[type|compact],-ul[type|compact],-li,br,-sub,-sup,"
+ "-blockquote,-table[border=0|cellspacing|cellpadding|width|height|align],-tr[rowspan|width|"
+ "height|align|valign],tbody,thead,tfoot,"
+ "#td[colspan|rowspan|width|height|align|valign],#th[colspan|rowspan|width|height|align|valign],"
+ "-span,-pre,address,-h1,-h2,-h3,-h4,hr[size|noshade],small,tt,big"


};
// tinymce table options
var mceTables = {
  plugins: { append:true, value: "table" },
  theme_advanced_buttons2: { append: true, value: "|,table,row_props,cell_props,delete_row,row_after"},
  table_styles: "Header 1=header1;Header 2=header2;Header 3=header3",
  table_cell_styles: "Header 1=header1;Header 2=header2;Header 3=header3;Table Cell=tableCel1",
  table_row_styles: "Header 1=header1;Header 2=header2;Header 3=header3;Table Row=tableRow1"
};
// helper function to combine tinymce option groups
function mceExtend() {
  var a = mceExtend.arguments, ac = a.length, obj = a[0];
  for (ai=1;ai<ac;ai++) {
    var ext = a[ai];
    for (i in ext) {
      if (typeof obj[i] == 'undefined') {
        obj[i] = ext[i];
      }
      if (typeof ext[i] == 'object') {
        obj[i] = ext[i].append == true ? obj[i]+","+ext[i].value : $.extend(obj[i],ext[i]);
      } else {
        obj[i] = ext[i];
      }
    }
  }
  return obj;
}