/**
* Javascript for Channel Video List
*/
//this variable so we can change the divReplaceID dinamically
var divReplaceID = "channelVideos";

function loadVideos(searchUrl, strQueryString, sReplaceID)
{
     divReplaceID = sReplaceID;
     
     if (window.jQuery)
     {
         //Show the loading spinner
         jQuery("#" + sReplaceID).html("<div style='position:relative; z-index:999; background-color:#fff; margin:20px;'><img src='/global/images/spinner_white.gif' />&nbsp;Loading...</div>" + jQuery("#" + sReplaceID).html());
         
        var url = searchUrl + (strQueryString != "" ? "?" + strQueryString : "");
        if (window.location.href.indexOf('https') >= 0)
            url = url + '&RequiresSecure=1';

         jQuery.ajax({
                type: "GET",
                url: url,
                success: showVideoResults,
                failure: showVideErrors
            });
     }
}


//show result
function showVideoResults(o)
{
     var resultObj = jQuery("#" + divReplaceID);
     if (resultObj)
     {
         resultObj.html(o)

         //add this if the source is change
         jQuery(document).ready(function() { media.init(); } );
     }
}

//show errors
function showVideErrors(o)
{
    var resultObj = jQuery("#" + divReplaceID);
    if (resultObj)
    {
        resultObj.html("<div style='color:red;'>Cannot load channel videos.</div>");
    }
}
