/*
 *  Font resizing script
 *
 *  This script will add the ability for the user to increase the text size.  Although built
 *  specifically for lemonlaw.com, it should be pretty easy to implement elsewhere by setting 
 *  the variables below.
 *
 *  Written by Adam Plante at Dinkum Interactive (http://www.dinkuminteractive.com)
 *
 */

jQuery.noConflict(); //no conflict mode

function aFunction() {
  // This is an empty function that exists only to prevent the page from scrolling
  // See http://blog.reindel.com/2006/08/11/a-hrefjavascriptvoid0-avoid-the-void/
}

jQuery(document).ready( function(){
  // Set the variables
  var containingElement = ".fullPost"; // What element currently contains the content we want to resize
  var putInterfaceHere = '#postTools'; // Leave this blank to put the interface above the container div.
  var targetElement = "fullPostContent"; // We'll need to wrap the existing content in a new div so our interface doesn't get effected by resizing
  
  var increment = 2.5; // How much of an increment in pixels do you want to increase the size.  Do not add 'px' to the end.
  
  var css = ''; //add any CSS here if you don't want to mess with the stylesheet.  MUST include style tags.
  
  //you can edit the resizing interface here if you need to.  Not necessary though.
  var sizingInterface = '   <span id="resizeFunctions">\n'+
    '    Text Size: <a id="default" href="#" onclick="aFunction();return false;">A</a> '+
    '    <a id="big" href="#" onclick="aFunction();return false;">A</a>'+
    '    <a id="bigger" href="#" onclick="aFunction();return false;">A</a>'+
    '    <a id="biggest" href="#" onclick="aFunction();return false;">A</a>\n'+
    '   </span>\n';
  
  /* 
   *#### Rarely should you need to go beyond here for basic confiuration. #### 
   */
  
  // get the existing size and set as default
  var defaultFontSize = jQuery(containingElement).css("font-size");

  function changeSize(size, returnValue) {
    var newSize;
    if (size == "default") {
      newSize = defaultFontSize;
    } else if ( typeof(parseFloat(size)) == "number" ) {
      newSize = parseFloat(defaultFontSize) + parseFloat(size);
      newSize = newSize.toString() + "px";
    }
    if (returnValue) {
      return newSize;
    } else {
      jQuery('#'+targetElement).css("font-size", newSize);
    }
  }
  
  // Add in the interface and wrap content
  if (putInterfaceHere) {
    jQuery(putInterfaceHere).append(sizingInterface);
    sizingInterface = '';
  }
  existingContent = jQuery(containingElement).html(); //get existing HTML
  jQuery(containingElement).html(
     css //add var css defined at top
     + sizingInterface // add the sizing interface defined at the top
     + '<div id="' + targetElement + '">\n' //add the wrapper div
     + existingContent //put the existing content back in there
     + '</div>' ); //complete the wrapper
  
  // Set size of buttons to be actual size of base text (like paragraphs).  H2 etc, will increase appropriately
  jQuery("#default").css("font-size", defaultFontSize);
  jQuery("#big").css("font-size", changeSize(increment, 1));
  jQuery("#bigger").css("font-size", changeSize(increment*2, 1));
  jQuery("#biggest").css("font-size", changeSize(increment*3, 1));
  
  //attribute proper function calls to the buttons
  jQuery("#default").click( function() { changeSize('default') });
  jQuery("#big").click( function() { changeSize(increment) });
  jQuery("#bigger").click( function() { changeSize(increment*2) });
  jQuery("#biggest").click( function() { changeSize(increment*3) });
});
