$(document).ready(function(){
	$(".tiptip").tipTip({maxWidth: "auto", edgeOffset: 10});
	$("a.fancy").fancybox();		 
  $("img").lazyload({         
       placeholder : "img/post-it-viola.jpg",
       effect : "fadeIn"
  }); 

  /* AFFICHAGE DES ARTICLES ----------------------------------------------------------- */
	
  $('#lucarnes ul li:nth-child(3n+1)').css({'margin': '5px 5px 10px 10px'});
  $('#lucarnes ul li:nth-child(3n+3)').css({'margin': '5px 10px 10px 5px'});

  var move = -15;
  var zoom = 1.2;
	$('#lucarnes .block').hover(function(){
        width = $('#lucarnes .block').width() * zoom;
        height = $('#lucarnes .block').height() * zoom;
        $(this).find('img.fond').stop(false,true).animate({'width':width, 'height':height, 'top':move, 'left':move}, {duration:500});
        $(".cover", this).stop(false,true).fadeIn(500);
	}, function() {
    $(this).find('img.fond').stop(false,true).animate({'width':$('#lucarnes .block').width(), 'height':$('#lucarnes .block').height(), 'top':'0', 'left':'0'}, {duration:200});
		$(".cover", this).stop(false,true).fadeOut(200);
	});

  /* AFFICHAGE DES ARTICLES ----------------------------------------------------------- */

  /* FONT RESIZE ---------------------------------------------------------------------- */
  
    var min=12; 
    var max=20;
    var reset = $('body').css('fontSize');
    var elm = $('.entry p'); 
    var size = str_replace(reset, 'px', '');
     
    $('a.fontSizePlus').click(function() { if (size<=max) { size++; elm.css({'fontSize' : size}); } return false; });
    $('a.fontSizeMinus').click(function() { if (size>=min) { size--; elm.css({'fontSize' : size}); }return false; });
     
    $('a.fontReset').click(function () { elm.css({'fontSize' : reset}); });
         
  /* FONT RESIZE ---------------------------------------------------------------------- */

  /* MONTHLY ARCHIVES ----------------------------------------------------------------- */

	$('a#archives-list').click(function(){
    $('#archives-monthly').stop(false,true).fadeIn(500);
    $('a#close-archives').stop(false,true).fadeIn(100);
    $('a#archives-list').stop(false,true).fadeOut(50);
    });    
	$('a#close-archives').click(function(){
    $('#archives-monthly').stop(false,true).fadeOut(500);
    $('a#archives-list').stop(false,true).fadeIn(100);
    $('a#close-archives').stop(false,true).fadeOut(50);
	 });    
  
  /* QUOTES ROTATOR ------------------------------------------------------------------------ */
    
  $('#tweet ul li').hide();
  $('#tweet ul li:first').stop(false,true).fadeIn(500); 
  Rotate();

  /* SWITCH STYLE ARTICLE ------------------------------------------------------------------ */
  
      $("a.switchNB").toggle(function(){
        $(this).addClass("swap");
        $("div.post").fadeOut("fast", function() {
            $(this).fadeIn("fast").addClass("white");
        });
    }, function () {
        $(this).removeClass("swap");
        $("div.post").fadeOut("fast", function() {
            $(this).fadeIn("fast").removeClass("white");
        });
    }); 

});

//A string replace function
function str_replace(haystack, needle, replacement) {
    var temp = haystack.split(needle);
    return temp.join(replacement);
    }
    
function Rotate(){
var current = $('#tweet ul li:visible');
var next = current.next().length ? current.next() : current.parent().children(':first'); 
current.hide();
next.stop(false,true).fadeIn(500);
setTimeout(Rotate, 10000);
}     

