


function calculateRoi( ) {

  searchEngineResultsFraction = new Array( 0, .4213, .119, .085, .0606, .0492, .0405, .0341, .0301, .0285, .0299, .0153, .0142, .013, .0119, .0108, .0097, .0084, .0073, .0062, .005, 0);

  monthlyVolume = Number($("#monthlysearches").attr('value'));
  competitiveness = Number($("#competitiveness").attr('value'));
  currentRanking = Number($("#serpranking").attr('value'));
  conversionRate = Number($("#conversionrate").attr('value'));
  lifetimeValue = Number($("#lifetimevalue").attr('value'));

  currentFraction = 0 ;
  if ((currentRanking > 0) && (currentRanking < 21)) {
    currentFraction = searchEngineResultsFraction[currentRanking];
  } /* if */     

  visitors10 = (searchEngineResultsFraction[10]  - currentFraction) * monthlyVolume;
  visitors5 = (searchEngineResultsFraction[4]  - currentFraction) * monthlyVolume;
  visitors1 = (searchEngineResultsFraction[1]  - currentFraction) * monthlyVolume;
  customers10 = visitors10 * conversionRate * 0.01;
  customers5 = visitors5 * conversionRate * 0.01;
  customers1 = visitors1 * conversionRate * 0.01;

  revenue10 = customers10 * lifetimeValue;
  revenue5 = customers5 * lifetimeValue;
  revenue1 = customers1 * lifetimeValue;

  $("div#roiresults").append( 'Searches per month: ' + monthlyVolume + '<br />Competitiveness: ' + competitiveness  + '<br />Current Ranking: ' + currentRanking + '<br />Conversion Rate: ' + conversionRate + '&#37;<br />Customer Lifetime Value: &#36;' + lifetimeValue + '<br />'  );

  $("div#roiresults").append( '<table><tr><th>&nbsp;</th><th>Top 10</th><th>Top 5</th><th>First</th></tr>'
   + '<tr><td>Increase in Monthly Visitors</td><td>' + visitors10.toFixed(2) + '</td><td>' + visitors5.toFixed(2) + '</td><td>' + visitors1.toFixed(2) + '</td></tr>'
   + '<tr><td>Increase in Monthly Customers</td><td>' + customers10.toFixed(2) + '</td><td>' + customers5.toFixed(2) + '</td><td>' + customers1.toFixed(2) + '</td></tr>'
   + '<tr><td>Increase in Monthly Revenue</td><td>$' + revenue10.toFixed(2) + '</td><td>$' + revenue5.toFixed(2) + '</td><td>$' + revenue1.toFixed(2) + '</td></tr>'
   + '</table>');
} 


// main
(function($) {
$(document).ready(function() {

  // start up the easy slider plug-in
  $("#slider").easySlider({
   prevText:'Previous',
   nextText:'Next',
   auto: true,
   continuous: true,
   pause: 4000
  });


   // initialize mega menu plug-in
   $("li.nmega").hoverIntent(
     {
     interval: 100,
     sensitivity: 4,
     over: function(){$(this).addClass("hovering");},
     timeout: 500,
     out: function (){ $(this).removeClass("hovering");}
     }
   ) ;
      

   $('#calculateroi').click(function() {   calculateRoi() ; });

    
});
})(jQuery)


