$(document).ready(function() {

/* 	Sniff out IE6 and make sure we don't give it stomach ache */
	// Using jquery.browserplugin.js
	var $browserMake = $.browser.name;
	var $browserVer = $.browser.versionX;
	var $iecrud = $browserMake+$browserVer;

/* 	Fix failure in Firefox v2.x -- inability to support display: inline-block */
//	$(function() {
//		if ($iecrud == 'firefox2') {
//			$('.linkToFaq a').append('&nbsp;&nbsp;&nbsp;&nbsp;') // brutal, but works perfectly
//			$('#home a.moreButton').addClass('fFox2'); // fFox 2 does not respect line-height for an inline-block link, so spoon feed it.
//		}
//	});


	$(function() {
		if ($iecrud == 'msie6' || $iecrud == 'msie7') {
//			stuff
		} else {
//			alt stuff
		}
	});





/* 	Navigation overflow control for long links -- wrapped in browswer sniff as hurst IE6's tummmykins */

	$(function() {
		if ($iecrud == 'msie6' || $iecrud == 'msie7') {
//			stuff
		} else {
			$( '#body-normal #content div#nav-minor-sections dl.nav dd a' ).addClass( 'navAprep' );
			$( '#body-normal #content div#nav-minor-sections dl.nav dd a span.inner' ).addClass( 'navAspanPrep' );

			$( '#body-normal #content div#nav-minor-sections dl.nav dd a span.inner' ).each(function() {
				var fred = $(this).width();
				if( fred > 210) {
					$( this ).addClass( 'truncateLink' );
					$( this ).parent().append( '<span class="plusSign"></span>' );
				}
			});
			$( '#body-normal #content div#nav-minor-sections dl.nav dd a.sub1 span.inner' ).each(function() {
				var fred = $(this).width();
				if( fred > 196) {
					$( this ).addClass( 'truncateLink' );
					$( this ).parent().append( '<span class="plusSign"></span>' );
				}
			});
			$( '#body-normal #content div#nav-minor-sections dl.nav dd a.sub2 span.inner' ).each(function() {
				var fred = $(this).width();
				if( fred > 181) {
					$( this ).addClass( 'truncateLink' );
					$( this ).parent().append( '<span class="plusSign"></span>' );
				}
			});
		}
	});


	$(function() {
		$( 'img.imageAuto' ).each(function (i) {
			/* Each img.imageAuto gets wrapped in div.imgWrap */
			$( this ).wrap( '<div class="imgWrap"> </div>' );
			/* Each img with alt text gets a span appended with the alt text inserted */
			var n = $( this ).attr('alt');
			if (n != "") {
				$( this ).parent().append('<span class="imgTitle">' + n + '</span>');
			}
			/* For each img that declares it's width (they all should as the image insertion upm_image_popper is
			set to add that attribute), set the now wrapping div to have that CSS width too + width to 
			accommodate the chosen CSS design for presenting images, namely:
			border = 1px QED	= 2px
			padding = 5px QED	= 10px
			margin = 5px QED	= 10px
			so the div is set to img width + 22px */
			var p = $( this ).attr('width');
			if ( p != "" ) {
				$( this ).parent().css('width', p + 22);
			}

			var r = $( this ).attr('class');
			if ( r != "" ) {
				$( this ).parent().addClass( r );
			}
		});
	});


	$( 'div.contactAperson input' ).focus(function() {
		$( this ).addClass( 'hasFocus' );
	});

	$( 'div.contactAperson textarea' ).focus(function() {
		$( this ).addClass( 'hasFocus' );
	});

	$( 'div.contactAperson input' ).blur(function() {
		$( this ).removeClass( 'hasFocus' );
	});

	$( 'div.contactAperson textarea' ).blur(function() {
		$( this ).removeClass( 'hasFocus' );
	});


	$( 'div.contactAperson textarea' ).autogrow();


	$( 'div.contactAperson label.zemTextarea' ).append( '<br />' );


	$( 'p.footnote' ).addClass( 'footnote' );
	$( 'p.footnote' ).addClass( 'quiet' );

	$( 'p.footnote:first' ).addClass( 'first' );



/* TOC stuff ---------- */
	$( 'ul#toc' ).tableOfContents(
		$("#innerContent"), // scope
		{
		startLevel: 3,		// H3 and up
		depth:      2,		// H3 through H4,
		topLinks:   true	// Add "Top" Links to Each Header
		}
	); 

	$( 'ul#tocHigher' ).tableOfContents(
		$("#innerContent"), // scope
		{
		startLevel: 2,		// H3 and up
		depth:      2,		// H3 through H4,
		topLinks:   true	// Add "Top" Links to Each Header
		}
	); 

	$( 'ul#toc' ).prepend( '<h3 class="tocTitle linkify">Table of contents</h3>' );
	$( 'ul#tocHigher' ).prepend( '<h3 class="tocTitle linkify">Table of contents</h3>' );

	$( 'ul#toc li ul li a' ).append( '<span class="more arrow">&raquo;</span>' );
	$( 'ul#tocHigher li ul li a' ).append( '<span class="more arrow">&raquo;</span>' );

	$( 'a.toc-top-link' ).append( '&uarr;' );

	$( 'ul#toc .tocTitle' ).toggle(function() {
		$( 'ul#toc *' ).slideDown();
		$( this ).addClass( 'active' );
	}, function() {
		$( 'ul#toc *' ).slideUp();
		$( this ).removeClass( 'active' ).slideDown();
	});
	$( 'ul#tocHigher .tocTitle' ).toggle(function() {
		$( 'ul#tocHigher *' ).slideDown();
		$( this ).addClass( 'active' );
	}, function() {
		$( 'ul#tocHigher *' ).slideUp();
		$( this ).removeClass( 'active' ).slideDown();
	});
/* TOC stuff ---------- */


	$( '.linkify' ).hover(function() {
		$( this ).addClass( 'hover' );
	}, function() {
		$( this ).removeClass( 'hover' );
	});
	

/* 	Mark all # links as .incomplete while we're building */
	$(function() {
		$( 'a' ).each(function (i) {
			var n = $( this ).attr('href');
			if (n == "#") {
				$( this ).addClass( 'incomplete' );
//				$( this ).wrap( '<span class="temp1"> </span>' );
			}
		}
	)});


	$(function() {
		$( 'div.moduleSpec' ).each(function (i) {
			$( this ).prepend( '<h3 class="spec">Module specification</h3>' );
		}
	)});
	$(function() {
		$( 'p.moduleSpec' ).each(function (i) {
			$( this ).prepend( '<h3 class="spec">Module specification</h3>' );
		}
	)});
	

	$( 'blockquote + blockquote' ).addClass( 'multiBqs' );


	$( "div#siteMap dd:contains('Sitemap')" ).replaceWith('');
	$( "div#siteMap dt:contains('Sitemap')" ).replaceWith('');


	$( 'hr' ).wrap( '<div class="hrLike"></div>' );


	$( '#highlights dl.recentArticlesList div.hrLike:last' ).hide();
	$( '#resources dl.recentArticlesList div.hrLike:last' ).hide();


	$( 'dl.recentArticlesList.newsEvents.future dd:last' ).addClass( 'last' );
	$( 'dl.recentArticlesList.newsEvents.today dd:last' ).addClass( 'last' );
	$( 'dl.recentArticlesList.newsEvents.past dd:last' ).addClass( 'last' );

	$( '#highlights dl.recentArticlesList dt:first' ).addClass( 'first' );
	$( '#resources dl.recentArticlesList dt:first' ).addClass( 'first' );


	$( '.thumbs li' ).css({'max-height' : '100px', 'min-height' : '100px', 'overflow' : 'hidden'});


	/* A little bit of a hack - the logic for the breadcrumb has to work for the section(s) of the college side and the section (singular) of the clinic side - this removes the dupe Clinic > Clinic breadcrumb. */
	var seen = {};
	$('ul.breadcrumbs li a').each(function() {
	    var txt = $(this).text();
	    if (seen[txt])
	        $(this).remove();
	    else
	        seen[txt] = true;
	});


	$( '.inPage li' ).append( '<span class="inPage">&darr;</span>' );


	$( 'ul.breadcrumbs li.last' ).click(function() {
		$( 'ul.breadcrumbs li.last' ).click(function() {
			$( 'ul.breadcrumbs li.last' ).click(function() {
				$('.chk').each(function() {
					$(this).addClass( 'chkHidden' );
				});
			});
		});
	});


	$("input#Subject").DefaultValue("Type your subject here");
	$("input#Email").DefaultValue("Type your Email Address here");
	$("textarea#Message").DefaultValue("Type your Message here...");



/*
	$('input#Subject').each(function() {
	    var txt = $(this).attr('value');
	    if (txt == "Type your subject here")
	        $(this).addClass( 'empty' );
	});
	$('input#Subject').each(function() {
	    var txt2 = $(this).attr('value');
	    if (txt2 != "Type your subject here")
	        $(this).removeClass( 'empty' );
	});
*/


/*
	$("#fname").DefaultValue("Enter your first name..");
	$("#lname").DefaultValue("Enter your last name..");
	$("#pass").DefaultValue("MyPassword");
	$("#desc").DefaultValue("Describe yourself...");
*/




/*
	$('.toCheck').each(function() {
		$(this).addClass( 'toCheckHidden' );
	});
*/


	//	Perhaps drop this attempt to strip [*] from the start of file names as seen in clinic newsletters (so likely the .stripNumber class is not needed in that article):	$( ".stripNumber li a:contains( '[' + * + ']' )" ).replaceWith('');


/* ALERT ALERT ALERT ALERT ALERT ALERT ALERT the follwing fn seems to kill and js after it :( */

	$('#thumbs').galleriffic({
		imageContainerSel:      '#slideshow',
//		controlsContainerSel:   '#controls',
		captionContainerSel:    '#caption'
	});






});




















































