jq(window).load(function(){
  // resize page
  jq('#portal-column-one').height(jq(window).height()-70);
  jq(window).resize(function() {
    jq('#portal-column-one').height(jq(window).height()-70);
  });
  // move colophon to left column
  jq('#portal-column-one .visualPadding').append(jq('#portal-colophon'));

  // dropdown selects replacement
  jq('#portal-column-one select').each(function(){
    jq(this).msDropDown({visibleRows:jq('option', this).size(), rowHeight:14});
  });
  jq('#content select').each(function(){
    jq(this).msDropDown({visibleRows:jq('option', this).size(), rowHeight:14});
  });
  // even odd f. table headers 
  jq('table.plain th:odd').addClass('odd');
  // fix empty cufons
  jq('.portletTopLeft').each(function(){
    jq(this).remove();
  });
  jq('.portletTopRight').each(function(){
    jq(this).remove();
  });
  // lawyer search title
  var portlettitle = jq('#portlet-lawyersearch dt');
  portlettitle.text(jq.trim(portlettitle.text()));
  // collage titles
  jq('.collage-item dt span').each(function(){
    var collagetitle = jq(this);
    collagetitle.text(jq.trim(collagetitle.text()));
  });
  // documentheading
  if(!jQuery('body').hasClass('template-newsitem_view') && !jQuery('body').hasClass('template-document_view')) {
    var heading = jq('span#parent-fieldname-title');
    if (heading.text() == '')
      heading = jq('h1.documentFirstHeading');
    heading.text(jq.trim(heading.text()));
  }
  Cufon.set('fontFamily', 'Helvetica Neue Light');
  Cufon.replace('li.fake');
  Cufon.replace(jq('ul#portal-globalnav>li>span>a'), { hover: true });
  // global nav
  // resize globalnav level1 widths
  jq('.sf-menu li').each(function(){
    var li = jq(this);
    var used_width = li.width();
    li.addClass('sfHover');
    jq('ul', li).each(function(){
      var ul = jq(this);
      ul.css('display', 'block');
      if(ul.width() <= li.width()) {
        ul.css('width', li.width());
      }
      else {
        ul.css('width', ul.width()+5);
      }
      ul.css('height', ul.height());
      if(jq.browser.msie){
        ul.css('filter', 'alpha(opacity=75)');
      }
      ul.css('display', 'none');
    });
    li.removeClass('sfHover');
  });
  // portletheaders
  Cufon.replace(portlettitle, { hover: false });
  Cufon.replace('.portletCollection dt span', { hover: false });
  
  // collage portlets
  Cufon.replace('.collage-item dt span', { hover: false });

  // collage discreet
  jq('.collage-item .discreet').each(function(){
    var discreet_link = jq('a', this);
    if (discreet_link.text() != '')
      Cufon.replace(discreet_link, { hover: true });
    else
      Cufon.replace(jq(this), { hover: false });
  });
  // map bubble headings
  jq('.bubble h3').each(function(){
    Cufon.replace(jq(this), {hover:false});
  });
  Cufon.replace('table.listing th', { hover: false });
  Cufon.replace('table.plain th', { hover: false });
  
  // sub headline
  // Cufon.replace('.template-atct_lawyer_view div.col1 h1', {hover: false});

  // document headlines
  Cufon.set('fontFamily', 'Helvetica Neue Thin');
  if (heading != undefined){
    Cufon.replace(heading, { hover: false });
    }

  // bibliography input reset
  var title_input = jQuery('#searchbox input#Title');
  var title_default_val = title_input.val();
  title_input.focus(function(){
      if(title_default_val == title_input.val())
        title_input.val('')
  });
  title_input.blur(function(){
      if(title_input.val() == '')
        title_input.val(title_default_val);
  });
  var authors_input = jQuery('#searchbox input#getAuthors');
  var authors_default_val = authors_input.val();
  authors_input.focus(function(){
      if(authors_default_val == authors_input.val())
        authors_input.val('')
  });
  authors_input.blur(function(){
      if(authors_input.val() == '')
        authors_input.val(authors_default_val);
  });
  // horizontal scroll for lawyer bar
  var hscrollpane = jQuery('.lawyer-bar .scroll-pane');
  if(hscrollpane.height() > 0) {
    var panewidth = 0;
    jQuery('.lawyer-bar .pane-content a').each(function(){
      panewidth += 4+14; // 2*7 padding + 4 extra
      panewidth += jQuery(this).width();
    });
    jQuery('.lawyer-bar .pane-content').width(panewidth);
    var originalSizes = new Array();
    hscrollpane.jScrollHorizontalPane({scrollbarHeight:0, scrollbarMargin:0,showArrows:true});
  }
  // indenting content
  var is_to_indent = false;
  var templates_to_indent = ["template-newsitem_view",
                             "template-newsitem_cufon_view",
                             "template-document_view",
                             "template-document_cufon_view",
                             "template-base_view",
                             "template-folder_tabular_view",
                             "template-collage_view",
                             "template-fg_base_view_p3",
                             "template-folder_listing",
                             "template-atct_topic_view"];
  var template = jQuery('body');
  for (i=0; i < templates_to_indent.length; i++) {
    if (template.hasClass(templates_to_indent[i]) && !template.hasClass('section-home'))
      is_to_indent = true;
  }
  if(is_to_indent) {
    var contents = jQuery('#content > *');
    if (contents.length == 1) {
      if (contents[0].id == 'collage')
        contents = jQuery('#collage .collage-row:not(:first) .collage-item > * > *');
      else if (jQuery(contents[0]).hasClass('newsItemView'))
        contents = jQuery('#content .newsItemView .col1 > *');
      else
        contents = jQuery('#content > * > *');
    }
    contents.each(function(){
      var elem = jQuery(this);
      if (!elem.hasClass('documentActions') && !elem.hasClass('documentFirstHeading') && !elem.hasClass('listingBar') && !elem.hasClass('subjects'))
        elem.addClass('content-margin');
    });
  }
});

