/**
 * DOM Ready Functions
 */
$(function(){
	/* Setup the top nav hovers */
	setupHovers();
	rightColSetup();
	searchBox();
	// zIndexHandler();
});

function searchBox(){
	$('input[name=search]').focus(function(){
		/* If it's "Search..." */
		if($(this).val() == "Search..."){
			/* Blank it */
			$(this).val("");
		}
	}).blur(function(){
		/* If it's blank */
		if($(this).val() == ""){
			/* Put "Search..." in */
			$(this).val("Search...");
		}
	});
}

/**
 * Setup the top navigation hovers and such
 */
function setupHovers(){
	/* Add a hover event to all ul topNav li's */
	$('ul#topNav li').hover(function(){		/* Hover in */
		/* Replace the Item, in it's id with Selected byt using the attr function */
		$(this).attr('id',$(this).attr('id').replace("Item","Selected"));		
	},function(){							/* Hover out */
		/* If it doesn't have a class of selected */
		if(!$(this).hasClass('selected')){
			/* Then re-switch the id back to show Item instead of Selected */
			$(this).attr('id',$(this).attr('id').replace("Selected","Item"));
		}
		/* End of Hover in/out, now add a click event function */
	}).click(function(){
		/* Once we click, iterate through this item's Siblings */
		$(this).siblings().each(function(index){
			/* Remove the selected Class and replace all 'Selected' text in id's with 'Item' so they are all unselected*/
			$(this).removeClass('selected').attr('id',$(this).attr('id').replace("Selected","Item"));
		});
		/* Now add the class of selected to this item,
		 * replace 'Item' with 'Selected' in the id 
		 * so we don't lose the selected state if we mouseOut */
		$(this).addClass('selected').attr('id',$(this).attr('id').replace("Item","Selected"));
	});
	
	/* End of setupHovers */
	
}

function rightColSetup(){
	
	if($('#left_col').height() > ($('#right_col').height() + 10)){
		var $height = $('#left_col').height();

		$('#right_col').height(($height - 31));
	}
	
}

/**
 * Sorts out the z-index bug in ie
 */
function zIndexHandler(){
	var zIndexNumber = 1000;
	$('div, ul, li').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 1;
	});
}
