// 
// js/VideoTools.js
//
// USER CENTRIC VIDEO LAUNCH PAGE SYSTEM - CLIENT-SIDE MEDIA PLAYER SCRIPTS
// Version: 1.0
// Date: 3/31/2008

// This Javascript defines functions used by the video launch
// page to control the Windows Media Player object, and to
// update portions of the UI to reflect the video currently
// being played.
// 


function PlayIt(anObj) {
    if (anObj.controls.isAvailable('Play')) {
        anObj.controls.play();
    }
}

function StopIt(anObj) {
    if (anObj.controls.isAvailable('Stop')) {
        anObj.controls.stop();
    }
}

function playVideo(strURL,intPageVideoWidth,intPageVideoHeight) {

    myWMPlayer("Video_Container",strURL,intPageVideoWidth,intPageVideoHeight,1,0,0,1,1);

}

function ClearDownloadLink() {

    WriteContentIntoID('Video_Download','&nbsp;');

}


function UpdateDownloadLink(strStreamURL) {

    if (typeof( window[ 'gstrUCDownloadFolder' ] ) != "undefined") {

		if (gstrUCDownloadFolder != "") {
			var strDownloadFolderWithLogin = gstrUCDownloadFolder.replace('http://', gstrAuthenticatePlayer);
	        var strDownloadURL = gstrUCDownloadFolder + strStreamURL.substring(gstrUCVideoFolder.length);
	        WriteContentIntoID('Video_Download','<a id="DownloadVideoLink" href="' + strDownloadURL + '">Right-click to Download</a>');
		}
    }

}


function playSelectedVideo(intPageVideoWidth,intPageVideoHeight) {

    // Toggle the "Previous" button and update the download link.
    if (Client_Page_Form.Video_Controls_Select_Video.selectedIndex > 0) {
        Client_Page_Form.Video_Controls_Previous.disabled=false;
        Client_Page_Form.Video_Controls_Previous.className="Video_Control_Enabled";

        // Update the download link, if present, to reflect the current video.
        UpdateDownloadLink(Client_Page_Form.Video_Controls_Select_Video.options[Client_Page_Form.Video_Controls_Select_Video.selectedIndex].value);

    } else {
	ClearDownloadLink();
        Client_Page_Form.Video_Controls_Previous.disabled=true;
        Client_Page_Form.Video_Controls_Previous.className="Video_Control_Disabled";
    }

    // Toggle the "Next" button if necessary.
    if (Client_Page_Form.Video_Controls_Select_Video.selectedIndex < Client_Page_Form.Video_Controls_Select_Video.options.length-1) {
        Client_Page_Form.Video_Controls_Next.disabled=false;
        Client_Page_Form.Video_Controls_Next.className="Video_Control_Enabled";
    } else {
        Client_Page_Form.Video_Controls_Next.disabled=true;
        Client_Page_Form.Video_Controls_Next.className="Video_Control_Disabled";
    }

    // Update the title to reflect the current video.
    WriteContentIntoID("Page_Subtitle_Video_Title","<span id=\"Page_Subtitle_Video_Title\">" + Client_Page_Form.Video_Controls_Select_Video.options[Client_Page_Form.Video_Controls_Select_Video.selectedIndex].text + "</span>")

    // Send the video to the player control.
    playVideo(Client_Page_Form.Video_Controls_Select_Video.options[Client_Page_Form.Video_Controls_Select_Video.selectedIndex].value,intPageVideoWidth,intPageVideoHeight);

}

function playPreviousVideo(intPageVideoWidth,intPageVideoHeight) {
    if (Client_Page_Form.Video_Controls_Select_Video.selectedIndex > 0) {
        Client_Page_Form.Video_Controls_Select_Video.selectedIndex--;
    }
    playSelectedVideo(intPageVideoWidth,intPageVideoHeight);
}

function playNextVideo(intPageVideoWidth,intPageVideoHeight) {
    if (Client_Page_Form.Video_Controls_Select_Video.selectedIndex < Client_Page_Form.Video_Controls_Select_Video.options.length) {
        Client_Page_Form.Video_Controls_Select_Video.selectedIndex++;
    }
    playSelectedVideo(intPageVideoWidth,intPageVideoHeight);
}

///////////////////////////////////////////////
// Generic "write content into ID" function. //
///////////////////////////////////////////////
// Copyright 2006 Bontrager Connection, LLC
function WriteContentIntoID(id,content) {
if(document.getElementById) {
	var idvar = document.getElementById(id);
	idvar.innerHTML = '';
	idvar.innerHTML = content;
	}
else if(document.all) {
	var idvar = document.all[id];
	idvar.innerHTML = content;
	}
else if(document.layers) {
	var idvar = document.layers[id];
	idvar.document.open();
	idvar.document.write(content);
	idvar.document.close();
	}
} // end of WriteContentIntoID()

