/*!jQuery d�lais sur menus et sous menus
 * jQuery doTimeout: Like setTimeout, but better! - v1.0 - 3/3/2010
 * http://benalman.com/code/projects/jquery-dotimeout
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */

 (function($) {
    '$:nomunge';
    // Used by YUI compressor.
    var cache = {},
    doTimeout = 'doTimeout',
    aps = Array.prototype.slice;


    $[doTimeout] = function() {
        return p_doTimeout.apply(window, [0].concat(aps.call(arguments)));
    };

    $.fn[doTimeout] = function() {
        var args = aps.call(arguments),
        result = p_doTimeout.apply(this, [doTimeout + args[0]].concat(args));

        return typeof args[0] === 'number' || typeof args[1] === 'number'
        ? this
        : result;
    };

    function p_doTimeout(jquery_data_key) {
        var that = this,
        elem,
        data = {},

        method_base = jquery_data_key ? $.fn: $,
        args = arguments,
        slice_args = 4,

        id = args[1],
        delay = args[2],
        callback = args[3];

        if (typeof id !== 'string') {
            slice_args--;

            id = jquery_data_key = 0;
            delay = args[1];
            callback = args[2];
        }

        if (jquery_data_key) {
            // Note: key is 'doTimeout' + id
            // Get id-object from the first element's data, otherwise initialize it to {}.
            elem = that.eq(0);
            elem.data(jquery_data_key, data = elem.data(jquery_data_key) || {});

        } else if (id) {
            // Get id-object from the cache, otherwise initialize it to {}.
            data = cache[id] || (cache[id] = {});
        }

        // Clear any existing timeout for this id.
        data.id && clearTimeout(data.id);
        delete data.id;

        // Clean up when necessary.
        function cleanup() {
            if (jquery_data_key) {
                elem.removeData(jquery_data_key);
            } else if (id) {
                delete cache[id];
            }
        };

        // Yes, there actually is a setTimeout call in here!
        function actually_setTimeout() {
            data.id = setTimeout(function() {
                data.fn();
            },
            delay);
        };

        if (callback) {
            // A callback (and delay) were specified. Store the callback reference for
            // possible later use, and then setTimeout.
            data.fn = function(no_polling_loop) {

                // If the callback value is a string, it is assumed to be the name of a
                // method on $ or $.fn depending on where doTimeout was executed.
                if (typeof callback === 'string') {
                    callback = method_base[callback];
                }

                callback.apply(that, aps.call(args, slice_args)) === true && !no_polling_loop

                // Since the callback returned true, and we're not specifically
                // canceling a polling loop, do it again!
                ? actually_setTimeout()

                // Otherwise, clean up and quit.
                : cleanup();
            };

            // Set that timeout!
            actually_setTimeout();

        } else if (data.fn) {
            // No callback passed. If force_mode (delay) is true, execute the data.fn
            // callback immediately, continuing any callback return-true polling loop.
            // If force_mode is false, execute the data.fn callback immediately but do
            // NOT continue a callback return-true polling loop. If force_mode is
            // undefined, simply clean up. Since data.fn was still defined, whatever
            // was supposed to happen hadn't yet, so return true.
            delay === undefined ? cleanup() : data.fn(delay === false);
            return true;

        } else {
            // Since no callback was passed, and data.fn isn't defined, it looks like
            // whatever was supposed to happen already did. Clean up and quit!
            cleanup();
        }

    };

})(jQuery);

/**
 * Gestion menu principal + secondaire
*/
$(function()
	{
		
	$(".menutitle-vintages").addClass("menutitle-mill--simes")
	$(".menutitle-mill--simes>ul>li").find('ul').remove()
	 
	if(navigator.userAgent.match(/iPad/i)) //----------------------------------------------------- Si on est sur un Ipad 
		{
		$('body').addClass('iPad')
		var liste = $(this).find("div.view-feature-03-millesimes")
		
		var LIs = $(liste).find(".dock-container a")
		var target = $("#dock")
		target.append("<select></select>") //------------------------------------------------------- On met les millesimes dans une BoxList
		var select = $(target).find("select")
		
		$(LIs).each(function(item){select.append('<option value="' + this.href + '">' + this.text + '</option>')})
		select.change(function(){
			var loc = this.options[this.selectedIndex].value
			window.location = loc
			})
		$(".dock-container").remove()
		$('#menuBackground').height(0)
		}
	else //----------------------------------------------------------------------------------------- Si on est pas sur un Ipad
		{
		$('nav.menu').slideDown("slow");
		$(".menu_down").mouseenter(function() {$('nav.menu').slideDown("slow"); });
		}
	

	$(".menu_principal").mouseleave(
		function()
			{
			$('#menuBackground').height(0)
			 if ($('body').hasClass('not-front') && !($('body').hasClass('iPad')) && !($.browser.msie)){//-------------------- Si on est pas sur Homepage ni sur Ipad
				$('nav.menu').slideUp("slow")
				}//------------------------- alors on peut fermer le menu
			}
		);
		
	$("nav>ul>li").mouseenter(
		function() {
			var bgMenu = $('#menuBackground')
			var menu = $(this).find('ul')
			
			if (menu != undefined)
				{
				oldMenu = menu
				var h = ($(menu).height() > 0) ? $(menu).height()+15:0;
				$(bgMenu).height(h)
				}
		}
	);
}
)
