if (typeof Frontend != 'object') {
	Frontend = {};
}
var spotLights = null;
var spotLightIndex = 0;
$(function() {
	//Set last class on li
	$('ul.navigation > li:last').addClass('last');
	//Create menu
	$("ul.navigation").superfish({
		speed : 0
	});
	spotlights = $('.spotlight ul li');
	if (spotlights.length > 0) {
		$(spotlights[0]).show();
		if (spotlights.length > 1) {
			rotateSpotLight();
		}
	}
	
	$(".video").click(function (event) {
		event.preventDefault();

		var video = event.currentTarget.href;

		$( "#dialog-modal-video" ).dialog({
			height: 465,
			width: 580,
			modal: true,
			closeText : '',
			open: function(e, ui) {
				var content = $(e.target);
				content.html('<div id="jwplayer"></div>');

				var flashvars = {file: video, autostart: true};
				var params = {allowfullscreen: 'true', allowscriptaccess: 'always'};
				var attributes = {};
				swfobject.embedSWF('/resources/javascript/jwplayer/player.swf', 'jwplayer', 550, 400, "9.0.0", false, flashvars, params, attributes);

			},
			close: function(e, ui) {
				var content = $(e.target);
				content.html('');
			}

		});

	});
	
});

function rotateSpotLight()
{
	var spotlight = $(spotlights[spotLightIndex]);
	spotLightIndex++;
	if (spotLightIndex >= spotlights.length) {
		spotLightIndex = 0;
	}
	var newspotlight = $(spotlights[spotLightIndex]);
	setTimeout(function() {
		spotlight.hide();
		newspotlight.show();
		rotateSpotLight();
	}, 3000);
}
