$.fn.savePos = function() {
  return this.each(function(){
    element = $(this);
    this.saved_pos = {
      top: element.css('top'),
      left: element.css('left'),
      bottom: element.css('bottom'),
      right: element.css('right')
    };
  });
};

$.fn.resetPos = function() {
  return this.each(function(){
    $(this)
      .css('top', this.saved_pos.top)
      .css('left', this.saved_pos.left)
      .css('bottom', this.saved_pos.bottom)
      .css('right', this.saved_pos.right);
  });
};

$.fn.href_add = function(s) {
  return this.each(function(){
    $(this).attr('href', ($(this).attr('href') + s));
  });
};

$.fn.anim_cascade = function(callback, delay) {
  return this.each(function(i){
    var obj = $(this);
    setTimeout(function() {callback(obj)}, delay * (i+1));
    obj;
  });
}

$.fn.glitter = function() {
  return this.each(function(i){
    var obj = $(this);
    if (obj.attr("glitter") == 'true') {
      var speed = 2000 - Math.floor(Math.random()*1000);
      var opacity = .7 - Math.random()*0.3;
      var delay = 800 - Math.floor(Math.random()*400);
      obj.fadeTo(speed, opacity, function(){
        obj.fadeTo(1, 1, function(){
          setTimeout(function(a){$(a).glitter();}, delay, [obj]);
        })
      });
    }
  });
}

$.fn.glitterOn = function() {
  return this.each(function(i){
    var obj = $(this);
    obj.attr("glitter", true).glitter();
  });
}

$.fn.glitterOff = function() {
  return this.each(function(i){
    var obj = $(this);
    obj.attr("glitter", false);
  });
}

$.fn.thickbox = function(w,h) {
  return this.each(function(){
    $(this).addClass("thickbox")
           .href_add('?TB_iframe=true&width='+w+'&height='+h);
  });
}

function FP_init() {
  var lien_enf = $("#txt_enf a");
  var lien_liens = $("#txt_liens a");
  var logo = $("#logoFP a");
  $("#txt_inst a").thickbox(970,575);
  $("#txt_enf a").thickbox(690,554);
  $("#txt_cdc a").thickbox(690,554);
  $("a.form_doc").thickbox(450,400);
  $("a.form_mail").thickbox(500,580);
  $("a.form_cplet").thickbox(830,395);
  $("a.form_anim").thickbox(830,395);
  $("a.form_artistes").thickbox(830,430);
  $("a.form_traiteur").thickbox(830,395);
  $("a.form_lieu").thickbox(830,395);
  TB_init();

  $(".lienblock").savePos().hide();
  setTimeout('$(".lienblock").show("slide",{ direction: "up", duration: "fast", callback: function(){$(this).resetPos();}});', 1500);
}

function preload(a) { //v3.0
  a=preload.arguments;
  for (i=0; i<a.length; i++) {
    image = new Image();
    image.src= a.i;
  }
}

function preload_all() {
  $(".preload").each(function() {
    if (this.tagName.toLowerCase() == "img") {
      url = this.src;
    }
    else {
      url = $(this).css("background-image");
      url = url.substring(4,url.length-1);
    }
    file = url.substring(0, url.length-4);
    ext = url.substring(url.length-3, url.length);
    image = new Image();
    image.src= file+'_high.'+ext;
  });
}

function log(msg) {
    if(typeof console != "undefined") {
      console.log(msg);
    }
}