rl.homeFeature = (function() {
	var parentID = null,
		currSelected = null,
	 	lastSelected = null,
	 	rollClick = null,
	 	defaultSel = null
	 	stopAnim = null,
	 	mouseReady = null;
	
	var setDefault = function() {		
		defaultSel = "#"+$("#homeFeatures .default").attr("id");
		
		$(rl.pagesParent).children().hide();
		$(rl.pagesParent + " " +  rl.pageBG).show();
		$(rl.pagesParent + " " +  rl.pageBGholder).show();
		
		$("#homePage").show();
		$(defaultSel + " .li-category").click();
		rollClick = false;
	}
	
	var listenRollOver = function() {	
		$("#homeFeatures .li-rollovers").hoverIntent(
			function(){					
				parentID = "#"+$(this).parent().attr("id");
				$(parentID + " .li-img").fadeOut(200);
				$(parentID + " .li-category").fadeIn(300);			
			},
			function(){
				if (rollClick) {
					rollClick = false;
					return;
				}
				
				$(parentID + " .li-category").fadeOut(200);
				$(parentID + " .li-img").fadeIn(300);				
			}
		);			
	}
	
	var listenRollClick = function() {
		$("#homeFeatures .li-category").click(function(){
			parentID = "#"+$(this).parent().parent().attr("id");
			parentRollClickID = parentID;

			if (stopAnim) return;
			
			lastSelected = (currSelected!=null) ? currSelected : null;
			currSelected = parentID;
			rollClick = true;
							
			if (lastSelected==currSelected) return;				
			stopAnim = true;
			
			var prevBgImgSrc = (lastSelected==null) ? $(parentID + " .pageBG").attr('src') : $(lastSelected + " .pageBG").attr('src');
			var bgImgSrc = $(parentID + " .pageBG").attr('src');
			var img = new Image();
			// set temp bg holder image to current bg image, and place on top
			$(rl.pageBGholder).css("background-image","url("+prevBgImgSrc+")")
							  .show();
			$("#thoughtfulLoader").show();
			$(img).attr('src',bgImgSrc).load(function(){
				$("#thoughtfulLoader").hide();
				// rewrite the top level pageBG to reflect the bg change
				$(rl.primPageID + " .pageBG:first").attr("src",bgImgSrc);
				// set real bg to loaded one and fade one on top to reveal the one underneath
	   		  	$(rl.pageBG).css("background-image","url("+bgImgSrc+")");		   		  	
	   		  	$(rl.pageBGholder).fadeOut("slow");
	   		  	// restore previous thumb
				$(lastSelected + " .li-rollovers").show();
				$(lastSelected + " .li-summary").hide();
				$(lastSelected + " .li-img").show();
	   		  	// fade out previous category text, and fade in summary text
				$(currSelected + " .li-rollovers").fadeOut(400,function(){$(currSelected + " .li-category").hide()});
				$(currSelected + " .li-summary").fadeIn(600,function(){stopAnim=false;}); // set stopAnim to false on slowest animation
				
				// animate the black bar up and down
				$('#thoughtfulWrap').show().animate({
					top:$(parentID).offset().top-9
				},{
					duration:500,
					complete:function() {
						//$(window).trigger('resize');
					}
				});
				
				// change the background color (inside jquery.color is code that changes the cufon txt color as well)
				$("body").animate({
					backgroundColor:$(parentID).css("color")
				},{
					duration:"slow",
					complete:function(){
						// store the bg image for a page switch to note the last bg color
						$(rl.primPageID + " .pageBG:first").attr("bgcolor",$(parentID).css("color"));
					}
				});
				
			}).each(function(){ 
				if ($.browser.msie)
					if(this.complete) $(this).trigger("load");
			});
		});
	}
	
	var listenClickClick = function() {
		$("#homeFeatures .li-summary").click(function(){
			if (stopAnim) return;
			$.bbq.pushState($(parentRollClickID).attr("src"));
		});
	}
	
	return {
		setDefault : setDefault,
		init : function() {
			listenRollOver();
			listenRollClick();
			listenClickClick();
			return;
		}
	}
}());
