//common variables
var pageurl = location.pathname;

//Do this jQuery stuff as soon as the DOM is ready to be manipulated
$(function() {
		   
	//make the pods clickable and add a hover event	
	$(".pod").click(function() {window.location = $(this).find("a:first").attr("href")});	
	$(".pod").hover(
      function () {$(this).addClass("pod-hover")}, 
      function () {$(this).removeClass("pod-hover")}
    );
	




	//do the following stuff, but don't bother doing it to IE6...
	if (!(jQuery.browser.msie && jQuery.browser.version <= 6)) {		
		//add rounded corners to the tabs
		$("#tabs li").append('<span class="tl"></span><span class="tr"></span>');
		
		//adds an extra bit of padding to the right of p elements if they're direct children of the col-r-inner element.
		//Avoids a lot of messy CSS to that would be needed to keep the designs like Mark's png's
		$(".col-r-inner > p").css("padding-right","40px");
		
	}		


	
	
	//auto highlight the tabs and footer links depending on the section/page, by checking to see if a certain id/class exists
	if ( $(".is-home").length > 0 ) {		
		$("li#tab-1").addClass("active");
		$("li#fl-1").addClass("active");
	}
	if ( $(".title-therapy").length > 0 ) {			
		$("li#tab-2").addClass("active");
		$("li#fl-2").addClass("active");
	}	
	if ( $(".title-services").length > 0 ) {			
		$("li#tab-3").addClass("active");
		$("li#fl-3").addClass("active");
	}		
	if ( $(".title-our-team").length > 0 ) {			
		$("li#tab-4").addClass("active");
		$("li#fl-4").addClass("active");
	}		
	if ( $(".title-locations").length > 0 ) {			
		$("li#tab-5").addClass("active");
		$("li#fl-5").addClass("active");
	}
	if ( $(".title-fees").length > 0 ) {			
		$("li#tab-6").addClass("active");
		$("li#fl-6").addClass("active");
	}
	if ( $(".title-faq").length > 0 ) {			
		$("li#tab-7").addClass("active");
		$("li#fl-7").addClass("active");
	}
	if ( $(".title-appointments").length > 0 ) {			
		$("li#tab-8").addClass("active");
		$("li#fl-8").addClass("active");
	}	


	//make links with rel="external" and rel="download" open in new windows. target="_blank" doesn't validate as XHTML STRICT
	$('a[href][rel*=external]').each(function(i){this.target = "_blank";})
	$('a[href][rel*=download]').each(function(i){this.target = "_blank";})
	
	
	$(".book-box-small").each(function(){
		$(this).find("img:first").wrap('<div style="height:155px"></div>');
		$(this).find(".book-box-foot").css("height","110px");
	});	
	
	//check if the footer-wrapper exists (it does so only on he homepage) and if it doesn't, create it
	if(!$('#footer-wrapper').length) {
		$("body").append('<div id="footer-wrapper"><div>');
	}
	
		// apply to all png images 
		//$(document).pngFix();
	
});




//only do this jQuery stuff after everything has loaded, includes images and video etc
$(window).load(function(){
												

						
	//load in the footer from the homepage and inset it into the #footer-wrapper div - avoding duplicate content/spam issues
	$("#footer-wrapper").load("index.html #footer-wrapper-inner");
	
	//if this IS NOT the homepage, load in the footer from the homepage	- avoding duplicate content/spam issues	
	/*if(!(pageurl.indexOf("/index.html") > -1) || !(pageurl.indexOf("index") > -1)) {   	
		$("#footer-wrapper").load("index.html #footer-wrapper-inner");
	}*/
						
	//auto highlight sub navigation link by checking to see if it's own href is in the current page's URL
	$("#section-nav li").each(function(){
		var linkurl = $(this).find("a:first").attr("href");  
		if(pageurl.indexOf(linkurl) > -1) {
			$(this).addClass("active");
		} 			
	});
	
	//auto highlight sub sub navigation link by checking to see if it's own href is in the current page's URL
	//also highlight the parent
	$("#section-nav li ul li").each(function(){
		var linkurl = $(this).find("a:first").attr("href");  
		if(pageurl.indexOf(linkurl) > -1) {
			$(this).addClass("active");
			$(this).parent().parent().addClass("active");
		} 			
	});	
});

