

function getMenu(menu){
    $('#menu_loading').show();
    $.ajax({
        url: '/inc/superMenus/getMenu.php?menu=' + menu,
        success: function(data) {
            $(".superMenu_content[rel='" + menu + "']").html(data);
            $('#menu_loading').hide();
            $(".superMenu_content[rel='" + menu + "']").show();
        }
    });
}

function invite() {
    $('#chatInvite').slideDown(250, function(){
        $('#questionCloud').animate({
            top: '-54px'
        }, 250)
    })
}

function hideMenu() {
    $.doTimeout('hidemenu', 600, function(){
        $('#navBar ul li a').removeClass('menuOpen');
        $('#superMenu_wrapper').slideUp('slow');
        $('.superMenu_content').fadeOut('fast');
        $('#contentContainer object').show();
    });
}


function scrollTo(elem) {
    target = $(elem);
		if (target.offset() !== null) {
			$('html,body').animate({
					scrollTop: target.offset().top
			}, 800);
		}
}


var decline_cookie = function(c_name, c_value, d_expire) {
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + d_expire);
    document.cookie = c_name+ "=" + escape(c_value) +
    ((d_expire == null) ? "" : ";expires="+exdate.toGMTString()) +
    ';path = /';

}

$(function(){
    var hidemenu = null;
    
    $("#navBar ul li:not('#signUp') > a.menuParent").bind('click', function(){
        var menu = $(this).parent().attr('id');
        $('#navBar ul li a').removeClass('menuOpen');
        $(this).addClass('menuOpen');
        $('#superMenu_wrapper').slideDown('fast', function(){
            $(".superMenu_content:not([rel='" + menu + "'])").hide();
            if($(".superMenu_content[rel='" + menu + "']").html() != '') {
                $(".superMenu_content[rel='" + menu + "']").show();
            } else {
                getMenu(menu);
            }
        });
        $('#contentContainer object').hide();
        return false;
    });
    $('#superMenu_wrapper').hover(function(){
        $.doTimeout('hidemenu');
    }, function(){
        hideMenu();
    });
    $('#navBar_inner, #navBar_inner a.menuParent').hover(function(){
        $.doTimeout('hidemenu');
    }, function(){
        hideMenu();
    });

    if ($.browser.msie && $.browser.version.substr(0,1)<7) {
        DD_belatedPNG.fix('#sideNav_menu h3, #gogrid_logo img, img.png, #navBar, #top_contact a, #connect a');
    }

    $('#liveChat_btn, .link_liveChat, .liveChat_link').click(function(){
        window.open('/inc/common/liveChat_tracker.php?referrer='+encodeURIComponent(document.location), 'chat69971338', 'width=472, height=320, resizable=yes, scrollbar=yes');
        //cmCreatePageviewTag("Live Chat Initiated", "Live Chat", null, null);
        return false;
    });

    $('#liveCall_btn, .link_liveCall, .liveCall_link').click(function(){
        window.open('/inc/common/liveCall_tracker.php?referrer='+encodeURIComponent(document.location), 'chat69971338', 'width=472, height=320, resizable=yes, scrollbar=yes');
        //cmCreatePageviewTag("Live Call Initiated", "Live Call", null, null);
        return false;
    });

    // SideNav accordion
    $('#sideNav_menu').accordion({
        header: 'h3',
        active: '.selected',
        autoheight: false
    });
    

    // Overlays
      $('.overlay').fancybox({
          transitionIn:'elastic',
          transitionOut: 'elastic'
      });

    // Generic tabs
    $('.tabbedContent').tabs();

    // Smooth Scrolling to Anchors
		$('.scrollMe').bind('click', function() {
				scrollTo($(this).attr('href'));
				return false;
		});

    // hide google conversion frame
    $('iframe[name="google_conversion_frame"]').css('display', 'none');
    
    // prevent ad pixels and scripts from creating gap at bottom of page
    $('#footerJS > img').css('display', 'none');
    $('#fancybox-hide-sel-frame').css('display', 'none');
    
    // custom chat slider

    setTimeout("invite()", 5000);
    $('#inviteClose').bind('click', function(){
        $('#chatInvite').slideUp(500, function(){
            var cookieName = 'chatDecline';
            var cookieOptions = {
                path: '/',
                expires: null
            }
            new decline_cookie(cookieName,'declined', cookieOptions);
        });
    });
    // Side nav accordion menu
    $('#sideNav_menu').accordion({
        header: 'h3',
        active: '.selected',
        autoheight: false
    });
});





