/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * Newsys Video Player Library
 *
 * This library provides common functionality needed to render widgets that load
 * the FlowPlayer video player into Newsys for all videos.
 *
 * @author Patrick O'Lone <polone@townnews.com>
 * @version 1.3
 */

document.write('<script type="text/javascript" src="/shared-content/flowplayer/flashembed.min.js"></script>');

// {{{ void thumbnailMovie( string, string, string )

/**
 * Generate a full scale view of a movie in a new window
 *
 * @param string szMovie
 * The URL to the movie in full path to the movie in question.
 *
 * @param string szWidth
 * The width of the movie window. 50 pixels will automatically be
 * added to this number.
 *
 * @param string szHeight
 * The height of the movie window. 100 pixels will automatically
 * be added to this number.
 *
 * @author Patrick O'Lone <polone@townnews.com>
 */
function thumbnailMovie( szMovie, szWidth, szHeight )
{
	var szParams;

	szParams += "toolbar=no";
	szParams += ",resizable=yes";
	szParams += ",status=no";
	szParams += ",scrollbars=no";
	szParams += ",menubar=no";
	szParams += ",width=" + (szWidth + 15);
	szParams += ",height="+ (szHeight + 15);

	hWnd = window.open(szMovie, "movie_window", szParams);
	hWnd.focus();
}

// }}}
// {{{ void newsys_video_instance( array )

/**
 * Create an instance of the video player
 *
 * @param array kConfig An array of parameters to supply. These are the same as
 * the options for the FlowPlayer widget
 * @author Patrick O'Lone <polone@townnews.com>
 */
function newsys_video_instance(kConfig)
{
	var kItem;
	var kOptions = {
		config: {
			loop: false,
			showLoopButton: false,
			showPlayListButtons: false,
			useNativeFullScreen: true,
			autoRewind: true,
			autoPlay: kConfig['autoPlay'],
 			autoBuffering: kConfig['autoBuffering'],
 			menuItems: [ true, true, true, true, true, true, false ],
 			playList: [{
 				url: kConfig['movie'],
 				type: 'flv',
 				controlEnabled: true
 			}]
 		}
 	};
 	
 	// Embed the ad from the system
 	
 	if(document.embededAd) {
 	
 		kItem = {
 			url: document.embededAd.itemUrl,
 			maxPlayCount: 1,
 			controlEnabled: false
 		};
 		
 		if(document.embededAd.itemLink.match(/[^\?r=]$/)) {
 			kItem['linkUrl'] = document.embededAd.itemLink;
 		}
 		
 		kItem['type'] = document.embededAd.itemType;
 		
 		if(kItem['type'] != 'flv'){
 			kItem['duration'] = 60;
 		}
 		
 		if(document.embededAd.preRoll == "1") {
 			kOptions['config']['playList'].unshift(kItem);
 		} else {
 			kOptions['config']['playList'].push(kItem);
 		}
 		
 		document.embededAd = null;
 	}
 	
 	//only add a stillframe to the playlist if one is found
 	if (kConfig['autoBuffering'] == false) {
 		kOptions['config']['playList'].unshift({
	 			overlayId: 'play',
	 			url: '/shared-content/newsys/common/video_preview.php?video=' + kConfig['movie'],
	 			type: 'jpg',
	 			controlEnabled: true
	 	});
 	}
 	
 	new flashembed("flowplayerblock" + kConfig['id'], {
 		src: "/shared-content/flowplayer/" + kConfig['skin'],
 		width: kConfig['width'],
 		height: kConfig['height'],
 		allowSciptAccess: true,
 		allowFullScreen: true,
 		allowNetworking: "all",
 		quality: "high",
 		scaleMode: "showAll" },
 		kOptions
 	);

}

/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * c-hanging-comment-ender-p: nil
 * End:
 */
