/**
 * Project: phpLD Archive
 * Description: A PHP-5 module for PHP Link Directory that builds an archive
 *              of your link submissions.
 *
 * File:    fm_calendar.js
 *
 * ********************************************************************************
 * THIS IS COPYRIGHTED SOFTWARE
 * PLEASE READ THE COMMERCIAL LICENSE AGREEMENT
 * http://www.frozenminds.com/commercial-license.html
 *
 * License Preview:
 * ----------------
 * 1) ONE license grants the right to perform ONE installation of the Software.
 *    Each additional installation of the Software requires an
 *    additional purchased license.
 * 2) You may NOT:
 *    Reproduce, distribute, or transfer the Software,
 *    or portions thereof, to any third party. Sell, rent, lease, assign,
 *    or sublet the Software or portions thereof. Grant rights to any other person.
 *    Use the Software in violation of any Romanian or international law or regulation.
 * 3) All copyright and proprietary notices, including logos,
 *    within the Software files must remain intact.
 * 4) There is NO refund! Even if the software might not work as expected or
 *    not work at all.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND!
 *
 * @see http://www.frozenminds.com/commercial-license.html
 * @see license.txt file
 * ********************************************************************************
 *
 * @link http://www.frozenminds.com/phpld-archive.html
 * @copyright 2008 Constantin Bejenaru (www.frozenminds.com)
 * @author Constantin Bejenaru (www.frozenminds.com)
 * @version 1.0 (initial release)
 */


/*
#########################################################
# MAKE AJAX REQUESTS FOR IN-PAGE CHANGES ON THE CALENDAR
#########################################################
*/

//Register event on page load
Event.observe(window, 'load', fm_track_links);

/**
 * Find all links that can do AJAX calls
 * Those links must have rel="cal_ajax"
 *
 * @param element
 */
function fm_track_links(e)
{
   //collect all calendar links that can do AJAX calls
   $$('a[rel=cal_ajax]').invoke('fm_cal_observer');
}



//Observe link clicks to AJAX callers and invoke events
var FM_CAL_OBSERVE =
{
   fm_cal_observer: function(element)
   {
      element.target  = '';
      element.dynamic = fm_cal_load.bindAsEventListener(element);

      Event.observe(element, 'click', element.dynamic);

      return element;
    }
}

//Mix own methods to the element object
Element.addMethods(FM_CAL_OBSERVE);

/**
 * Make the AJAX call and update elements
 *
 * @param object element
 */
function fm_cal_load(e)
{
   element = Event.element(e);

   new Ajax.Updater('fm_calendar', element.href, {
         method: 'get',
         parameters: 'ajax=true',
         onComplete: function()
         {
            fm_track_links(element);

            //You may now apply some script.aculo.us effects
            //new Effect.Highlight('fm_calendar_table', {duration: 1});
         }
   });

   //Stop following link
   Event.stop(e);
   return false;
}
