$(document).ready(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);

var temoin = 0;
function init()
{
    var divanim = $("#anim_top");
    var img_load = new Image();
    var img_fd = new Image();
    var img_sup = new Image();
    
    // on charge l image de fond
    divanim.html("Chargement...");
    // on charge le loader

        img_load.onload = function(){
            if (temoin < 1 )
            {
                temoin = 1;
                divanim.html('<div style="text-align:center;" id="img_load"><img style="margin-top:30px;" src="'+img_load.src+'" border="0"></div>');
                // on charge le fd
                img_fd.onload = function(){
                    // on charge le supplement

                    img_sup.onload = function(){
                        f_anim(divanim, img_load, img_fd, img_sup)
                    }

                    img_sup.onerror = function(){divanim.html("Erreur pendant le chargement de l image 3");}
                    img_sup.src = "../decor2008/nos_instants.gif";
                }
                img_fd.onerror = function(){divanim.html("Erreur pendant le chargement de l image 2");}
                img_fd.src = "../decor2008/instants.jpg";
            }
        }
        img_load.onerror = function(){divanim.html("Erreur pendant le chargement de l image 1");}
        img_load.src = "../images/fleuranim_b.gif";
    
}



function f_anim(obj,img_load,img_fd,img_sup)
{
    obj.customFadeOut('slow',function(){
        obj.html('<div id="img_fd" style="background-image:url('+img_fd.src+');background-repeat:no-repeat;position:relative;width:597px;height:161px;z-index:10;overflow:hidden;"></div>')
        obj_img_fd = $("#img_fd");
        obj_img_fd.html('<div id="img_sup" style="background-image:url('+img_sup.src+');background-repeat:no-repeat;width:155px;height:19px;z-index:20;position:absolute;bottom:0px;right:-155px"></div>');
        obj_img_sup = $("#img_sup");
        obj.customFadeIn('slow',function(){
            obj_img_sup.dequeue();
            obj_img_sup.animate({right:"70px"},500);
        });
    });  
}