$(document).ready(function(){
		init_navigation();	
		init_ajax_images();
		download_resume('keiko_kamata_resume_web.pdf', 'filename=resume&format=pdf&content=keikoresume');
	});
	
	//tab navigation
	function init_navigation(){
		$(".page").hide();
		
		$("#toc li").each(function(){
			var navLink = $(this).find("a[rel='page']");
			var linkId = $(navLink).attr("href");
			
			//Set the default active class
			if($(this).hasClass("active")){
				$(linkId).show();
			}
			
			//set the link click functionality
			 $(navLink).click(function(){
				//check the pages
				$(".page").each(function(){
					if(linkId=="#"+$(this).attr("id")){
						$(this).show();
					} else {
						$(this).hide();
					}
				});
				
				//set button active state
				$("#toc li").each(function(){
					$(this).removeClass("active");											
				});
				
				$(this).parents("li").addClass("active");
				
				return false;
			});
		});
	}
	
	//ajax images
	function init_ajax_images(){
		$("a.ajax_image_load").each(function(){
			$(this).click(function(){
				//The rel attribute on the A link is the ID of the "featured" content page
				//this is where the image will go
				var rel = $(this).attr("rel");
				
				//the href is the image to load
				var href = $(this).attr("href");
				
				//Creates a new image
				var img = new Image();
				$(img).attr("src", "images/loading.gif");
				$(rel).html(img);
				$(img).load(function(){
					//when image has loaded, replace the current HTML 
					//inside the div with the ID referenced in the link rel
					$(rel).html(img);
				}).attr("src", href);
							
				
				//the title is the caption to load... use NAME rather than TITLE so tooltip doesn't pop up...
				var caption = $(this).attr("name");
				$(rel + "_caption").html(caption);
				
				return false;
			});
		});
	}
	
	

	function download_resume(url, data, method){
		$("a.download_resume").each(function(){
				$(this).click(function(){

					var inputs = '';

					//send request
					jQuery('<form action="'+ url +'" method="'+ (method||'post') +'">'+inputs+'</form>')
					.appendTo('body').submit().remove();
					
					
					return false;

			});
		});
	}
	
	function ddownload_resume(url, data, method){
		$("a.download_resume").each(function(){
				$(this).click(function(){
				//url and data options required
				if( url && data ){ 
					//data can be string of parameters or array/object
					data = typeof data == 'string' ? data : jQuery.param(data);
					//split params into form inputs
					var inputs = '';
					jQuery.each(data.split('&'), function(){ 
						var pair = this.split('=');
						inputs+='<input type="hidden" name="'+ pair[0] +'" value="'+ pair[1] +'" />'; 
					});
					//send request
					jQuery('<form action="'+ url +'" method="'+ (method||'post') +'">'+inputs+'</form>')
					.appendTo('body').submit().remove();
					
					
					return false;
				};
			});
		});
	}