var scrollDone = true;
var totItems, scrolledItems;
var itemWidth;
var scrollJQ;

function InitializeVideoScroll(divID)
{
	scrollJQ = $('#' + divID);
	totItems = scrollJQ.find('ul li img').size();
	scrolledItems = 0;
	itemWidth = 158;	// scrollJQ.find('li:first a').outerWidth(true);
	scrollJQ.css('width', (totItems * itemWidth) + "px");
}

function ScrollVideosLeft(clickedElem)
{
	if (! scrollDone || scrolledItems + 4 == totItems)
		return;

	scrollDone = false;

	var amount = parseInt(scrollJQ.css('margin-left')) - itemWidth;	// $('li:first', scroll).outerWidth(true);

	scrollJQ.animate({marginLeft: amount + "px"}, 200, "linear", function() {
		scrolledItems++;
		scrollDone = true;
	});
}

function ScrollVideosRight(clickedElem)
{
	if (! scrollDone || scrolledItems == 0)
		return;

	scrollDone = false;

	var amount = parseInt(scrollJQ.css('margin-left')) + itemWidth;	// $('li:first', scrollJQ).outerWidth(true);

	scrollJQ.animate({marginLeft: amount + "px"}, 200, "linear", function() {
		scrolledItems--;
		scrollDone = true;
	});
}

var videoWidth, videoHeight;

function PlayVideoFP(fileURL, width, height)
{
	var $wrapper = $('#videoWrapper');

	if ($wrapper.size() == 0)
	{
		var def = '<div id="videoBackground" style="top:0;bottom:0;left:0;right:0;"></div><div id="videoWrapper" style="top:0;bottom:0;left:0;right:0;"><div id="videoClose" onclick="StopVideoFP();">Close</div></div>';

		$(def).appendTo('#content');

		$wrapper = $('#videoWrapper');
	}

	var vPos = (($wrapper.outerHeight(true) - height) / 2) + "px";
	var hPos = (($wrapper.outerWidth(true) - width) / 2) + "px";

	$('#video').remove();
	$('#videoBackground').show();

	var videoDiv = '<div id="video" width="' + width + '" height="' + height + '"></div>';

	$(videoDiv).appendTo($wrapper)
				.css({ top: vPos, left: hPos, position: 'relative', 'width': width, 'height': height, backgroundColor: 'black' })
				.parent()
				.show();

	flowplayer("video", "/player/flowplayer-commercial-3.1.5.swf", {
		key: '#$9cbe9fd661b35f3a862',

		logo: {
			url: '/img/logo-video.png',
			bottom: 35,
			left: 20,
			opacity: 0.7,

				// for SWF-based logos you can supply a relative size (to make the logo larger in fullscreen)

			//width: '6.5%',
			//height: '6.5%',

				// if set to false, then the logo is also shown in non-fullscreen mode

			fullscreenOnly: false,

				// time to display logo (in seconds). 0 = show forever

			displayTime: 7,

				// if displayTime > 0 then this specifies the time it will take for
				// the logo to fade out. this happens internally by changing the opacity
				// property from its initial value to full transparency.
				// value is given in milliseconds.

			fadeSpeed: 4000
		},

		clip: {
			url: fileURL,
			autoPlay: true,
			autoBuffering: true,
			bufferLength: 8
		},
		plugins: {
			controls: {
				autoHide: 'always'
			}
		}
	});

/*
	$f().onMouseOver(function() {
		this.getPlugin("controls").css({display: 'block'});
	}).onMouseOut(function() {
		this.getPlugin("controls").css({display: 'none'});
	});
*/
}

function StopVideoFP()
{
	$('#videoWrapper').hide();
	$('#videoBackground').hide();
	$('#video').remove();
}
