function TurnSpotlightOn(event)
{
	//First get the 'thing' that was clicked.
	var linkHandle = Event.element(event);
	
	//Remember the parent of the thing that was clicked
	var spotlightContentLocation = linkHandle.up(".spotlight_this");

	var SpotlightControl = $('SpotlightControl');

	//Get the content to be spotlit
	var spotlightContent = spotlightContentLocation.down(".spotlight_content");

	var html;
	var width;
	var height;

	//If it's a movie, just load the movie string. Else, grab the content that hidden on the page.
	if (spotlightContent.hasClassName("run_demo_movie")) {
		html = getMovieAsHTMLString('/tutorcom-overview.swf?spak=sv', 510, 355, null, null, 400);
		width = 510;
		height = 355;
	}
	else if (spotlightContent.hasClassName("run_cmt_movie")) {
		html = getMovieAsHTMLString('/tutorcom-overview-cmt.swf?spak=sv', 510, 355, null, null, 400);
		width = 510;
		height = 355;
	}
	else if (spotlightContent.hasClassName("run_new_video")) {
		html = getMovieAsHTMLString('/new-video.swf?spak=sv', 510, 340, null, null, 510);
		width = 510;
		height = 340;
	}
	else if (spotlightContent.hasClassName("run_slideshow")) {
		html = getMovieAsHTMLString('/slideshow.swf?spak=sv', 510, 355, null, null);
		width = 510;
		height = 355;
	}
	else if (spotlightContent.hasClassName("run_resume_video")) {
		html = getMovieAsHTMLString('/media/resume-workshop.swf?spak=sv', 740, 518, 760, 700, 643);
		width = 740;
		height = 518;
	}
	else if (spotlightContent.hasClassName("run_library_video")) {
		html = getMovieAsHTMLString('/lhhv4-sales-tour.swf', 740, 600, 760, 700, 643);
		width = 740;
		height = 600;
	}
	else if (spotlightContent.hasClassName("run_career_center_video")) {
		html = getMovieAsHTMLString('/CareerCenterOffer/career-center-video.swf', 740, 518, 760, 700, 643);
		width = 740;
		height = 518;
	}
	else if (spotlightContent.hasClassName("run_custom_video")) {
		//pull values from hidden values in the markup
		var custom_height = spotlightContent.down(".spotlight_height").getValue();
		var custom_width = spotlightContent.down(".spotlight_width").getValue();
		var custom_video = spotlightContent.down(".spotlight_video").getValue();
		var custom_content_height = spotlightContent.down(".spotlight_content_height").getValue();

		//You must multiply the value of custom height in order to ensure you're getting back an int.
		html = getMovieAsHTMLString(custom_video, custom_width, custom_height, custom_width * 1 + 20, custom_height * 1 + 35, custom_content_height);
		width = custom_width;
		height = custom_height;
	}
	else {
		//Inject the content into the spotlight
		html = spotlightContent.innerHTML;
		width = 550;
		height = 400;
	}

	width += 25;
	height += 50;

	SpotlightElement(linkHandle.up(".spotlight_this").title, null, width, height, html);
}

function SpotlightElement(title, moviePath, width, height, html) {
	if (typeof moviePath != 'undefined' && moviePath != null) {
		html = getMovieAsHTMLString(moviePath, width, height, width + 20, height + 35, height);
	}
	else if (typeof html != 'undefined' && html != null) {
		//nothing to do
	}
	
	jQuery('#SpotlightControl_JQuery').html(html);
	
	jQuery('#SpotlightControl_JQuery').dialog({
		autoOpen: false,
		draggable: false,
		closeText: 'Close Window [X]',
		resizable: false,
		modal: true
	});

	//reset title, width, etc.
	jQuery('#SpotlightControl_JQuery').dialog('option', 'title', title);
	jQuery('#SpotlightControl_JQuery').dialog('option', 'width', width);
	jQuery('#SpotlightControl_JQuery').dialog('option', 'height', height);
	
	jQuery('#SpotlightControl_JQuery').dialog('open');
}

function getMovieAsHTMLString(video_path, video_width, video_height, container_width, container_height, content_height) 
{
	return '<object type="application/x-shockwave-flash" data="' + video_path + '" width="' + video_width + '" height="' + video_height + '">' +
		 '<param name="movie" value="' + video_path + '">' +
		 '<param name="bgcolor" value="#FFFFFF">' +
		 '<param name="menu" value="false">' +
		 '<param name="quality" value="high">' +
		  '<h3>No flash</h3>' +
		  '<br>Please install <a href="http://www.macromedia.com/go/getflashplayer" target="_blank">FLASH plugin</a>.' +
		'</object>';
}

function TurnSpotlightOff(event)
{
	jQuery('#SpotlightControl_JQuery').dialog('close');
}

var SPOTLIGHT_LOADED = false; //global var to track spotlight loaded status
Event.observe(window, 'load', function() {

	var spotlights_on = $$('div.spotlight_display_object');
	//if there are no on switches, then there's no point in doing anything else

	if (spotlights_on.length > 0) {
		for (var index = 0; index < spotlights_on.length; index++) {
			Event.observe(spotlights_on[index], 'click', TurnSpotlightOn);
			Event.observe(spotlights_on[index], 'spotlight:show', TurnSpotlightOn);

			//There's 2 types of additional
			//calls we want to make depending on if a homepage video or a secondary video was clicked.
			if (spotlights_on[index].up("#DemoVideo.homepage")) {
				Event.observe(spotlights_on[index], 'click', function() {
					Analytics_TrackPage("session-demo.html?event=HomepageVideo-Clicked", '/session-demo.html?event=HomepageVideo-Clicked');
				});
			}
			else {
				Event.observe(spotlights_on[index], 'click', function() {
					Analytics_TrackPage("session-demo.html?event=SecondaryPageVideo-Clicked", '/session-demo.html?event=SecondaryPageVideo-Clicked');
				});
			}

		}
	}
});
SPOTLIGHT_LOADED = true;
