var $ = jQuery.noConflict();

(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
			if($(this).height() > tallest) {
			tallest = $(this).height();
		}
	});
	if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
		$(this).height(tallest).css("overflow","auto");
	});
}
})(jQuery);

(function($) {

	$.fn.textReplacement = function(options) {
	
	var settings = $.extend({}, $.fn.textReplacement.defaults, options);
	
	return this.each( function() {
	var input = $(this);
	
	var newval = input.parent().find('label').text()
	input.parent().find('label').hide();
	input.val(newval);
	
	var originalvalue = input.val();
	var originalcolor = input.css('color');
	
	input.focus( function(){
	if( $.trim(input.val()) == originalvalue ){ input.val('').css("color", settings.color); }
	});
	input.blur( function(){
	if( $.trim(input.val()) == '' ){ input.val(originalvalue).css("color", settings.color); }
	});
	
	});
	};
	
	$.fn.textReplacement.defaults = {color: '#666'};


})(jQuery); 

function hideNav() { $('#nav > ul > li').removeClass('show'); }

$(function() {
	
	if( jQuery('#feature').length > 0 ) {
		jQuery('#feature').featureRotator();
	}
	
	$('.feature ul li').equalHeights();
	
	$('ul li a.selected').parent().addClass('parentItem');
	
	
	
	if(typeof document.body.style.maxHeight === "undefined") {
		
		$('#nav > ul > li > a').mouseenter(
			function() { $(this).parent().addClass('show'); }
		);
		$('#nav > ul > li').mouseleave( function() 
			 { $(this).removeClass('show');
			//setTimeout( "hideNav()"  , 1500); 
			});
			
			
		$('#nav ul li a[title="About CS | Appraisals"]').addClass('width-fix');

	} else {
		$('#nav > ul > li > a').mouseenter(
			function() { $(this).parent().addClass('show'); }
		);
		$('#nav > ul li').mouseleave(
			function() { $(this).removeClass('show'); }
		);
	}
	
	
	
	$('#nav > ul > li').append('<span class="tl"></span><span class="tr"></span>');
	
	$('#content .news ul li:last, #content .pubs ul li:last, #content .events ul li:last, #content .leadership ul li:last').addClass('last-child');
	
	
	
	// SEPHO SPECIFIC
	$('form input#newsletter-email').textReplacement({color: '#000'});
	$('form input#search-head').textReplacement({color: '#000'});
	$('#header .search input[type=text]').textReplacement();
	
	
	
	$('table .attributeDrillDown:even').parent().addClass('even');
	
	$('a[href=http://sph-csas.fry-it.com/about]').css('width', '160px');
	
	
	$(".bookmark").parent('a').click(function(event){
		
		event.preventDefault(); // prevent the anchor tag from sending the user off to the link
		var url = document.location;
		var title = document.title;
		
		if (window.sidebar) { // Firefox 
		window.sidebar.addPanel(title, url,"");
		} else if( window.external ) { // IE
		window.external.AddFavorite( url, title);
		} else { // for Safari, Konq
		alert('Press <Command>+D to bookmark in Safari or Chrome.');
		}
		
	});
	

	
	
});

// adds file icon and size
$(function() {
	
	$('.main-content a[mime][size]:not(:has(img))').each(function()
	{
		var a = $(this)
		a.addClass(a.attr('mime')+'Icon')
		a.after('<sup>('+a.attr('size')+')</sup>');
	});


});


//autorotate homepage images - moved to featureRotator.js

