$(function() { 
    // Drop down menu
    $("#menu li.menuBTN").hover(function(){
        $(this).addClass("active");
        $(this).children("div").stop(true, true).slideDown("fast");
    }, function(){
        $(this).removeClass("active");
        $(this).children("div").stop(true, true).slideUp("fast");
    });
	// Sidebar Accordian
	$("li.sideBTN a.lvlM").click(function(){
        $(this).toggleClass("active");
		$("div.side-menu").not($(this).next("div")).stop(true, true).slideUp();
        $(this).next("div").stop(true, true).slideToggle();
		if ( ! $(this).parent("li").hasClass("sbCU") ) { return false };
    });
	// Sidebar sub top no border
	$(".side-menu-abo a:first").css("border", "none");
	$(".side-menu-mar a:first").css("border", "none");
	$(".side-menu-car a:first").css("border", "none");
	
	// Active sidebars down
	var folder = jQuery.url.attr("directory");
    var aboutRE = new RegExp("/about/");
	var marketsRE = new RegExp("/markets/");
	var careersRE = new RegExp("/careers/");
	if (aboutRE.test(folder)) {$("li.sbAU a.lvlM").next("div").show(); };
	if (marketsRE.test(folder)) {$("li.sbVM a.lvlM").next("div").show(); };
	if (careersRE.test(folder)) {$("li.sbCA a.lvlM").next("div").show(); };
	
	if ( $('.type-status .entry-content').length ) {
		var myVar = $('.type-status .entry-content');
	    myVar.html(myVar.html().replace('WebSupport[at]LTnow.com', '<a href="mailto:WebSupport@LTnow.com">WebSupport@LTnow.com</a>')); 
	};
	
	// Sidebar dynamic sidebar
	if ( $("li.widget-container").length ) { 
		$("li.widget-container:first").wrap("<div class='kwMain'><ul class='xoxo'></ul></div>");
		$(".kwMain:first").before("<div class='kwTop'> </div>");
		$(".kwMain:first").after("<div class='kwBot'> </div>");
	};
	
	// Sortable Gallery
	$('ul#filter a').click(function() {
		$(this).css('outline','none');
		$('ul#filter .current').removeClass('current');
		$(this).parent().addClass('current');

		var filterVal = $(this).text().toLowerCase().replace(' ','-');

		if(filterVal == 'all') {
			$('ul#gallery li.hidden').fadeIn('slow').removeClass('hidden');
			$('ul#gallery li').each(function() { $(this).addClass('all'); });
			$('#gallery li.all a').lightBox(); 
		} else {
			$('ul#gallery li').each(function() {
				$(this).removeClass('all');
				if(!$(this).hasClass(filterVal)) {
					$(this).fadeOut('normal').addClass('hidden');
				} else {
					$(this).fadeIn('slow').removeClass('hidden');
					$(this).parent().find('a[rel='+filterVal+']').lightBox();
				}
			});
		}
		return false;
	});	
		
});
