var originalArticleHeight; // set from inline
var origTextSize;
var origQuoteSize;
$(document).ready(function(){
  origTextSize = parseFloat($('#articleText').css('font-size'));
  changePreviewHeadline($('#relatedContentAlt .relatedContentRow:first').attr('id'));
  $('#articleRelated').css('min-height',$('#articleComments').height());
});

function resizeText(multiplier)
{
  multiplier = parseFloat(multiplier);
  if(multiplier != 1)
  {
    currTextSize = parseFloat($('#articleText').css('font-size'));
    $('#articleText').css('font-size', currTextSize * multiplier);
  }
  else
  {
    $('#articleText').css('font-size', origTextSize);
  }
}

function toggleReadMore()
{
  var height = ($('#articleText.fishingArticle').length > 0 ? '550' : '800');
  if($('#articleText').height()==height)
  {
    $('#articleText').css('height', 'auto');
    $('#readMoreLink').text('{-} read less');
  }
  else
  {
    $('#articleText').css('height',height+'px');
      $('#readMoreLink').text('{+} read more');
  }
  $('#innerContent').css('height','auto');
  resizeInnerContent();
}

function toggleShowComments()
{
  if($('.comment:visible').length > 1)
  {
    $('.comment:not(:first)').hide();
    $('#showCommentsLink').text($('#showCommentsLink').text().replace('Hide','Show All'));
  }
  else
  {
    $('.comment').show();
    $('#showCommentsLink').text($('#showCommentsLink').text().replace('Show All','Hide'));
  }
  $('#articleRelated').css('min-height',$('#articleComments').height());
}

function postComment()
{
  $.post(window.location.href.replace(/\?.+$/,''),
    {
      commentFormName: $('#commentFormName').val(),
      commentFormEmail: $('#commentFormEmail').val(),
      commentFormText: $('#commentFormText').val(),
      captcha: $('#commentFormCaptcha').val()

    },postedComment);
  return false;
}

function postedComment(response)
{
  var responses = response.split('|||');
  $('#commentError').html(responses[0]);
}

function changePreviewHeadline(itemId) {
  if($('#relatedPreviewHeadline').length == 0)
    return false;
  
  $('#articleRelated *').stop(true,true);
  clearTimeout(headlineTimer);
  var headline = $('#'+itemId);
  if(headline.hasClass('activeHeadline')) return null;
  $('.headline').removeClass('activeHeadline');
  var headlineType = headline.attr('className');
  headline.children('.headline').addClass('activeHeadline');
 if ($('#articleTags').html() && $('#articleTags').html().replace(/^\s*/, '').replace(/\s*$/, '')!="") {
  $('#relatedPreviewHeadline').css('background-image',
      $('#relatedPreviewHeadline').css('background-image').replace('icons.png','icons_active.png'));
  $('#relatedPreviewHeadline').css('background-position',
      headline.children('.headline').css('background-position'));
  } else {
     $('#articleTags').hide();
 }
  $('#relatedPreviewHeadline').text(headline.children('a').text());
  $('#relatedPreviewThumb img').attr('src',headline.find('.headlineThumb img:first').attr('src'));
  $('#relatedPreviewDesc').html(headline.children('p').html());
  $('#relatedContentPreview a').attr('href',headline.children('a').attr('href'));
}

  function changePreviewHeadlineIE(itemId) {
    var headline = $('#'+itemId);
    if(headline.hasClass('activeHeadline')) return null;
    $('#headlines *').stop(true,true);
    clearTimeout(headlineTimer);
    $('#headlinesList li').removeClass('activeHeadline');
    var headlineType = headline.attr('className');
    headline.addClass('activeHeadline');
    $('#headlinesPreview *').hide();
    $('#previewIcon').css('background-image',$('#previewIcon').css('background-image').replace(/[a-z_]+\.png/i, headlineType + '.png'));
    $('#previewHeadline a').text(headline.children('a').text());
    $('#previewImage img').attr('src',headline.children('.headlineImageUrl').text());
    $('#previewText').children('p').text(headline.children('p').text());
    $('#headlinesPreview a').attr('href',headline.children('a').attr('href'));
    $('#headlinesPreview *').show();
  }

