jQuery(document).ready(function () {

	var userAgent = navigator.userAgent.toLowerCase();
	var browser = jQuery.browser;
	browser.chrome = /chrome/.test(userAgent.toLowerCase());

	if (browser.msie) {
		// Is this a version of IE?
		jQuery('body').addClass('browserIE');

		// Add the version number
		jQuery('body').addClass('browserIE' + browser.version.substring(0,1));
	}
	else if(browser.chrome) {
		// Is this a version of Chrome?

		jQuery('body').addClass('browserChrome');

		//Add the version number
		userAgent = userAgent.substring(userAgent.indexOf('chrome/') +7);
		userAgent = userAgent.substring(0,1);
		jQuery('body').addClass('browserChrome' + userAgent);

		// If it is chrome then jQuery thinks it's safari so we have to tell it it isn't
		browser.safari = false;
	}
	else if (browser.safari) {
		// Is this a version of Safari?
		jQuery('body').addClass('browserSafari');

		// Add the version number
		userAgent = userAgent.substring(userAgent.indexOf('version/') +8);
		userAgent = userAgent.substring(0,1);
		jQuery('body').addClass('browserSafari' + userAgent);
	}
	else if (browser.mozilla) {
		// Is this a version of Mozilla?

		// Is it Firefox?
		if (userAgent.indexOf('firefox') != -1) {
			jQuery('body').addClass('browserFirefox');

			// Add the version number
			userAgent = userAgent.substring(userAgent.indexOf('firefox/') +8);
			userAgent = userAgent.substring(0,1);
			jQuery('body').addClass('browserFirefox' + userAgent);
		}
		else {
			// If not then it must be another Mozilla
			jQuery('body').addClass('browserMozilla');
		}
	}
	else if (browser.opera) {
	// Is this a version of Opera?
		jQuery('body').addClass('browserOpera');
	}


	// Hide all tabs but first.
	jQuery(".card:gt(0)").hide();

//	if (typeof console == 'undefined') {
//		console = {
//			log: function(msg) {
//				// alert(msg);
//			}
//		};
//	}

	// Enable Tabs functionality
	jQuery("ul.tabs li a").click(function(event) {
		event.preventDefault();
		//console.log("Tab clicked");
		jQuery(".card:visible").hide();
		var cardId = jQuery(this).attr("id").replace("tab", "card");
		//console.log("Card : " + cardId);
		jQuery("#" + cardId).show();
		jQuery("ul.tabs li").removeClass("active");
		jQuery(this).parent().addClass("active");
	});

	/* Need to display YouTube description on mouse over
	 * Take the description from the alt text of the image
	 * Look for #youtube_image_description div
	 */
	jQuery("#youtube_image_list li a").mouseover(
		function(event) {
			var description = jQuery(this).attr("title");
			jQuery("#youtube_image_description").html(description);
		}
	);
	
	/* Need to hide YouTube description when user
	 * moves mouse outside youtube area in peripheral content
	 */
	jQuery("div.peripheralcontent").mouseleave(
		function(event) {
			jQuery("#youtube_image_description").html("");
		}
	);

	/*
	 * Fix layout in staff listing (vertical centring required of content of
	 * unknown height in a block of unknown height).
	 */
	jQuery("li.staff_list_item").each(
		function(index) {
			var jContent = jQuery("p", this);
			var offset = (jQuery(this).innerHeight() - jContent.height())/2 - 5;
				// The -5 is to allow for the padding of the <li> tag, which
				// is included in the inner height.
			jContent.css("margin-top", offset);
		}
	);

	/*
	 * Fix layout in student testimonial (vertical height of quote needs to match image).
	 */
	jQuery("div.article_heading").each(function(index) {
		var $img = jQuery("div.image", this);
		var $quote = jQuery("div.intro", this);
		var height = $img.outerHeight() - ($quote.outerHeight() - $quote.height());
		if (height > $quote.height()) {
			$quote.height(height);
		}
	});

	/* 
	 * shrink image list area if there are fewer than 3 videos
	 */
	if (jQuery("#youtube_image_list li a").size() <3){
		jQuery("#youtube_image_list").css("min-height","50px");
	};
	
	/*
	 * set height correctly by clearing out description
	 */
	jQuery("#youtube_image_description").html("");
	
	/*
	 * Slide the image captions up when rolled over
	 */
	jQuery("div.image").hover(
        function(event) {
    		jQuery("div.moreContainer", this).slideToggle(400);
    	},
    	function(event) {
    		jQuery("div.moreContainer", this).slideToggle(400);
    	}
    );

	/*
	 * Slide the image captions up when rolled over
	 */
	jQuery("#searchText").focus(function(event) {
		if (this.value == this.defaultValue) {
			this.value = '';
		}
	}).blur(function(event) {
		if (this.value == '') {
			this.value = this.defaultValue;
		}
    });


});

