// =======================================================
//  Foxbright Budget Badge Script
//  Copyright 2010 Foxbright
// =======================================================
//
//  License Agreement
//
//   1. You may use the Foxbright Budget Badge Script on your website to comply with the State of Michigan's new Budget Transparency Requirements for all school websites
//   2. You may NOT distribute or republish this script, even if you make modifications to it. The script can only be distributed by the author, Foxbright.
//   3. THE SCRIPT AND HTML CODE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR 
//      PURPOSE. YOU AGREE TO BEAR ALL RISKS AND LIABILITIES ARISING FROM THE USE OF THIS SCRIPT.
//   4. If you cannot agree to any of the above conditions, you may not use this service nor any of the scripts and HTML code.
//
// =======================================================

  // IMPORTANT
  // =========


	// Change this value to the absolute path of the Budget Badge directory, e.g. /scripts/budgetBadge/
  var budgetBadgeDirectory = '/Scripts/BudgetBade/';

	// Change this value to the absolute path of the budget information web page on your site, e.g. /example/path/to/budgetInformationPage.htm
  var budgetInfoPage = 'http://www.grantps.net/P/Administration/Transparency%20Reports';



// =======================================================
// ============ DO NOT EDIT BELOW THIS LINE ==============
// =======================================================






















































// Add trailing slash to path if it doesn't exist
if(budgetBadgeDirectory.charAt(budgetBadgeDirectory.length-1) != '/'){
  budgetBadgeDirectory += '/';
}

// Define budget badge HTML

  var FB_PNG = '/Images/BudgetBadge/budgetbadge.png';

  var budgetBadgeHTML  = '<div id="FB_budgetLinkDiv" class="FB_budgetLink_minimized">';
      budgetBadgeHTML += '  <a id="FB_budgetLink" href="'+budgetInfoPage+'" title="Click to learn more...">';
      budgetBadgeHTML += '    <img src="'+FB_PNG+'" alt="Budget &amp; Salary/Compensation Transparency Reporting" />';
      budgetBadgeHTML += '  </a>';
      budgetBadgeHTML += '  <a id="FB_bbCloser"></a>';
      budgetBadgeHTML += '</div>';


// Check if jQuery's loaded
    function FB_wait() {
      if (typeof jQuery == 'undefined') {  
        window.setTimeout(FB_wait,100);
      }
      // If jQuery is loaded
      else {
        // Make sure body is loaded
        jQuery('document').ready(function () {
          var t=setTimeout("FB_addBudgetBadge()",3000);
          //FB_addBudgetBadge();
        });
      }
    }
    FB_wait();


function hideBudgetButton(){
  jQuery('#FB_budgetLinkDiv').removeClass('FB_budgetLink_minimized');
  jQuery('#FB_budgetLink').animate({ 
    width: 0,
    height: 0,
    opacity: 0.4
    }, {
          duration: 1000, 
          complete: function() {
            jQuery('#FB_budgetLink').hide();
            jQuery('#FB_budgetLinkDiv').addClass('FB_budgetLink_minimized');
            jQuery.cookie("hideBudgetBadge", "Hidden");
          } // end complete function
        }
  ); // end animate
}

function showBudgetButton(){
  jQuery('#FB_budgetLinkDiv').removeClass('FB_budgetLink_minimized');
  jQuery('#FB_budgetLink').width(0).height(0).show().animate({ 
    width: 150,
    height: 150,
    opacity: 1
    }, {
          duration: 1000, 
          complete: function() {
            jQuery.cookie("hideBudgetBadge", null);
          } // end complete function
        }
  ); // end animate
}

// Execute code
    function FB_addBudgetBadge(){
      // Check we're not in the editor
      if(jQuery('#contenteditorcontainer').length == 0){
        jQuery(budgetBadgeHTML).appendTo('body');
        addCookieFunctions();
//        alert(jQuery.cookie("hideBudgetBadge"));
        if(jQuery.cookie("hideBudgetBadge") == null){
          jQuery('#FB_budgetLink').hide();
          jQuery('#FB_budgetLinkDiv').removeClass('FB_budgetLink_minimized');
          showBudgetButton();
        }

        jQuery('#FB_bbCloser').click(
          function(){
            if(jQuery('#FB_budgetLinkDiv').outerWidth() > 50){
              hideBudgetButton();
            } // end if
            else{
              showBudgetButton();
            } // end else
            
          } // end click function
        ); // end click
      } // end check for editor (#contenteditorcontainer)
    } // end function FB_addBudgetBadge()



function addCookieFunctions(){
  jQuery.cookie = function(name, value, options) {
      if (typeof value != 'undefined') { // name and value given, set cookie
          options = options || {};
          if (value === null) {
              value = '';
              options.expires = -1;
          }
          var expires = '';
          if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
              var date;
              if (typeof options.expires == 'number') {
                  date = new Date();
                  date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
              } else {
                  date = options.expires;
              }
              expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
          }
          // CAUTION: Needed to parenthesize options.path and options.domain
          // in the following expressions, otherwise they evaluate to undefined
          // in the packed version for some reason...
          var path = options.path ? '; path=' + (options.path) : '';
          var domain = options.domain ? '; domain=' + (options.domain) : '';
          var secure = options.secure ? '; secure' : '';
          document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
      } else { // only name given, get cookie
          var cookieValue = null;
          if (document.cookie && document.cookie != '') {
              var cookies = document.cookie.split(';');
              for (var i = 0; i < cookies.length; i++) {
                  var cookie = jQuery.trim(cookies[i]);
                  // Does this cookie string begin with the name we want?
                  if (cookie.substring(0, name.length + 1) == (name + '=')) {
                      cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                      break;
                  }
              }
          }
          return cookieValue;
      }
  };
}

// =======================================================
//  Foxbright Budget Badge Script
//  Copyright 2010 Foxbright
// =======================================================

