﻿function GetHomePageVideos(feed)
{
/// <summary>Main AJAX method for getting video results for the page</summary>
/// <param name="feed">What feed is required</param>
    ManageFeedLinks(feed);

    // Show the comments AJAX loader
    document.getElementById("AJAXLoader").style.display = "inline";

    HomeVideoGridService.HelloWorld(feed, currentVideoType, countryCode, familyFilterOn, GetHomePageVideosSuccess, GetHomePageVideosFail);
}


function GetHomePageVideosSuccess(result, eventArgs)
{ 
    // Hide the comments AJAX loader
    document.getElementById("AJAXLoader").style.display = "none";
    
    // Display the result of the comments webservice in the placeholder.
    var RelatedVideosPlaceHolder = document.getElementById("mainResultsArea");
    RelatedVideosPlaceHolder.innerHTML = result;
}


function GetHomePageVideosFail(error)
{
    // Hide the comments AJAX loader
    document.getElementById("AJAXLoader").style.display = "none";
    
    // Display the error.
    var RelatedVideosPlaceHolder = document.getElementById("mainResultsArea");

    var errorMessage = "<div style=\"height:400px\"><div class=\"userMessage\" style=\"width:98%; padding: 5px 0px 5px 0px; margin-top:10px; \"><strong>D'oh!, sorry it appears an error occured. Please try again.</strong></div></div>";
    RelatedVideosPlaceHolder.innerHTML = errorMessage;
}



var currentFeedType = "recently_featured";

function ManageFeedLinks(feed)
{
    currentFeedType = feed;
    var mainResultsHeading = document.getElementById("mainResultsHeading");
    var moreVideosTopLink = document.getElementById("moreVideosTop");
    var moreVideosBottomLink = document.getElementById("moreVideosBottom");

    var lnkFeatured = document.getElementById("lnkFeatured");
    var lnkMostViewed = document.getElementById("lnkMostViewed");
    var lnkMostDiscussed = document.getElementById("lnkMostDiscussed");
    var lnkTopFavorites = document.getElementById("lnkTopFavorites");

    switch(feed)
    {
        case "recently_featured":
        case "top rated":
        
         if (currentVideoType == videoTypeYouTube)
        {
            mainResultsHeading.innerHTML = "YouTube Featured Videos";
            
            moreVideosTopLink.innerHTML = "See More Featured Videos";
            moreVideosTopLink.href = "youtube.aspx?c=0&ti=0&st=5";
            moreVideosBottomLink.innerHTML = "See More Featured Videos";
            moreVideosBottomLink.href = "youtube.aspx?c=0&ti=0&st=5";
       }  
       else if (currentVideoType == videoTypeVeoh)
        {
             mainResultsHeading.innerHTML = "Veoh Top Rated Videos";
        
            moreVideosTopLink.innerHTML = "See More Top Rated Videos";
            moreVideosTopLink.href = "veoh.aspx?c=0&ti=1&s=12";
            moreVideosBottomLink.innerHTML = "See More Top Rated Videos";
            moreVideosBottomLink.href = "veoh.aspx?c=0&ti=1&s=12";
        }
        
            lnkFeatured.removeAttribute("href");
            lnkFeatured.className = "subcategory selected"; 
            
            lnkMostViewed.className = "subcategory"; 
            lnkTopFavorites.className = "subcategory"; 
            lnkMostDiscussed.className = "subcategory"; 
           
            
            if (currentVideoType == videoTypeYouTube)
            {
                lnkTopFavorites.href = "javascript:GetHomePageVideos(\"top_favorites\")";
                lnkMostViewed.href = "javascript:GetHomePageVideos(\"most_viewed\")";
                lnkMostDiscussed.href = "javascript:GetHomePageVideos(\"most_discussed\")";
            }
            else if (currentVideoType == videoTypeVeoh)
            {
                lnkTopFavorites.href = "javascript:GetHomePageVideos(\"most subscribed\")";
                lnkMostViewed.href = "javascript:GetHomePageVideos(\"most viewed\")";
                lnkMostDiscussed.href = "javascript:GetHomePageVideos(\"most discussed\")";
            
            }

            break;
        case "most_viewed":
        case "most viewed":
        
          moreVideosTopLink.innerHTML = "See More Most Viewed Videos";
          moreVideosBottomLink.innerHTML = "See More Most Viewed Videos";
        
          if (currentVideoType == videoTypeYouTube)
        {
            mainResultsHeading.innerHTML = "YouTube Most Viewed Videos";
            moreVideosTopLink.href = "youtube.aspx?c=0&ti=0&st=0";
            moreVideosBottomLink.href = "youtube.aspx?c=0&ti=0&st=0";
        }
         else if (currentVideoType == videoTypeVeoh)
        {
             mainResultsHeading.innerHTML = "Veoh Top Rated Videos";
        
            moreVideosTopLink.href = "veoh.aspx?c=0&ti=1&s=1";
            moreVideosBottomLink.href = "veoh.aspx?c=0&ti=1&s=1";
        }
        
            lnkMostViewed.removeAttribute("href");
            lnkMostViewed.className = "subcategory selected"; 
            
            lnkFeatured.className = "subcategory"; 
            lnkMostDiscussed.className = "subcategory"; 
            lnkTopFavorites.className = "subcategory"; 
           
            if (currentVideoType == videoTypeYouTube)
            {
                lnkMostDiscussed.href = "javascript:GetHomePageVideos(\"most_discussed\")";
                lnkFeatured.href = "javascript:GetHomePageVideos(\"recently_featured\")";
                lnkTopFavorites.href = "javascript:GetHomePageVideos(\"top_favorites\")";
            }
            else if (currentVideoType == videoTypeVeoh)
            {
                lnkMostDiscussed.href = "javascript:GetHomePageVideos(\"most discussed\")";
                lnkFeatured.href = "javascript:GetHomePageVideos(\"top rated\")";
                lnkTopFavorites.href = "javascript:GetHomePageVideos(\"most subscribed\")";
            }
            
            break;
        case "most_discussed":
        case "most discussed":
        
        moreVideosTopLink.innerHTML = "See More Most Discussed Videos";
        moreVideosBottomLink.innerHTML = "See More Most Discussed Videos";
        
          if (currentVideoType == videoTypeYouTube)
        {
            mainResultsHeading.innerHTML = "YouTube Most Discussed Videos";
            moreVideosTopLink.href = "youtube.aspx?c=0&ti=0&st=1";
            moreVideosBottomLink.href = "youtube.aspx?c=0&ti=0&st=1";
        }
         else if (currentVideoType == videoTypeVeoh)
        {
             mainResultsHeading.innerHTML = "Veoh Most Discussed Videos";
        
            moreVideosTopLink.href = "veoh.aspx?c=0&ti=1&s=7";
            moreVideosBottomLink.href = "veoh.aspx?c=0&ti=1&s=7";
        }
        
            lnkMostDiscussed.removeAttribute("href");
            lnkMostDiscussed.className = "subcategory selected"; 
            
            if (currentVideoType == videoTypeYouTube)
            {
                lnkMostViewed.href = "javascript:GetHomePageVideos(\"most_viewed\")";
                lnkFeatured.href = "javascript:GetHomePageVideos(\"recently_featured\")";
                lnkTopFavorites.href = "javascript:GetHomePageVideos(\"top_favorites\")";
            }
            else if (currentVideoType == videoTypeVeoh)
            {
                lnkMostViewed.href = "javascript:GetHomePageVideos(\"most viewed\")";
                lnkFeatured.href = "javascript:GetHomePageVideos(\"top rated\")";
                lnkTopFavorites.href = "javascript:GetHomePageVideos(\"most subscribed\")";
            }
           
            lnkMostViewed.className = "subcategory"; 
            lnkFeatured.className = "subcategory"; 
            lnkTopFavorites.className = "subcategory"; 
            
            break;
        case "top_favorites":
        case "most subscribed":
        
       
        
        if (currentVideoType == videoTypeYouTube)
        {
            mainResultsHeading.innerHTML = "YouTube Top Favorites Videos";
        
            moreVideosTopLink.innerHTML = "See More Top Favorites Videos";
            moreVideosTopLink.href = "youtube.aspx?c=0&ti=0&st=6";
            moreVideosBottomLink.innerHTML = "See More Top Favorites Videos";
            moreVideosBottomLink.href = "youtube.aspx?c=0&ti=0&st=6";
        }
        else if (currentVideoType == videoTypeVeoh)
        {
             mainResultsHeading.innerHTML = "Veoh Most Subscribed Videos";
        
            moreVideosTopLink.innerHTML = "See More Most Subscribed Videos";
            moreVideosTopLink.href = "veoh.aspx?c=0&ti=1&s=6";
            moreVideosBottomLink.innerHTML = "See More Most Subscribed Videos";
            moreVideosBottomLink.href = "veoh.aspx?c=0&ti=1&s=6";
        }
        
            lnkTopFavorites.removeAttribute("href");
            lnkTopFavorites.className = "subcategory selected"; 
           
            
            if (currentVideoType == videoTypeYouTube)
            {
                lnkMostViewed.href = "javascript:GetHomePageVideos(\"most_viewed\")";
                lnkMostDiscussed.href = "javascript:GetHomePageVideos(\"most_discussed\")";
                lnkFeatured.href = "javascript:GetHomePageVideos(\"recently_featured\")";
            }
            else if (currentVideoType == videoTypeVeoh)
            {
                lnkMostViewed.href = "javascript:GetHomePageVideos(\"most viewed\")";
                lnkMostDiscussed.href = "javascript:GetHomePageVideos(\"most discussed\")";
                lnkFeatured.href = "javascript:GetHomePageVideos(\"top rated\")";
            
            }
            lnkMostViewed.className = "subcategory";
            lnkMostDiscussed.className = "subcategory"; 
            lnkFeatured.className = "subcategory"; 
            
            break;
    }
}


function ChangeVideoType(videoType)
{

    currentVideoType = videoType;

    var lnkYouTube = document.getElementById("lnkYouTubeImg");
    var lnkVeoh = document.getElementById("lnkVeohImg");


    var lnkFeatured = document.getElementById("lnkFeatured");
    var lnkTopFavorites = document.getElementById("lnkTopFavorites");

    if (videoType == videoTypeVeoh)
    {

        lnkYouTube.href = "javascript:ChangeVideoType(\"YouTube\")";
        lnkVeoh.removeAttribute("href");
        currentVideoType = videoTypeVeoh;
        
        lnkVeoh.className = "videoTypeImageSelected";
        lnkYouTube.className = "videoTypeImage";
        
        
        // This works for IE
        lnkFeatured.innerText = "Top Rated";
        // This works for FireFox
        lnkFeatured.innerHTML = "Top Rated";
        
        lnkTopFavorites.innerText = "Most Subscribed";
        lnkTopFavorites.innerHTML  = "Most Subscribed";
        
        if(currentFeedType == "most_viewed")
        {
            currentFeedType = "most viewed";
        }
        else if(currentFeedType == "most_discussed")
        {
            currentFeedType = "most discussed";
        }
        else if(currentFeedType == "recently_featured")
        {
             currentFeedType = "top rated";
        }
        else if(currentFeedType == "top_favorites")
        {
             currentFeedType = "most subscribed";
        }
    }

    if (videoType == videoTypeYouTube)
    {
        lnkVeoh.href = "javascript:ChangeVideoType(\"Veoh\")";
        lnkYouTube.removeAttribute("href");
        currentVideoType = videoTypeYouTube;
        //GetHomePageVideos
        
        lnkVeoh.className = "videoTypeImage";
        lnkYouTube.className = "videoTypeImageSelected";
        
        lnkFeatured.innerText = "Featured";
        lnkTopFavorites.innerText = "Top Favorites";
        
        lnkFeatured.innerHTML = "Featured";
        lnkTopFavorites.innerHTML = "Top Favorites";
        
        if(currentFeedType == "most viewed")
        {
            currentFeedType = "most_viewed";
        }
        else if(currentFeedType == "most discussed")
        {
              currentFeedType = "most_discussed";
        }
        else if(currentFeedType == "top rated")
        {
             currentFeedType = "recently_featured";
        }
        else if(currentFeedType == "most subscribed")
        {
             currentFeedType = "top_favorites";
        }
        
    }
  GetHomePageVideos(currentFeedType);

}