
function applyShadows(obj, options) {
    var output = '';
    obj.addClass('apply-shadow');
    if (options == undefined) {
        opt = { clt: true, crt: true, clb: true, crb: true, mb: true, mt: true, ml: true, ml: true, mr: true, isDrop: false, css: '' };
    } else {
        opt = options;
        opt.css = ' ' + opt.css;
    }

    var contWidth = obj.width() + 'px';
    var contHLeft = obj.height() + 'px';
    var contHright = obj.height() + 'px';

    if (opt.clt) { output += '<span class="clt shadow-remove' + opt.css + '"></span>'; }
    if (opt.crt) { output += '<span class="crt shadow-remove' + opt.css + '"></span>'; }
    if (opt.clb) { output += '<span class="clb shadow-remove' + opt.css + '"></span>'; }
    if (opt.crb) { output += '<span class="crb shadow-remove' + opt.css + '"></span>'; }
    if (opt.mb) {

        var offset = (opt.isDrop) ? -20 : 0;

        styles = (obj.width() + offset) + 'px;left:25px;';
        output += '<span class="mb shadow-remove' + opt.css + '" style="width:' + styles + '"></span>';
    }
    if (opt.mt) {

        var offset = (opt.isDrop) ? 2 : -23;

        styles = 'width:' + (obj.width() + offset) + 'px;';
        output += '<span class="mt shadow-remove' + opt.css + '" style="' + styles + '"></span>';
    }

    if (opt.ml) {

        var offset = (opt.isDrop) ? -10 : -10;

        styles = (obj.height() + offset) + 'px;';
        output += '<span class="ml shadow-remove' + opt.css + '" style="height:' + styles + '"></span>';
    }
    if (opt.mr) {

        var offset = (opt.isDrop) ? -10 : -10;

        styles = (obj.height() + offset) + 'px;';
        output += '<span class="mr shadow-remove' + opt.css + '" style="height:' + styles + '"></span>';
    }
    return output;
}

//Flyout navigation menu
function openMenu() {
    var appObj = $(this).children('.p-menu-item-0-a');
    var hasSelect = $(this).hasClass('p-menu-item-current');

    if (hasSelect) { $(this).removeClass('select'); }
    appObj.append(applyShadows(appObj, { clt: true, crt: true, mt: true, ml: true, mr: true, css: 'p-shadow-a' }));
    $(this).children('.p-menu-panel').show();

    // ie hover issue fix
    $('.p-menu-item-text', this).addClass('p-menu-item-text-hover');
    $('.p-menu-item-a', this).addClass('p-menu-item-a-hover');
    if ($(this).closest('.c-top-menu').length > 0)
        $('.p-menu-item-a', this).addClass('p-menu-item-text-hover');
}
function closeMenu() {
    var appObj = $(this).children('.p-menu-item-0-a');
    var hasSelect = $(this).hasClass('p-menu-item-current');

    appObj.children('.shadow-remove').remove();
    $(this).children('.p-menu-panel').hide();
    if (hasSelect) { $(this).addClass('select'); }

    // ie hover issue fix
    $('.p-menu-item-text', this).removeClass('p-menu-item-text-hover');
    $('.p-menu-item-a', this).removeClass('p-menu-item-a-hover');
    if ($(this).closest('.c-top-menu').length > 0)
        $('.p-menu-item-a', this).removeClass('p-menu-item-text-hover');
    if (ie) {
        mflag = false;
    }
}
var ie = /*@cc_on!@*/false;
var cFlag = null;
var mflag = false;
var mtm = null;
$(function () {

    $('.p-menu-item-has-children').each(function () {

        $(this).hover(
		    function () {
		        if (ie && cFlag != $(this).attr('id'))
		            closeMenu.apply($("#" + cFlag));

		        if ((ie && !mflag) || !ie) {
		            openMenu.apply($(this));
		            if (ie) {
		                mflag = true;
		                cFlag = $(this).attr('id');
		            }
		        }
		        if (ie) {
		            clearTimeout(mtm);
		        }
		    },
		    function () {
		        if (!ie) {
		            closeMenu.apply($(this));
		        }
		        else {
		            var $this = $(this);
		            mtm = setTimeout(function () {
		                closeMenu.apply($this);
		                //mflag = false;
		            }, 500);
		        }
		    });
    });

    $('.p-menu-panel').each(function () {
        $(this).append(applyShadows($(this), { clb: true, crb: true, mb: true, ml: true, mr: true, isDrop: true, css: 'p-shadow-panel' }));
    });

});

/*
$(function () {

    $('.p-menu-item-has-children').each(function () {
        var appObj = $(this).children('.p-menu-item-0-a');
        var hasSelect = $(this).hasClass('p-menu-item-current');
        $(this).hover(
		    function () {
		        if (hasSelect) { $(this).removeClass('select'); }
		        appObj.append(applyShadows(appObj, { clt: true, crt: true, mt: true, ml: true, mr: true, css: 'p-shadow-a' }));
		        $(this).children('.p-menu-panel').show();

		        // ie hover issue fix
		        $('.p-menu-item-text', this).addClass('p-menu-item-text-hover');
		        $('.p-menu-item-a', this).addClass('p-menu-item-a-hover');
		        if ($(this).closest('.c-top-menu').length > 0)
		            $('.p-menu-item-a', this).addClass('p-menu-item-text-hover');
		    },
		    function () {
		        appObj.children('.shadow-remove').remove();
		        $(this).children('.p-menu-panel').hide();
		        if (hasSelect) { $(this).addClass('select'); }

		        // ie hover issue fix
		        $('.p-menu-item-text', this).removeClass('p-menu-item-text-hover');
		        $('.p-menu-item-a', this).removeClass('p-menu-item-a-hover');
		        if ($(this).closest('.c-top-menu').length > 0)
		            $('.p-menu-item-a', this).removeClass('p-menu-item-text-hover');
		    });
    });
    $('.p-menu-panel').each(function () {
        $(this).append(applyShadows($(this), { clb: true, crb: true, mb: true, ml: true, mr: true, isDrop: true, css: 'p-shadow-panel' }));
    });
});
*/
