function isIE6()
{
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	
	if(browser == "Microsoft Internet Explorer" && version < 7)
		return true
}

function resizeBigGuy()
{
	var guyHeight = $("#content").height();
	//alert("content height = "+guyHeight);
	$("#bigGuy").height( (guyHeight) );
	
	if(isIE6())	
		$("#bigGuy").height( (guyHeight) );

}

function getFlashSlideshow()
{
	//get the file name
	pathname = getFileName();
	
	var flash="";
	switch(pathname)
	{
		case 'our_doctors':	flash = "flash/our_doctors/rotator.swf";
			break;
		case 'medical_dermatology':	
			flash = "flash/medical_dermatology/rotator.swf";		
			break;
		case 'surgical_dermatology':
			flash = "flash/surgical_dermatology/rotator.swf";			
			break;
		case 'cosmetic_dermatology':
			flash = "flash/cosmetic_dermatology/rotator.swf";			
			break;
		case 'ent':
			flash = "flash/ent/rotator.swf";			
			break;
		case 'audiology':	
			flash = "flash/audiology/rotator.swf";		
			break;
		default:
			flash = "flash/home/rotator.swf";
			pathname = "home";
			break;
	}
	
	var so = new SWFObject( flash, "myFlash", "286", "182", "8" );
	so.addParam("wmode", "transparent");
	so.addParam("base", "flash/"+pathname+"/");
	so.write("flashRotation");
	$("#flashRotation").css("backgroundImage", "none");
}


function resourcePage()
{
	// Check if current page is the patient resources page for resource page sub sections of
	// forms and FAQ's
	if("body#resources")
	{
		
		$(".resource_category").hide();
		$("#resources_splash_hidden").show();
		
		$(".sub_link").click(function()
		{	
			$(".resource_category").hide();		
			var url = $(this).attr("href");
			url = url.substring(1,(url.length));
			
			$("#"+url+"_hidden").fadeIn("medium");
			return false;
		});
	}
}

function subPageEvents()
{
	//Initially hide all divs
	$(".subcontent").hide();
	
	//Initially show the "intro text" with the id=0
	$("#0").show();
	
	// Actions for clicking on a sub_page link, if the content isn't visible, show it.
	// Regardless of if the content is visible or not, scroll to it for the user.
	$(".subcontent_links a").click(function()
	{		
		var id = $(this).attr("href");
		
		if(!$(id).is(":visible"))
		{
			//hide all sub_content
			$(".subcontent").hide();			
			//show corresponding id
			$(id).show();
					
		} else {
			// If the corresponding content is visible, fade in and out, so the user knows some action has been taken
			$(id).fadeOut("fast", function(){ $(this).fadeIn("fast") });
		}
		
		//Scroll to top of content
		$.scrollTo(id, 800);
		
		//resize Ghostly guy based on content height
		resizeBigGuy();		
		
		return false;
	});
	
	// Actions for "to top" link
	// set scrollSpeed based on page height
	$(".topLink").click(function()
	{	
		var bodyHeight = $("body").height();
		var scrollSpeed = (parseFloat(bodyHeight)) * 0.75;
		
		$.scrollTo("#topAnchor", scrollSpeed);
		return false;
	});
}

//Return the name of the file the user is currently viewing
function getFileName()
{
	var pathname = window.location.pathname;	
	var result = pathname.split("/");
	pathname = result[result.length-1];
	pathname = pathname.split(".")[0];
	return pathname;
}

$(document).ready(function() 
{	
	//check if resource page and do actions
	resourcePage();
	
	// actions to show and hide subsections
	subPageEvents();
		
	//Size ghostly guy
	resizeBigGuy();
	
	//get the flash slideshow for the corresponding page
	getFlashSlideshow();
	
	//png transparency fix for ie6 
	$(document).pngFix();	
	
	//form validation
	if($("#contact_form"))
		$("#contact_form").validate();
		
	
});
