﻿$(document).ready(function() {

    function addMega(){
        var menuDiv = $(this);
        var pos = menuDiv.offset(); 
        //alert(pos.left);
        if (pos.left > 474)
        {
            var leftPixels = (473 - pos.left);
            leftPixels = leftPixels +'px';
            $(this).find('div').css({'left' : 'auto', 'right' : '0px', '-moz-border-radius-topleft' : '8px', '-webkit-border-top-left-radius' : '8px', '-moz-border-radius-topright' : '0px', '-webkit-border-top-right-radius' : '0px'});
            //alert(leftPixels+'|'+pos.left);
            if (pos.left > 819)
                $(this).find('div').css({'left' : 'auto', 'right' : '0px', '-moz-border-radius-topright' : '0px', '-webkit-border-top-right-radius' : '0px'});
        }
        $(this).addClass("hovering");
        $(this).find('div').hide().fadeIn('fast');
    }

    function removeMega(){
        $(this).removeClass("hovering");
        $(this).find('div').fadeOut('fast');
    }

    var megaConfig = {
        interval: 25,
        sensitivity: 4,
        over: addMega,
        timeout: 25,
        out: removeMega
    };

    $("li.mega").hoverIntent(megaConfig)
});
