// file name gets the page URL 
var file_name = document.location.href;
// gets the end of the URL 
var end = (file_name.indexOf(".html") == -1) ? file_name.length : file_name.indexOf(".html"); 
// gets the page name 
var current_page = file_name.substring(file_name.lastIndexOf("/")+1, end);

// changes source of the given image to the image path of the hover image 
function over( img_name ) {
	document[img_name].src = "images/images/" + img_name + ".png"; 
}

// changes hover image back to original image 
function out( img_name ) {
	document[img_name].src = "images/" + img_name + ".png"; 
}

// once window loads, execute function 
window.onload = highlight_current_page;

// tests current_page to cases to make navigation image activate 
function highlight_current_page(){ 
	switch ( current_page ){ 
		case ('pencils'): 	add_active_image('nav-pencils');
												break; 
		case ('faq'): 			add_active_image('nav-pencils');
												current_page = "pencils"; 
												break; 
		case ('tutorial'): 	add_active_image('nav-pencils');
												current_page = "pencils"; 
												break; 
		case ('websites'): 	add_active_image('nav-websites');
												break; 
		case ('websites-request'): 	add_active_image('nav-websites');
												current_page = "websites"; 
												break; 
		case ('about'): 		add_active_image('nav-about');
												break; 
		case ('contact'): 	add_active_image('nav-contact');
												break; 
		case ('blog'): 	add_active_image('nav-blog');
												break; 

		default: 						add_active_image('nav-welcome');
												current_page = "welcome"; 
												break;
	} 
}

// makes given image the activate one 
function add_active_image(img_name){ 
	document[img_name].src = "images/" + img_name + "2.png";  
}

// checks if given image matches current_page. if yes, keep image. else, perform over function. 
function over_handler ( img_name ){   
	if ( img_name == "nav-" + current_page )  
		add_active_image ( img_name );  
	else  
		over ( img_name ); 
}

// checks if given image matches current_page. if yes, keep image. else, perform out function. 
function out_handler(img_name){  
	if ( img_name == "nav-" + current_page )  
		add_active_image (img_name);  
	else  
		out (img_name); 
}