$(document).ready(function(){

	loadIntro();

	var checkIE6 = isIE6();
	
	if (checkIE6 != true) {

		addLinkEvents();
		alterTreatments('treatmentsList');
		alterTreatments('priceList');
		alterTreatments('aboutUsList');

	} else {

		fixPNG();

	}

});

//load FlashIntro
function loadIntro() {

	var h1 = $("#mainContent h1").html();

	if (h1 == 'Welcome') {

		$("#sideContent").append('<div id="flashIntro"></div>'); 

		createFlv();
	}

}

//crate flash object
function createFlv() {

	var so = new SWFObject("videos/t1.swf", "mymovie", "293", "446", "8", ""); 
   	so.addParam("wmode", "transparent");
	so.write("flashIntro");

}

//Add events to the main navigation links
function addLinkEvents() {
	
	//for links in the Navigation div
	$("#mainNav li a").each(
		function() {
				var linkText = $(this).html();
			
				$(this).click(
					function(event) {
						loadNewPage(linkText);
						return false;
					}
				);
		}
	);

}

//clcl
function loadNewPage(linkText) {

	$("#mainContent").hide("slow", function () {
		$("#mainContent").slideUp("slow");
	});
	$("#sideContent").hide("slow", function () {
		$("#sideContent").slideUp("slow");
	});

	if (document.getElementById("loadingText")) {
		$("#loadingText").fadeIn("slow");
	} else {
		$("#container").append('<img src="images/loadingText.png" id="loadingText" style="display:none" />'); 
		$("#loadingText").fadeIn("slow");
	}
	
	$("#headerGraphic").attr("src","images/loadingGraphic.gif");
	var t1 = setTimeout("$('#headerGraphic').attr('src','images/headerGraphic.png');",5000);

		if (linkText == "Home") {
			var t=setTimeout("loadHome();$('#mainContent').slideDown('slow').fadeIn('slow');$('#sideContent').slideDown('slow').show('2000', function() { loadIntro(); });",2000);
		} else if (linkText == "Treatments") {
			var t=setTimeout("loadTreatments();$('#mainContent').slideDown('slow').fadeIn('slow');$('#sideContent').slideDown('slow').show('2000', function() { alterTreatments('treatmentsList'); });",2000);
		} else if (linkText == "Prices") {
			var t=setTimeout("loadPrices();$('#mainContent').slideDown('slow').fadeIn('slow');$('#sideContent').slideDown('slow').show('2000', function() { alterTreatments('priceList'); });",2000);
		} else if (linkText == "Schedule") {
			var t=setTimeout("loadSchedule();$('#mainContent').slideDown('slow').fadeIn('slow');$('#sideContent').slideDown('slow').show('2000');",2000);
		} else if (linkText == "About us") {
			var t=setTimeout("loadAbout();$('#mainContent').slideDown('slow').fadeIn('slow');$('#sideContent').slideDown('slow').show('2000', function() { alterTreatments('aboutUsList'); });",2000);
		} else if (linkText == "Contact us") {
			var t=setTimeout("loadContact();$('#mainContent').slideDown('slow').fadeIn('slow');$('#sideContent').slideDown('slow').show('2000');",2000);
		}

}

//load the home page
function loadHome() {

		$("#mainContent").load("index.html #mainContent");
		$("#sideContent").load("index.html #sideContent");
		document.title = "Stepping Stones | Home ";
		$("#loadingText").fadeOut("slow");

}

//load the Treatments page
function loadTreatments() {

		$("#mainContent").load("treatments.html #mainContent");
		$("#sideContent").load("treatments.html #sideContent");
		document.title = "Stepping Stones | Treatments ";
		$("#loadingText").fadeOut("slow");

}

//load the Prices page
function loadPrices() {

		$("#mainContent").load("prices.html #mainContent");
		$("#sideContent").load("prices.html #sideContent");
		document.title = "Stepping Stones | Prices ";
		$("#loadingText").fadeOut("slow");

}

//load the Schedule page
function loadSchedule() {

		$("#mainContent").load("schedule.html #mainContent");
		$("#sideContent").load("schedule.html #sideContent");
		document.title = "Stepping Stones | Schedule ";
		$("#loadingText").fadeOut("slow");

}

//load the About page
function loadAbout() {

		$("#mainContent").load("about.html #mainContent");
		$("#sideContent").load("about.html #sideContent");
		document.title = "Stepping Stones | About Us ";
		$("#loadingText").fadeOut("slow");

}

//load the home page
function loadContact() {

		$("#mainContent").load("contact.html #mainContent");
		$("#sideContent").load("contact.html #sideContent");
		document.title = "Stepping Stones | Contact Us ";
		$("#loadingText").fadeOut("slow");

}

//maniupulate the treatments page
function alterTreatments(id) {

	if ( document.getElementById( id ) ) { 

		hideDivs();
		$("#intro").show();

		//for links in the sideContent div
		$("#sideContent li a").each( 
			function() { 
					var linkText2 = $(this).attr('href');
					var lt3 = linkText2.split("#");
					var lt4 = lt3[1];
					var lt5 = '#' + lt4;
					

					$(this).click(
						function(event) {
							if ( $( lt5 ).parent().attr('id') == 'theTeam' ) {
								$("#mainContent").hide("slow", function () {
									hideDivs();
									$( lt5 ).show("fast");
									$( lt5 ).parent().show("slow");
								});
							} else {
								$("#mainContent").hide("slow", function () {
									hideDivs();
									$( lt5 ).show("slow");
								});
							}
							if (document.getElementById("loadingText")) {
								$("#loadingText").fadeIn("slow");
							} else {
								$("#container").append('<img src="images/loadingText.png" id="loadingText" style="display:none" />'); 
								$("#loadingText").fadeIn("slow");
							}
							var t=setTimeout("$('#loadingText').fadeOut('slow');$('#mainContent').slideDown('slow').fadeIn('slow'); ", 2000);
							return false;
						}
					);
			}
		);

	}

}

//hides all the div elements of 'mainContent'
function hideDivs() {

	//elements from Treatments page & Prices page
	$("#intro").hide();
	$("#physiotherapy").hide();
	$("#reflexology").hide();
	$("#chiropody").hide();
	$("#eft").hide();
	$("#holistic").hide();
	$("#acupuncture").hide();
	$("#homeopathy").hide();
	$("#massageTherapies").hide();
	$("#osteopathy").hide();
	$("#hypnotherapy").hide();
	$("#osteopathy").hide();
	$("#hypnotherapyNLP").hide();
	$("#nutritionist").hide();
	$("#counsellor").hide();
	$("#alexander").hide();
	$("#ayurvedic").hide();
	$("#psychotherapy").hide();
	$("#reiki").hide();
	$("#shiatsu").hide();
	$("#beautician").hide();
	$("#yoga").hide();
	$("#tuiNa").hide();
	$("#specialOffers").hide();
	$("#links").hide();
	

	//elements from Treatments page
	$("#theTeam").hide();
	$("#theClinic").hide();
	$("#productInfo").hide();

	//elements from About Us page - The Team
	$("#teamIntro").hide();
	$("#maxAlexander").hide();
	$("#kapilanBalasubramanium").hide();
	$("#simonCastle").hide();
	$("#elizabetCibilis").hide();
	$("#cletusDsouza").hide();
	$("#hilaryFennelly").hide();
	$("#pattyHemingway").hide();
	$("#martinHempel").hide();
	$("#beatriceLeadbetter").hide();
	$("#imranMirza").hide();
	$("#tonyNovissimo").hide();
	$("#vishalpatel").hide();
	$("#arunaRavithasan").hide();
	$("#shirleyScott").hide();

}

//check for ie6 
function isIE6() {

	var IE6=(navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) && (navigator.userAgent.toLowerCase().indexOf('msie 7') == -1);
	return IE6;

}

//fix png for ie6
function fixPNG() {

for(var i=0; i<document.images.length; i++)

{

var img = document.images[i]

var imgName = img.src.toUpperCase()

if (imgName.substring(imgName.length-3, imgName.length) == "PNG")

{

var imgID = (img.id) ? "id='" + img.id + "' " : ""

var imgClass = (img.className) ? "class='" + img.className + "' " : ""

var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "

var imgStyle = "display:inline-block;" + img.style.cssText

if (img.align == "left") imgStyle = "float:left;" + imgStyle

if (img.align == "right") imgStyle = "float:right;" + imgStyle

if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle

var strNewHTML = "<span " + imgID + imgClass + imgTitle

+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"

+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"

+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"

img.outerHTML = strNewHTML

i = i-1

}

}

}

