var	filesToLoadTemplate		= new Array();
var	currentFileTemplate		= 0;
function loadFilesTemplate()
{
	if (typeof filesToLoadTemplate[currentFileTemplate] == 'string')
	{
		$.getScript(SCORE_URL + 'Includes/Javascripts/' + filesToLoadTemplate[currentFileTemplate], loadFilesTemplate);
		currentFileTemplate++;
	}
	else
	{
		executeTemplate();
	}
}

$(document).ready(loadFilesTemplate);

function executeTemplate()
{
	$('#bookmarkLink').click(headerBookmark);
	$('#paymentStart').click(paymentStart);

	if ($('a.startMovie').length)
		$.getScript(SCORE_URL + 'Includes/Javascripts/JQuery.Plugin.NyroModal.js', startMovieInit);

}

/* Payment display function */
function paymentStart()
{
	$('#info').hide(500, function (){$('#payment').show()});
}

/*	Start movie in modal	*/
function startMovie(e)
{
	e.preventDefault();
	$.nyroModalManual(
	{
		ajax			: {
			url			: $(this).attr('href') + ($(this).attr('href').toString().split('?').length > 1 ? '&' : '?') + 'modal=true'
		},
		closeButton		: '',
		minWidth		: 100,
		minHeight		: 100,

		endShowContent	: startMovieStart
	});
	return false;
}
function startMovieInit()
{
	$.getScript(SCORE_URL + 'Includes/Javascripts/SWFObject' +  (debug ? '2' : '') + '.js')
	$('a.startMovie').click(startMovie);
}
function startMovieStart()
{
	if ($('div#nyroModalFull div#nyroModalWrapper div#nyroModalContent div#notify').length)
	{
		$('div#nyroModalFull div#nyroModalWrapper div#nyroModalContent div#notify a.continue').click(startMovie);
	}
	else
	{
		sessId	= $('div#nyroModalFull div#nyroModalWrapper div#nyroModalContent div').attr('class');

		var so	= new SWFObject(SCORE_URL + '/Includes/Flash/Player.swf', 'mpl', $('div#nyroModalFull div#nyroModalWrapper div#nyroModalContent div').css('width'), $('div#nyroModalFull div#nyroModalWrapper div#nyroModalContent div').css('height'), '9');
			so.addParam('allowscriptaccess',	'always');
			so.addParam('allowfullscreen',		'true');
			so.addParam('flashvars',			'file=' + $('div#nyroModalFull div#nyroModalWrapper div#nyroModalContent div').attr('title') + '.mp4&streamer=rtmpt://streams.vodpartner.nl:80/protected/&tags=' + sessId + '&volume=100&controlbar=over&autostart=false');
//		if (!debug)
			so.write('player');
			setTimeout(startPlayerPlay, 1000);
	}
}
function startPlayerPlay()
{
	if (typeof mpl != 'object')
		setTimeout(startPlayerPlay, 1000);
	if (typeof mpl == 'object')
		mpl.sendEvent('PLAY');
}

/*	Bookmark function	*/
function headerBookmark(e)
{
	if (window.sidebar)
	{
		window.sidebar.addPanel($($('title')[0]).html(), this, "");
	}
	else if(document.all)
	{
		window.external.AddFavorite(this, $($('title')[0]).html());
	}
}
