// JavaScript Document

$(document).ready(function() {
	
	/*
	 *
	 *
	 * Transition
	 */
	 $("body").css("display", "none"); 
         $("body").fadeIn(1000);
		
        /*
	 *
	 *
	 * Scrolling top
	 */
         $('.scrollTop').click(function() {
             $('html,body').animate({scrollTop: 0}, 1000); 
             return false;
         });
	
        /*
	 *
	 *
	 * Ajout de quotes
	 */	
 	$('.quotes').prepend('<img alt="quotes-start" src="include/images/modele/quote-start.png"> ');
        $('.quotes').append(' <img alt="quotes-end" src="include/images/modele/quote-end.png">');	
	
	/*
	 *
	 *
	 * Clignotement
	 */	 		
	 durationBlink =500;//ms
	 classBlink = 'blink';
	 alternBlink = false;
	 function blink()
	 {		 
		 if(alternBlink)
		 {
			$('.'+classBlink).css('opacity', '0');
			alternBlink = false;
		 }
		 else
		 {
			$('.'+classBlink).css('opacity', '1');
			alternBlink = true;
		 }
		 setTimeout(function(){blink();}, durationBlink);
	 }
	if ($('.'+classBlink).length) blink();
	
	
        /*
	 *
	 *
	 * Multimed Popup
	 */	
	 $('.ms_popup').click(function(){
		 
		 classlist = $('.ms_popup').attr('class');
		 classlist = classlist.split(' ');
		 idpopup = classlist[1];	
		 displayPopup(idpopup);	 
         });
	 
	 function displayPopup(idcontent)
	 {
		  content = $('#'+idcontent).html() + '<div id="close_ms_popup"></div>';
		  
		  if (!$('#bg_ms_popup').length)
		     $('body').prepend('<div id="bg_ms_popup"></div><div id="ms_popup"></div>');
			 
		  $('#bg_ms_popup').css({
			 'width'      : $(window).width(),
			 'height'     : $(window).width(),
			 'background' : '#000',
			 'opacity'    : '0.8'
		  });
		  
		  $('#ms_popup').css({
			 'background' : '#fff'		  
		  });
		  
		  $('#ms_popup').html(content);
		  
		  $('#bg_ms_popup').show();
		  $('#ms_popup').show();
	 }
	 //Fermeture
	 $('#bg_ms_popup').live('click', function(){closepopup()});
	 $('#close_ms_popup').live('click', function(){closepopup()});
	 
	 function closepopup()
         {
	    $('#bg_ms_popup').hide();
	    $('#ms_popup').hide();
         }    	 
	 
	/*
	 *
	 *
	 * Checkbox & Radio
	 */
	 $(".form input[type=radio], .form input[type=checkbox]").uniform();
         

});



/*
// 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');
});
