$(document).ready(function(){


	// Nav over states:
	curr_category = $("#nav").attr("cat");
	
	$("#nav a").hover(
	  function () {
		 var name = $(this).attr("id");
		$(this).children("img").attr("src", "http://emilygoligoski.com/wp-content/themes/panz_theme/images/nav_"+name+"_over.png");
	  }, 
	  function () {
		var name = $(this).attr("id");
		$(this).children("img").attr("src", "http://emilygoligoski.com/wp-content/themes/panz_theme/images/nav_"+name+".png");

	  }
	);
	
	// Turn on nav image when clicked
	if(curr_category!="") {
		$("#nav a#"+curr_category).children("img").attr("src", "http://emilygoligoski.com/wp-content/themes/panz_theme/images/nav_"+curr_category+"_over.png");
		$("#nav a#"+curr_category).hover(
										 function () {
		 var name = $(this).attr("id");
		$(this).children("img").attr("src", "http://emilygoligoski.com/wp-content/themes/panz_theme/images/nav_"+name+"_over.png");
	  }, 
	  function () {
		 var name = $(this).attr("id");
		$(this).children("img").attr("src", "http://emilygoligoski.com/wp-content/themes/panz_theme/images/nav_"+name+"_over.png");

	  });
		//$("#nav a#"+curr_category).css("border","3px solid #ff0000");
	}
	//$("input[name!=newsletter]")
	
	// Move any images and objects from post into a seperate DIV. 
	
	$(".post object").each(function(index) {
				$(this).prependTo($(this).parents(".entry").children(".post_images"));
				$(this).attr("width", 388);
	});
	
	$(".post embed").attr("width",388);
	
	
	$(".post a:has(img)[class!=a_speak_btn][class!=section_head]").each(function(index) {
																				 
																				 
      $(this).prependTo($(this).parents(".entry").children(".post_images"));
	  $(this).children("img").css("border","solid 1px #ff0066");
	  $(this).children("img").fadeIn();
	  	var width = $(this).children("img").width();    // Current image width
        var height = $(this).children("img").height();  // Current image height
 
 		
 		 
 		var maxWidth = 385;
		var maxHeight = 385;
 
        // Check if the current width is larger than the max
        if(width > maxWidth){
            ratio = maxWidth / width;   // get ratio for scaling image
            $(this).children("img").css("width", maxWidth+"px"); // Set new width
            $(this).children("img").css("height", (height * ratio)+"px");  // Scale height based on ratio
            height = height * ratio;    // Reset height to match scaled image
            width = width * ratio;    // Reset width to match scaled image
        }
 
        // Check if current height is larger than max
        if(height > maxHeight){
            ratio = maxHeight / height; // get ratio for scaling image
            $(this).children("img").css("height", maxHeight+"px");   // Set new height
            $(this).children("img").css("width", (width * ratio) + "px");    // Scale width based on ratio
            width = width * ratio;    // Reset width to match scaled image
        }
		
		
  	});

	$("#twitter_update_list a:contains('@')").css("color","#ff0000");
	
	$(".speak a.a_speak_btn").click(function() {
		$(this).hide();						 
		$(".speak #respond").fadeIn();						 
	});

});

