var playerAPI = null;

$(document).ready(function() {
	initVideo();
});

pauseCurrent = function() {
	playerAPI.Pause();
};

playCurrent = function() {
	playerAPI.DoPlay();
};

toggleCurrent = function() {
	
};

playClip = function(index) {
	if( playerAPI ) {
		playerAPI.DoPlay();
		playerAPI.ToClip(index);
	};
};

var indexName = { 
	1 : 'burntest',
	2 : 'watertest',
	3 : 'dirtyfueltest',
	4 : 'gumstest'
};

onClipChanged = function(clip) {
	if( playerAPI.getCurrentClip ) {
		
		$('.video_link_active').attr('class', 'video_link');
		var currentIndex = playerAPI.getCurrentClip();
		$('#' + indexName[currentIndex]).attr('class', 'video_link_active');
		
		var description = $('#video_description');
		
		if( description ) {
			var target = $('#video_description_' + currentIndex);
			description.attr('innerHTML', target.attr('innerHTML'));
		}
	};
};

initVideo = function() {
	var media_url = $('#media_url').val();
	var api = flashembed("display", 
		{
			src : media_url + '/video/FlowPlayerDark.swf',
			width : 486, 
			height : 364
		},
		{ 
			config: {   
				autoPlay : false,
				autoBuffering : false,
				controlBarBackgroundColor : '0x505050',
				initialScale : 'scale',
				playList : [ 
					{ url : media_url + '/images/bottles_video.jpg', overlayId: 'play' },
					{ url : media_url + '/video/burntest.flv' },
					{ url : media_url + '/video/watertest.flv' },
					{ url : media_url + '/video/dirtyfueltest.flv' },
					{ url : media_url + '/video/gumstest.flv' }
				],
				loop : false,
				autoRewind : true
			}
		} 
	);	
	
	if( playerAPI == null ) {
		playerAPI = api;
	};
	
	onClipChanged(null);
};