﻿<?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:import href="../../GenericTemplates/StringReplace.xslt"/>
    
    <xsl:output method="xml" indent="yes"/>

    <xsl:template name="WorkoutMedia">
        <xsl:param name="ThumbnailURL" select="'N/A'"></xsl:param>
        <xsl:param name="VideoURL" select="'N/A'"></xsl:param>
        <xsl:param name="VideoKeyValue" select="'N/A'"></xsl:param>
        <xsl:param name="WorkoutExerciseID" select="'N/A'"></xsl:param>
        <xsl:param name="TemplateURL" select="'N/A'"></xsl:param>
        <xsl:param name="VideoImage" select="'N/A'"></xsl:param>
        <xsl:param name="VimeoThumbnailURL" select="'N/A'"></xsl:param>
        <xsl:param name="ImageURL" select="'N/A'"></xsl:param>
        <xsl:param name="ExerciseName" select="'N/A'"></xsl:param>
        <xsl:param name="VideoThumbnailURL" select="'N/A'"></xsl:param>

        

        <xsl:variable name="StringExerciseName">
            <xsl:call-template name="replaceCharsInString">
                <xsl:with-param name="stringIn" select="$ExerciseName"></xsl:with-param>
                <xsl:with-param name="charsIn">
                    <xsl:text>'</xsl:text>
                </xsl:with-param>
                <xsl:with-param name="charsOut">
                    <xsl:text>\'</xsl:text>
                </xsl:with-param>
            </xsl:call-template>
        </xsl:variable>


        <xsl:variable name="VideoImageURL">
            <xsl:choose>
                <xsl:when test="$ThumbnailURL != ''">
                    <xsl:value-of select="$ThumbnailURL"/>
                </xsl:when>
                <xsl:when test="$VideoThumbnailURL != ''">
                    <xsl:value-of select="$VideoThumbnailURL"/>
                </xsl:when>
            </xsl:choose>
        </xsl:variable>


        <xsl:choose>

            <xsl:when test="$ThumbnailURL != '' and $VideoURL != ''">
                <xsl:choose>
                    <xsl:when test ="$VideoURL != '' and $VideoKeyValue != ''">
                        <xsl:choose>
                            <xsl:when test ="contains($VideoURL, 'youtube')">
                                <div id="divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}" style="margin-bottom:15px; margin-right:5px;">
                                    <div>
                                        <img src="{$ThumbnailURL}" class="link"
                                           title="Play Video" onClick="workout_LoadYouTubeVideo('{$VideoKeyValue}','divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}','Workout', '{$StringExerciseName}');"></img>
                                    </div>
                                    <div style="margin-top:-30px;">
                                        <img class="link" title="Play Video"
                                             onClick="workout_LoadYouTubeVideo('{$VideoKeyValue}','divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}','Workout', '{$StringExerciseName}');"
                                             src="{$TemplateURL}/Web/Images/Play_Icon.png" width="30" height="30"></img>
                                    </div>
                                </div>
                            </xsl:when>
                            <xsl:when test ="contains($VideoURL, 'vimeo')">
                                <div id="divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}" style="margin-bottom:15px; margin-right:5px;">
                                    <div>
                                        <img src="{$VideoImageURL}" class="link" width="100" height="70"
                                           title="Play Video"
                                           onClick="LoadVimeoVideo('{$VideoKeyValue}','divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}','Workout', '{$StringExerciseName}');"></img>
                                    </div>
                                    <div style="margin-top:-30px;">
                                        <img class="link" title ="Play Video"
                                             onClick="LoadVimeoVideo('{$VideoKeyValue}','divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}','Workout', '{$StringExerciseName}');"
                                             src="{$TemplateURL}/Web/Images/Play_Icon.png" width="30" height="30"></img>
                                    </div>
                                </div>
                            </xsl:when>
                            <xsl:when test="contains($VideoURL, 'dailymotion')">
                                <div id="divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}" style="margin-bottom:15px; margin-right:5px;">
                                    <div>
                                        <img src="{$ThumbnailURL}" class="link" width="120" height="90"
                                           title="Play Video" onClick="LoadDailyMotionVideo('{$VideoKeyValue}','divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}','Workout', '{$StringExerciseName}');"></img>
                                    </div>
                                    <div style="margin-top:-30px;">
                                        <img class="link" title ="Play Video"
                                             onClick="LoadDailyMotionVideo('{$VideoKeyValue}','divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}','Workout', '{$StringExerciseName}');"
                                             src="{$TemplateURL}/Web/Images/Play_Icon.png" width="30" height="30"></img>
                                    </div>
                                </div>
                            </xsl:when>
                            <xsl:when test="contains($VideoURL, 'dmcloud.net')">
                                <div id="divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}" style="margin-bottom:15px; margin-right:5px;">
                                    <div>
                                        <img src="{$ThumbnailURL}" class="link" width="120" height="90"
                                           title="Play Video" onClick="LoadDailyMotionVideo('{$VideoURL}','divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}','Workout', '{$StringExerciseName}');"></img>
                                    </div>
                                    <div style="margin-top:-30px;">
                                        <img class="link" title ="Play Video"
                                             onClick="LoadDailyMotionVideo('{$VideoURL}','divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}','Workout', '{$StringExerciseName}');"
                                             src="{$TemplateURL}/Web/Images/Play_Icon.png" width="30" height="30"></img>
                                    </div>
                                </div>
                            </xsl:when>
                        </xsl:choose>
                    </xsl:when>
                    <xsl:when test ="$ImageURL != ''">
                        <img src="{$ImageURL}" style="margin-bottom:15px; margin-right:5px;"
                            width="100" height="75"></img>
                    </xsl:when>
                    <xsl:otherwise>
                        <div id="divWorkoutVideoContainer" style="display:block;">
                            <img src="{$TemplateURL}/Web/Images/Ver_2_0/exercise100X75.jpg" width="100" height="75" Title="No Video"></img>
                        </div>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:when  test="$ThumbnailURL != ''">
                <img src="{$ThumbnailURL}" align="absmiddle"
                     width="100" height="75"></img>
            </xsl:when>
            <xsl:when test="$VideoURL != ''">
                <xsl:choose>
                    <xsl:when test ="$VideoURL != '' and $VideoKeyValue != ''">
                        <xsl:choose>
                            <xsl:when test ="contains($VideoURL, 'youtube')">
                                <div id="divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}" style="margin-bottom:15px; margin-right:5px;">
                                    <div>
                                        <img src="http://img.youtube.com/vi/{$VideoKeyValue}/1.jpg" class="link"
                                           title="Play Video" onClick="workout_LoadYouTubeVideo('{$VideoKeyValue}','divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}','Workout', '{$StringExerciseName}');"></img>
                                    </div>
                                    <div style="margin-top:-30px;">
                                        <img class="link" title="Play Video"
                                             onClick="workout_LoadYouTubeVideo('{$VideoKeyValue}','divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}','Workout', '{$StringExerciseName}');"
                                             src="{$TemplateURL}/Web/Images/Play_Icon.png" width="30" height="30"></img>
                                    </div>
                                </div>
                            </xsl:when>
                            <xsl:when test ="contains($VideoURL, 'vimeo')">
                                <div id="divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}" style="margin-bottom:15px; margin-right:5px;">
                                    <div>
                                        <img src="{$VideoImageURL}" class="link" width="100" height="70"
                                           title="Play Video"
                                           onClick="LoadVimeoVideo('{$VideoKeyValue}','divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}','Workout', '{$StringExerciseName}');"></img>
                                    </div>
                                    <div style="margin-top:-30px;">
                                        <img class="link" title ="Play Video"
                                             onClick="LoadVimeoVideo('{$VideoKeyValue}','divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}','Workout', '{$StringExerciseName}');"
                                             src="{$TemplateURL}/Web/Images/Play_Icon.png" width="30" height="30"></img>
                                    </div>
                                </div>
                            </xsl:when>
                            <xsl:when test="contains($VideoURL, 'dailymotion')">
                                <div id="divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}" style="margin-bottom:15px; margin-right:5px;">
                                    <div>
                                        <img src="http://www.dailymotion.com/thumbnail/video/{$VideoKeyValue}" class="link" width="120" height="90"
                                           title="Play Video" onClick="LoadDailyMotionVideo('{$VideoKeyValue}','divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}','Workout', '{$StringExerciseName}');"></img>
                                    </div>
                                    <div style="margin-top:-30px;">
                                        <img class="link" title ="Play Video"
                                             onClick="LoadDailyMotionVideo('{$VideoKeyValue}','divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}','Workout', '{$StringExerciseName}');"
                                             src="{$TemplateURL}/Web/Images/Play_Icon.png" width="30" height="30"></img>
                                    </div>
                                </div>
                            </xsl:when>
                            <xsl:when test="contains($VideoURL, 'dmcloud.net')">
                                <div id="divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}" style="margin-bottom:15px; margin-right:5px;">
                                    <div>
                                        <img src="http://static.dmcloud.net/{$VimeoThumbnailURL}/jpeg_thumbnail_medium-1308342384.jpeg" class="link" width="120" height="90"
                                           title="Play Video" onClick="LoadDailyMotionVideo('{$VideoURL}','divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}','Workout', '{$StringExerciseName}');"></img>
                                    </div>
                                    <div style="margin-top:-30px;">
                                        <img class="link" title ="Play Video"
                                             onClick="LoadDailyMotionVideo('{$VideoURL}','divWorkOutYouTubeVideoContainer_{$WorkoutExerciseID}','Workout', '{$StringExerciseName}');"
                                             src="{$TemplateURL}/Web/Images/Play_Icon.png" width="30" height="30"></img>
                                    </div>
                                </div>
                            </xsl:when>
                        </xsl:choose>
                    </xsl:when>
                    <xsl:when test ="$ImageURL != ''">
                        <img src="{$ImageURL}" style="margin-bottom:15px; margin-right:5px;"
                            width="100" height="75"></img>
                    </xsl:when>
                    <xsl:otherwise>
                        <div id="divWorkoutVideoContainer" style="display:block;">
                            <img src="{$TemplateURL}/Web/Images/Ver_2_0/exercise100X75.jpg" width="100" height="75" Title="No Video"></img>
                        </div>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
                <div id="divWorkoutVideoContainer" style="display:block;">
                    <img src="{$TemplateURL}/Web/Images/Ver_2_0/exercise100X75.jpg" width="100" height="75" Title="No Video"></img>
                </div>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>
