highlightComingNext = function() {
	if (document.getElementById("comingNext").style.cssText == "") {
		document.getElementById("comingNext").style.cssText = "background: #F2F7FA;";
	} else {
		document.getElementById("comingNext").style.cssText = "";
	}
}

startShuffle = function() {	
	getShuffleChannel();
}

stopShuffle = function() {
	removeCookie("videoShuffle");
	nextVideo.source = "video";
	loadComingNext();
}

getShuffleChannel = function() {
	var scriptNode = document.getElementById("videoCallback");
	var head = document.getElementsByTagName("head")[0];
	var sVideoChannel = "1";
	switch(strLocalization) {
		case "UK":
			sVideoChannel = "-9992";
			break;
		case "JP":
			sVideoChannel = "-9993";
			break;
		case "IN":
			sVideoChannel = "-9994";
			break;
		default:
			sVideoChannel = "-9991";
	}
	if ((scriptNode != null) && (head.removeChild)) {
		head.removeChild(scriptNode);
	}    
	if (document.createElement) {
		scriptNode = document.createElement('script');
		scriptNode.id = "videoCallback";
		scriptNode.setAttribute('type', 'text/javascript');
		scriptNode.setAttribute('src', '/assets/videoJSON?videoChannel='+sVideoChannel);
	}	
	head.appendChild(scriptNode);
	return;
}

videoChannelCallback = function() {
	var sViewedVideos = getCookie("videoShuffle");
try { console.debug("Shuffle cookie: "+sViewedVideos); } catch (e) {}	
	var iVideoFound = 0;
	while (iVideoFound == 0) {
		iRandomVideo = Math.round(Math.random() * (RTR_VideoChannelInfo.length - 1));
		iProposedVideo = RTR_VideoChannelInfo[iRandomVideo].id;
try { console.debug("Shuffle tries: "+iProposedVideo + ":" + RTR_VideoChannelInfo[iRandomVideo].title); } catch(e) {}
		if (sViewedVideos != null) {
			var aViewedVideos = sViewedVideos.split(",");
			if (!(aViewedVideos.contains(iProposedVideo))) {
				iVideoFound = iProposedVideo;
			}
		} else {
			iVideoFound = iProposedVideo;
		}
	}	
	nextVideo.id = RTR_VideoChannelInfo[iRandomVideo].id;
	nextVideo.title = RTR_VideoChannelInfo[iRandomVideo].title;
	nextVideo.duration = RTR_VideoChannelInfo[iRandomVideo].duration;
	nextVideo.type = RTR_VideoChannelInfo[iRandomVideo].type;
	nextVideo.channel = RTR_VideoChannelInfo[iRandomVideo].channel;
	nextVideo.thumbnail = RTR_VideoChannelInfo[iRandomVideo].thumbnail;
	nextVideo.source = "shuffle";
try { console.debug("Retrieved Shuffle: "+nextVideo.id); } catch (e) {}
	loadComingNext();	
	if (sViewedVideos != null) {
		sViewedVideos += ","+iVideoFound;
	} else {
		sViewedVideos = iVideoFound;
	}
	setCookie("videoShuffle", sViewedVideos);
}

Array.prototype.contains = function(sValue) {
	for (a=0; a<this.length; a++) {
		if (this[a] == sValue) {
			return true;
		}
	}
	return false;
}
