// JavaScript Document

$(document).ready(function(){
	
	$(function(){$(document).pngFix();});
	
	$("#hp #splash-image").css("background", "url('/images/hp-splash-0" + Math.floor(Math.random()*1) + ".jpg')");
	$("#hp #tagline").stop().hide().fadeIn(1000);
	$("#hp #tagline p").stop().hide().fadeIn(3000);
			
	$("#search input:text[name=q]").focus(function() {				  
		
		var originalvalue = $(this).val();
		$(this).val("");
		$(this).css({color: "#000"});
		
		$(this).blur(function() {
			if ($(this).val() == "") {
				$(this).val(originalvalue);
				$(this).css({color: "#ccc"});
			}
		});
	});
	
	//Set up submenu styling
	$('<li class="active-shadow"></li>').insertAfter($('#submenu li.active'));
	$('#submenu li.active').prev().css('border', '1px');
	$('#submenu li.active').prev().css('border-color', '#fff');
	
	//Drop down menu stylizing
    $("#menu li").hoverClass("sfhover");
	
	//Project Filter click actions
	$("#submenu input[type='checkbox']").live('click', function() {
																
		var className = $(this).val();
		
		if (!this.checked) {
			$("#projects .row").each(function(){
				if ($(this).hasClass(className)) {
					$(this).css("display","none");
				}
			});	
		}
		else {
			$("#projects .row").each(function(){
				if ($(this).hasClass(className)) {
					$(this).css("display","block");
				}
			});	
		}
		

		if ( $("#submenu input[type='checkbox']:checked").length == 0) {
			$("#projects .alert").remove();
			$("#projects").append("<div class='alert'><p>Please select one of the criteria to filter the projects by.</p></div>");
		}
		else if ( $("#projects .row:visible").size() == 0 ) {
			$("#projects .alert").remove();
			$("#projects").append("<div class='alert'><p>None of the projects met your criteria.</p></div>");
		}
		else {
			$("#projects .alert").remove();
		}
		
	});
	
});

$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover( 
            function() { $(this).addClass(c);  },
            function() { $(this).removeClass(c); }
        );
    });
};