function debug(a) {
    //document.getElementById("aaa").innerHTML += a + "";
}
window.menu_showhide_delay = 150;
window.box_animation_frames = 3;
var jMenuTimer;
var jIsOut = true;
var jEffectX = 0;
var jEffectY = 0;
var jDropDownOffsetY = 25;
var jOverImage = "/Assets/images/m2-2.gif";
var jOutImage = "/Assets/images/m2-1.gif";
var jMenuId, jDropDownId, jEffectId, jFrameId;
function jInitMenu() {
    $(jMenuId).bind("mouseover", function() {
        debug("-1");
        jIsOut = false;
        jShow();
    });
    $(jMenuId).bind("mouseout", function() {
        debug("-2");
        jIsOut = true;
        jHide();
    });
    $(jDropDownId).bind("mouseover", function() { 
        jIsOut = false;
        jShow();
    });
    $(jDropDownId).bind("mouseout", function() { 
        jIsOut = true;
        jHide();
    });
    //setTimeout("jShowEffect();", menu_showhide_delay);

    if ($.browser.msie) {
        if (parseInt($.browser.version, 10) == 8) {
            window.box_animation_frames = 3;
        }
        else if (parseInt($.browser.version, 10) == 7) {
        jDropDownOffsetY += 15;
        window.box_animation_frames = 3;
        }
        else if (parseInt($.browser.version, 10) == 6) {
        jDropDownOffsetY += 15;
        window.box_animation_frames = 3;
        }
    }
    else if ($.browser.mozilla) {
    jDropDownOffsetY -= 5;
    window.box_animation_frames = 3;
    }
    else if ($.browser.safari) {
        window.box_animation_frames = 4;
    }
    else {
    }


    jEffectX = $(jDropDownId).outerWidth() / 2 / box_animation_frames;
    jEffectY = $(jDropDownId).outerHeight() / 2 / box_animation_frames;


        if ($('#producten')[0]) {
            $('#productenmenu')[0].src = '/Assets/images/m2-2.gif';
        }


}; 
function jShow(){
    if(window.jMenuTimer){
        clearTimeout(window.jMenuTimer);
    }
    //jMenuTimer = setTimeout("jShowTimer() ;clearTimeout(window.jMenuTimer);", menu_showhide_delay);
    jShowTimer();
};
function jHide() {
    if (jMenuTimer) {
        clearTimeout(window.jMenuTimer);
    }
    window.jMenuTimer = setTimeout("jHideTimer();clearTimeout(window.jMenuTimer);", window.menu_showhide_delay);
};
function jShowTimer() {
    //jShowDropDown();
    jShowEffect(); 
};
function jHideTimer() {
    jHideDropDown();
    jShowEffect(); 
};
function jShowDropDown() {
    var offset = $(jMenuId).offset(true);

    var left = offset.left;
    var top = offset.top + window.jDropDownOffsetY;
    $(jDropDownId).css("left",  left);
    $(jDropDownId).css("top", top);
    $(jFrameId).css("left", left);
    $(jFrameId).css("top", top);
    $(jFrameId).css("width", $(jDropDownId).width());
    $(jFrameId).css("height", $(jDropDownId).height());
    $(jDropDownId).show();
    $(jFrameId).show();
    document.jMenuIsVisible = true;

    if( $(jMenuId+" img").attr("src") !=jOverImage )$(jMenuId+" img").attr("src", jOverImage);
    $(jEffectId).hide();
};
function jHideDropDown() { 
    $(jDropDownId).hide();
    $(jFrameId).hide();
    if($(jMenuId + " img").attr("src")!=jOutImage) $(jMenuId + " img").attr("src", jOutImage);
    document.jMenuIsVisible = false;
};

window.jCurI = 0;
var jEffectTimer;
function jShowEffect() {



    //document.title = jCurI;

    if (jIsOut) {
        window.jCurI--;
    }
    else {
        window.jCurI++;
    }
    
    var curx = jEffectX * window.jCurI; 
    if (curx < 0) {
        window.jCurI++;
        $(jEffectId).hide();
        clearTimeout(window.jEffectTimer);
    }
    else if (curx > $(jDropDownId).outerWidth() / 2) {
        window.jCurI--;
        $(jEffectId).hide();
        jShowDropDown();
        clearTimeout(window.jEffectTimer);
    }
    else {
        


        var curx = jEffectX * window.jCurI;
        var cury = jEffectY * window.jCurI;
        var width = curx * 2;
        var height = cury * 2;
        var left = $(jMenuId).offset().left + $(jDropDownId).outerWidth()/2 - width /2 ;
        var top = $(jMenuId).offset().top +  $(jDropDownId).outerHeight() / 2 - height / 2;
        top = top + jDropDownOffsetY; 


        $(jEffectId).css("left", left);
        $(jEffectId).css("top", top);
        $(jEffectId).css("width", width);
        $(jEffectId).css("height", height);

        //document.title = getVisible($(jEffectId));
        //document.title = $(jEffectId).css("visibility") + $(jEffectId).css("display");
        if (!getVisible($(jEffectId))) {
            $(jEffectId).show();
        }
    }
    jEffectTimer = setTimeout("jShowEffect();", window.menu_showhide_delay);
    return;
     
}
function getVisible(obj) {
    var b = false;
    if ($.browser.msie) {
        b = obj.css("visibility") == "visible";
    }
    else if ($.browser.mozilla) {
        b=obj.css("display")!="none";
    }
    else if ($.browser.safari) {
        b = obj.css("display") != "none";
    }
    else {
        b = obj.css("visibility") == "visible";
    }
    return b;
}
$(document).ready(function() {
    jDropDownId = "#jm_drop";
    jMenuId = "#jm_";
    jEffectId = "#jm_effect";
    jFrameId = "#jm_frm";
    jInitMenu();
});