/*
 * Script édité par Chaudret florian, skill informatique
 * Tout droit réservé
 */
var timeOut = 10000;
var timeFade = 800;
var File = '../box_airlinair.php';

// attent chargement avant initialisation
$(document).ready(function(){
 Init();
});
// fade in pour ie
(function($) {
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(!$.support.opacity)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(!$.support.opacity)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeTo = function(speed,to,callback) {
		return this.animate({opacity: to}, speed, function() {
			if (to == 1 && jQuery.browser.msie)
				this.style.removeAttribute('filter');
			if (jQuery.isFunction(callback))
				callback();
		});
	};
})(jQuery);

// Initialise
function Init(){
  jslog('Init:: lunch');
  BindClick();
  alerte_full_show(File, timeOut);
  
}

// rend clicquable les div
function BindClick(){
  jslog('BindClick:: lunch');
  divfullscreen = $("#fullscreen");  
  divfullscreen.die();
  divfullscreen.live("click",function(){alerte_full_hide_anim(timeFade);});
}

// div fullscreen avec chargement de fichier dans la box
// timeOut a 0 si pas de disparition de la box
function alerte_full_show(file,timeOut){
  jslog('alerte_full_show:: file='+file+' timeOut='+timeOut);
  divalertebox = $("#alertebox");
  divfullscreen = $("#fullscreen");
  divalertebox.customFadeOut('fast');
  divfullscreen.customFadeOut('fast');
  divalertebox.empty();
  divfullscreen.empty();
  divalertebox.load(file, '',
    function(){
	  divfullscreen.customFadeIn('slow',
        function(){
		  divalertebox.customFadeIn('slow',	  
            function(){
			  if ( timeOut > 0 ){
			    setTimeout(function(){alerte_full_hide_anim(timeFade);},timeOut);
			  }
			}
          );
	    }
      );
    }
  );
}

// cache box et fullscreen
function alerte_full_hide(timeFade){
  jslog('alerte_full_hide:: timeFade='+timeFade);
  divalertebox = $("#alertebox");
  divfullscreen = $("#fullscreen");
  divalertebox.customFadeOut(timeFade,
    function(){divfullscreen.customFadeOut(timeFade);}
  );
}

// exécute une animation avant de cacher l alerte
function alerte_full_hide_anim(timeFade){
  jslog('alerte_full_hide_anim:: timeFade='+timeFade);
  alerte_full_hide(timeFade);
  setTimeout(
    function(){
      $("#logo").customFadeOut(timeFade,
       function(){
	     $("#logo").html('<img src="http://www.lagapa.com/dec2/logo_resto.gif" border="0">');
		 $("#logo").customFadeIn(timeFade);    
	   }	   
      );     
    },
	timeFade
  );
}

function jslog(txt){
  //console.log(txt);
}
