/* TODO : set the icon on the right side of ReadMore*/
var iconAlign = 'right';
/* TODO : customize Read More label */
var readMoreLbl = 'Read More'

$(document).ready(function(){
  function changeVisibility($element) {
    var $div = $element.next('div');
    $div.find('*:first').css('display') == 'none' ? showContent($div)
                                  : hideContent($div);
  }
  function hideContent($element) {
    $element.find('*').css('display','none');
    $element.parent().find('h2 div').css('background-position', iconAlign+' -56px');
  }
  function showContent($element) {
    $element.find('*').css('display','');
    $element.parent().find('h2 div').css('background-position', iconAlign+' 0px');
  }
  var regex = new RegExp('^(?:.|\n)*?<h2>((?:.|\n)*?)</h2>((?:.|\n)*)$','i');
  $('.solutionToolbox .contentCenter .publication').each(function(){
    $(this).html($(this).html().replace(regex,'<h2><div>'+readMoreLbl+'</div>$1</h2><div>$2</div>'));
  });

  /* TODO : styles css */
  var sel = '.solutionToolbox .contentCenter .publication h2';
  $(sel+' div').css('float', 'right')
               .css('height', '25px')
               .css('padding-'+iconAlign, '28px')
               .css('background','transparent url(http://www.webdesignerwall.com/demo/jquery/images/arrow-square.gif) no-repeat '+iconAlign+' 0')
               .css('color', '#4FA600')
               .css('font-weight', 'normal');
  $(sel).css('cursor','pointer').css('padding','7px 0 10px 10px').css('margin','0 0 8px').css('background-color','#EAEAEA');
  /* TODO : styles css */

  $(sel).click(function(){changeVisibility($(this));})
               .hover(function(){$(this).css('text-decoration','underline')},function(){$(this).css('text-decoration','none')});
  $(sel).parent().css('border','solid 0px green').css('padding','10px 10px 5px');
  $('.solutionToolbox .contentCenter .publication h2 + div').each(function(i){hideContent($(this));});
  //$('.solutionToolbox .contentCenter .publication:eq(2) h2').click();
});
