$(document).ready(function() {
	$('input[type="text"]').addClass("idleField");
	$('input[type="text"]').focus(function() {
		
		if (this.value == this.defaultValue){ 
			this.value = '';
			$(this).removeClass("idleField").addClass("focusField");
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('input[type="text"]').blur(function() {
		
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
			$(this).removeClass("focusField").addClass("idleField");
		}
	});
});	

$(document).ready(function() {
	$('textarea').addClass("idleField");
	$('textarea').focus(function() {
		
		if (this.value == this.defaultValue){ 
			this.value = '';
			$(this).removeClass("idleField").addClass("focusField");
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('textarea').blur(function() {
		
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
			$(this).removeClass("focusField").addClass("idleField");
		}
	});
});

function sendScrollPosition() {
    document.forms[0].elements["previousScrollPosition"].value = document.documentElement.scrollTop;
    return true;
} 

function setScrollPosition() {
	if(document.getElementsByName("previousScrollPosition").length > 0) {
		document.documentElement.scrollTop = document.forms[0].elements["previousScrollPosition"].value;
	}
}

$(function() {

    $("#explore-nav li a").click(function() {
        
        // Figure out current list via CSS class
        var curList = $("#explore-nav li a.current").attr("rel");
        
        // List moving to
        var $newList = $(this);
        
        // Set outer wrapper height to height of current inner list
        var curListHeight = $("#all-list-wrap").height();
        $("#all-list-wrap").height(curListHeight);
        
        // Remove highlighting - Add to just-clicked tab
        $("#explore-nav li a").removeClass("current");
        $newList.addClass("current");
        
        // Figure out ID of new list
        var listID = $newList.attr("rel");
        
        if (listID != curList) {
            
            // Fade out current list
            $("#"+curList).fadeOut(300, function() {
                
                // Fade in new list on callback
                $("#"+listID).fadeIn();
                
                // Adjust outer wrapper to fit new list snuggly
                var newHeight = $("#"+listID).height();
                $("#all-list-wrap").animate({
                    height: newHeight
                });
            
            });
            
        }        
        
        // Don't behave like a regular link
        return false;
    });

});

