/*--FUNCTIONS.JS--*/

//Fonction permettant de contrer le problème d'affichage des PNG sur IE6
/*function pngFix(){
	$(".pngFix").each(function(){
		$(this).children('img').css('visibility','hidden');
		$(this).css('display','block');
		$(this).css('width',$(this).children('img').width()+"px");
		$(this).css('height',$(this).children('img').height()+"px");
		$(this).css('filter',"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+$(this).children('img').attr('src')+"', sizingMethod='crop');");
	});
}*/

$(document).ready(function () { 
        var userAgent = navigator.userAgent.toLowerCase(); 
        jQuery.browser = { 
            version: (userAgent.match( /.+(?:rv|it|ra|ie|me)[\/: ]([\d.]+)/ ) || [])[1], 
            chrome: /chrome/.test( userAgent ), 
            safari: /webkit/.test( userAgent ) && !/chrome/.test( userAgent ), 
            opera: /opera/.test( userAgent ), 
            msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ), 
            mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent ) 
        }; 
        /*$.each($.browser, function(i, val) { 
         $("<div>" + i + " : <span>" + val + "</span></div>") 
            .appendTo(document.body); 
        }); */
})


$(document).ready(function(){
							   
	if(jQuery.browser.chrome){
		$('#mainMenu li.lastChild a.levelOne').each(function(){
			$(this).css('padding-right', '5px');
			$(this).css('padding-left', '4px');
		});	
	}

	if(jQuery.browser.msie && jQuery.browser.version=="7.0"){
		$('#mainMenu div.sub').each(function(){
			$(this).parent('li').mouseenter(function(){
				$(this).children('div.sub').css('top', '52px');
			});
			$(this).parent('li').mouseleave(function(){
				$(this).children('div.sub').css('top', '-999px');
			});
			/*$(this).mouseleave(function(){
				$(this).css('top', '-999px');
			});*/
		});
		
		$('#topMenu div.sub').each(function(){
			$(this).parent('li').mouseenter(function(){
				$(this).children('div.sub').css('top', '22px');
			});
			$(this).parent('li').mouseleave(function(){
				$(this).children('div.sub').css('top', '-999px');
			});
		});
	}
	
	if(jQuery.browser.msie && jQuery.browser.version=="6.0"){
		
		//Gestion des PNG sur IE6
		//pngFix();
	
		$('#mainMenu div.sub').each(function(){
			$(this).parent('li').mouseenter(function(){
				$('select').each(function(){
					$(this).css('visibility','hidden');
				});
			});
			$(this).parent('li').mouseleave(function(){
				$('select').each(function(){
					$(this).css('visibility','visible');
				});
			});
		});
		
		$('#topMenu div.sub').each(function(){
			$(this).parent('li').mouseenter(function(){
				$('select').each(function(){
					$(this).css('visibility','hidden');
				});
			});
			$(this).parent('li').mouseleave(function(){
				$('select').each(function(){
					$(this).css('visibility','visible');
				});
			});
		});
	
	}
	
   // dans IE7 on corrige les pb d'affichage du popup sur la barre verte et surtout sa disparition
    if (jQuery.browser.msie && jQuery.browser.version == "7.0") {
        $('#mainMenu div.sub').each(function() {
            $(this).parent('li').mouseenter(function() {
                $(this).children('div.sub').css('top', '52px');
            });
            $(this).parent('li').mouseleave(function() {
                $(this).children('div.sub').css('top', '-999px');
            });
        });
    }

    // puis pareil pour IE6
    if (jQuery.browser.msie && jQuery.browser.version == "6.0") {

        $('#mainMenu div.sub').each(function() {
            $(this).parent('li').mouseenter(function() {
                $('select').each(function() {
                    $(this).css('visibility', 'hidden');
                });
            });
            $(this).parent('li').mouseleave(function() {
                $('select').each(function() {
                    $(this).css('visibility', 'visible');
                });
            });
        });
    }


    // le menu au dessus par contre ne doit réagir que sur click
    if (jQuery.browser.msie && jQuery.browser.version == "6.0") {
        $('#topMenu div.sub').each(function() {
            $(this).parent('li').mouseenter(function() {
                $('select').each(function() {
                    $(this).css('visibility', 'hidden');
                });
            });
            $(this).parent('li').mouseleave(function() {
                $('select').each(function() {
                    $(this).css('visibility', 'visible');
                });
            });
        });
    }
    else {
        $('#topMenu div.sub').each(function() {
            $(this).parent('li').click(function() {
                $(this).children('div.sub').css('top', '22px');
            });
            $(this).parent('li').mouseleave(function() {
                $(this).children('div.sub').css('top', '-999px');
            });
        });
    }

});

