// JavaScript Document

$(document).ready(function() {
	
	//Afficher/Masquer du footer
    $('#displayFooter').click(function() {
        $('#footer').hide();
		$('#displayFooter img').show();
		$('#displayFooter').height(2);
		$('html,body').animate({scrollTop: $('html').height()}, 1000); 
		return false;
    });
		
    //Scrolling top
    $('.scrollTop').click(function() {
      $('html,body').animate({scrollTop: 0}, 1000); 
      return false;
    });
	
	//Ajout de quotes
	/*$('.cadre').prepend('<img alt="quotes-start" src="include/images/modele/quote-start.png">&nbsp;&nbsp;');
    $('.cadre').append('&nbsp;&nbsp;<img alt="quotes-end" src="include/images/modele/quote-end.png">');*/
	
});


/* ---- CLIGNOTEMENT ---------------------------*/
(function ($, undefined) {
    "use strict";
    var blink = function (obj, durationOut, durationIn) {
        $(obj).animate({ opacity: 0.1 }, durationOut, 'linear', function () {
            $(obj).animate({ opacity: 1 }, durationIn, 'linear', function () {
                if ($(this).hasClass('blink')) { blink(obj, durationOut, durationIn); }
            });
        });
    };
    $.fn.blink = function (durationOut, durationIn) {
        if (durationOut !== undefined) {
            if (durationIn === undefined) { durationIn = durationOut; }
            return this.each(function () {
                $(this).addClass('blink');
                blink(this, durationOut, durationIn);
            });
        } else {
            return this.each(function () {
                $(this).removeClass('blink').stop(true).css('opacity', 1);
            });
        }
    };
}(jQuery));

$(document).ready(function() {
	$('#blink').blink('400'); 
});


// Fait clignoter un element

function changeOpac(opacity, id) 
{
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function Opacity (id, opacStart, opacEnd, millisec) 
{
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;
	
	if(opacStart > opacEnd) 
	{
		for(i = opacStart; i >= opacEnd; i--) 
		{
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
    	}
	} 
	else if(opacStart < opacEnd) 
	{
		for(i = opacStart; i <= opacEnd; i++) 
		{
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
	}
}



/*
// Fait défiler un texte
function Defile ( eid , speed )
{
	if ( speed == undefined ) speed = 20;

	jQuery('#' + eid).marquee('pointer').mouseover
	(
		function ()
		{
			$(this).trigger('stop');
		}
	).mouseout
	(
		function ()
		{
			$(this).trigger('start');
		}
	)
	
}
*/


// Gère un slideshow
function Slideshow ( eid , ctrls , speed )
{
	if ( ctrls  == undefined ) ctrls = true;
	if ( speed  == undefined ) speed = 3000;
	
	
	// Determine la taille de la plus grande image
	var width = 0;
	var height = 0;
	var element = document.getElementById( eid );
	for ( i = 0; i < element.childNodes.length; i++ )
	{
		var child = element.childNodes[i];
		if ( child.width > width )
			width = child.width;
		if ( child.height > height )
			height = child.height;
	}

	
	
	jQuery(document).ready(
	function()
	{
		jQuery('#' + eid).slideshow(
		{
			title:false,
			width:width,
			height:height,
			playframe:false,
			time:speed,
			play:true,
			imgresize:false,
			imgzoom:false,
			panel:ctrls,
			imgcenter:true,
			
			controls:
			{
				'hide':false,
				'help':false
			}
		});
	}
);
}

// --------- Bouton haut de page ----------

$(window).scroll(function() {
  if($(window).scrollTop() == 0){
    $('#scrollToTop').fadeOut("slow");
  } else {
    if($('#scrollToTop').length == 0){
      $('body').append('<div id="scrollToTop">'+
        '<a href="#">Haut de page</a>'+
        '</div>');
    }
    $('#scrollToTop').fadeIn("slow");
  }
});

$('#scrollToTop a').live('click', function(event){
  event.preventDefault();
  $('html,body').animate({scrollTop: 0}, 'slow');
});
