$(document).ready(function() {


/*	txpDebug
--------------------------------------------- */

//	$( '#txpDebug' ).fadeTo( 'slow', 0.2 );
//
//
//	$( '#txpDebug' ).click(function() {
//		$( this ).fadeTo( 'fast', 1.0 );
//	});
//
//
//	$( '#txpDebug' ).mouseleave(function() {
//		$( this ).slideUp();
//	});



/* 	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>');
//				$( this ).closest().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('');
	$( "div#siteMap dd:contains('People')" ).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[id^=Subject]' ).addClass( 'subjectClass' );
	$( 'input[id^=Email]' ).addClass( 'emailClass' );
	$( 'input[id^=Email2]' ).addClass( 'email2Class' );
	$( 'textarea[id^=Message]' ).addClass( 'messageClass' );

	$( 'input[id^=p-Name]' ).addClass( 'p-nameClass' );

	$("input.subjectClass").DefaultValue("Type your subject here");
	$("input.emailClass").DefaultValue("Type your Email Address here");
	$("input.email2Class").DefaultValue("Re-type your Email Address here");
	$("textarea.messageClass").DefaultValue("Type your Message here...");


	$("input.p-nameClass").DefaultValue("Your name");

	$( '#patty textarea' ).autogrow();


/*
	$('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('');


	$( 'div.vcard .fn, div.vcard .org, div.vcard div.adr:not(:empty), div.vcard .tel' ).prepend( '<span class="inner"></span>' );
	
	$( 'div.adr:empty' ).hide();
	
//	$( 'span.postal-code' ).append( '<span class="quiet"> &laquo; click for map</span>' );


	$( '.countryRegionList a' ).append( ' &raquo;' );
	$( '.countryRegionList dt a:contains(Canada)' ).addClass( 'canada flag' );
	$( '.countryRegionList dt a:contains(USA)' ).addClass( 'usa flag' );
	$( '.countryRegionList dt a:contains(Mexico)' ).addClass( 'mexico flag' );
	$( '.countryRegionList dt a:contains(New Zealand)' ).addClass( 'newZealand flag' );


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

	$( 'span.cihaLogo' ).toggle(function() {
		$( this ).addClass( 'open' );
		$( this ).after( '<div class="cihaLogoMessage" style="display: none;"><p>This symbol indicates this person is a member of the <a href="http://heilkunstinternational.com/">Canadian-International Heilkunst Association (CIHA)</a>.</p><p>Someone who adheres to the CIHA&#8217;s standards of practice and <a href="http://heilkunstinternational.com/documents/ciha-regulation-code-of-ethics/">Code of Ethics</a>, who engages in continuing education and research to advance their understanding and to ensure their practice adheres to the principles set forth by Dr. Samuel Hahnemann.</p></div>' );
		$( this ).next().slideDown();
	}, function() {
		$( 'span.cihaLogo' ).removeClass( 'open' );
		$( 'div.cihaLogoMessage' ).slideUp(function() {
			$( this ).remove();		
		});
	});


	$( 'li a.fileDownload' ).parent().addClass( 'liFileDownload' );
	$( 'p a.fileDownload' ).parent().addClass( 'pFileDownload' );


	$( '.tocLike h2:first' ).addClass( 'topH2or3' );
	$( '.tocLike h3:first' ).addClass( 'topH2or3' );


	$( 'table#dhhpVdsh tr:even' ).addClass( 'alt' );


	$( 'p.loginError:empty' ).hide();

	$( 'form' ).submit(function() {
		$( ':submit', this ).attr( 'disabled', 'disabled' );
		$( 'p#loginSubmit' ).addClass( 'processing' );
	})



	$( ".zemError li:contains('[url, http, www, href not allowed')" ).replaceWith( '<li><strong>We are sorry, but links have to be kept out of emails to avoid spam.</strong> If you need to send us a link, just email us <em>without</em> the link, let us know and will hook up with you directly. Thank you.</li>' );


	/* someone did a search - a normal click() won't do as Ggl code is there too, hence live() */
	$( 'input.gsc-search-button' ).live( 'click', function() {
		$( 'div#cse' ).slideDown( 'fast' );
		$( 'div.gsc-clear-button' ).addClass( 'showUp' );
		$( 'div.gsc-clear-button' ).html( '<span id="clearCseLink">Clear results</span>' );
	});
	/* someone cleared a search */
	$( 'div.gsc-clear-button' ).live( 'click', function() {
		$( 'div.gsc-clear-button' ).removeClass( 'showUp' );
		$( 'div#cse' ).slideUp( 'fast' );
	});



/*	smooth scrolling
	limited to links with a #
	n.indexOf is a way to search variables (as
	opposed to :contains for searching strings)
--------------------------------------------- */

	$(function() {
		$( 'a' ).each(function (i) {
			var n = $( this ).attr('href');
			if (n.indexOf('#') >= 0) {
				$( this ).addClass( 'smooth' );
			}
		}
	)});

	$('a.smooth').smoothScroll();



/* OK
	$( 'span.cihaLogo' ).toggle(function() {
		$( this ).addClass( 'open' );
		$( this ).next().slideDown();
	}, function() {
		$( 'span.cihaLogo' ).removeClass( 'open' );
		$( 'span.cihaLogo' ).next().slideUp();	//	as opposed to $( this )... -- this ver closes all opened versions of this info
	});
*/



/*	OK
	$( 'div.cihaLogoPerson span.cihaLogo' ).click(function() {
		$( this ).next().slideDown();
	});
*/






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

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

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





});





















































