﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
	<xsl:output method="xml" indent="yes" omit-xml-declaration ="yes"/>

	<xsl:template match="/">
		
		<xsl:variable name="TemplateURL" select="normalize-space(AjaxRequest/TemplateURL)"></xsl:variable>
		<xsl:variable name="HostName" select="normalize-space(AjaxRequest/HostName)"></xsl:variable>
		<xsl:variable name="Format" select="normalize-space(AjaxRequest/Params/Format)"></xsl:variable>
		<xsl:variable name="VideoURL" select="normalize-space(AjaxRequest/Params/VideoURL)"></xsl:variable>
		<xsl:variable name="VideoKeyValue" select="normalize-space(AjaxRequest/VideoKeyValue)"></xsl:variable>
		
		<xsl:call-template name="VideoDisplay">
			<xsl:with-param name="VideoURL" select="$VideoURL"></xsl:with-param>
			<xsl:with-param name="Format" select="$Format"></xsl:with-param>
			<xsl:with-param name="VideoKeyValue" select="$VideoKeyValue"></xsl:with-param>
		</xsl:call-template>
		
	</xsl:template>

	<xsl:template name="VideoDisplay">
		<xsl:param name="VideoURL" select="'N/A'"></xsl:param>
		<xsl:param name="Format" select="'N/A'"></xsl:param>
		<xsl:param name="VideoKeyValue" select="'N/A'"></xsl:param>
		<xsl:param name="videoWidth">
			<xsl:number value="720"/>
		</xsl:param>
		<xsl:param name="videoHeight">
			<xsl:number value="480"/>
		</xsl:param>
		<xsl:param name="autoPlay">
			<xsl:number value="1"/>
		</xsl:param>
		
		<xsl:choose>
			<xsl:when test="$Format = 'DailyMotion'">
				<xsl:choose>
					<xsl:when test="contains($VideoURL, 'dmcloud.net')">
						<iframe frameborder="0" width="{$videoWidth}" height="{$videoHeight}" scrolling="no"
										src="{$VideoKeyValue}&amp;autoplay={$autoPlay}"></iframe>
					</xsl:when>
					<xsl:otherwise>
						<object width="{$videoWidth}" height="{$videoHeight}">
							<param name="movie" value="http://www.dailymotion.com/swf/video/{$VideoKeyValue}&amp;autoplay={$autoPlay}"></param>
							<param name="allowFullScreen" value="true"></param>
							<param name="allowScriptAccess" value="always"></param>

							<embed src="http://www.dailymotion.com/swf/video/{$VideoKeyValue}&amp;autoplay={$autoPlay}"
										   type="application/x-shockwave-flash"
										   width="{$videoWidth}"
										   height="{$videoHeight}"
										   allowfullscreen="true"></embed>
						</object>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:when test="$Format = 'Vimeo'">
				<iframe src="http://player.vimeo.com/video/{$VideoKeyValue}?autoplay={$autoPlay}&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1"
                        width="{$videoWidth}"
                        height="{$videoHeight}"
                        frameborder="0">
				</iframe>
			</xsl:when>
			<xsl:otherwise>
				<object width="{$videoWidth}" height="{$videoHeight}">
					<param name="movie" value="{$VideoKeyValue}?autoplay={$autoPlay}&amp;version=3&amp;autohide=1&amp;showinfo=0"></param>
					<param name="allowFullScreen" value="true"></param>
					<param name="allowScriptAccess" value="always"></param>
					<param name="wmode" value="opaque" />

					<embed src="http://www.youtube.com/v/{$VideoKeyValue}?autoplay={$autoPlay}&amp;version=3&amp;autohide=1&amp;showinfo=0"
									type="application/x-shockwave-flash"
									allowfullscreen="true"
									allowscriptaccess="always"
									wmode="opaque"
									width="{$videoWidth}"
									height="{$videoHeight}">
					</embed>
				</object>

			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>
