$(document).ready(function(){
	$('#homeslides').cycle({ 
		fx:    'scrollHorz', 
		pause:  1,
		speed:    600, 
		timeout:  6000
	});
	$('#projectslides').cycle({ 
		fx:    'scrollHorz', 
		pause:  1,
		speed:    600, 
		timeout:  0,
	    pager: '#local_controls'
	});
	
	$('.zoom').fancyZoom({scaleImg: true, closeOnClick: true});
	$('.zoom').fancyZoom({scaleImg: true, closeOnClick: true});
	
	$('#subnav dl dd:last-child').css("background","none");
	
	$('#local_controls a:last-child').addClass("last-child");
	
	populateElement('#search', 'search this blog...');

	/* Function for highlighting project types */


	$("#project_types dd").click(function(){
			  var projClassClick = $(this).attr("class");
			  var projClass = $('#thumbs ul').attr("class");
			  if (projClassClick == "all") 
				{
					$(".screen").css("z-index","-1");
					$("#thumbs ul li a").css("color","#444");
					$('#thumbs ul').removeClass(projClass);
					$('#project_types a').removeClass();
					$('#project_types').removeClass(projClass);
					$('#project_types').addClass("all");
				}
			  else 
				{
					$(".screen").css("z-index","5");
					$("#thumbs ul li a").css("color","#ccc");
					$('#thumbs ul').removeClass();
					$('#project_types').removeClass();
					$('#project_types a').removeClass();
			  		$("#thumbs ul").addClass(projClassClick);
		      		$("#project_types").addClass(projClassClick);
					$("dl." + projClassClick + " dd." + projClassClick + " a").addClass("active");
				}
			}
	);
	
	var filterActive = $('.thumb_index #project_types').attr("class");
	// $("dd."+filterActive + " a."+filterActive).addClass("active");
	$("dd." + filterActive + " a." + filterActive).addClass("active");
	
	/* Function to adjust the height of the recent publications feed on the homepage to fit the tallest item */
	
	var maxHeight = 0;
    $('.recent_thumb img').each(function(){
        if (maxHeight < $(this).height()) {maxHeight = $(this).height()}
    });
    $('.recent_thumb .recent_outer').each(function(){
        $(this).height(maxHeight);
    });
	
}); 

// Function to add and remove "SEARCH" prompt

function populateElement(selector, defvalue) {
   $(selector).each(function() {
       if($.trim(this.value) == "") {
           this.value = defvalue;
       }
   });
 
   $(selector).focus(function() {
       if(this.value == defvalue) {
           this.value = "";
       }
   });
   
   $(selector).blur(function() {
       if($.trim(this.value) == "") {
           this.value = defvalue;
       }
   });
}
