$(function() {
	// internal sub nav toggle
	jQuery.fn.subNavToggle = function(container) {
		var $this = $(this);
		var selectedState;
		$this.each(function() {
			$(this).click(function() {
				selectedState = $(this).attr("rel").toLowerCase();
				$this.each(function() {				
					$(this).toggleClass('selected', $(this).attr("rel").toLowerCase() == selectedState);
				});
				
				if(container && $(container).length)
				{
					$(container).each(function() {					
						if($(this).attr("id").toLowerCase() == selectedState)
						{
							$(this).show();													
						}
						else
						{
							$(this).hide();
						}
					});
					window.scrollTo(0, 0);	
				}
				return false;
			});
		});
		return this;
	};
	
	// check deeplink hash
	checkDeeplink();
	
	
	// school:staff
	$('a.btnStaff').subNavToggle('.staffContainer');
	// experience::P3
	$('a.btnP3').subNavToggle('.p3Container');
	
	// school::affvideos
	$('#affPlayerLinks a').subNavToggle();
	
	// facilities
	$('a.btnFacilities').subNavToggle('.facilitiesContainer');
	
	// school:affvideos
	if($("#affPlayer").length)
	{
		$("#affPlayerLinks a").click(function() {
			var id = $(this).attr("href").substr(1);
			loadAffVideo(id);
		});	
		
		loadAffVideo(1)
	}	
});

function checkDeeplink()
{
	if(document.location.hash)
	{
		var hash = document.location.hash.substr(1);
		var deepLinkDiv = $("#" + hash);

		if(deepLinkDiv.length)
		{
			var link = $("a[rel='" + hash + "']");
			link.parent().find("a").removeClass("selected");
			link.addClass("selected");		
			var cls = deepLinkDiv.attr("class");
			$("." + cls).hide();
			deepLinkDiv.show();
		}
	}
}

function getFlashMovie(movieName) 
{
	return (navigator.appName.indexOf("Microsoft") != -1) ? window[movieName] : document[movieName];
}

function loadAffVideo(id)
{
	swfobject.embedSWF("/userfiles/flash/video" + id + ".swf", "affPlayer", "100%", "100%", "8", "assets/swf/expressInstall.swf", null, {});
}

function goBack()
{
	history.back();
}


