using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Collections.Generic;
using System.Text.RegularExpressions;

public partial class Controls_YouTubeVideoPlayer : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            dsYouTubeLinks.ConnectionString = ConfigurationManager.ConnectionStrings["SabrinContent"].ToString();         
            ddlYouTubeLinks.SelectedIndex = 0;
        }
    }

    protected void dsYouTube_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
    }
    string _embedCode = "";
    string _youTubeID = "";
    protected string YouTubeID { get { return _youTubeID;  } }
    protected void SetActiveVideo() {
        string sql = "SELECT YouTubeID FROM YouTubeVideos WHERE ID = " + ddlYouTubeLinks.SelectedValue;
         _youTubeID = SqlHelper.ExecuteScalar(CommandType.Text, sql).ToString();
         _embedCode = string.Format("<object width=\"334\" height=\"278\"><param name=\"YouTubePlayer\" id=\"YouTubePlayer\" value=\"http://www.youtube.com/v/{0}&rel=0\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"http://www.youtube.com/v/{0}&rel=0\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"334\" height=\"278\"></embed></object>", _youTubeID); 
    
    }
    protected string EmbedCode() { return _embedCode;  }
    protected void ddlYouTubeLinks_Changed(object sender, EventArgs e)
    {
        SetActiveVideo();
        lblYouTubePLayer.Text = _embedCode;
    }
    protected void ddlYouTube_DataBound(object sender, EventArgs e)
    {
        SetActiveVideo();
        lblYouTubePLayer.Text = _embedCode;
    }
}
