/***************************************************************
*  Copyright notice
*
*  (c) 2010-2011 Francis Grandjean <Francis.Grandjean@ac-orleans-tours.fr>
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
 * Plugin 'Plugin TS pour popup UI' for the 'aot_annuaire' extension.
 *
 * @author	Francis Grandjean <Francis.Grandjean@ac-orleans-tours.fr>
 * @package	TYPO3
 * @subpackage	tx_aotannuaire
 */
jQuery(function() {
    // First we had the overlay to the page
  jQuery('body').append('<div class="apple_overlay" id="tx_aotannuaire_pi1_overlay"><div class="tx_aotannuaire_contentWrap"></div></div>');
	  // Bind on any aotannuaire a Tag
  jQuery("a[aotannuaire]").overlay({
    mask: {
      maskId : 'exposeMask'
    },
    top: 'center',
    effect: 'apple',
    onBeforeLoad: function() {
      var dep = this.getTrigger().attr('dep');
      var type = this.getTrigger().attr('type');
      var statut = this.getTrigger().attr('statut');
      var rne = this.getTrigger().attr('rne');
      var comm = this.getTrigger().attr('comm');
      if (jQuery('#tx_aotannuaire_pi1_overlay .tx_aotannuaire_contentWrap>*').length != 0) {
	// reset all value + set new filter
	jQuery('#tx_aotannuaire_pi1_etab_dFilter_sName').val(rne).blur();
      }
    },
    onLoad: function() {
      var dep = this.getTrigger().attr('dep');
      var type = this.getTrigger().attr('type');
      var statut = this.getTrigger().attr('statut');
      var rne = this.getTrigger().attr('rne');
      var comm = this.getTrigger().attr('comm');
      
      // correct exposeMask behavior
      jQuery('#exposeMask').css('position','fixed');
      // If first load...
      if (jQuery('#tx_aotannuaire_pi1_overlay .tx_aotannuaire_contentWrap>*').length == 0) {
        // Display loading screen
        jQuery('#tx_aotannuaire_pi1_overlay .tx_aotannuaire_contentWrap').html('<div style=text-align:center; ><br /><br /><img src=typo3conf/ext/aot_annuaire/res/img/big-snake-loader-bg.gif /><br />Patientez chargement en cours...</div>');
        // Call the real JS script and launch it... 
        jQuery.ajax({
          url: 'typo3conf/ext/aot_annuaire/res/js/tx_aotannuaire_core.js',
          success: function () {
            jQuery('#tx_aotannuaire_pi1_overlay').Annuaire({
	      etab_initConf: {'dep':dep,'type':type,'statut':statut,'rne':rne,'comm':comm}
            });
          }
        });
      }
      /*else {
	
	/*
	jQuery('#tx_aotannuaire_pi1_overlay').Annuaire({
	  etab_initConf: {'dep':dep,'type':type,'statut':statut,'rne':rne,'comm':comm}
	});
	
      }*/
    }
  });
});
