$(document).ready (function() {
	//change active css to the right image
	$('.active').find('img').attr('src', path + '/images/nav_'+ $('.active').find('img').attr('alt') +'_over.png');
	//Set Seccondary action nav
	$('.nav').each(function() {
		if ( $(this).find('img').attr('alt') == action ) {
			$(this).find('img').attr('src', path + '/images/nav_' + $(this).find('img').attr('alt') + '_over.png');
		}
	});
	
	
	//Clear the question text area when focused.
	$('#questions').find('textarea').focus(function(fn) {
		if ( $(this).val() == 'Type your STD-related question here and we\'ll do our best to answer it. But please, one at a time.' ) {
			$(this).val(''); 
		}
	});
	$('#questions').find('textarea').blur(function(fn) {
		var qval = $(this).val().replace(' ', '');
		if ( qval == '') {
			$(this).val('Type your STD-related question here and we\'ll do our best to answer it. But please, one at a time.');
		} 
	});
	
	
	//Hover State of the location box
	$('.info').parent().hover(
		function() {
			$(this).css({'background-color' : '#b5d152'});
		},
		function() {
			$(this).css({'background-color' : '#A0BB42'});
		}
	);
	
	
	//Info box clicked
	$('.info').parent().click(function() {
		window.location=$(this).find('a').attr('href');
	});
	
	
	//Top Navagation
	$('#top_nav a img').hover(
		function() {
			$(this).attr('src', path + '/images/nav_' + $(this).attr('alt') + '_over.png');
		},
		function() {
			if ( $(this).parent().attr('class') == 'active' ) { } else {
				$(this).attr('src', path + '/images/nav_' + $(this).attr('alt') + '.png');
			}
		}
	);

	//Left Navagation
	$('.nav img').hover(
		function() {
			$(this).attr('src', path + '/images/nav_' + $(this).attr('alt') + '_over.png');
		},
		function() {
			if ( $(this).parent().attr('class') == 'active' ) { } else {
				$(this).attr('src', path + '/images/nav_' + $(this).attr('alt') + '.png');
			}
		}
	);
	
	
	// Toggleing functionality
	$(".toggle").find('span.title').click(function () {
		var me = $(this).find('a').attr('name');
		var down = true;
		
		if ($(this).parent().find('p').is(':hidden') == false) {
			down = false;
		}
		
		$(this).parent().parent().find('.toggle').each(function() {
			// Slide Up Each Toggle!
			$(this).find('p').each(function() { $(this).slideUp('normal'); });
			$(this).find('span.title').css({'background-image' : 'url(' + path + '/images/arrow_down.png)', 'border-bottom' : '1px solid #58afbd'})
		});
		
		if (down == true) {
			//Slide Down the one we clicked on!
			$(this).parent().find('span.title').css({'background-image' : 'url(' + path + '/images/arrow_up.png)', 'border' : 'none'});
			$(this).parent().find('p').slideDown('normal', function() {
				$(this).css({'border-bottom' : '1px solid #58afbd'});
			});
		}
	});
	
	
	//Locate Box
	$('#locate').change(function() {
		if ($(this).val() != '') {
			window.location= path+"/index/locate/id/" + $(this).val();
		}
	});
	
	
	//Home link
	$('.logo').click(function() { window.location=path; });
	
	
	// QA Open question on #
	if (location.hash) {
		$(document).find('a').each(function() {
			if ($(this).attr('name') == location.hash) {
				$(this).parent().parent().find('span.title').css({'background-image' : 'url(' + path + '/images/arrow_up.png)', 'border' : 'none'});
				$(this).parent().parent().find('p').slideDown('normal', function() {
					$(this).css({'border-bottom' : '1px solid #58afbd'});
				});
			}
		});
	}
});