var flashElement;
var highlightsIds;
var currentSelected;
var HighlightSlideShowVar;

window.addEvent('domready', function() {
	$('highlights_list').getElements('li').each(function(item, index) {
		item.addEvent('mouseenter', function() {
			item.addClass('hover');
		});

		item.addEvent('mouseleave', function() {
			item.removeClass('hover');
		});
	});
	currentSelected = highlightsData[0]["id"];

	flashElement = document.getElementById(flashElementId);
	flashElement.style.positon = "relative";
	domReadyExtras();

	changeHighlight(1, currentSelected);
});
var calledAgain = false;
function changeHighlight(position, element) {
	var flashElement = document.getElementById(flashElementId); //mootools 1.11 doesn't allow flash objects to be $('id') called
	var titleTarget = $('selected_highlight_title');

	$('highlights_list').getElements('li').each(function(item, index) {
		item.removeClass('selected');
	});
	$$('div.highlight_fader_wrap').each(function(item, index) {
		item.setStyle('display', 'block');
		item.setStyle('position', 'relative');
		//item.setStyle('top', '-237px'); //235ish for IE6 !!!
		item.setStyle('top', '-257px'); //235ish for IE6 !!!
	});

	currentSelected = element ? element : highlightsData[0]["id"];

	var type = highlightsData[position - 1]["type"];
	var url = highlightsData[position - 1]["url"];
	var title = highlightsData[position - 1]["title"];

	$(currentSelected).addClass('selected');

	titleTarget.innerHTML = title;
	if (type == "video") {

		$$('div.highlight_fader_wrap').each(function(item, index) {
			item.setStyle('display', 'none'); //hide any image faders that may be visible
		});

		flashElement.style.position = "relative";
		flashElement.style.zIndex = "1";

		var str = SiteConfig.fileHost + "/file" + url + "?token=" + SiteConfig.token + "&url=" + escape(location.href);
		setTimeout('flashElement.playVideo("' + str + '")', 500);
	}
	else {
		if (flashElement.style.zIndex == "1") //if a video has been playing before, stop it
		{
			flashElement.playVideo("end"); //flash movie looks for "end"
		}
		$$('div.highlight_fader_wrap').getElements('img').each(function(item, index) {
			item.setStyle('display', 'none'); //hide any image faders that may be visible
		});
		var imageFaderDiv = "images_" + currentSelected;
		$(imageFaderDiv).style.display = "block";
		flashElement.style.zIndex = "-1";
		HighlightSlideShowVar = null;
		HighlightSlideShowVar = new HighlightSlideShow({
			slides: $(imageFaderDiv).getElements('img')
            , controlTarget: $('selected_highlight_player')
		});
	}
}

function updateStatus(string) {
	console.log(string);
}
function moveToNext(string) {
	var position;
	for (var i = 0; i < highlightsData.length; i++) {
		if (highlightsData[i]["id"] == currentSelected) {
			position = i + 1;
			if (position < highlightsData.length) {
				currentSelected = highlightsData[position]["id"]
				break;
			}
		}
	}
	if (position < 4) {
		changeHighlight(position + 1, currentSelected);
	}
	else {
		changeHighlight(1, highlightsData[0]["id"]);
	}
}

