jQuery.noConflict();

// Figure out what browser is being used
var userAgent = navigator.userAgent.toLowerCase();
jQuery.browser = {
	version: (userAgent.match( /.+(?:rv|it|ra|ie|me)[\/: ]([\d.]+)/ ) || [])[1],
	chrome: /chrome/.test( userAgent ),
	safari: /webkit/.test( userAgent ),
	opera: /opera/.test( userAgent ),
	msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
	mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
};
// Define constants for use in all .js files
var ISIE = jQuery.browser.msie;
var ISIE6 = jQuery.browser.msie && jQuery.browser.version == 6.0 ? true : false;
var ISCHROME = jQuery.browser.chrome ? true : false;


jQuery(document).ready(function($)
{
	var temp = new Object();
	
	// equal heights
	/*
		? Didn't work as separate plugin
		Modifications from original implementation: http://www.filamentgroup.com/lab/setting_equal_heights_with_jquery/
		some custom filters and properties
		Mostly applies to main columns in the main content area
	*/
	var toMakeEqualHeight = $("#the_content > .inner");
	
	toMakeEqualHeight.each(function()
	{
		var currentTallest = 0;
		var myFilter = "div[class*='col_'][class!='col_banner']";
			// expandable
		var myFilterChild = "div[class*='c_accordion']";
			// expandable
		var myPadding = -45;
			// ? should be in css
		
		if (ISIE6)
			myPadding = 15;
			
		else if (ISIE)
			myPadding = -90;
				
		$(this).children().filter(myFilter).each(function()
		{ // each container
			if ($(this))
			{		
				if ($(this).height() > currentTallest)
				{ 
					currentTallest = $(this).height() - $(this).contents(myFilterChild).height(); 
				} // each child
				
				//alert('Tallest: ' + currentTallest + '\nOverflow: ' + $(this).css('overflow') + '\nHeight: ' + $(this).css('height') + '\nMin-Height: ' + $(this).css('min-height') + '\nMax-Height: ' + $(this).css('max-height'));
			}
		});
		
		if (ISIE6) 
			$(this).children().filter(myFilter).css({'height': currentTallest + myPadding});		
			// for ie6, set height since min-height isn't supported
		
		$(this).children().filter(myFilter).css({'min-height': currentTallest + myPadding});
	});


	// accordion
	/*
		Each item must have exactly two elements - the first one for the header, and the second one for the content.
		Modifications from original implementation
			tooltips
			smart height
			scrollTo plugin integration
			show_all button
	*/
	
	if ($.ui && $.isFunction($.ui.accordion)) {
		
		var myAccordion = $(".c_accordion .blades");
	
		myAccordion.find(".header").attr("title", "expand");
		myAccordion.find(".blade_opened .header").attr("title", "collapse");
	
		var maxHeight = 0;
		myAccordion.find(".content").each(function() {
			maxHeight = maxHeight < $(this).height() ? $(this).height() : maxHeight;
		});
		//myAccordion.height(myAccordion.find(".blade").height() + maxHeight);
	
		myAccordion.accordion({

			event: "click",
			autoHeight: false,
			alwaysOpen: false,
			selectedClass: "blade_opened",
			header: ".header",
			content: ".content"	

			// active: ".current", (first child)
			// animated: "bounceslide", (requires easing)
			// fillSpace: true,
			// clearStyle: true,
			// navigation: true,

			/* navigationFilter: function() {
	      		return this.href.toLowerCase() == location.href.toLowerCase();
			   } (add to it) */

		}).bind("accordionchange", function (event, ui) { 
			/*	
				ui.options, ui.newHeader, ui.oldHeader, ui.newContent, ui.oldContent
			*/
		
			ui.oldHeader.attr("title", "expand");
			ui.newHeader.attr("title", "collapse");
			
			/*
			var scrollDestination = ui.oldHeader.attr("class") == ui.newHeader.attr("class") ? $(".c_accordion") : ui.newHeader;	
			$.scrollTo( scrollDestination, 500, {
				easing: "linear", 
				offset: { top: -18 }
				// axis: x,
				// margin: true,
				// over: [1/n of width or height],
				// queue: yx,
				// onAfterFirst: [function],
				// onAfter: [function],
			});*/
		});
				
		$(".c_accordion .title a.show_all").toggle(function(){
			
			$('.c_accordion .content:hidden').slideDown(500, function(){
				$(this).prev().attr("title", "collapse");
				$(this).parent().addClass("blade_opened");
			});
			$(this).text("hide all");
			
		}, function(){

			$('.c_accordion .content:visible').slideUp(500, function(){
				$(this).prev().attr("title", "expand");
				$(this).parent().removeClass("blade_opened");
			});
			$(this).text("show all");			
		});
		
		// myAccordion.accordion("enable");
		// myAccordion.accordion("disable");
		// myAccordion.accordion("destroy");
		/* 	
		manual toggling
			myAccordion.accordion("activate", 0);			// 1st content
			myAccordion.accordion("activate", false);	 	// close all contents
			myAccordion.accordion("activate", "a:first"); 	// select descendants
		*/

	}


/*
	other
*/
	// dynamic text

	$("#search_input").focus(function() {
		if ($(this).attr("value").toLowerCase() == 'search the college')
		{	
			$(this).attr("value", "");
		}
	});
	$("#search_input").blur(function() {
		if ($(this).attr("value").toLowerCase() == '')
		{
			$(this).attr("value", 'Search the College');
		}
	});
		
/*
	css shortcomings
*/

	// consistent cursors
	
	$("ul[id*='nav'] li").css("cursor", "default");

	// smart heights with widget column

	equalizeCols([$("#the_content"), $("#the_sidebar")]);

	function equalizeCols (arrCols)
	{
		var maxColHeight;
		var i = 0
		for (var i = 0; i < arrCols.length; i++) {
			maxColHeight = Math.max(arrCols[i].height(), arrCols[i].height());
		}
		for (var i = 0; i < arrCols.length; i++) {
			arrCols[i].css({'min-height': maxColHeight});
		}
	}

	// tiger-striping
	
	$("ul.c_main_stripes > li:even").addClass("gray");
	
	// hovering
	
	$("input[type='image']").hover(
	    function() {
	        var url = $(this).attr("src");
	        $(this).attr("src", url.replace(/.gif/, "_over.gif"));
	    }, function() {
	        var url = $(this).attr("src");
	        $(this).attr("src", url.replace(/_over.gif/, ".gif"));
	    }
	);
	
	$(".media_archive li").hover(
	    function() {
	        $(this).children("a").css("border-color", "#878787");
	        $(this).next().children("a").css("border-color", "#878787");
	    }, function() {
	        $(this).children("a").css("border-color", "#767676");
	        $(this).next().children("a").css("border-color", "#767676");                    
	    }
	);
	$(".media_archive li:last-child").hover(
	    function() {
	        $(this).children("a").css("border-color", "#878787");
	        $(".media_archive > ul").css("border-color", "#878787");
	    }, function() {
	        $(this).children("a").css("border-color", "#767676");
	        $(".media_archive > ul").css("border-color", "#767676");                    
	    }
	);

	// video slider effect
	if(document.getElementById('slider')){$("#slider").easySlider();}
});
