$(document).ready(function() {
	
	//Appelle alex affichage heure 
	typerecette = date_heure('heurerecette');
	//Appelle ajax recherche recette

	$.ajax({
			   	type: "GET",
			   	url: "http://"+location.host+"/nosRecettes/ajaxrecette.html",
			   	data: "idtyperecette="+typerecette,
			   	success: function(msg){
				var obj = jQuery.parseJSON(msg);
				if($('#visuelrecette').length > 0){
			 	document.getElementById('visuelrecette').innerHTML = '<img src="'+obj.visuel+'" alt="Planta Fin" />';
		 		}
				if($('#lienrecette').length >0){
			 	document.getElementById('lienrecette').innerHTML = '<a href="'+obj.urlrecette+'">'+obj.titre+'</a>';
		 		}
				
				
			   }
			 });
	//-----------------------------------------------------------------------------------------------
	// Actus
	
	$(function(){
		$("ul#news-ticker").liScroll({travelocity: 0.05});
	});
	
	//-----------------------------------------------------------------------------------------------
	// Slider gauche
	$(function(){
		$('#slides').slides({
			preload: true,
			preloadImage: 'http://'+location.host+'/images/commun/slider/loading.gif',
			play: 5000,
			pause: 2500,
			hoverPause: true,
			animationStart: function(current){
				$('.caption').animate({
					bottom:-35
				},100);
			}
		});
	});
	
	
	
	//-----------------------------------------------------------------------------------------------
	// Scrolls page détail recette et accueil produits
	//$('.scroll-pane').load(function() {	
	
	$(function(){
	
			
		// Initialisation des scrollbars
		if($('.scroll-pane').length > 0){
			$('.scroll-pane').jScrollPane({showArrows:true,scrollbarWidth:17,maintainPosition:false});
		}
		
	
		
		/*var isResizing;
				
				// and the body scrollpane
				var setContainerHeight = function()
				{
					// IE triggers the onResize event internally when you do the stuff in this function
					// so make sure we don't enter an infinite loop and crash the browser
					if (!isResizing) { 
						isResizing = true;
						$w = $(window);
						$c = $('#container');
						var p = (parseInt($c.css('paddingLeft')) || 0) + (parseInt($c.css('paddingRight')) || 0);
						$('body>.jScrollPaneContainer').css({'height': $w.height() + 'px', 'width': $w.width() + 'px'});
						$c.css({'height': ($w.height()-p) + 'px', 'width': ($w.width() - p) + 'px', 'overflow':'auto'});
						$c.jScrollPane();
						isResizing = false;	
					}
				}
				$(window).bind('resize', setContainerHeight);
				setContainerHeight();
				
				// it seems like you need to call this twice to get consistantly correct results cross browser...
				setContainerHeight();
		*/
		
	});
	
	
	
	//});

	//-----------------------------------------------------------------------------------------------
	// Animation menu produits
	if($('#menu-visuel-produits').length > 0){
		$('#menu-visuel-produits li').hover(function() {
		  	$(this).animate({top: "-10px"}, 300);
		},function(){
			$(this).animate({top: "0px"}, 300);
		});

	}
	
	//-----------------------------------------------------------------------------------------------
	
	
	

	//-----------------------------------------------------------------------------------------------
	// Sous menus déroulant menu principal
	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
			
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}


	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 100, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	//---------------------------------------------------------------------------------
	// Menu principal
	
	$("ul#topnav li .sub").css({'opacity':'0'});
	$("ul#topnav li").hoverIntent(config);
	
	
	$('ul#topnav li a.mm').mouseover(function(){
		$('ul#topnav .sub ul.sub-img').css('display','none');
		$('ul#topnav .sub ul.sub-img li').css('display','none');
		$('ul#topnav li .sub ul.sub-text li a').css('border-right','1px solid #f9f9f9');

	});
	
	// Gestion de l'affichage des visuels dans le menu
	/*$('ul#topnav li .sub ul.sub-img').css('padding-top','0px');
	$('ul#topnav li .sub ul.sub-text li a').css('border-right','1px solid #f9f9f9');
	$('ul#topnav .sub ul.sub-img').css('display','none');
	$('ul#topnav .sub ul.sub-img li').css('display','none');*/
	
	
	//--------------------------------------------------------------------------------
	// Correction problème de z-index entre fil d'ariane et sous-menus déroulants du meu principal
	
	/*$('ul#topnav').hover(function(){
		$(this).css('z-index','600');
		$('#breadcrumb').css('z-index','500');
		$('#header').css('z-index','400');
	},function(){
		$(this).css('z-index','500');
		$('#breadcrumb').css('z-index','600');
		$('#header').css('z-index','400');
	});*/
	//---------------------------------------------------------------------------------
	
	$('ul#topnav .sub ul.sub-text li').hover(function(){
		
		$('ul#topnav li .sub ul.sub-text li a').css('border-right','1px solid #f9f9f9');
		$('ul#topnav .sub ul.sub-img').css('display','none');
		$('ul#topnav .sub ul.sub-img li').css('display','none');
	
		if ($('ul#topnav .sub ul.sub-img li').is(':visible')) {
			$('ul#topnav li .sub ul.sub-text li a').css('border-right','1px solid #f9f9f9');
			$('#imgsm'+ $(this).attr('id')).parent().css('display','none');
			$('ul#topnav .sub ul.sub-img li').css('display','none');
		}
	
		if($('#imgsm'+ $(this).attr('id')).length > 0){
			$('#imgsm'+ $(this).attr('id')).parent().css('display','block');
			$('#imgsm'+ $(this).attr('id')).css('display','block');
			$(this).parent().children().children('a').css('border-right','1px solid #003c8c');
			$('ul#topnav li .sub ul.sub-img').css('padding-top','10px');
			
			$('#imgsm'+ $(this).attr('id')).parent().height($(this).parent().height());
			
		}
		else{
		   $(this).parent().children().children('a').css('border-right','1px solid #f9f9f9');
			$('#imgsm'+ $(this).attr('id')).parent().css('display','none');
			$('#imgsm'+ $(this).attr('id')).css('display','none');
		}
		
		$('ul#topnav li .sub ul.sub-img li a').mouseover(function(){
			
			 $(this).parent().children().children('a').css('border-right','1px solid #003c8c');
		})
		
		$('ul#topnav li .sub ul.sub-img li a').mouseout(function(){
			 $(this).parent().children().children('a').css('border-right','1px solid #f9f9f9');
			$('#imgsm'+ $(this).attr('id')).parent().css('display','none');
			$('#imgsm'+ $(this).attr('id')).css('display','none');
		})

	})


	
	//---------------------------------------------------------------------------------
	
	// Sous menus déroulant menu intérieur horizontal
	var config2 = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 100, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#intnav li .sub").css({'opacity':'0'});
	$("ul#intnav li").hoverIntent(config2);
	
	
	$('ul#intnav li a.smih').mouseover(function(){
		$('ul#intnav li .sub ul.sub-text2').css('width','235px');
		$('ul#intnav .sub ul.sub-img2').css('display','none');
		$('ul#intnav .sub ul.sub-img2 li').css('display','none');
		$('ul#intnav li .sub ul.sub-text2 li a').css('border-right','1px solid #f9f9f9');
	});
	
	$('ul#intnav .sub ul.sub-text2 li').hover(function(){
		
		$('ul#intnav li .sub ul.sub-text2 li a').css('border-right','1px solid #f9f9f9');
		$('ul#intnav .sub ul.sub-img2').css('display','none');
		$('ul#intnav .sub ul.sub-img2 li').css('display','none');
	
		if ($('ul#intnav .sub ul.sub-img2 li').is(':visible')) {
			$('ul#intnav li .sub ul.sub-text2 li a').css('border-right','1px solid #f9f9f9');
			$('#imgsm2'+ $(this).attr('id')).parent().css('display','none');
			$('ul#intnav .sub ul.sub-img2 li').css('display','none');
		}
	
		if($('#imgsm2'+ $(this).attr('id')).length > 0){
			$('#imgsm2'+ $(this).attr('id')).parent().css('display','block');
			$('#imgsm2'+ $(this).attr('id')).css('display','block');
			$(this).parent().children().children('a').css('border-right','1px solid #003c8c');
			$('ul#intnav li .sub ul.sub-img2').css('padding-top','10px');
			$(this).parent().css('width','160px');
			
			$('#imgsm2'+ $(this).attr('id')).parent().height($(this).parent().height());
			
		}
		else{
		   $(this).parent().children().children('a').css('border-right','1px solid #f9f9f9');
			$('#imgsm2'+ $(this).attr('id')).parent().css('display','none');
			$('#imgsm2'+ $(this).attr('id')).css('display','none');
		}
		
		$('ul#intnav li .sub ul.sub-img2 li a').mouseover(function(){
			
			 $(this).parent().children().children('a').css('border-right','1px solid #003c8c');
		})
		
		$('ul#intnav li .sub ul.sub-img2 li a').mouseout(function(){
			 $(this).parent().children().children('a').css('border-right','1px solid #f9f9f9');
			$('#imgsm2'+ $(this).attr('id')).parent().css('display','none');
			$('#imgsm2'+ $(this).attr('id')).css('display','none');
		})

	})
	
});


//Alex affichage de l heure et recherche de la recette associée

var typerecette = 0;
var inforepas = new String();

function date_heure(id)
{
        date = new Date();
		
        h = date.getHours();
        if(h<10)
        {
                h = "0"+h;
        }
		//petit dej
		if(h>=0 && h<11)
		{
			 
			 typerecette = 1;
			 if($('#info-repas').length>0){
			 inforepas = "C'est l'heure du<br />petit déjeuner";
			 document.getElementById("info-repas").innerHTML = inforepas;
			
			 }
		}
		//apero 
		if(h>=11 && h <12)
		{
			 typerecette = 6;
			 if($('#info-repas').length>0){
			 inforepas = "C'est l'heure de<br />l'apéritif";
			 document.getElementById("info-repas").innerHTML = inforepas;
			 }
		}
		//plat 
		if(h>=12&& h <15)
		{
			 typerecette = 3;
			 if($('#info-repas').length>0){
			 inforepas = "C'est l'heure du<br />déjeuner";
			 document.getElementById("info-repas").innerHTML = inforepas;
			 }
		}

		//gouter 
		if(h>=15 && h <18)
		{
			 typerecette = 4;
			 if($('#info-repas').length>0){
			 inforepas = "C'est l'heure du<br />goûter";
			 document.getElementById("info-repas").innerHTML = inforepas;
			 }
		}
		//apero 
		if(h>=18 && h <19)
		{
			 typerecette = 6;
			 if($('#info-repas').length>0){
			 inforepas = "C'est l'heure de<br />l'apéritif";
			 document.getElementById("info-repas").innerHTML = inforepas;
			 }
		}

		//soir	
		if(h>=19 && h <=24)
		{
			 typerecette = 3;
			 if($('#info-repas').length>0){
			 inforepas = "C'est l'heure du<br />dîner";
			 document.getElementById("info-repas").innerHTML = inforepas;
			 }
		}

        m = date.getMinutes();
        if(m<10)
        {
                m = "0"+m;
        }
		
		
        s = date.getSeconds();
        if(s<10)
        {
                s = "0"+s;
        }
        resultat = h+'&nbsp;:&nbsp;'+m+'&nbsp;:&nbsp;'+s;
		
         if($('#'+id).length>0){
			 document.getElementById(id).innerHTML = resultat;
		 }


        setTimeout('date_heure("'+id+'");','1000');
        return typerecette;
}

 


