/*=============================================================================================
Custom JAVASCRIPT ::: BORDEAU CHESNEL ::: © 2010 - ADVISA
=============================================================================================*/

var mainMenuWidth		=	0;
var contentWidth		=	960;

var mainButtonHeight		=	45;
var subButtonHeight		=	28 + 1;	// 2 de padding en haut et en bas



$(document).ready( function() {
 	
	
	// --> Injecte bloc saucisson dans la colonne de droite
	if ( $('.liste-74').length > 0 )
	{
		$('.liste-74').css('display', 'none');
		var daDl = $('.liste-74').html();
		$('.liste-18').append(daDl);
	}
	
	
	if ( $('.menu-top li') || $('.menu-uk li') )
	{
		
		
		// --> Afficher le menu
			$('.menu-top li').mouseenter(function() {
				
				var nbItems		=	$(this).find('ul li').length;
				var daWidth		=	$(this).innerWidth();
				var daHeight		=	nbItems * subButtonHeight + mainButtonHeight;
				
				//debugJS( daWidth + '---' + daHeight );
				
				var daItem		=	$(this).find('.outerMenu');
				var daItemInner 	=	$(this).find('.innerMenu');
				
				daItem.css('width',daWidth + 40 );
				daItem.css('margin-left', parseInt( - (daWidth + 40) / 2 ) );
					
				daItem.css('height',daHeight );
				daItemInner.css('height',daHeight );
					
				$(this).find('.top-corner-right').css('width', daWidth + 20);
				$(this).find('.bottom-corner-right').css('width', daWidth + 20);
				
				
				$(this).addClass('menuOver');
				
			});
			$('.menu-top li').mouseleave(function() {
				var daItem		=	$(this).find('.outerMenu');
				var daItemInner =	$(this).find('.innerMenu');
				
				daItem.css('height', mainButtonHeight );
				daItemInner.css('height', mainButtonHeight );
				
				$(this).removeClass('menuOver');
				
				//$(this).css('display','none');
			});
			
			$('.menu-uk li').mouseenter(function() {
				
				var nbItems		=	$(this).find('ul li').length;
				var daWidth		=	$(this).innerWidth();
				var daHeight		=	nbItems * subButtonHeight + mainButtonHeight;
				
				//debugJS( daWidth + '---' + daHeight );
				
				var daItem		=	$(this).find('.outerMenu');
				var daItemInner 	=	$(this).find('.innerMenu');
				
				daItem.css('width',daWidth + 40 );
				daItem.css('margin-left', parseInt( - (daWidth + 40) / 2 ) );
					
				daItem.css('height',daHeight );
				daItemInner.css('height',daHeight );
					
				$(this).find('.top-corner-right').css('width', daWidth + 20);
				$(this).find('.bottom-corner-right').css('width', daWidth + 20);
				
				
				$(this).addClass('menuOver');
				
			});
			$('.menu-uk li').mouseleave(function() {
				var daItem		=	$(this).find('.outerMenu');
				var daItemInner =	$(this).find('.innerMenu');
				
				daItem.css('height', mainButtonHeight );
				daItemInner.css('height', mainButtonHeight );
				
				$(this).removeClass('menuOver');
				
				//$(this).css('display','none');
			});
			
			
			
			/*$('.menu-top li li a').mouseenter(function() {
				$(this).addClass('txt-white');
			});
			$('.menu-top li li a').mouseleave(function() {
				$(this).unwrap();
			});*/
		/**
		 * PICTURES : Affichage actualités
		 */
			if ( $('.zoom-pic').length > 0 )
			{
				$('.zoom-pic').fancybox({
					'padding'		: 2,
					'titleShow'		: false,
					'overlayOpacity': 0.8
				});
			}
			if ( $('.zoom-pic-en').length > 0 )
			{
				$('.zoom-pic-en').fancybox({
					'padding'		: 2,
					'titleShow'		: false,
					'overlayOpacity': 0.8
				});
			}
			
			
			
			if ( $('.nutrition').length > 0 )
			{
				$('.bt-zoom-nutrition').fancybox({
					'scrolling'		: 'no',
					'titleShow'		: false,
					'padding'		: 2,
					'onClosed'		: function() {
					    $(".tab-nutrition").hide();
					}
				});
			}
			
			if ( $('.pad-art-content-txt').length > 0 )
			{
				$('.pad-art-content-txt').each( function () {
					var trameDebut	=	'<div class="bloc-txt"><div class="corner-left-top"><div class="corner-right-top"></div></div><div class="corner-left-bottom"><div class="corner-right-bottom"></div></div>';
					var trameFin	=	'</div>';
					
					$(this).html(trameDebut + $(this).html() + trameFin );
					//pad-art-content-txt
					//if($.browser.msie && $.browser.version=="6.0")
					//{
						$('.bloc-txt li').addClass('.li-ie6 ');
						
					//}
					
					
				});
			}
			
			if ( $('.vidLink').length > 0 )
			{
				$(".vidLink").click(function() {
					//$(".mainDoc").css('display','none');
					
					$.fancybox({
						'padding'		: 0.8,
						'autoScale'		: false,
						'overlayOpacity': 0.8,
						'transitionIn'	: 'none',
						'transitionOut'	: 'none',
						'title'			: this.title,
						'width'			: 640,
						'height'		: 385,
						'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
						'type'			: 'swf',
						'swf'			: {
						   	 'wmode'		: 'transparent',
							'allowfullscreen'	: 'true'
						}
					});

				return false;
				});
			}
			if ( $('.vidLinkAlone').length > 0 )
			{
				$(".vidLinkAlone").click(function() {
					//$(".mainDoc").css('display','none');
					
					$.fancybox({
						'padding'		: 0.8,
						'autoScale'		: false,
						'overlayOpacity': 0.8,
						'transitionIn'	: 'none',
						'transitionOut'	: 'none',
						'title'			: this.title,
						'width'			: 640,
						'height'		: 385,
						'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
						'type'			: 'swf',
						'swf'			: {
						   	 'wmode'		: 'transparent',
							'allowfullscreen'	: 'true'
						}
					});

				return false;
				});
			}
			
			if ( $('.roundedCorner').length > 0 )
			{
				$('.roundedCorner').each( function () {
					
					var innerIMG	=	$(this).find('img');
					
					var trameDebut	=	'<div class="bloc-img" style="height:'+innerIMG.height()+'px"><div class="corner-left-top" style="width:'+innerIMG.width()+'px"><div class="corner-right-top"></div></div><div class="corner-left-bottom" style="width:'+innerIMG.width()+'px"><div class="corner-right-bottom"></div></div>';
					var trameFin	=	'</div>';
					
					$(this).html(trameDebut + $(this).html() + trameFin );
				});
			}
			
			if ( $('.country').length > 0 )
			{
				$('.country').change( function() {
					$('.country-displayed').removeClass('country-displayed');
					$('.liste-' + $(this).attr('value') ).addClass('country-displayed');
					$('p.liste-pays').addClass('country-displayed');
				});
				
				$('.liste-pays').change( function() {
					document.location = $(this).attr('value');
				});
			}
			
			
			
			
			

			
	}
	
	/**
	 * FORMULAIRE : Messages d'erreur
	 */
	if ( $("#errorPad") )
	{
		$("#errorPad").click(function(){
			$(this).fadeOut();
			$("#erlogPad").fadeOut();
		});
		$("#erlogPad").click(function(){
			$(this).fadeOut();
			$("#errorPad").fadeOut();
		});
	}

if ( $(".one-legend").length > 0 )
			{
				if ( $('.post_it').length > 0 ) {
					
					$('.one-legend').mousemove(function(e) {
                		if ( $('.post_it').css('display','none') )
						{
							if ($(this).children("em").text().length > 0){
								text = '<td class="legend-text">'+$(this).children("em").text()+'</td>';
							}
							else {
								text = '<td class="legend-text">'+$(this).children("i").text()+'</td>';
							}
                    
                    
                    //alert()
                    if ( $('.post_it').html() == '' )
		    {
			
			
			var textExplication =   '<table class="tabInfo"><tr><td class="arrow"></td>' + text + '</tr></table><p class="bt">&nbsp;</p>';
			//alert(textExplication);
			$('.post_it').html(textExplication);
		    }

                    
                    //alert($(this).children("em").text());
                    
                    $('.post_it').css('display', 'block');
                    $('.post_it').css('z-index', '1000000'); 
                }
                if (e.pageX || e.pageY) {
                    posx = e.pageX;
                    posy = e.pageY;
                }
                else if (e.clientX || e.clientY) {
                    posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
                    posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
                }
                
		var hauteurPostIt = $('.post_it').height();
		hauteurPostIt	=	parseInt(hauteurPostIt);
		
		if($.browser.msie)
		{
		    marge = 12;
		}
		else
		{
		    marge = 7;
		}
		
		
                topZoom = posy - (hauteurPostIt / 2) + marge ;
                
                $('.post_it').css('left', posx + 50);
                $('.post_it').css('top', topZoom);
            
            });
            
            $('.one-legend').mouseout(function(ev) {
		 $('.post_it').html('');
                $('.post_it').css('display', 'none');
                $('.post_it').css('left', '0');
                $('.post_it').css('top', '0');
            });
	    
	    
            
        }
      
      }	


});
function GetFocus( obj, txtDefault )
{
	
	if ( obj.value == txtDefault )
	{
		obj.value	=	"";
	}

}
function GetBlur( obj, txtDefault )
{
	
	if ( obj.value == "" )
	{
		obj.value	=	txtDefault;
	}

}

function openoverlay( urlDuLien ) {
		$.fancybox({
				'padding'		: 0,
				'href'			: urlDuLien,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});

}
	
	
// ---> Debuggage JS
		function debugJS(elem)
		{
			$('.debugJS').append(elem+"<br />");
		}
		
