
function openCloseDoors() {
  $("#border-left").animate({
      marginLeft: '-548px'
    },
    {duration:100}
  ).animate({
      marginLeft: '-900px'
      }, 
      {duration: 1100, easing: "easeInOutBack"}
  );
  
  $("#border-right").animate({
      marginRight: '-548px'
    },
    {duration:100}
  ).animate({
      marginRight: '-900px'
      }, 
      {duration: 1100, easing: "easeInOutBack"}
    );
};
  
$(function() {
  openCloseDoors();
});

  // Fog qui se deplace
/*
$(function() {
  setInterval(function() {
    $('#contact .fog').animate({'background-position': '-=10px 0px'}, 1000);
    $('#contact .fog2').animate({'background-position': '+=5px -100px'}, 1000);
  }, 1000);
});
*/

// Mouseover jo ou oli
$(function() {
  $(".oli,.jo").hover(function() {
    $(this).children('div').show();
  }, function() {
    $(this).children('div').hide();
  });
  $(".oli,.jo").mousemove(function(event) {
    //console.log('over ' + this.className);
    var padding = 0;
    var x, y;
    
    var y = event.pageY - $(this).offset().top - ($(this).children('div').outerHeight()) - padding;
    
    if ($(this).hasClass('oli')) {
      //console.log($(this).outerWidth());
      x = event.pageX - $(this).offset().left - padding - ($(this).children('div').outerWidth());
    }
    else {
      x = event.pageX - $(this).offset().left + padding;
    } 
    
     
    //console.log('positioning at: ' + x + ',' + y);
    
    
    $(this).children('div').css('top', y).css('left', x);
  });
  
  // , function(event) {
  //   console.log('out ' + this.className);
  // });
});

// Fancybox questionnaire
$(function() {
  $("#contact a[href=#soumission]").fancybox({
    autoScale: true,
    height:"100%",
    width:632,
    overlayOpacity: 0.8,
    overlayColor: "#000",
    type: "iframe",
    href: "https://spreadsheets.google.com/a/vozlabs.com/viewform?hl=en&ndplr=1&formkey=dEdUNFF6cU1xdWN4WFpWVDVfbmthRlE6MQ#gid=0"
  });
  $("#contact a[href=#soumission-en]").fancybox({
    autoScale: true,
    height:"100%",
    width:632,
    overlayOpacity: 0.8,
    overlayColor: "#000",
    type: "iframe",
    href: "https://spreadsheets.google.com/a/vozlabs.com/viewform?hl=en&formkey=dDhpUjFFRTc5WDhrdjFfZTltaUN2ZUE6MA"
  });
});

// Navigation des cadres dans Realisations
$(function() {
  $("#realisations > ul > li").bind('click', function(event) {
    //console.log('clicked ');
    //console.log(this);
    $("#realisations > ul > li").removeClass('active');
    //$(this).removeClass('active');
    $("#realisations").scrollTo(this, {
      duration: 800, 
      offset: {left:-185, top:0},
      easing: "linear", 
      onAfter: (function(ele) {
        return function() {
          //console.log(ele);
          $(ele).addClass('active');
        };
      })(this)
    });
  });
});

// Cadre mouseover 
$(function() {
  $("#realisations-carousel > li .inner-cadre").hover(function(event) {
    if($(this).parents('li').hasClass("active")) {
      $(this).find(".actions").fadeIn('fast');
    }
  },function(event) {
      $(this).find(".actions").fadeOut('fast');
  });
  
  $("#realisations-carousel > li .inner-cadre .actions").bind('mousemove', function(event) {
    event.stopPropagation();
  });
  // in case mouse starts over element (when refreshing page for example)
  $("#realisations-carousel > li .inner-cadre").bind("mousemove", function(event) {
    if ($(this).parents('li').hasClass('active'))
      $(this).find(".actions").fadeIn('fast');
  });
});

// Set up realisations / images galleries 
$(function() {
  //console.log($("a[rel=gallerieVoz]"));
  var gallery_options = {
    'transitionIn' : 'none', 
    'transitionOut' : 'none',
    'overlayOpacity' : 0.8,
    'overlayColor': '#000',
    'autoDimensions': false
  };
  $("a[rel=gallerieVoz]").fancybox(gallery_options); 
  $("a[rel=gallerieZenco]").fancybox(gallery_options); 
  $("a[rel=gallerieSummum]").fancybox(gallery_options);
  $("a[rel=gallerieImagea9]").fancybox(gallery_options);
/*
        $("a.expand").click(function() {
          $.fancybox([
            'http://farm5.static.flickr.com/4044/4286199901_33844563eb.jpg',
            'http://farm3.static.flickr.com/2687/4220681515_cc4f42d6b9.jpg',
            {
              'href'  : 'http://farm5.static.flickr.com/4005/4213562882_851e92f326.jpg',
              'title' : 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
            }
          ], {
            'padding'     : 0,
            'transitionIn'    : 'none',
            'transitionOut'   : 'none',
            'type'              : 'image',
            'changeFade'        : 0
        });
*/
    // $.fancybox([
    //   'http://farm5.static.flickr.com/4044/4286199901_33844563eb.jpg',
    //   'http://farm3.static.flickr.com/2687/4220681515_cc4f42d6b9.jpg',
    //   {
    //     'href'  : 'http://farm5.static.flickr.com/4005/4213562882_851e92f326.jpg',
    //     'title' : 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
    //   }
    // ], {
    //   'padding'     : 0,
    //   'transitionIn'    : 'none',
    //   'transitionOut'   : 'none',
    //   'type'              : 'image',
    //   'changeFade'        : 0
    // });
  //});
});


$(function() {
  var text = $("#cursor").prev().text();
  var stop_animation;
  $("div.oli").hover(function(event) {
    //console.log($("#cursor").prev().text());
    $("#cursor").parent().find("code").text("");
    printChar(0);
    stop_animation = false;
    function printChar(i) {
      setTimeout(function() {
        //console.log(i);
        $("#cursor").prev().append(text[i]);
        if (i < text.length && !stop_animation) printChar(++i); 
      }, 20);
    }
  }, function() {
    stop_animation = true;
  });
setInterval(function() {$("#cursor").toggle()}, 500);
});
