$(document).ready(function(){
	
	// Add body class based on URL... Not working too well ATM
	var pathname = window.location.pathname;
	var pathSlashesReplaced = pathname.replace(/\//g, "-");
	var pathSlashesReplacedNoFirstDash = pathSlashesReplaced.replace("-","");
	var newID = pathSlashesReplacedNoFirstDash.replace(/(\.[\s\S]+)/ig, "");

 	$("body").attr("id",newID);

 	if ( $("body").attr("id") == ""){
		$("body").attr("id","home-page");
	}
	
	// Grab and add page title as class to body
	var thePage = $('ul li.nav_selected a:first').text().replace(/ /g,'');
	$('body').addClass(thePage);
	
	
	// Homepage slideshow
	$('#intro-mod-slide').cycle({ 
    delay:  2000, 
    speed:  1000 
	});
	
	
	$('#intro-mod').parent().addClass('home-slide');
	
	// Add class of current to the page being displayed
	$("*").find("a[href='"+window.location.href+"']").each(function(){
		$(this).addClass("current");
	});
	
	$('#content_area > table table b a:last').addClass('current');
	var pagetitle = $('.current').text();
	
	
	// Clean up extra junk.... 
	if($('.PageText_L517n').length > 0){
		$('.PageText_L517n').parent().after($('h2.page-title'));
	}
	
	
	// Clean up mailing list
	$('form[name="MailingList"]').hide();
	$('#login #content_area').prepend('<h2 class="page-title">Login</h2>');
	$('#MailingList_subscribe #content_area').prepend('<h2 class="page-title">Mailing List Confirmation</h2>');
	
	
	// Move greeting text to a more appropriate spot
	//$('.greet').parent().addClass('greet-wrap');
	$('#header-right').append($('.greet'));
	
	if($('.greet').length > 0){
		$('#default .home-slide').css('margin-top','0px');
		$('#home-page .home-slide').css('margin-top','0px');
	}
	
	
	//Cleaning up junk... again.
	$('#content_area table td:first br').remove();
	
	
	
	// Move subcategories so they can be real links
	$('a.subcategory_link').each(function(){
		$('.page-title').after($(this));
	});
	
	
	$('#footer #menu_1 ul').prepend('<li class="nav"><a href="http://www.secure-booker.com/eyemax/MakeAppointment/Search.aspx" target="_blank">Book & Pay Online</a></li>');
	
	$('#footer #menu_2 ul li').eq(1).after('<li class="nav"><a href="/SearchResults.asp?Cat=30">Contact Us</a></li>');
	
	
	$('#new-nav > li:first-child').addClass('first');
	$('#new-nav > li:last-child').addClass('last');
	
	$('#new-nav > li > a').hover(function(){
		$(this).parent().addClass('active');
	}, function(){
		$(this).parent().removeClass('active');
	});
	
	$('#new-nav li ul').each(function(){
		$('li:last-child a',this).addClass('last-child');
	});
	
	$('#new-nav li ul').hover(function(){
		$(this).parent().addClass('active');
	}, function(){
		$(this).parent().removeClass('active');
	});
	
	
	
	
	
}); 
