/*
jQuery Clear-Input plugin - Aidan Feldman
*/

(function( $ ){
  // define the initialValue() function
  $.fn.initialValue = function(value) {
    if (value) {
      return this.attr('initial-value', value);
    } else {
      return this.attr('initial-value');
    }
  };
  
  $.fn.clearInput = function() {
    return this
      .focus(function(){
        if (this.value == $(this).initialValue()) {
          this.value = '';
        }
      })
      .blur(function(){
        if (this.value == '') {
          this.value = $(this).initialValue();
        }
      })
      .each(function(index, elt) {
        $(this).initialValue(this.value);
      });
  };

 
})( jQuery );




/* ******************************** */
/*       ZEBRA                     */
/* ****************************** */

function zebra() { 
	$('table').each(function() {
			$('tr:even', this).addClass('pair');
	});
} 
 

/* ******************************** */
/*  CLEAR INPUT                    */
/* ****************************** */

function clearInput() { 

$("input[type='text']").clearInput();
$("textarea").clearInput();	

}


 
/* ******************************** */
/*  SELECT BOX                     */
/* ****************************** */
 
function selectBox() { 
 
 $('#produits-nav p').click(function(){	
 	if ($('#produits-nav .content').is(":hidden")) {
       $('#produits-nav .content').slideDown("slow");
      } else {
 		$('#produits-nav .content').not(':first').slideUp("Slow");
      }
	  return false;
	});

	// slide sur le body 
    $('body').click(function(){	
	if ($('#produits-nav .content').is(":visible")) {
	$('#produits-nav .content').slideUp("Slow");
      }
	});
	

	// select
    $('#produits-nav .content ul li ul').hide();
	//$('#produits-nav .content ul li ul').not(':first').hide();
 
	$('#produits-nav .content ul li a').hover(function() {

      var checkElement = $(this).next();
	  
	  if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
			checkElement.hide().parent().addClass('active');
		}
	  
	  if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
		$('#produits-nav .content ul ul:visible').hide().parent().removeClass('active');
		checkElement.show().parent().addClass('active');
	 
		}
		$('#produits-nav ul li:first').hover();
 });

 /* hauteur de colonne */
 $('#produits-nav ul li').hover(function() {

 var myheightfirst = $('#produits-nav ul').height();
 var myheightsecond = $(this).find('ul').height();
 var showmyheight = myheightsecond + "px";
  
  $("#produits-nav ul:first").css({'min-height': showmyheight});  
  
}); 

} 

/* ******************************** */
/*  TABULATION                     */
/* ****************************** */

 
function myTab() { 

 	$('.my-tab-box').hide();
 	$('.my-tab-box:first').show();
	
	
 	$('#my-tab ul li:first').addClass('active');
	
	var tabBoxContainers = $('#my-tab > .my-tab-box');		
	
	$('#my-tab ul a').click(function () {
			$(this).parent().addClass('active').siblings().removeClass('active');
			tabBoxContainers.hide();
			tabBoxContainers.filter(this.hash).show();
			return false;
	 });

}


/* ******************************** */
/*  myFAQ                          */
/* ****************************** */


function myFaq() { 
	$('.block-date').click(function(){
		if(!$(this).hasClass('hover')) {
			var whatisit = $(this).find('.resume');
			whatisit.slideToggle("slow","linear");
		}
	});
	$('.block-date a').click(function(){
		if($(this).attr('rel')!='lightbox') {
			if($(this).attr('target')=='_blank') window.open($(this).attr('href'));
			else document.location.href=$(this).attr('href');
		}
	});
}


/* ******************************** */
/*  Resize                         */
/* ****************************** */

function resizeColonnes()	{


 /* hauteur de colonne pour la colonne droite */
 var windowW = $(window).width();
 var windowH = $(document).height()

 var colheight = windowH + "px";
 $(".colonne-droite").css({'min-height': colheight});  
 
}



function bgBody() {
  $("#body-background").ezBgResize();	
}
/* ******************************** */
/*  Initialisation des fonctions   */
/* ****************************** */

$(document).ready(function() {
	 zebra();
	 myFaq();
	 bgBody();
	 clearInput();
 
	 selectBox();
	// resizeColonnes();
	 myTab();
	 // produitHover();
});
