/*
jQuery(document).ready(function() {
	jQuery("#events-list h3").replaceWith('<h3><a href="/events/">UPCOMING EVENTS</a></h3>')
});
*/

// Navigation effects

//Fades subnavs in and out
jQuery(document).ready(function() {
	if(!(jQuery("#mc_submenu_2 li").hasClass("current_page_item"))) {
		jQuery("#menu_item_2").hover(
			function() {
				jQuery("#mc_submenu_2").stop().fadeIn();
			},
			function() {
				jQuery("#mc_submenu_2").stop().fadeOut();
			}
		);
	};
	
	if(!(jQuery("#mc_submenu_4 li").hasClass("current_page_item"))) {
		jQuery("#menu_item_4").hover(
			function() {
				jQuery("#mc_submenu_4").stop().fadeIn();
			},
			function() {
				jQuery("#mc_submenu_4").stop().fadeOut();
			}
		);
	};
});
// END :: Fades subnavs in and out

jQuery(document).ready(function() {
	// prevents the ABOUT and COMMUNITY parent navigation from reloading the page onClick
	jQuery("#menu_item_2 a:first, #menu_item_4 a:first").click(function(){
		return false;
	});
	// END :: prevents the ABOUT and COMMUNITY parent navigation from reloading the page onClick
	
	// Magic Line Navigation script
    var el, leftPos, newWidth,
        mainNav = jQuery("#mc_menu_1");
    
    var el1, leftPos1, newWidth1,
  		subNav1 = jQuery("#mc_submenu_2");
    
    var el2, leftPos2, newWidth2,
    	subNav2 = jQuery("#mc_submenu_4");

    mainNav.append("<li id='magic-line'></li>");
    var magicLine = jQuery("#magic-line");
    
    subNav1.append("<li id='magic-line1'></li>");
    var magicLine1 = jQuery("#magic-line1");
    
    subNav2.append("<li id='magic-line2'></li>");
    var magicLine2 = jQuery("#magic-line2");
    
    if (jQuery("body").hasClass("blog")) {
    	jQuery("#menu_item_8").addClass("current_page_item")
    };
    
    if (jQuery("body").hasClass("pageid-90")) {
    	jQuery("#menu_item_18").addClass("current_page_item")
    };

    if (jQuery(".current_page_item").parents().is("#menu_item_2")) {
    	magicLine
	        .width(jQuery("#menu_item_2").width())
	        .css("left", jQuery("#menu_item_2").position().left)
	        .data("origLeft", magicLine.position().left)
	        .data("origWidth", magicLine.width());
    } else if (jQuery(".current_page_item").parents().is("#menu_item_4")) {
    	magicLine
	        .width(jQuery("#menu_item_4").width())
	        .css("left", jQuery("#menu_item_4").position().left)
	        .data("origLeft", magicLine.position().left)
	        .data("origWidth", magicLine.width());
    } else {
    	magicLine
        .width(jQuery(".current_page_item").width())
        .css("left", jQuery(".current_page_item a").position().left)
        .data("origLeft", magicLine.position().left)
        .data("origWidth", magicLine.width());
    };
    
    if (jQuery(".current_page_item").parents().is("#menu_item_2")) {
	    magicLine1
		    .width(jQuery(".current_page_item").width())
		    .css("left", jQuery(".current_page_item a").position().left)
		    .data("origLeft1", magicLine1.position().left)
		    .data("origWidth1", magicLine1.width());
    } else {
    	magicLine1
    		.css({left: "0px", width: "0px"});
    };
    
    if (jQuery(".current_page_item").parents().is("#menu_item_4")) {
    	magicLine2
		    .width(jQuery(".current_page_item").width())
		    .css("left", jQuery(".current_page_item a").position().left)
		    .data("origLeft2", magicLine2.position().left)
		    .data("origWidth2", magicLine2.width());
    } else {
    	magicLine2
			.css({left: "0px", width: "0px"});
    };

    jQuery("#mc_menu_1 li a").hover(function() {
        el = jQuery(this);
        leftPos = el.position().left;
        newWidth = el.parent().width();
        magicLine.stop().animate({
            left: leftPos,
            width: newWidth
        });
    }, function() {
        magicLine.stop().animate({
            left: magicLine.data("origLeft"),
            width: magicLine.data("origWidth")
        });
    });
    jQuery("#mc_submenu_2 li a").hover(function() {
        el1 = jQuery(this);
        leftPos = jQuery("#menu_item_2").position().left;
        leftPos1 = el1.position().left;
        newWidth = jQuery("#menu_item_2").width();
        newWidth1 = el1.parent().width();
        magicLine.stop().animate({
        	left: leftPos,
        	width: newWidth
        });
        magicLine1.stop().animate({
            left: leftPos1,
            width: newWidth1
        });
    }, function() {
        magicLine1.stop().animate({
            left: magicLine1.data("origLeft1"),
            width: magicLine1.data("origWidth1")
        });
    });
    jQuery("#mc_submenu_4 li a").hover(function() {
        el2 = jQuery(this);
        leftPos = jQuery("#menu_item_4").position().left;
        leftPos2 = el2.position().left;
        newWidth = jQuery("#menu_item_4").width();
        newWidth2 = el2.parent().width();
        magicLine.stop().animate({
        	left: leftPos,
        	width: newWidth
        });
        magicLine2.stop().animate({
            left: leftPos2,
            width: newWidth2
        });
    }, function() {
        magicLine2.stop().animate({
            left: magicLine2.data("origLeft2"),
            width: magicLine2.data("origWidth2")
        });
    });
	// END :: Magic Line Navigation script
});