function toggleTab(szDivID, tabID, istyle) // 1 visible, 0 hidden
{
        var obj = document.getElementById(szDivID);
		var objtabl = document.getElementById(tabID);
		obj.style.backgroundColor = istyle;
}

function embedCode(vid_id, width, height)
{	
		//alert(video_hide_id);
		
		 var curtextval = document.getElementById("videoembed");
		 var setbgcolor = document.getElementById("vid_"+ vid_id );
		 var setbgcolormain = document.getElementById("vid_"+ video_hide_id );
		 
		
		if ( (video_hide_id != 0) && (video_hide_id != vid_id) ) {
				setbgcolormain.style.backgroundColor = "#ffffff";
		}
		
		video_hide_id = vid_id;

		setbgcolor.style.backgroundColor = "#e9f1f7";
		//setbgcolor.style.visibility = "hidden";
		//setbgcolor.style.display = "none";
			
		var sethid1 = document.getElementById("img_"+ vid_id );
			//sethid1.style.visibility = "hidden";
			//sethid1.style.display = "none";
		var sethid2 = document.getElementById("extra_"+ vid_id );
			//sethid2.style.visibility = "hidden";
			//sethid2.style.display = "none";

        curtextval.innerHTML = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width='" +width  + "' height='" +height  + "'><param name='allowfullscreen' value='true' /><param name='allowscriptaccess' value='always' /><param name='movie' value='http://vimeo.com/moogaloop.swf?clip_id="+vid_id+"&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1&amp;autoplay=1' /><embed src='http://vimeo.com/moogaloop.swf?clip_id="+vid_id+"\
&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1&amp;autoplay=1' type='application/x-shockwave-flash' allowfullscreen='true' allowscriptaccess='always' width='" +width  + "' height='" +height  + "'></embed></object>"; 


}

function embedDelveCode(vid_id, chan_id, width, height)
{	
		var curtextval = document.getElementById("videoembed");
        curtextval.innerHTML = "<object width='" + width + "' height='" + height + "' id=\"delve_player611817o\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"><param name=\"movie\" value=\"http://assets.delvenetworks.com/player/loader.swf\"/><param name=\"wmode\" value=\"transparent\"/><param name=\"allowScriptAccess\" value=\"always\"/><param name=\"allowFullScreen\" value=\"true\"/><param name=\"flashvars\" value=\"mediaId=" + vid_id +"&amp;channelId=" + chan_id + "&amp;playerForm=8bdb35f29c22449c9a93ccc2a87512bd\"/><embed src=\"http://assets.delvenetworks.com/player/loader.swf\" name=\"delve_player273703e\" wmode=\"transparent\" width='" + width + "' height='"+ height + "' allowScriptAccess=\"always\" allowFullScreen=\"true\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.adobe.com/go/getflashplayer\" flashvars=\"mediaId=" + vid_id + "&amp;channelId=" + chan_id + "&amp;playerForm=8bdb35f29c22449c9a93ccc2a87512bd\"></embed></object>"; 

}

function embedKitCode(vid_id, chan_id, width, height)
{	
		var curtextval = document.getElementById("videoembed");
		curtextval.innerHTML = "<object width='" + width + "' height='" + height + "'><param name='allowFullScreen' value='true'/><param name='allowScriptAccess' value='always'/><param name='movie' value='http://royce.pb.feedroom.com/pb-comp/royce/custom7/player.swf?SiteID=royce&SkinName=custom7&ChannelID=" + chan_id + "&StoryID=" + vid_id +"'/><embed src='http://royce.pb.feedroom.com/pb-comp/royce/custom7/player.swf?SiteID=royce&SiteName=RoyceFunds&SkinName=custom7&ChannelID=" + chan_id + "&StoryID=" + vid_id +"' height='"+ height + "' width='" + width + "' allowFullScreen='true' allowScriptAccess='always'/></object>";

}


// This function puts the video on the page
function embedVideo(video) {
	videoEmbedCode = video.html;
	document.getElementById('videoembed').innerHTML = unescape(video.html);
}
		
// This function goes through the clips and puts them on the page
function showThumbsAlbum1(clips) {
	var thumbs = document.getElementById('country1');
	var strHTML = '';
	thumbs.innerHTML = '';
	var strStyle = '';
	strHTML = strHTML + '<table cellpadding="0" cellspacing="0" border="0">';
	for (var i = 0; i < clips.length; i++) {
		if (clips[i].clip_id == video_hide_id) {
			//strStyle = 'hideme';
		}
		strHTML = strHTML + '<tr>';
		strHTML = strHTML + '<td style="'+strStyle+'" id="img_'+ clips[i].clip_id +'"><a href=#" onclick="embedCode(' + clips[i].clip_id + ')"><img src="' + clips[i].thumbnail_medium + '" border="0" width="80" height="60" alt=""></a></td>';
		strHTML = strHTML + '<td class="text-video ' + strStyle + '" id="vid_'+ clips[i].clip_id +'"><div class="text-section"><a href=#" onclick="embedCode(' + clips[i].clip_id + ')">' + clips[i].title + '</a> ' + convertToMins(clips[i].duration) + '</div></td>';			
		strHTML = strHTML + '</tr><tr><td class="' + strStyle + '" id="extra_'+ clips[i].clip_id +'" colspan="2"><img src="/images/designelements/spacer.gif" border="0" width="0" height="10" alt=""></td></tr>';
	}
	strHTML = strHTML + '</table>';
	thumbs.innerHTML = strHTML;
}

function showThumbsAlbum2(clips) {
	var thumbs2 = document.getElementById('country2');
	var strHTML = '';
	thumbs2.innerHTML = '';
	strHTML = strHTML + '<table cellpadding="0" cellspacing="0" border="0">';
	for (var i = 0; i < clips.length; i++) {
		strHTML = strHTML + '<tr>';
		strHTML = strHTML + '<td><a href=#" onclick="embedCode(' + clips[i].clip_id + ')"><img src="' + clips[i].thumbnail_medium + '" border="0" width="80" height="60" alt=""></a></td>';
		strHTML = strHTML + '<td class="text-video" id="vid_'+ clips[i].clip_id +'"><div class="text-section"><a href=#" onclick="embedCode(' + clips[i].clip_id + ')">' + clips[i].title + '</a> ' + convertToMins(clips[i].duration) + '</div></td>';			
		strHTML = strHTML + '</tr><tr><td colspan="2"><img src="/images/designelements/spacer.gif" border="0" width="0" height="10" alt=""></td></tr>';
	}
	
	strHTML = strHTML + '</table>';
	thumbs2.innerHTML = strHTML;
}

String.prototype.pad = function(l, s){
	return (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length) + 1).join(s)).substr(0, s.length) + this + s.substr(0, l - s.length) : this;
};


function convertToMins( intNumber ) {
	var secVarTemp = 0;
	if (intNumber) {
		var secVar0 = intNumber;
		var minVar = Math.floor(secVar0/60);
		var secVar = secVar0 % 60;
		secVarTemp = '<span style="color:#676767">' + minVar + ':' + secVar.toFixed().pad(2, "0") + '</span>';
	}
	return secVarTemp;
}


// This function loads the data from Vimeo
function init() {
	/*
        var js = document.createElement('script');
	js.setAttribute('type', 'text/javascript');
	js.setAttribute('src', urlalbum1);
	document.getElementsByTagName('head').item(0).appendChild(js);
	
	var js = document.createElement('script');
	js.setAttribute('type', 'text/javascript');
	js.setAttribute('src', urlalbum2);
	document.getElementsByTagName('head').item(0).appendChild(js);
	*/
	var js2 = document.createElement('script');
	js2.setAttribute('type', 'text/javascript');
	js2.setAttribute('src', url2);
	document.getElementsByTagName('head').item(0).appendChild(js2);
} 

//New functions for Delve Video Pages
function delvePlayerCallback(playerId, eventName, data) {
	switch (eventName) {
		case 'onPlayerLoad':
		doOnPlayerLoad();
		break;
	
	case 'onChannelLoad':
		doOnChannelLoad(data);
		break;
	
	case 'onMediaLoad':
		doOnMediaLoad(data);
		break;
	
	case 'onPlayStateChanged':
		doOnPlayStateChanged(data);
		break;
	
	case 'onPlayheadUpdate':
		doOnPlayheadUpdate(data);
		break; 
	}
}

//function doOnMediaLoad(e) {
//	listChannelMedia(DelvePlayer.doGetCurrentChannel().id, DelvePlayer.doGetCurrentChannel().mediaList);
//}

function doOnChannelLoad(e) {
	listChannelMedia(e.id, e.mediaList);
}

function converMilliToSeconds( intMilli ) {
	var milliseconds = parseInt(intMilli);
	var hours = Math.floor(milliseconds / 3600000);
	var minutes = Math.floor((milliseconds - (hours * 3600000)) / 60000);
	var seconds = parseInt((milliseconds - (hours * 3600000) - (minutes * 60000)) / 1000);
	if (seconds < 10){
		return minutes + ":0" + seconds;
	}
	else {
		return minutes + ":" + seconds;
	}
}

function changeBg( vid_id ) {	
	var setbgcolor = document.getElementById("vid_"+ vid_id );
	var setbgcolormain = document.getElementById("vid_"+ video_hide_id );
	
	if ( (video_hide_id != 0) && (video_hide_id != vid_id) ) {
		setbgcolormain.style.backgroundColor = "#ffffff";
	}
	video_hide_id = vid_id;
	setbgcolor.style.backgroundColor = "#e9f1f7";
	//alert(video_hide_id);
}

function listChannelMedia( channelid, arrayList ) {
	var x;
	var style_str = '';
	if (arrayList.length > 1) {
	var strHTML = '<table cellpadding="0" cellspacing="0" border="0">';
	for (x in arrayList) {
		
		if (video_hide_id == arrayList[x].id) { 
			style_str = 'background-color:#e9f1f7';
		}
		else {
			style_str = 'background-color:#ffffff';
		}
		if (arrayList[x].title != 'undefined'){
		strHTML += '<tr>';
		strHTML += '<td><a href="javascript:DelvePlayer.doSetMedia(\'' + arrayList[x].id + '\'' + ',' + '\'1\'' + ',' + '\'\');" onclick="changeBg( \'' + arrayList[x].id + '\' )"><img src="' + arrayList[x].thumbnailUrl + '" border="0" width="80" height="60" alt="" /></a></td>';
		strHTML += '<td class="text-video" id="vid_' + arrayList[x].id + '" style="'+ style_str +'" onclick="changeBg( \'' + arrayList[x].id + '\' )">';
		if (arrayList[x].description != '') {
			//strHTML += '<div onmouseout="fadeOutMyPopup(\'pop_' + arrayList[x].id + '\');" id=\'pop_' + arrayList[x].id + '\' name=\'styled_popup\' class="video_class"><div style="padding:5px;">' +  arrayList[x].description + '</div></div>';
		}
		strHTML += '<div class="text-section"><a '; 
		if (arrayList[x].description != '') {
			//strHTML += 'onmouseover="fireMyPopup(\'pop_' + arrayList[x].id + '\')" ';
		}
		strHTML += 'href="javascript:DelvePlayer.doSetMedia(\'' + arrayList[x].id + '\'' + ',' + '\'1\'' + ',' + '\'\');">' + arrayList[x].title + '</a> <span id="video-time">' + converMilliToSeconds(arrayList[x].durationInMilliseconds) + '</span></div></td>';
		strHTML += '</tr><tr><td colspan="2"><img src="/images/designelements/spacer.gif" border="0" width="0" height="10" alt=""></td></tr>';
		}
	}
	strHTML += '</table>';
	//alert(strHTML);
	document.getElementById('country1').innerHTML = strHTML;
	}
	else {
		//document.getElementById('video-list').style.display = 'none';
	}
}

function gotoMediaUrl( intmediaid, intchannelid ) {
	window.location = 'testvideo.asp?media_id=' + intmediaid + '&channel_id=' + intchannelid;
}


// Browser safe opacity handling function
function setOpacity( value, div_id ) {
 document.getElementById('' + div_id + '').style.opacity = value / 10;
 document.getElementById('' + div_id + '').style.filter = 'alpha(opacity=' + value * 10 + ')';
}

function fadeInMyPopup(div_id) {
 for( var i = 0 ; i <= 100 ; i++ )
   setTimeout( 'setOpacity(' + (i / 10) + ',\'' + div_id + '\')' , 8 * i );
}

function fadeOutMyPopup(div_id) {
 for( var i = 0 ; i <= 100 ; i++ ) {
   setTimeout( 'setOpacity(' + (10 - i / 10) + ',\'' + div_id + '\')' , 8 * i );
 }

 setTimeout('closeMyPopup(\''+  div_id + '\')', 800 );
}

function closeMyPopup(div_id) {
 document.getElementById('' + div_id + '').style.display = "none"
}

function fireMyPopup(div_id) {
 setOpacity( 0, div_id );
 document.getElementById('' + div_id + '').style.display = "block";
 fadeInMyPopup(div_id);
}