	var requiredMajorVersion 	= 9;
	var requiredMinorVersion 	= 0;
	var requiredRevision 		= 45;
	
	var params = HttpUtils.getQueryAsObject();
	
	var dsregEx;
	var dsreplace;
	var dsconfigPath;
	
	var freeWheelSectionID;
	var freeWheelSectionIDforAutoPlaylist;
	
	var pageUrl = "http://www.cartoonnetwork.com/video/index.html";

	////////////////////// vars for config.xml ///////////////////////
																	//
	var dsConfigInfo;												//
																	//		
	var ndsallcollections;											//
	var loadedAllcollections			= false;					//
																	//
	var ndsEpisodesByShowPath;										//
	var pathEpisodeByShow;											//
	var loadedEpisodesByShow 			= false;					//
																	//	
	var ndsGetAllEpisodesPath;										//
	var pathGetAllEpisodes;											//
	var loadedGetAllEpisodesPath		= false;					//
																	//
	var ndsEpisodesMoreLikeThisPath;								//
	var pathMoreEpisodeLikeThis;									//
	var loadedMoreEpisodesLikeThisPath	= false;					//
																	//
	var ndsVideoPlayListPath;										//
	var pathVideoPlayList;											//
	var loadedVideoPlaylistPath 		= false;					//
																	//
	var ndsRatingsPath;												//
	var pathRatings;												//
	var loadedRatingsPath 				= false;					//
																	//
	var ndsEpisodesByCategoryPath;									//
	var pathEpisodesByCategory;										//
	var loadedEpisodesByCategoryPath 	= false;					//
																	//
	var ndsEpisodesByIDsPath;										//
	var pathEpisodesByID;											//
	var loadedEpisodesByIDsPath			= false;					//
																	//
	var ndsGetTimeStamp;											//
	var timeStampNextGen;											//
	var loadedTimeStamp 				= false;					//
																	//
	//////////////////////////////////////////////////////////////////

	var dsDeepLinkEpisodeIDCheck;
	var deepLinkID 						= null;
	var deepLinkCollectionID 			= null;

	////////////////////// vars for show data ////////////////////////
																	//
	var resultsLimit;												//	
																	//
	var dsGetEpisodesByShow;										//
																	//
	var dsEpisodesByCategory;										//
																	//	
	var ndsCategoryRecentlyAdded;									//
	var ndsCategoryByFullEp;										//
	var ndsCategoryByFullEpSeasons;									//
	var ndsCategoryClips;											//
	var ndsCategoryClipsSeasons;									//
	var ndsCategoryTopRated;										//
	var ndsCategoryMostViewed;										//
																	//
	var ndsCategoryRecentlyAddedIDs;								//
	var ndsCategoryTopRatedIDs;										//
	var ndsCategoryMostViewedIDs;									//
																	//
	var loadedCategoryRecentlyAdded		= false;					//
	var loadedCategoryByFullEp			= false;					//
	var loadedCategoryByFullEpSeasons	= false;					//
	var loadedCategoryClips				= false;					//
	var loadedCategoryClipsSeasons		= false;					//
	var loadedCategoryTopRated			= false;					//
	var loadedCategoryMostViewed		= false;					//
																	//
	var loadedCategoryRecentlyAddedIDs	= false; 					//
	var loadedCategoryTopRatedIDs		= false;					//	
	var loadedCategoryMostViewedIDs		= false;					//
																	//	
	var getShowData_collectionID;									//
																	//
	//////////////////////////////////////////////////////////////////
	
	var dsWhatsNewGetAllEpisodes;

	////////////////////// vars for MORE show data ///////////////////
																	//
	var associatedContentName	= "";								//
																	//
	var dsMoreEpisodesByShow;										//
	var dsMoreGetAllEpisodes;										//
																	//
	var moreFromVideoList 		= new Array(0);						//
	var moreVideoList 			= new Array(0);						//
																	//
	//////////////////////////////////////////////////////////////////

	var flashVideoCommunication = new FlashVideoCommunication();
	
	var videoList 				= null;
	var autoPlayList			= null;
	var allcollections			= new Array(0);
	 
	var videoListIndex 			= 0;
	var autoPlayListIndex		= 0;
	var allcollectionsIndex		= 0;

	var reachedPlayListEnd		= false;
	var initialPlay				= true;
	var continuousPlayEnabled 	= true;
	
	var categoryData			= null;
	var categoryList 			= new Array("MOSTVIEWED", "TOPRATED", "CLIPS", "FULLEP", "RECENT");
	var currentCategory			= "";

	var nodeFullEpSeasons		= null;
	var nodeClipsSeasons		= null;
	
	var vdSect 					= "RECENT";
	var vdepType 				= "ALL";
	var vdseasonNumber 			= "NONE";

	var rankingList				= new Array(0);
	
	var validDeepLinkEpisode	= false;
	var validSeg 				= true;

	var videoTimer;
	var videoPlayingNow			= "";
	var tabPlayingNow			= "";

	var allshows_sort 				= "sortByDate";
	var allshows_whatsnew_default	= "ALL";
	var allshows_toprated_default 	= "ALL";
	var allshows_mostviewed_default	= "ALL";
	
	var viralID						= "0";
	
	
	//spry and episode data ------------------------------------------------------------------------------------------------------------------------------------------//
	function episodeData(p_id, p_thumb, p_title, p_description, p_morebutton, p_episodeType, p_collectionTitle, p_ranking, p_collectionId, p_epiSeasonNumber, p_epiSeasonName, p_epiRatingImage, p_numberOfViews, p_epiOverlayURL, p_genre, p_embed){
		
		if(p_ranking > 5){
			p_ranking = 5;
		}
		
		this.id 				= p_id;
		this.thumb 				= p_thumb;
		this.title 				= p_title;
		this.description 		= p_description;
		this.morebutton			= p_morebutton;
		this.episodeType 		= p_episodeType;
		this.collectionTitle	= p_collectionTitle;
		this.ranking			= p_ranking;
		this.collectionId		= p_collectionId;
		this.epiSeasonNumber	= p_epiSeasonNumber;
		this.epiSeasonName		= p_epiSeasonName;
		this.epiRatingImage		= p_epiRatingImage;
		this.epiOverlayURL		= p_epiOverlayURL;
		this.numberOfViews		= p_numberOfViews;
		this.genre				= p_genre;
		this.embed				= (p_embed == "Y") ? true : false;
			

		this.recentlyAdded		= false;
		this.topRated			= false;
		this.mostViewed			= false;
		
		this.segment 			= new Array();
		this.duration 			= new Array();
		this.thumbnailUrl 		= new Array();

	}
	
	function collectionData(p_id, p_name, p_contextpageurl, p_contextpageurltitle, p_category, p_header1, p_header2, p_thumbnail, p_brandimg, p_cmacontentid, p_position){
    
		this.id 					= p_id;
		this.name 					= p_name;
		this.contextpageurl 		= p_contextpageurl; ////vist link for brand graphic
		this.contextpageurltitle 	= p_contextpageurltitle; //vist copy uner vist button for brand graphic
		this.category				= p_category;
		this.header1 				= p_header1;			//dont need
		this.header2				= p_header2;
		this.thumbnail				= p_thumbnail;			//dont need
		this.brandimg				= p_brandimg;
		this.cmacontentid 			= p_cmacontentid;
		this.position				= p_position;
		this.description			= "No description";

	}

	function categoryDataObj(p_categoryName, p_categoryShortName, p_totalItems){
		
		this.categoryName 		= p_categoryName;
		this.categoryShortName	= p_categoryShortName;
		this.totalItems			= p_totalItems;
		this.seasons			= new Array();

	}

	
	function seasonData(p_seasonNumber, p_seasonName){
		
		this.seasonNumber 		= p_seasonNumber;
		this.seasonName			= p_seasonName;

	}
	
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Start init load ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function startVideoLoad(){
		var vidEnvironment 	= (document.URL.indexOf("staging.cartoonnetwork.com") > -1) == true ? "stg" : "prd"; 

		//whatsnew
		//http://staging.cartoonnetwork.com/cnvideosvc2/svc/episodeSearch/getAllEpisodes?limit=30&offset=0&sortByDate=DESC&networkName=CN2
		//toprated
		//http://staging.cartoonnetwork.com/cnvideosvc2/svc/episodeSearch/getAllEpisodes?limit=30&offset=0&sortByEpisodeRanking=DESC&networkName=CN2
		//most viewed
		//http://staging.cartoonnetwork.com/cnvideosvc2/svc/episodeSearch/getAllEpisodes?limit=30&offset=0&sortByVideoRequest=DESC&networkName=CN2

		switch(vidEnvironment){
			case "stg" :
				dsregEx 				= /ctn\dcma\d.\d\d\d\d/;
				dsreplace				= "staging.cartoonnetwork.com/cnvideosvc2";
				dsconfigPath			= "http://staging.cartoonnetwork.com/cnvideosvc2/staged/CN2.staging.configuration.xml?r="  + getRandomNumber();
				 
			break;
			
			default :
				dsregEx 				= /cnvideosvc2.cartoonnetwork.com/;
				dsreplace				= "www.cartoonnetwork.com/cnvideosvc2";
				dsconfigPath			= "http://www.cartoonnetwork.com/video/staged/CN2.configuration.xml?r="  + getRandomNumber();

			break;

		}

		getVidConfigXMLData();
		
	}
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// END init load /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// GET CONFIG.XML DATA AND PARSE DATA ////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function getVidConfigXMLData(){

		dsConfigInfo = new Spry.Data.XMLDataSet(dsconfigPath, "/config", { entityEncodeStrings: false });					
		dsConfigInfo.addObserver(configObserverFunc);
		dsConfigInfo.loadData();

	}

	function getNestedConfigData(){

		ndsallcollections				= new Spry.Data.NestedXMLDataSet(dsConfigInfo, "allcollections/collection", { entityEncodeStrings: false });
		ndsEpisodesByCategoryPath		= new Spry.Data.NestedXMLDataSet(dsConfigInfo, "services/episodesByCategory", { entityEncodeStrings: false });
		ndsEpisodesByShowPath			= new Spry.Data.NestedXMLDataSet(dsConfigInfo, "services/episodesByShow", { entityEncodeStrings: false });
		ndsGetAllEpisodesPath			= new Spry.Data.NestedXMLDataSet(dsConfigInfo, "services/getAllEpisodes", { entityEncodeStrings: false });
		ndsEpisodesMoreLikeThisPath		= new Spry.Data.NestedXMLDataSet(dsConfigInfo, "services/episodesMoreLiskeThis", { entityEncodeStrings: false });
		ndsEpisodesByIDsPath			= new Spry.Data.NestedXMLDataSet(dsConfigInfo, "services/episodesByIDs", { entityEncodeStrings: false });
		ndsVideoPlayListPath			= new Spry.Data.NestedXMLDataSet(dsConfigInfo, "services/getVideoPlaylist", { entityEncodeStrings: false });
		ndsRatingsPath					= new Spry.Data.NestedXMLDataSet(dsConfigInfo, "services/rankEpisode", { entityEncodeStrings: false });
		ndsGetTimeStamp					= new Spry.Data.NestedXMLDataSet(dsConfigInfo, "timestamp", { entityEncodeStrings: false });

		ndsallcollections.addObserver(configObserverFunc);
		ndsEpisodesByCategoryPath.addObserver(configObserverFunc);
		ndsEpisodesByShowPath.addObserver(configObserverFunc);
		ndsGetAllEpisodesPath.addObserver(configObserverFunc);
		ndsEpisodesMoreLikeThisPath.addObserver(configObserverFunc);
		ndsEpisodesByIDsPath.addObserver(configObserverFunc);
		ndsVideoPlayListPath.addObserver(configObserverFunc);
		ndsRatingsPath.addObserver(configObserverFunc);
		ndsGetTimeStamp.addObserver(configObserverFunc);

		ndsallcollections.loadData();
		ndsEpisodesByCategoryPath.loadData();
		ndsEpisodesByShowPath.loadData();
		ndsGetAllEpisodesPath.loadData();
		ndsEpisodesMoreLikeThisPath.loadData();
		ndsEpisodesByIDsPath.loadData();
		ndsVideoPlayListPath.loadData();
		ndsRatingsPath.loadData();
		ndsGetTimeStamp.loadData();
	
	}
		
	function configObserverFunc(notificationType, dataSet, data){
		
		if (notificationType == "onLoadError"){
			alert("Unable to Load Data. Please reload page. Error 100")
		}
	
		if (notificationType == "onPostLoad"){

			if(dataSet == dsConfigInfo){

				dsConfigInfo.removeObserver(configObserverFunc);
				
				var j;
				j = setTimeout("getNestedConfigData()", 500);

			}
			
			if(dataSet == ndsallcollections){

				ndsallcollections.removeObserver(configObserverFunc);

				var rows = ndsallcollections.getData();

				var currentRow;
				var segments 			= new Array();
				var duration			= new Array();
				var thumb				= new Array();
				var newID				= true;
				var matchingIndex		= 0;
				
				for(var i=0; i <= rows.length - 1; i++){
					currentRow = ndsallcollections.getData()[i]["ds_RowID"];
					ndsallcollections.setCurrentRow(currentRow);

					var newCollection = new collectionData(rows[i]["@id"], rows[i]["@name"], rows[i]["@contextpageurl"], rows[i]["@contextpageurltitle"], rows[i]["@category"], rows[i]["@header1"], rows[i]["@header2"], rows[i]["@thumbnail"], rows[i]["@brandimg"], rows[i]["@cmacontentid"], rows[i]["@position"]);
					allcollections.push(newCollection);
				}

				writeAllVideoNav();
				writeSearchBar();
				
				loadedAllcollections = true;
				ndsallcollections = null;
			}
			
			if(dataSet == ndsEpisodesByShowPath){

				ndsEpisodesByShowPath.removeObserver(configObserverFunc);

				pathEpisodeByShow = getConfigNode(ndsEpisodesByShowPath, "@url");

				pathEpisodeByShow = pathEpisodeByShow.replace(dsregEx, dsreplace);

				resultsLimit = getConfigNode(ndsEpisodesByShowPath, "@limit");

				loadedEpisodesByShow = true;
				ndsEpisodesByShowPath = null;
			}

			if(dataSet == ndsGetAllEpisodesPath){

				ndsGetAllEpisodesPath.removeObserver(configObserverFunc);

				pathGetAllEpisodes = getConfigNode(ndsGetAllEpisodesPath, "@url");

				pathGetAllEpisodes = pathGetAllEpisodes.replace(dsregEx, dsreplace);

				loadedGetAllEpisodesPath = true;
				ndsGetAllEpisodesPath = null;
			}


			if(dataSet == ndsEpisodesMoreLikeThisPath){

				ndsEpisodesMoreLikeThisPath.removeObserver(configObserverFunc);

				pathMoreEpisodeLikeThis = getConfigNode(ndsEpisodesMoreLikeThisPath, "@url");

				pathMoreEpisodeLikeThis = pathMoreEpisodeLikeThis.replace(dsregEx, dsreplace);

				pathMoreEpisodeLikeThis = pathMoreEpisodeLikeThis.substring(0, pathMoreEpisodeLikeThis.indexOf("networkName=CN2") + 15);
				
				loadedMoreEpisodesLikeThisPath = true;
				ndsEpisodesMoreLikeThisPath = null;
			}
			
			if(dataSet == ndsVideoPlayListPath){

				ndsVideoPlayListPath.removeObserver(configObserverFunc);
				
				pathVideoPlayList = getConfigNode(ndsVideoPlayListPath, "@url");
				
				pathVideoPlayList = pathVideoPlayList.replace(dsregEx, dsreplace);
				
				loadedVideoPlaylistPath = true;
				ndsVideoPlayListPath = null;
			}
			
			if(dataSet == ndsRatingsPath){

				ndsRatingsPath.removeObserver(configObserverFunc);
				
				pathRatings = getConfigNode(ndsRatingsPath, "@url");
				
				pathRatings = pathRatings.replace(dsregEx, dsreplace);
				
				loadedRatingsPath = true;
				ndsRatingsPath = null;
			}
			
			if(dataSet == ndsEpisodesByCategoryPath){

				ndsEpisodesByCategoryPath.removeObserver(configObserverFunc);
				
				pathEpisodesByCategory = getConfigNode(ndsEpisodesByCategoryPath, "@url");
				
				pathEpisodesByCategory = pathEpisodesByCategory.replace(dsregEx, dsreplace);
				
				loadedEpisodesByCategoryPath = true;
				ndsEpisodesByCategoryPath = null;
			}
			
			if(dataSet == ndsEpisodesByIDsPath){

				ndsEpisodesByIDsPath.removeObserver(configObserverFunc);
				
				pathEpisodesByID = getConfigNode(ndsEpisodesByIDsPath, "@url");
				
				pathEpisodesByID = pathEpisodesByID.replace(dsregEx, dsreplace);
				
				loadedEpisodesByIDsPath = true;
				ndsEpisodesByIDsPath = null;
			}

			if(dataSet == ndsGetTimeStamp){

				ndsGetTimeStamp.removeObserver(configObserverFunc);

				timeStampNextGen = getConfigNode(ndsGetTimeStamp, "@value");

				loadedTimeStamp = true;
				ndsGetTimeStamp = null;
			}
			
			if(loadedEpisodesByShow && loadedGetAllEpisodesPath && loadedMoreEpisodesLikeThisPath && loadedTimeStamp && loadedVideoPlaylistPath && loadedRatingsPath && loadedEpisodesByCategoryPath && loadedEpisodesByIDsPath && loadedAllcollections){

				
				if(document.getElementById("carouselWidget")){
					document.getElementById("carouselWidget").style.display = "block";
				}

				startSlideShow();

				pathVideoPlayList = pathVideoPlayList + "&r=" + timeStampNextGen; 
				
				if(params.collectionID != null) {
					getShowData(params.collectionID);
				}else if(params.episodeID != null){
					deepLinkID = params.episodeID;
					validateDeepLink(deepLinkID);				
				}else{
					getAllEpisodesData("sortByDate", "default");
				}
				
				dsConfigInfo = null;
			}
		}
	}
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// END CONFIG.XML DATA AND PARSE DATA ////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Check for deep link of episodes ///////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function validateDeepLink(p_episodeID){
		
		var s = pathEpisodesByID  + "&ids=" + p_episodeID;

		dsDeepLinkEpisodeIDCheck = new Spry.Data.XMLDataSet(s, "/episodes/episode", { entityEncodeStrings: false });
		dsDeepLinkEpisodeIDCheck.addObserver(deeplinkObserverFunc);
		dsDeepLinkEpisodeIDCheck.loadData();
		
	}

	function deeplinkObserverFunc(notificationType, dataSet, data){

		if (notificationType == "onLoadError" && dataSet == dsDeepLinkEpisodeIDCheck){
			alert("Unable to Load Data. Please reload page. Error 202")
		}
		
		if (notificationType == "onPostLoad"){
			if(dataSet == dsDeepLinkEpisodeIDCheck){
			
				dsDeepLinkEpisodeIDCheck.removeObserver(deeplinkObserverFunc);

				deepLinkID 				= getConfigNode(dsDeepLinkEpisodeIDCheck, "@id")
				deepLinkCollectionID 	= getConfigNode(dsDeepLinkEpisodeIDCheck, "@collectionId")

				dsDeepLinkEpisodeIDCheck = null;

				if(deepLinkCollectionID == null || deepLinkID == null){
					getAllEpisodesData("sortByDate", "default");
				}else{
					getShowData(deepLinkCollectionID);
				}
			}
		}
	}
	
	function getConfigNode(dsName, nodeName){

		var rows = dsName.getData(); 
		
		if(dsName.getData() == ""){
			return null;
		}else{
			return rows[0][nodeName];  
		}		

	}
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// END Check for deep link of episodes ///////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// load All episode Data /////////////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function doLoaderScreen(){
		var swfURL 		= "http://www.cartoonnetwork.com/tools/media/cnLoading.swf";
					
		var swfParams 	= { allowScriptAccess	: "always",
							allowFullScreen		: "true",
							bgcolor				: "#000000",
							wmode 				: "transparent"};

		swfobject.embedSWF(swfURL, "loaderscreen", "100", "28", "9.0.0");
	}
	function getAllEpisodesData(p_sortBy, p_epType){

		allshows_sort = p_sortBy; 
		
		if(document.getElementById("video_whatsnew_sect_content")){
			
			document.getElementById("video_whatsnew_sect_content").innerHTML = "<div id='loaderscreen' style='color: #ffffff; margin-left:325px; margin-top:125px; font: bold 20px arial,helvetica,sans-serif;'>Loading...</div>";

			//setTimeout("doLoaderScreen()",5);

		}
			
		var url_path = pathGetAllEpisodes + "&limit=30&offset=0&" + p_sortBy + "=DESC";

		resetTabView();

		if(p_sortBy == "sortByDate"){
			if(document.getElementById("searchBarWhatsNew")){
				document.getElementById("searchBarWhatsNew").className	= "btnRedOn";
			}
			
			for(var i=0; i <= allcollections.length - 1; i++){
				if(allcollections[i].id == "8a250ab0230ec20c012334ad4f650371"){
					allcollectionsIndex = i;
				}
			}
	
			url_path = pathEpisodeByShow  + "&id=8a250ab0230ec20c012334ad4f650371&limit=" + resultsLimit + "&offset=0&r=" + timeStampNextGen;
			allshows_whatsnew_default = (p_epType == "default") ? allshows_whatsnew_default : p_epType;

		}else if(p_sortBy == "sortByEpisodeRanking"){
		 
			if(document.getElementById("searchBarTopRated")){
				document.getElementById("searchBarTopRated").className		= "btnRedOn";
			}

			allshows_toprated_default = (p_epType == "default") ? allshows_toprated_default : p_epType;
		
		}else if(p_sortBy == "sortByVideoRequest"){
		
			if(document.getElementById("searchBarMostViewed")){
				document.getElementById("searchBarMostViewed").className	= "btnRedOn";
			}

			allshows_mostviewed_default = (p_epType == "default") ? allshows_mostviewed_default : p_epType;

		}
		
		setFreeWheelID("", p_sortBy);
		
		dsWhatsNewGetAllEpisodes = new Spry.Data.XMLDataSet(url_path, "/episodes/episode", { subPaths: [ "segments/segment"] });
		dsWhatsNewGetAllEpisodes.addObserver(getAllEpisodesObserverFunc);
		dsWhatsNewGetAllEpisodes.loadData();
			
	}
	
	function getAllEpisodesObserverFunc(notificationType, dataSet, data){

		if (notificationType == "onLoadError" && dataSet == dsGetEpisodesByShow){
			alert("Unable to Load Data. Please reload page. Error 210")
		}

		if (notificationType == "onPostLoad"){
			
			if(dataSet == dsWhatsNewGetAllEpisodes){

				dsWhatsNewGetAllEpisodes.removeObserver(getShowDataObserverFunc);
			
				var rows = dsWhatsNewGetAllEpisodes.getData();

				var currentRow;
				var segments 			= new Array();
				var duration			= new Array();
				var thumb				= new Array();
				var newID				= true;
				var matchingIndex		= 0;

				videoList				= new Array(0);
				videoListIndex			= 0;
			
				for(var i=0; i <= rows.length - 1; i++){
					currentRow = dsWhatsNewGetAllEpisodes.getData()[i]["ds_RowID"];
					dsWhatsNewGetAllEpisodes.setCurrentRow(currentRow);

					for(var n=0; n <= videoList.length - 1; n++){
						if(rows[i]["@id"] == videoList[n].id){
							newID = false;
							matchingIndex = n;
						}
					}
					
					if(newID || videoList.length == 0){
						var newEPType = rows[i]["@episodeType"];
						newEPType = newEPType.substring(0, 3);
						
						var newDescr = rows[i]["description"];
						newDescr = doReplaceSpecialChar(newDescr);
						
						var newTitle = rows[i]["@title"];
						newTitle = doReplaceSpecialChar(newTitle);
						
						var newEP = new episodeData(rows[i]["@id"], rows[i]["@thumbnailUrl"], newTitle, newDescr, rows[i]["@contentTags"], newEPType, rows[i]["@collectionTitle"], rows[i]["@ranking"], rows[i]["@collectionId"], rows[i]["@epiSeasonNumber"], rows[i]["@epiSeasonName"], rows[i]["@epiRatingImageUrl"], rows[i]["@numberOfViews"], rows[i]["@epiOverlayURL"], rows[i]["@genre"], rows[i]["@embed"]);
						videoList.push(newEP);
						matchingIndex = videoList.length == 0 ? 0 : videoList.length -1;
					}
					
					if(rows[i]["segments/segment/@id"] == ""){
						validSeg = false;
					}
					videoList[matchingIndex].segment.push(rows[i]["segments/segment/@id"]);
					videoList[matchingIndex].duration.push(rows[i]["segments/segment/@duration"]);
					videoList[matchingIndex].thumbnailUrl.push(rows[i]["segments/segment/@thumbnailUrl"]);
					
					newID = true;
				}
				
				dsWhatsNewGetAllEpisodes = null;

				if(validSeg){
					doDrawNavigation("ALLSHOWS");
				}else{
					alert("Unable to Load Data SegmentID");
				}
			}
		}
	}
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// END load All episode Data /////////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// load Show Data ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function getShowData(p_collectionID){

		getShowData_collectionID = p_collectionID;

		resetTabView();

		for(var i=0; i <= allcollections.length - 1; i++){
			if(allcollections[i].id == p_collectionID){
				allcollectionsIndex = i;
			}
		}
			
		setFreeWheelID(p_collectionID, allcollections[allcollectionsIndex].category);

		var s = pathEpisodeByShow  + "&id=" + p_collectionID + "&limit=" + resultsLimit + "&offset=0&r=" + timeStampNextGen;

		dsGetEpisodesByShow = new Spry.Data.XMLDataSet(s, "/episodes/episode", { subPaths: [ "segments/segment"] });
		dsGetEpisodesByShow.addObserver(getShowDataObserverFunc);
		dsGetEpisodesByShow.loadData();

	}

	function getShowDataObserverFunc(notificationType, dataSet, data){

		if (notificationType == "onLoadError" && dataSet == dsGetEpisodesByShow){
			alert("Unable to Load Data. Please reload page. Error 200")
		}

		if (notificationType == "onPostLoad"){
			
			if(dataSet == dsGetEpisodesByShow){
			
				videoList				= new Array(0);
				videoListIndex			= 0;
				
				categoryData			= new Array(0);
				nodeFullEpSeasons		= new Array(0);
				nodeClipsSeasons		= new Array(0);

				dsGetEpisodesByShow.removeObserver(getShowDataObserverFunc);
			
				var rows = dsGetEpisodesByShow.getData();
				if(rows == "" ){ 
					getAllEpisodesData("sortByDate", "default");
				}else{
					var currentRow;
					var segments 			= new Array();
					var duration			= new Array();
					var thumb				= new Array();
					var newID				= true;
					var matchingIndex		= 0;
					
					for(var i=0; i <= rows.length - 1; i++){
						currentRow = dsGetEpisodesByShow.getData()[i]["ds_RowID"];
						dsGetEpisodesByShow.setCurrentRow(currentRow);
	
						for(var n=0; n <= videoList.length - 1; n++){
							if(rows[i]["@id"] == videoList[n].id){
								newID = false;
								matchingIndex = n;
							}
						}
						
						if(newID || videoList.length == 0){
							var newEPType = rows[i]["@episodeType"];
							newEPType = newEPType.substring(0, 3);
							
							var newDescr = rows[i]["description"];
							newDescr = doReplaceSpecialChar(newDescr);
							
							var newTitle = rows[i]["@title"];
							newTitle = doReplaceSpecialChar(newTitle);
							
							var newEP = new episodeData(rows[i]["@id"], rows[i]["@thumbnailUrl"], newTitle, newDescr, rows[i]["@contentTags"], newEPType, rows[i]["@collectionTitle"], rows[i]["@ranking"], rows[i]["@collectionId"], rows[i]["@epiSeasonNumber"], rows[i]["@epiSeasonName"], rows[i]["@epiRatingImageUrl"], rows[i]["@numberOfViews"], rows[i]["@epiOverlayURL"], rows[i]["@genre"], rows[i]["@embed"]);
							videoList.push(newEP);
							matchingIndex = videoList.length == 0 ? 0 : videoList.length -1;
						}
						
						if(rows[i]["segments/segment/@id"] == ""){
							validSeg = false;
						}
						videoList[matchingIndex].segment.push(rows[i]["segments/segment/@id"]);
						videoList[matchingIndex].duration.push(rows[i]["segments/segment/@duration"]);
						videoList[matchingIndex].thumbnailUrl.push(rows[i]["segments/segment/@thumbnailUrl"]);
						
						newID = true;
					}
					
					dsGetEpisodesByShow = null;
	
					if(validSeg){
						getCategoryData(getShowData_collectionID);
					}else{
						alert("Unable to Load Data SegmentID");
					}
				}
			}
		}
	}
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// END load Show Data ////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// load Category Data for Show ///////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function getCategoryData(p_collectionID){
		var s = pathEpisodesByCategory  + "&id=multiCat&filterByCollectionId=" + p_collectionID + "&limit=" + resultsLimit + "&offset=0&r=" + timeStampNextGen;

		dsEpisodesByCategory = new Spry.Data.XMLDataSet(s, "/episodes", { entityEncodeStrings: false });
		
		dsEpisodesByCategory.addObserver(categoryObserverFunc);
		dsEpisodesByCategory.loadData();

	}
	
	function categoryObserverFunc(notificationType, dataSet, data){
	
		if (notificationType == "onLoadError"){
			alert("Unable to Load Data. Please reload page. Error 300")
		}
	
		if (notificationType == "onPostLoad"){
			
			if(dataSet == dsEpisodesByCategory){
				dsEpisodesByCategory.removeObserver(categoryObserverFunc);
				getNestedData();
			}else if(dataSet == ndsCategoryRecentlyAdded){
				parseCategoryData(ndsCategoryRecentlyAdded, "RECENT");
			}else if(dataSet == ndsCategoryByFullEp){
				parseCategoryData(ndsCategoryByFullEp, "FULLEP");
			}else if(dataSet == ndsCategoryByFullEpSeasons){
				parseCategorySeasonData(ndsCategoryByFullEpSeasons, "FULLEP");
			}else if(dataSet == ndsCategoryClips){
				parseCategoryData(ndsCategoryClips, "CLIPS");
			}else if(dataSet == ndsCategoryClipsSeasons){
				parseCategorySeasonData(ndsCategoryClipsSeasons, "CLIPS");
			}else if(dataSet == ndsCategoryTopRated){
				parseCategoryData(ndsCategoryTopRated, "TOPRATED");
			}else if(dataSet == ndsCategoryMostViewed){
				parseCategoryData(ndsCategoryMostViewed, "MOSTVIEWED");
			}
			
			if(loadedCategoryByFullEp && loadedCategoryByFullEpSeasons && loadedCategoryRecentlyAdded && loadedCategoryClips && loadedCategoryClipsSeasons && loadedCategoryTopRated && loadedCategoryMostViewed){

				ndsCategoryRecentlyAdded		= null;
				ndsCategoryByFullEp 			= null;
				ndsCategoryByFullEpSeasons 		= null;
				ndsCategoryClips				= null;
				ndsCategoryClipsSeasons			= null;
				ndsCategoryTopRated				= null;
				ndsCategoryMostViewed			= null;

				loadedCategoryRecentlyAdded		= false;
				loadedCategoryByFullEp			= false;
				loadedCategoryByFullEpSeasons	= false;
				loadedCategoryClips				= false;
				loadedCategoryClipsSeasons		= false;
				loadedCategoryTopRated			= false;
				loadedCategoryMostViewed		= false;

				getNestedCategoryData();
				
			}
		}
	}
	
	function getNestedData(){

		ndsCategoryByFullEp 		= new Spry.Data.NestedXMLDataSet(dsEpisodesByCategory, "/episodes/episodesBySeasons", { entityEncodeStrings: false });
		ndsCategoryByFullEpSeasons	= new Spry.Data.NestedXMLDataSet(dsEpisodesByCategory, "/episodes/episodesBySeasons/Season", { entityEncodeStrings: false });
		ndsCategoryRecentlyAdded 	= new Spry.Data.NestedXMLDataSet(dsEpisodesByCategory, "/episodes/recentlyAdded", { entityEncodeStrings: false });
		ndsCategoryClips 			= new Spry.Data.NestedXMLDataSet(dsEpisodesByCategory, "/episodes/clips", { entityEncodeStrings: false });
		ndsCategoryClipsSeasons		= new Spry.Data.NestedXMLDataSet(dsEpisodesByCategory, "/episodes/clips/Season", { entityEncodeStrings: false });
		ndsCategoryTopRated 		= new Spry.Data.NestedXMLDataSet(dsEpisodesByCategory, "/episodes/topRated", { entityEncodeStrings: false });
		ndsCategoryMostViewed 		= new Spry.Data.NestedXMLDataSet(dsEpisodesByCategory, "/episodes/mostViewed", { entityEncodeStrings: false });

		ndsCategoryByFullEp.addObserver(categoryObserverFunc);
		ndsCategoryByFullEpSeasons.addObserver(categoryObserverFunc);
		ndsCategoryRecentlyAdded.addObserver(categoryObserverFunc);
		ndsCategoryClips.addObserver(categoryObserverFunc);
		ndsCategoryClipsSeasons.addObserver(categoryObserverFunc);
		ndsCategoryTopRated.addObserver(categoryObserverFunc);
		ndsCategoryMostViewed.addObserver(categoryObserverFunc);
		
		ndsCategoryByFullEp.loadData();
		ndsCategoryByFullEpSeasons.loadData();
		ndsCategoryRecentlyAdded.loadData();
		ndsCategoryClips.loadData();
		ndsCategoryClipsSeasons.loadData()
		ndsCategoryTopRated.loadData();
		ndsCategoryMostViewed.loadData();
		
	}

	function parseCategoryData(p_nestedDataSet, p_catshortname){
	
		switch(p_catshortname){
			case "RECENT" :
				catFullName = "@recentlyAddedName";
			break;
			case "FULLEP":
				catFullName = "@episodesBySeasonsName";
			break;
			case "CLIPS":
				catFullName = "@clipsName";
			break;
			case "TOPRATED":
				catFullName = "@topRatedName";
			break;
			case "MOSTVIEWED":
				catFullName = "@mostViewedName"
			break;
		}
				
		p_nestedDataSet.removeObserver(categoryObserverFunc);
				
		var rows = p_nestedDataSet.getData();
		p_nestedDataSet.setCurrentRow(0);
				
		var newCatData = new categoryDataObj(rows[0][catFullName], p_catshortname, rows[0]["@totalItems"]);
		categoryData.push(newCatData);

		switch(p_catshortname){
			case "RECENT":
				loadedCategoryRecentlyAdded = true;
			break;
			case "FULLEP":
				loadedCategoryByFullEp = true;
			break;
			case "CLIPS":
				loadedCategoryClips = true;
			break;
			case "TOPRATED":
				loadedCategoryTopRated = true;
			break;
			case "MOSTVIEWED":
				loadedCategoryMostViewed = true;
			break;
		}
		
	}
	
	
	function parseCategorySeasonData(p_nestedDataSet, p_catshortname){
		
		p_nestedDataSet.removeObserver(categoryObserverFunc);
				
		var rows = p_nestedDataSet.getData();
		var currentRow;
		
		for(var i=0; i <= rows.length - 1; i++){
		
			currentRow = p_nestedDataSet.getData()[i]["ds_RowID"];
			p_nestedDataSet.setCurrentRow(currentRow);
					
			var newSeasonData = new seasonData(rows[i]["@seasonNumber"], rows[i]["@seasonName"]);
			
			switch(p_catshortname){
				case "FULLEP":
					nodeFullEpSeasons.push(newSeasonData);
				break;
				case "CLIPS":
					nodeClipsSeasons.push(newSeasonData);
				break;
			}
		}
		
		switch(p_catshortname){
			case "FULLEP":
				loadedCategoryByFullEpSeasons = true;
			break;
			case "CLIPS":
				loadedCategoryClipsSeasons = true;
			break;
		}		
	}
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// END load Category Data for Show ///////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// load Nested Category Data for Show ////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function getNestedCategoryData(){

		ndsCategoryRecentlyAddedIDs	= new Spry.Data.NestedXMLDataSet(dsEpisodesByCategory, "/episodes/recentlyAdded/episode", { entityEncodeStrings: false });
		ndsCategoryTopRatedIDs 		= new Spry.Data.NestedXMLDataSet(dsEpisodesByCategory, "/episodes/topRated/episode", { entityEncodeStrings: false });
		ndsCategoryMostViewedIDs	= new Spry.Data.NestedXMLDataSet(dsEpisodesByCategory, "/episodes/mostViewed/episode", { entityEncodeStrings: false });

		ndsCategoryRecentlyAddedIDs.addObserver(nestedCategoryObserverFunc);
		ndsCategoryTopRatedIDs.addObserver(nestedCategoryObserverFunc);
		ndsCategoryMostViewedIDs.addObserver(nestedCategoryObserverFunc);
		
		ndsCategoryRecentlyAddedIDs.loadData();
		ndsCategoryTopRatedIDs.loadData();
		ndsCategoryMostViewedIDs.loadData();
	
	}
	
	function nestedCategoryObserverFunc(notificationType, dataSet, data){

		if (notificationType == "onLoadError"){
			alert("Unable to Load Data. Please reload page. Error 400");
		}

		if (notificationType == "onPostLoad"){
		
			if(dataSet == ndsCategoryRecentlyAddedIDs){
				parseCategoryIDs(ndsCategoryRecentlyAddedIDs, "RECENT");
			}else if(dataSet == ndsCategoryTopRatedIDs){
				parseCategoryIDs(ndsCategoryTopRatedIDs, "TOPRATED");
			}else if(dataSet == ndsCategoryMostViewedIDs){
				parseCategoryIDs(ndsCategoryMostViewedIDs, "MOSTVIEWED");
			}
			
			if(loadedCategoryRecentlyAddedIDs && loadedCategoryTopRatedIDs && loadedCategoryMostViewedIDs){
				
				ndsCategoryRecentlyAddedIDs 	= null;
				ndsCategoryTopRatedIDs 			= null;
				ndsCategoryMostViewedIDs 		= null;
				
				dsEpisodesByCategory 			= null;
				
				loadedCategoryRecentlyAddedIDs	= false; 
				loadedCategoryTopRatedIDs		= false;
				loadedCategoryMostViewedIDs		= false;
		
				doDrawNavigation("");
			}
		}
		
		function parseCategoryIDs(p_nestedDataSet, p_catshortname){
		
			p_nestedDataSet.removeObserver(categoryObserverFunc);
					
			var rowsRA = p_nestedDataSet.getData();
			var currentRow;
	
			for(var i=0; i <= rowsRA.length - 1; i++){
	
				currentRow = p_nestedDataSet.getData()[i]["ds_RowID"];
				p_nestedDataSet.setCurrentRow(currentRow);
						
				var isID = rowsRA[i]["@id"];
				
				for(var n=0; n <= videoList.length - 1; n++){
					if(videoList[n].id == isID){
						
						switch(p_catshortname){
							case "RECENT" :
								videoList[n].recentlyAdded = true;
							break;
							case "TOPRATED" :
								videoList[n].topRated = true;
							break;
							case "MOSTVIEWED":
								videoList[n].mostViewed = true;
							break;
						}
					}
				}
			}
		
			switch(p_catshortname){
				case "RECENT" :
					loadedCategoryRecentlyAddedIDs = true;
				break;
				case "TOPRATED" :
					loadedCategoryTopRatedIDs = true;
				break;
				case "MOSTVIEWED":
					loadedCategoryMostViewedIDs = true;
				break;
			}
		}
	}
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// END load Nested Category Data for Show ////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// load "More" video Data for Show ///////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function getMoreFromGenre(p_collectionId, p_genre, p_collectionTitle){
		
		associatedContentName = p_collectionTitle;	

		var url_path = pathMoreEpisodeLikeThis  + "&filterByCollectionId=" + p_collectionId + "&limit=50&howMany=6&colGenre=" + p_genre; 

		dsMoreEpisodesByShow = new Spry.Data.XMLDataSet(url_path, "/episodes/episode", { subPaths: [ "segments/segment"] });
		dsMoreEpisodesByShow.addObserver(getMoreEpisodesObserverFunc);
		dsMoreEpisodesByShow.loadData();
	
	}
	
	function getMoreFromCollectionId(p_collectionId){

		var url_path = pathGetAllEpisodes + "&limit=50&offset=0&sortByEpisodeRanking=DESC&filterByCollectionId=" + p_collectionId;
		
		dsMoreGetAllEpisodes = new Spry.Data.XMLDataSet(url_path, "/episodes/episode", { subPaths: [ "segments/segment"] });
		dsMoreGetAllEpisodes.addObserver(getMoreEpisodesObserverFunc);
		dsMoreGetAllEpisodes.loadData();
		
	}

	function getMoreEpisodesObserverFunc(notificationType, dataSet, data){

		if (notificationType == "onLoadError" && dataSet == dsMoreEpisodesByShow){
			alert("Unable to Load Data. Please reload page. Error 201");
		}

		if (notificationType == "onLoadError" && dataSet == dsMoreGetAllEpisodes){
			alert("Unable to Load Data. Please reload page. Error 203");
		}

		if (notificationType == "onPostLoad"){
			
			//////dsMoreGetAllEpisodes
			if(dataSet == dsMoreGetAllEpisodes){

				dsMoreGetAllEpisodes.removeObserver(getMoreEpisodesObserverFunc);
			
				var rows = dsMoreGetAllEpisodes.getData();

				var currentRow;
				var segments 			= new Array();
				var duration			= new Array();
				var thumb				= new Array();
				var newID				= true;
				var matchingIndex		= 0;

				moreFromVideoList		= new Array(0);
				
				
				
				for(var i=0; i <= rows.length - 1; i++){
					currentRow = dsMoreGetAllEpisodes.getData()[i]["ds_RowID"];
					dsMoreGetAllEpisodes.setCurrentRow(currentRow);

					for(var n=0; n <= moreFromVideoList.length - 1; n++){
						if(rows[i]["@id"] == moreFromVideoList[n].id){
							newID = false;
							matchingIndex = n;
						}
					}
					
					if(newID || moreFromVideoList.length == 0){
						var newEPType = rows[i]["@episodeType"];
						newEPType = newEPType.substring(0, 3);
						
						var newDescr = rows[i]["description"];
						newDescr = doReplaceSpecialChar(newDescr);
						
						var newTitle = rows[i]["@title"];
						newTitle = doReplaceSpecialChar(newTitle);
						
						var newEP = new episodeData(rows[i]["@id"], rows[i]["@thumbnailUrl"], newTitle, newDescr, rows[i]["@contentTags"], newEPType, rows[i]["@collectionTitle"], rows[i]["@ranking"], rows[i]["@collectionId"], rows[i]["@epiSeasonNumber"], rows[i]["@epiSeasonName"], rows[i]["@epiRatingImageUrl"], rows[i]["@numberOfViews"], rows[i]["@epiOverlayURL"], rows[i]["@genre"], rows[i]["@embed"]);
						moreFromVideoList.push(newEP);
						matchingIndex = moreFromVideoList.length == 0 ? 0 : moreFromVideoList.length -1;
					}

					moreFromVideoList[matchingIndex].segment.push(rows[i]["segments/segment/@id"]);
					moreFromVideoList[matchingIndex].duration.push(rows[i]["segments/segment/@duration"]);
					moreFromVideoList[matchingIndex].thumbnailUrl.push(rows[i]["segments/segment/@thumbnailUrl"]);
					newID = true;
				}

				dsMoreGetAllEpisodes = null;
				
				writeAssociatedTopContent();

			}
			
			if(dataSet == dsMoreEpisodesByShow){

				dsMoreEpisodesByShow.removeObserver(getMoreEpisodesObserverFunc);
			
				var rows = dsMoreEpisodesByShow.getData();

				var currentRow;
				var segments 			= new Array();
				var duration			= new Array();
				var thumb				= new Array();
				var newID				= true;
				var matchingIndex		= 0;
				
				moreVideoList 			= new Array(0);
				
				for(var i=0; i <= rows.length - 1; i++){
					currentRow = dsMoreEpisodesByShow.getData()[i]["ds_RowID"];
					dsMoreEpisodesByShow.setCurrentRow(currentRow);

					for(var n=0; n <= moreVideoList.length - 1; n++){
						if(rows[i]["@id"] == moreVideoList[n].id){
							newID = false;
							matchingIndex = n;
						}
					}
					
					if(newID || moreVideoList.length == 0){
						var newEPType = rows[i]["@episodeType"];
						newEPType = newEPType.substring(0, 3);
						
						var newDescr = rows[i]["description"];
						newDescr = doReplaceSpecialChar(newDescr);
						
						var newTitle = rows[i]["@title"];
						newTitle = doReplaceSpecialChar(newTitle);
						
						var newEP = new episodeData(rows[i]["@id"], rows[i]["@thumbnailUrl"], newTitle, newDescr, rows[i]["@contentTags"], newEPType, rows[i]["@collectionTitle"], rows[i]["@ranking"], rows[i]["@collectionId"], rows[i]["@epiSeasonNumber"], rows[i]["@epiSeasonName"], rows[i]["@epiRatingImageUrl"], rows[i]["@numberOfViews"], rows[i]["@epiOverlayURL"], rows[i]["@genre"], rows[i]["@embed"]);
						moreVideoList.push(newEP);
						matchingIndex = moreVideoList.length == 0 ? 0 : moreVideoList.length -1;
					}
					
					moreVideoList[matchingIndex].segment.push(rows[i]["segments/segment/@id"]);
					moreVideoList[matchingIndex].duration.push(rows[i]["segments/segment/@duration"]);
					moreVideoList[matchingIndex].thumbnailUrl.push(rows[i]["segments/segment/@thumbnailUrl"]);
					newID = true;
				}

				dsMoreEpisodesByShow = null;

				writeAssociatedBottomContent();

			}
		}
	}
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// END load "More" video Data for Show ///////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Start Video and Display Navigation ////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function doDrawNavigation(p_view){

		//determine view
		if(deepLinkID != null && initialPlay){

			for(var f=0; f <= videoList.length - 1; f++){
				if(videoList[f].id == deepLinkID){
					videoListIndex = f;
				}
			}
			
			vdSect 			= "DEEPLINK";
			vdepType 		= "ALL";
			vdseasonNumber 	= "NONE";
			
		}else if(p_view == "ALLSHOWS"){
			var s_epType = "ALL";
						
			switch (allshows_sort) {
				case "sortByDate":
					s_epType = allshows_whatsnew_default;
				break;
				case "sortByEpisodeRanking":
					s_epType = allshows_toprated_default;
				break;
				case "sortByVideoRequest":
					s_epType = allshows_mostviewed_default;
				break;
			}
			
			vdSect 			= p_view;
			vdepType 		= s_epType;
			vdseasonNumber 	= "NONE";
		}else{
			findDefaultViewForCollection();
		}
		
		if(initialPlay){
			playVideo(videoList, videoListIndex);
		}
		
		showView(vdSect);
		
		writeNavigation(vdSect, vdepType, vdseasonNumber, true);
	}

	function showView(p_videoSection){

		if(document.getElementById("video_whatsnew_sect")){ document.getElementById("video_whatsnew_sect").style.display 		= "none";}
		if(document.getElementById("video_search_subnav")){ document.getElementById("video_search_subnav").style.display 		= "none";}
		if(document.getElementById("video_brandimg")){ document.getElementById("video_brandimg").style.display 					= "none";}
		if(document.getElementById("video_dsVidNav")){ document.getElementById("video_dsVidNav").style.display 					= "none";}
		if(document.getElementById("videoListArea")){ document.getElementById("videoListArea").style.display 					= "none";}
		
		switch (p_videoSection) {
		
			case "ALLSHOWS":
				if(document.getElementById("video_whatsnew_sect")){ document.getElementById("video_whatsnew_sect").style.display 		= "block";}
				if(document.getElementById("video_search_subnav")){ document.getElementById("video_search_subnav").style.display 		= "block";}
				if(document.getElementById("video_ContinuousPlay")){ document.getElementById("video_ContinuousPlay").style.marginTop	= "27px";}
				if(document.getElementById("vidShadowTop")){ document.getElementById("vidShadowTop").style.marginTop					= "50px";}
			break;
				
			default :
				//"RECENT" || "FULLEP" || "CLIPS" || "TOPRATED" || "MOSTVIEWED" || "DEEPLINK"
				if(document.getElementById("vidShadowTop")){ document.getElementById("vidShadowTop").style.marginTop					= "122px";}
				if(document.getElementById("video_ContinuousPlay")){ document.getElementById("video_ContinuousPlay").style.marginTop	= "98px";}
				if(document.getElementById("video_brandimg")){ document.getElementById("video_brandimg").style.display 					= "block";}
				if(document.getElementById("video_dsVidNav")){ document.getElementById("video_dsVidNav").style.display 					= "block";}
				if(document.getElementById("videoListArea")){ document.getElementById("videoListArea").style.display 					= "block";}
			break;
		}
	}
		
	function findDefaultViewForCollection(){
	
		for (var y = 0; y <= categoryList.length - 1; y++ ) {
			for (var x = 0; x <= categoryData.length - 1; x++ ) {
				if(categoryData[x].totalItems != "0" && categoryList[y] == categoryData[x].categoryShortName){
					for(var z = 0; z <= videoList.length - 1; z++){
						if(categoryData[x].categoryShortName == "MOSTVIEWED" && videoList[z].mostViewed == true){
							videoListIndex 	= z;
							vdSect 			= "MOSTVIEWED";
							vdepType 		= "ALL";
							vdseasonNumber 	= "NONE";
							break;
						}
						if(categoryData[x].categoryShortName == "TOPRATED" && videoList[z].topRated == true){
							videoListIndex 	= z;
							vdSect 			= "TOPRATED";
							vdepType 		= "ALL";
							vdseasonNumber 	= "NONE";
							break;
						}
						if(categoryData[x].categoryShortName == "CLIPS" && videoList[z].episodeType == "CLI"){
							videoListIndex 	= z;
							vdSect 			= "CLIPS";
							vdepType 		= "CLI";
							vdseasonNumber 	= nodeClipsSeasons[0].seasonNumber;
							break;
						}
						if(categoryData[x].categoryShortName == "FULLEP" && videoList[z].episodeType == "EPI"){
							videoListIndex 	= z;
							vdSect 			= "FULLEP";				
							vdepType 		= "EPI";
							vdseasonNumber 	= nodeFullEpSeasons[0].seasonNumber;
							break;
						}
						if(categoryData[x].categoryShortName == "RECENT" && videoList[z].recentlyAdded == true){
							videoListIndex 	= z;
							vdSect 			= "RECENT";
							vdepType 		= "ALL";
							vdseasonNumber 	= "NONE";
							break;
						}
					}
				}						
			}
		}
	}
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// END Start Video and Display Navigation ////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Play video functions //////////////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function playVideo(p_vidArr, p_val){
		var arrIndex;
		var fwID;

		if(videoPlayerIsReady()){

			VideoAchievementModule.achievementShowHidePreGame("none");
			
			if(p_val.toString() == "next"){
				autoPlayListIndex = locateNextVideo(p_vidArr, autoPlayListIndex);
				reachedPlayListEnd = hasReachPlayListEnd();
				arrIndex = autoPlayListIndex;
				fwID = freeWheelSectionIDforAutoPlaylist;
			}else{
				if(p_vidArr == videoList){
					buildAutoPlaylist(vdSect, vdepType, vdseasonNumber, videoList);	
					reachedPlayListEnd = hasReachPlayListEnd();
					autoPlayListIndex 	= parseInt(p_val);
					videoListIndex 		= parseInt(p_val);
					arrIndex 			= parseInt(p_val);
				}
				fwID = freeWheelSectionID;
			}

			initializeAndPlayVideo(p_vidArr[arrIndex], fwID);
	
			writeVideoNavigation(p_vidArr, arrIndex);

		}		
	}

	function initializeAndPlayVideo(p_vidArr, p_fwID){

		if(p_vidArr.id != flashVideoCommunication.episodeId){
			
			flashVideoCommunication.segments = new Array();	
	
			for(var x=0; x <= p_vidArr.segment.length - 1; x++){
				var segDuration = p_vidArr.duration[x];	
				var segID 		= p_vidArr.segment[x];
				var segThumb 	= p_vidArr.thumbnailUrl[x];
	
				flashVideoCommunication.addSegment(segDuration, segID, segThumb);
			}
			 
			flashVideoCommunication.collectionId		= p_vidArr.collectionId;
			flashVideoCommunication.collectionTitle		= p_vidArr.collectionTitle;
			flashVideoCommunication.episodeId			= p_vidArr.id;
			flashVideoCommunication.episodeType 		= p_vidArr.episodeType;
			flashVideoCommunication.episodeTitle 		= p_vidArr.title;
			flashVideoCommunication.pageUrl 			= pageUrl; 
			flashVideoCommunication.pathVideoPlayList	= pathVideoPlayList;
			flashVideoCommunication.playEndSlate 		= false;
			flashVideoCommunication.ranking 			= "0";
			flashVideoCommunication.sectionId 			= p_fwID;
			flashVideoCommunication.embed				= p_vidArr.embed;
			//alert("Freewheel Id sent " + p_fwID);
			doDelayinitializeAndPlayVideo()

			highlightThumbnail(false);

			videoPlayingNow = p_vidArr.id;

			var setPlayNowTimer = setTimeout("highlightThumbnail(true)",1000);

		}

		getMoreFromGenre(p_vidArr.collectionId, p_vidArr.genre, p_vidArr.collectionTitle);
		getMoreFromCollectionId(p_vidArr.collectionId);

		initialPlay = false;
	}

	function doDelayinitializeAndPlayVideo(){

		if(videoPlayerIsReady()){
			flashVideoCommunication.playVideo();
		}else{
			videoTimer = setTimeout("doDelayinitializeAndPlayVideo()",20);
		}
		
	}
	//// achievement -------------------------////	
	function doAchievementWatchNow(){
		flashVideoCommunication.onResumeVideo();
	}

	function doAchievementLoginNowComplete(){
		flashVideoCommunication.onResumeVideo();
	}
	//// achievement -------------------------////	
	
	function buildAutoPlaylist(p_cat, p_epType, p_seasonNumber, p_videoListArr){
		var condition;

		freeWheelSectionIDforAutoPlaylist = freeWheelSectionID;

		autoPlayList = new Array(0);
		
		for(n=0; n <= p_videoListArr.length - 1; n++){
			switch (p_cat) {
	
				case "ALLSHOWS" :
					condition = true;
				break;
				
				case "TOPRATED_ALLSHOWS" :
					condition = (p_videoListArr[n].topRated);
				break;
				
				case "MOSTVIEWED_ALLSHOWS" :
					condition = (p_videoListArr[n].mostViewed);
				break;
				
				case "RECENT" :
					condition = (p_videoListArr[n].recentlyAdded);
				break;
	
				case "FULLEP" :
					condition = (p_seasonNumber == p_videoListArr[n].epiSeasonNumber && p_epType == p_videoListArr[n].episodeType);
				break;
	
				case "CLIPS" :
					condition = (p_seasonNumber == p_videoListArr[n].epiSeasonNumber && p_epType == p_videoListArr[n].episodeType);
				break;
	
				case "TOPRATED" :
					condition = (p_videoListArr[n].topRated);
				break;
				
				case "MOSTVIEWED" :
					condition = (p_videoListArr[n].mostViewed);
				break;
				
				case "DEEPLINK" :
					condition = (p_videoListArr[n].id == params.episodeID);
				break;
			}


			if(condition){
				autoPlayList.push(p_videoListArr[n]);
			}
		}
	}
	
	function playMoreVideo(p_vidArr, p_val){
		if(videoPlayerIsReady()){
		
			VideoAchievementModule.achievementShowHidePreGame("none");
		
			params.episodeID =  p_vidArr[p_val].id;
			deepLinkID = p_vidArr[p_val].id;
			initialPlay = true;
			validateDeepLink(deepLinkID);
		}
	}

	function videoPlayerIsReady(){

		if(flashVideoCommunication.swfIsReady == false || flashVideoCommunication.videoAdPlaying){
			return false;
		}else{
			return true;
		}
		
	}

	function locateNextVideo(p_vidArr, p_arrIndex){

		var nextIndexNumber = 0;
	
		if(p_vidArr.length > 0){
			if(p_arrIndex < p_vidArr.length - 1){
				nextIndexNumber = p_arrIndex + 1;
			}
		}
		
		return nextIndexNumber;
	}
	
	function hasReachPlayListEnd(){
			if(autoPlayList.length - 1 == autoPlayListIndex){
				return true;
			}else{
				return false;
			}
	}
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// END Play video functions //////////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// SET Freewheel ID //////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function setFreeWheelID(p_collectionId, p_category, p_setCurrentFreeWheelId){
		
		if(params.fwSectionID != null){
			freeWheelSectionID = params.fwSectionID;	
		}else{
			if(p_category == "sortByDate"){
				freeWheelSectionID = "cn.com_videos_whatsnew";	
			}else if(p_category == "sortByEpisodeRanking"){
				freeWheelSectionID = "cn.com_videos_toprated";	
			}else if(p_category == "sortByVideoRequest"){
				freeWheelSectionID = "cn.com_videos_mostviewed";	
			}else if(p_collectionId == "8a25c39218ef808e0118f1012d1a0013"){
				freeWheelSectionID = "cn.com_videos_premieres";
			}else if(p_collectionId == "8a250ab0230ec20c012334ad4f650371"){
				freeWheelSectionID = "cn.com_videos_whatsnew";
			}else if(p_collectionId == "8a25c3921dabeacd011dabfc870c0005"){
				freeWheelSectionID = "cn.com_extras_instores";
			}else if(p_collectionId == "8a25c3920d9d36d1010d9ec2ae870016"){
				freeWheelSectionID = "cn.com_extras_movietrailers";
			}else if(p_category == "Extras"){
				freeWheelSectionID = "cn.com_extras_homepage";	
			}else{
				freeWheelSectionID = "cn.com_videos_archive"; 
			}
		}
		
	}
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// END SET Freewheel ID //////////////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Write Navigations /////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function writeVideoNavigation(p_vidArr, p_arrIndex){

		viralID = p_vidArr[p_arrIndex].id
		showViralButton(p_vidArr[p_arrIndex].embed);
		
		document.tv_rating_img.src = p_vidArr[p_arrIndex].epiRatingImage;
	
		writeTitle(p_vidArr[p_arrIndex]);
		writeDescription(p_vidArr[p_arrIndex]);
		writeMoreButton(p_vidArr[p_arrIndex]);
			
		createRating(p_vidArr[p_arrIndex]);
	}

	function writeVideoSeasonNavigation(){
	
		document.getElementById("dsVidNav_RECENT").innerHTML 			= "";
		document.getElementById("dsVidNav_RECENT").style.display 		="none";
		document.getElementById("dsVidNav_FULLEP").innerHTML 			= "";
		document.getElementById("dsVidNav_FULLEP").style.display 		="none";
		document.getElementById("dsVidNav_FULLEPSeasons").innerHTML 	= "";
		document.getElementById("dsVidNav_FULLEPSeasons").style.display ="none";
		document.getElementById("dsVidNav_CLIPS").innerHTML 			= "";
		document.getElementById("dsVidNav_CLIPS").style.display 		="none";
		document.getElementById("dsVidNav_CLIPSSeasons").innerHTML 		= "";
		document.getElementById("dsVidNav_CLIPSSeasons").style.display 	="none";
		document.getElementById("dsVidNav_TOPRATED").innerHTML 			= "";
		document.getElementById("dsVidNav_TOPRATED").style.display 		="none";
		document.getElementById("dsVidNav_MOSTVIEWED").innerHTML 		= "";
		document.getElementById("dsVidNav_MOSTVIEWED").style.display 	="none";
		
		for ( x = 0; x <= categoryData.length - 1; x++ ) {
			if(categoryData[x].totalItems != "0"){

			 	var linkVarClipType = "ALL";
			 	var linkVarSeason	= "ALL";
			 	
			 	switch(categoryData[x].categoryShortName){
					case "FULLEP" :
						linkVarClipType = "EPI";
						linkVarSeason	= nodeFullEpSeasons[0].seasonNumber;
					break;
					case "CLIPS" :
						linkVarClipType = "CLI";
						linkVarSeason	= nodeClipsSeasons[0].seasonNumber;
					break;
				}
				 		
				var content = "";

				content += "<a class='videoNavLinks' href=" + '"' + "JavaScript:showHideVideoNavDiv('dsVidNav_"+ categoryData[x].categoryShortName +"'); writeNavigation('"+ categoryData[x].categoryShortName +"', '"+linkVarClipType+"','" + linkVarSeason +  "', false);" + '" ';
				content += "id='videolink" + categoryData[x].categoryShortName + "'>";
				content += categoryData[x].categoryName  + " (" + categoryData[x].totalItems + ")";
				content += "</a><br>";
				
				var linkID = "dsVidNav_" + categoryData[x].categoryShortName;

				document.getElementById(linkID).innerHTML = content;
				document.getElementById(linkID).style.display = "block";
				
				if(categoryData[x].categoryShortName == "FULLEP"){
					content = "";
						
					for(n=0; n <= nodeFullEpSeasons.length - 1; n++){
						content += "<div class='padLeft'><a class='videoNavLinks' href=" + '"' + "JavaScript:writeNavigation('"+ categoryData[x].categoryShortName +"', '"+linkVarClipType+"','" + nodeFullEpSeasons[n].seasonNumber +  "', false);" + '"' + "  >";
						content += nodeFullEpSeasons[n].seasonName ;
						content += "</a></div>";
					}
					document.getElementById("dsVidNav_"+categoryData[x].categoryShortName+"Seasons").innerHTML = content;
				}

				if(categoryData[x].categoryShortName == "CLIPS"){
					content = "";
		
					for(n=0; n <= nodeClipsSeasons.length - 1; n++){
						content += "<div class='padLeft'><a class='videoNavLinks' href=" + '"' + "JavaScript:writeNavigation('"+ categoryData[x].categoryShortName +"', '" +linkVarClipType+ "','" + nodeClipsSeasons[n].seasonNumber +  "', false);" + '"' + "  >";
						content += nodeClipsSeasons[n].seasonName ;
						content += "</a></div>";		
					}
		
					document.getElementById("dsVidNav_"+categoryData[x].categoryShortName+"Seasons").innerHTML = content;
				}

			}
		}
	}
	
	
	function writeNavigation(p_cat, p_epType, p_seasonNumber, p_updateSeasonNav){

		var condition;
		var displayCopy;
		var displayedVideos = new Array(0);
		
		var content = "";
		
		if(p_cat == "ALLSHOWS"){
		
			content += "<div id='video_carousel_fpo'> </div>";

		}else{

			content += "<div style='height:15; width:400px;'> </div>"; 
		
		}
		
		for(var n=0; n <= videoList.length - 1; n++){
			switch (p_cat) {
				case "ALLSHOWS" :
					condition = (p_epType == "ALL") ? true : (p_epType == videoList[n].episodeType);
					displayCopy = "short";
				break;
				
				case "RECENT" :
					condition = (videoList[n].recentlyAdded);
					displayCopy = "full";
				break;
	
				case "FULLEP" :
					condition = (p_seasonNumber == videoList[n].epiSeasonNumber && p_epType == videoList[n].episodeType);
					displayCopy = "full";
				break;
	
				case "CLIPS" :
					condition = (p_seasonNumber == videoList[n].epiSeasonNumber && p_epType == videoList[n].episodeType);
					displayCopy = "full";
				break;
				
				case "TOPRATED" :
					condition = (videoList[n].topRated);
					displayCopy = "full";
				break;
				
				case "MOSTVIEWED" :
					condition = (videoList[n].mostViewed);
					displayCopy = "full";
				break;
				
				case "DEEPLINK" :
					condition = (videoList[n].id == params.episodeID);
					displayCopy = "full";
				break;
			}
		
			if(condition){
				displayedVideos.push(n);
				content += returnNavigationString(n, displayCopy);
			}

			condition = false;
		}

		content += "<div style='height:45; width:400px;'> </div>" 
		
		if(p_cat == "ALLSHOWS"){

			if(document.getElementById("video_whatsnew_sect_content")){
				document.getElementById("video_whatsnew_sect_content").innerHTML = content;
			}
			if(document.getElementById("video_search_subnav")){
				var s_class1 = "class='videoEPType'";
				var s_class2 = "class='videoEPType'";
				var s_class3 = "class='videoEPType'";
				var s_eptype = "";
				
				switch (allshows_sort) {
					case "sortByDate":
						s_eptype = allshows_whatsnew_default
					break;
					case "sortByEpisodeRanking":
						s_eptype = allshows_toprated_default
					break;
					case "sortByVideoRequest":
						s_eptype = allshows_mostviewed_default
					break;
				}
				
				switch (s_eptype) {
					case "ALL":
						s_class1 = "class='videoEPTypeOn'";
					break;
					case "CLI":
						s_class2 = "class='videoEPTypeOn'";
					break;
					case "EPI":
						s_class3 = "class='videoEPTypeOn'";
					break;
				}
			
			 	var s = "<a " + s_class1 + " href='javascript:getAllEpisodesData(" + '"'+ allshows_sort + '" , "ALL"' + ");'>ALL</a>";
				s += " &nbsp;<span class='videoEPType'>|</span>&nbsp; ";
			 	s += " <a " + s_class2 + " href='javascript:getAllEpisodesData(" + '"'+ allshows_sort + '" , "CLI"' + ");'>CLIPS</a>";
				s += " &nbsp;<span class='videoEPType'>|</span>&nbsp; ";
			 	s += " <a " + s_class3 + " href='javascript:getAllEpisodesData(" + '"'+ allshows_sort + '" , "EPI"' + ");'>FULL EPISODES</a>";
			 	
				document.getElementById("video_search_subnav").innerHTML = s;
			}

		}else{
			if(p_updateSeasonNav){
				writeVideoSeasonNavigation();
			}

			document.getElementById('videoSlidingPanelsContentGroup').innerHTML = content;
			
			if(document.getElementById('video_brandimg')){

				if(allcollections[allcollectionsIndex].contextpageurl == "/video/dlink/index.html" || allcollections[allcollectionsIndex].contextpageurl == "/video/index.html"){
					document.getElementById('video_brandimg').innerHTML = "<div><img src='" + allcollections[allcollectionsIndex].brandimg + "' class='video_brand_img' border='0' width='640' height='65'></div>" ;
				}else{
					document.getElementById('video_brandimg').innerHTML = "<div><a href='" + allcollections[allcollectionsIndex].contextpageurl + "'><img src='" + allcollections[allcollectionsIndex].brandimg + "' class='video_brand_img' border='0' width='640' height='65'></a></div>" ;
				}
			}
		}
		
		for(var x=0; x <= displayedVideos.length - 1; x++){
			createEpisodeRating(displayedVideos[x]);			
		}

		var setPlayNowTimer = setTimeout("highlightThumbnail(true)",1000);

		doUpdateVideoScrollBars(p_cat);
		
	}

	function writeAllVideoNav(){

		var content = "";
			
		content += "<div style='height:8px; width:265px;'></div>" 
		
		for(i=0; i<=allcollections.length -1; i++){
			content += returnAllVideoNavigationString(i);
		}

		content += "<div style='height:15px; width:265px;'></div>" 
			
		document.getElementById('video_allVideo').innerHTML = content;

		doUpdateVideoScrollBars("allVideoAreaComplete");
		
	}
	
	function writeSearchBar(){

		var content = "";

		content += "<div id='searchBarWhatsNew' class='btnRed' onclick='javascript:getAllEpisodesData(" + '"sortByDate"' + ' , "default"' + ");'>WHAT'S NEW</div> <div id='searchBarTopRated' class='btnRed' onclick='javascript:getAllEpisodesData(" + '"sortByEpisodeRanking"' + ' , "default"' + ");'>TOP RATED</div> <div id='searchBarMostViewed' class='btnRed' onclick='javascript:getAllEpisodesData(" + '"sortByVideoRequest"' + ' , "default"' + ");'>MOST VIEWED</div>";
			
		document.getElementById('video_search_navbar').innerHTML = content;

		doUpdateVideoScrollBars("allVideoAreaComplete");
	}
	
	
	function writeTitle(p_vidArr){

		var content = p_vidArr.title;
		
		document.getElementById('cnv_html_title').innerHTML = content; 

	}
	
	function writeMoreButton(p_vidArr){

		var content;
		var indexNum = 0;
		
		for (var i = 0; i < allcollections.length - 1; i++ ) {
			if(p_vidArr.collectionId == allcollections[i].id){
				indexNum = 	i;			
			}
		}

		if(allcollections[indexNum].contextpageurltitle != ""){
			var upperStr =  allcollections[indexNum].contextpageurltitle;
			content = "<a class='html_morelink' href='" + allcollections[indexNum].contextpageurl + "'>" + upperStr.toUpperCase() + "</a>";
		}else{
			content = "";
		}

		document.getElementById('cnv_html_more').innerHTML = content; 

	}
	
	function writeDescription(p_vidArr){

		var content = p_vidArr.description;
		
		document.getElementById('rating_init').value = p_vidArr.ranking;
	}
	
	function writeAssociatedBottomContent(){
		
		var content = "";

			content += '	<div id="videoAC3">MORE VIDEOS LIKE THIS:</div>';
			content += '	<div id="videoAC4">';

		for(var n=0; n <= 2; n++){
			if(moreVideoList[n]){
				content += "<div class='video_association_clip_container'>";
				content += "<div class='video_association_clip' style='position: absolute; z-index:1;'><img width='80' height='45' border='0' src='"+moreVideoList[n].thumb+"'/></div>";
				content += "<div class='video_association_clip' style='position: absolute; z-index:2;'><a href='javascript:playMoreVideo(moreVideoList, " + n + ");'><img class='video_moreThumb_overlay_sash' width='80' height='45' border='0' src='" + moreVideoList[n].epiOverlayURL + "'/></a></div>";
				content += "</div>";
			}
		}

			content += '	</div>';
		
		document.getElementById('video_association_bottom').innerHTML = content; 
		
		for(var n=0; n <= 2; n++){
			var s = "createEpisodeRatingMoreSection('videolistrating_" + moreVideoList[n].id + "_moreLikeRate" + "','" + moreVideoList[n].ranking + "')";
			setTimeout(s,10);
		}
	
	}
	
	function writeAssociatedTopContent(){

		var indexArray = new Array(0);
		var uniqueID = true;

		for(var n=0; n <= moreFromVideoList.length - 1; n++){
			// do you have 3 items in the array		
			if(indexArray.length == 3){
				break;
			}else{
				// case is id != to video list
				if(moreFromVideoList[n].id != flashVideoCommunication.episodeId){

					// does the id already exist in the array
					if(indexArray.length > 0){
						for(var i=0; i <= indexArray.length - 1; i++){
							if(indexArray[i] == moreFromVideoList[n].id){
								uniqueID = false;							
								break;
							}
						}
					}
					
					if(uniqueID){
						indexArray.push(n);
					}
					
					uniqueID = true;
				}		
			}
		}

		var content = "";
			
			content += '	<div id="videoAC1">MORE FROM ' + associatedContentName.toUpperCase() + ':</div>';

			content += '	<div id="videoAC2">';

		for(var n=0; n <= indexArray.length - 1; n++){
		
			content += "<div class='video_association_clip_container'>";
			content += "<div class='video_association_clip' style='position: absolute; z-index:1;'><img width='80' height='45' border='0' src='"+moreFromVideoList[indexArray[n]].thumb+"'/></div>";
			content += "<div class='video_association_clip' style='position: absolute; z-index:2;'><a href='javascript:playMoreVideo(moreFromVideoList, " + indexArray[n] + ");'><img class='video_moreThumb_overlay_sash' width='80' height='45' border='0' src='";
			content += 	moreFromVideoList[indexArray[n]].epiOverlayURL == "" ? "http://i.cdn.turner.com/toon/tools/img/pixel.gif" : moreFromVideoList[indexArray[n]].epiOverlayURL;
			content += "'/></a></div>";
			content += "</div>";
		
		

//			content += 		"	<div class='video_association_clip'><a href='javascript:playMoreVideo(moreFromVideoList, " + indexArray[n] + ");'><img class='video_moreThumb_overlay_sash' width='45' height='80' border='0' src='"
//			content += 			moreFromVideoList[indexArray[n]].epiOverlayURL == "" ? "http://i.cdn.turner.com/toon/tools/img/pixel.gif" : moreFromVideoList[indexArray[n]].epiOverlayURL;
//			content += 				"'/></a></div>";
		}

			content += '	</div>';
			document.getElementById('video_association_top').innerHTML = content; 
			
		for(var n=0; n <= indexArray.length - 1; n++){
			var s = "createEpisodeRatingMoreSection('videolistrating_" + moreFromVideoList[indexArray[n]].id + "_moreFromRate" + "','" + moreFromVideoList[indexArray[n]].ranking + "')";
			setTimeout(s,10);
		}
	}
	
	function returnNavigationString(n, p_version){
		if(p_version == "short"){

		var s = "";
		
		s += "<div class='videoSlidingPanelsContent_small' id='videoContentPanel" + videoList[n].id + "' style='float:left;' >";

		s += "	<div style='height:45px; width:80px; margin-left:4px; margin-top:4px; position: absolute;border: 2px solid #aaaaaa;'>";
		s += "		<img class='video_thumb_overlay_sash' width='45' height='80' border='0' src='" + videoList[n].thumb +"'/>";
		s += "	</div>";
		
		s += "	<div class='video_thumb_img_small' id='thumbroll" + n + "' name='thumbroll" + n + "' >";

		if(videoList[n].epiOverlayURL != ""){
		s += "		<img class='video_thumb_overlay_sash' width='45' height='80' border='0' src='"
		s += videoList[n].epiOverlayURL;
		s += "'/>";
		}
		s += "	</div>";

		s += "  <div id='videoThumbPlaying" + videoList[n].id + "' class='video_thumb_overlay_playing'>";
		s += "  </div>";

		s += "	<div class='video_thumb_view_small'> " + videoList[n].numberOfViews + " VIEWS </div>";	
		s += "	<div id='video_thumb_rank_small'><div>" + returnRatingsString(videoList[n].ranking, videoList[n].id) + "</div></div>";

		s += "	<div class='video_thumb_inv_btn'>";
		s += "		<a href='javascript:playVideo(videoList, " + n + ");'><img src='http://i.cdn.turner.com/toon/tools/img/pixel.gif' border='0' height='87' width='230'></a>";
		s += "	</div>";		

		s += "	<div class='video_thumb_copy_small'>";			
		s += " 		<div class='video_thumb_title_copy'> " + videoList[n].collectionTitle + "</div>";
		s += "	</div>";

		s += "</div>";
		
		//////////////////////////////////////////////////////////////////////////////
		
		return s;
		
		}else{
		
		var s = "";
		
		////////////////////////////////////////////////////////////////////////////		
		
		s += "<div class='videoSlidingPanelsContent' id='videoContentPanel2" + videoList[n].id + "'  >";

		s += "	<div style='height:45px; width:80px; border: 2px solid #000000; margin-left:15px; margin-top:4px; position: absolute;'>";
		s += "		<img class='video_thumb_overlay_sash' width='45' height='80' border='0' src='" + videoList[n].thumb +"'/>";
		s += "	</div>";


		s += "	<div class='video_thumb_img' id='thumbroll" + n + "' name='thumbroll" + n + "'  >";
		
		if(videoList[n].epiOverlayURL != ""){
			s += "		<img class='video_thumb_overlay_sash' width='45' height='80' border='0' src='"
			s += videoList[n].epiOverlayURL;
			s += "'/>";
		}
		s += "	</div>";

		s += "  <div id='videoThumbPlaying2" + videoList[n].id + "' class='video_thumb_overlay_playing2'>";
		s += "  </div>";
		
		s += "	<div class='video_thumb_view'> " + videoList[n].numberOfViews + " VIEWS </div>";	
		s += "	<div class='video_thumb_rank'><div>" + returnRatingsString(videoList[n].ranking, videoList[n].id) + "</div></div>";

		s += "	<div class='video_thumb_inv_btn'>";
		s += "		<a href='javascript:playVideo(videoList, " + n + ");'><img src='http://i.cdn.turner.com/toon/tools/img/pixel.gif' border='0' height='87' width='470'></a>";
		s += "	</div>";		

		s += "	<div class='video_thumb_copy'>";			
		s += " 		<div class='video_thumb_title_copy'> " + videoList[n].title + "</div><div class='video_thumb_desc_copy'>" + videoList[n].description + "</div>";
		s += "	</div>";

		s += "</div>";
		
		////////////////////////////////////////////////////////////////////////////	
		
		return s;
		}
	
	}
	
	function returnAllVideoNavigationString(n){

		var s = "";
		
		s += "<div class='allVideoImg'>";
		s += "		<a href='javascript:getShowData(" + '"' + allcollections[n].id + '");' + "'>";
		s += "<img src='";
		s +=  allcollections[n].header2;
		s += "' border='0' width='265' height='65' ></a>";
		s += "</div>";
		
		return s;
		
	}
	
	function returnRatingsString(rank, rankName){

		var s = "";

		s += "<span id='videolistrating_" + rankName + "' >";
		s += "	<span class='ratingButton'></span>";
		s += "	<span class='ratingButton'></span>";
		s += "	<span class='ratingButton'></span>";
		s += "	<span class='ratingButton'></span>";
		s += "	<span class='ratingButton'></span>";
		s += "</span>";

		return s;
		
	}
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// END Write Navigations /////////////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Various Navigational functions ////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function doReplaceSpecialChar(p_str){

		var str_regEx 		= /\Wamp\Wamp\W/;
		var str_replace		= "&";
		var str_VidCopy		= p_str;
		
		while(str_VidCopy.indexOf("&amp;amp;") > -1){

			str_VidCopy = str_VidCopy.replace(str_regEx, str_replace);
		
		}
		
		str_regEx 		= /\Wamp\W\W39\W/;
		str_replace		= "'";
		
		while(str_VidCopy.indexOf("&amp;#39;") > -1){

			str_VidCopy = str_VidCopy.replace(str_regEx, str_replace);
		
		}

		str_regEx 		= /\Wamp\Wquot\W/;
		str_replace		= "&quot;"

		while(str_VidCopy.indexOf("&amp;quot;") > -1){

			str_VidCopy = str_VidCopy.replace(str_regEx, str_replace);
		
		}

		return str_VidCopy;
				
	}
	
	
	function showHideVideoNavDiv (styleObj) {
	
		switch(styleObj){
			case "dsVidNav_CLIPS" :
				document.getElementById("dsVidNav_FULLEPSeasons").style.display = "none";
				document.getElementById("dsVidNav_CLIPSSeasons").style.display = document.getElementById("dsVidNav_CLIPSSeasons").style.display == "none" ? "block" : "none";			
			break;
			
			case "dsVidNav_FULLEP" :
				document.getElementById("dsVidNav_CLIPSSeasons").style.display = "none";						
				document.getElementById("dsVidNav_FULLEPSeasons").style.display = document.getElementById("dsVidNav_FULLEPSeasons").style.display == "none" ? "block" : "none";
			break;
			
			default :
				if(document.getElementById("dsVidNav_CLIPSSeasons").style.display == "block"){
					document.getElementById("dsVidNav_CLIPSSeasons").style.display = "none";
				}
				if(document.getElementById("dsVidNav_FULLEPSeasons").style.display == "block"){
					document.getElementById("dsVidNav_FULLEPSeasons").style.display = "none";
				}

			break;

		}
		
	}
	
	function resetTabView(){
		
		if(document.getElementById("searchBarWhatsNew")){
			document.getElementById("searchBarWhatsNew").className		= "btnRed";
		}
		if(document.getElementById("searchBarTopRated")){
			document.getElementById("searchBarTopRated").className		= "btnRed";
		}
		if(document.getElementById("searchBarMostViewed")){
			document.getElementById("searchBarMostViewed").className	= "btnRed";
		}
	}
	
	function showSectionPlaying (p_section) {

		if(document.getElementById("videolinkRECENT")){
			document.getElementById("videolinkRECENT").className		= "videoNavLinks";
		}
		if(document.getElementById("videolinkFULLEP")){
			document.getElementById("videolinkFULLEP").className		= "videoNavLinks";
		}
		if(document.getElementById("videolinkCLIPS")){
			document.getElementById("videolinkCLIPS").className			= "videoNavLinks";
		}
		if(document.getElementById("videolinkTOPRATED")){
			document.getElementById("videolinkTOPRATED").className 		= "videoNavLinks";
		}
		if(document.getElementById("videolinkTOPRATED")){
			document.getElementById("videolinkTOPRATED").className 		= "videoNavLinks";
		}
		if(document.getElementById("videolinkMOSTVIEWED")){
			document.getElementById("videolinkMOSTVIEWED").className 	= "videoNavLinks";
		}
		
		currentCategory = p_section;

		switch(p_section){
			
			case "RECENT" :
				if(document.getElementById("videolinkRECENT")){
					document.getElementById("videolinkRECENT").className = "videoNavLinkActive";
				}
			break;
			
			case "FULLEP" :
				if(document.getElementById("videolinkFULLEP")){
					document.getElementById("videolinkFULLEP").className = "videoNavLinkActive";
				}
			break;

			case "CLIPS" :
				if(document.getElementById("videolinkCLIPS")){
					document.getElementById("videolinkCLIPS").className = "videoNavLinkActive";
				}
			break;
			
			case "TOPRATED" :
				if(document.getElementById("videolinkTOPRATED")){
					document.getElementById("videolinkTOPRATED").className = "videoNavLinkActive";
				}
			break;
			
			case "MOSTVIEWED" :
				if(document.getElementById("videolinkMOSTVIEWED")){
					document.getElementById("videolinkMOSTVIEWED").className = "videoNavLinkActive";
				}
			break;

		}
		
	}
	
	function showHideVidNav(p_show){

		var dsp = (p_show) ? "none" : "block";
		
		document.getElementById('dsVidNav_RECENT').style.display 		= dsp;
		document.getElementById('dsVidNav_FULLEP').style.display 		= dsp;
		document.getElementById('dsVidNav_FULLEPSeasons').style.display = dsp;
		document.getElementById('dsVidNav_CLIPS').style.display 		= dsp;
		document.getElementById('dsVidNav_CLIPSSeasons').style.display 	= dsp;
		document.getElementById('dsVidNav_TOPRATED').style.display 		= dsp;
		document.getElementById('dsVidNav_MOSTVIEWED').style.display 	= dsp;
	
	}
	
	function highlightThumbnail(p_state){

		var elmID = "videoThumbPlaying" + videoPlayingNow;
		var elmID2 = "videoThumbPlaying2" + videoPlayingNow;
		var elmID3 = "videoContentPanel" + videoPlayingNow;
		var elmID4 = "videoContentPanel2" + videoPlayingNow;

		var dsp = (p_state) ? "block" : "none";
		var content = (p_state) ? "<img width='80' height='45' border='0' src='/video/tools/img/playing.gif'/>" : "";			

		if(document.getElementById(elmID)){
			document.getElementById(elmID).innerHTML = content;	
			document.getElementById(elmID).style.display = dsp;
		}
		
		if(document.getElementById(elmID3)){
			document.getElementById(elmID3).className = (p_state) ? "videoSlidingPanelsContent_smallOn" : "videoSlidingPanelsContent_small" ;	
		}

		if(document.getElementById(elmID4)){
			document.getElementById(elmID4).className = (p_state) ? "videoSlidingPanelsContentOn" : "videoSlidingPanelsContent" ;	
		}

		if(document.getElementById(elmID2)){
			document.getElementById(elmID2).innerHTML = content;	
			document.getElementById(elmID2).style.display = dsp;
		}
		
	}


	function doUpdateVideoScrollBars(p_cat){

		switch(p_cat){
			case "allVideoAreaComplete" :
				resetVAVScroller();
			break;
			
			case "ALLSHOWS":
				resetVWNScroller();
			break;

			default :
				resetVSPCGScroller();
			break;

		}
	
	}
	
	function getRandomNumber(){
		var randomNumber;
		
		var m   	= new Date().getMonth() + 1;
		var d  		= new Date().getDate();
		var yr  	= new Date().getFullYear();
		var h 	 	= new Date().getHours();
		var min 	= new Date().getMinutes();
		var newMin 	= "00";
		
		if(min >= 0 && min <= 15){
			newMin = "00";
		}
		
		if(min >= 16 && min <= 30){
			newMin = "15";
		}
		
		if(min >= 31 && min <= 45){
			newMin = "30";
		}
		
		if(min >= 46 && min <= 59){
			newMin = "45";
		}
		
		randomNumber = m + "" + d + "" + yr + "" + h + "" + newMin;
		
		return randomNumber;        	
	}
	
	function getRandomNumberByRange(m, n, numberUsed){
	
		var getRandomNumber = Math.round(Math.random() * n) + m;
		
		while(numberUsed == getRandomNumber){
			getRandomNumber = Math.round(Math.random() * n) + m;
		}
		
		return getRandomNumber;
	}
	
	function videoContinuousPlay(){

		if(continuousPlayEnabled){
			continuousPlayEnabled = false;
			document.getElementById('img_continuousplay').src = "/tools/img/video/contplayoff.gif"
		}else{
			continuousPlayEnabled = true;
			document.getElementById('img_continuousplay').src = "/tools/img/video/contplay.gif";
		}

	}
	
	function continuousPlayOver(){
		
		if(continuousPlayEnabled){
			document.getElementById('img_continuousplay').src = "/tools/img/video/contplayoff.gif";
		}else{
			document.getElementById('img_continuousplay').src = "/tools/img/video/contplay.gif";
		}

	}

	function continuousPlayOut(){
		
		if(continuousPlayEnabled){
			document.getElementById('img_continuousplay').src = "/tools/img/video/contplay.gif";
		}else{
			document.getElementById('img_continuousplay').src = "/tools/img/video/contplayoff.gif";
		}

	}
	
	function createRating(p_vidArr){
										
		var rate = new Spry.Widget.Rating("spryrating", {rateHandler: ratingMsg,allowMultipleRating: false, ratingValueElement: 'rating_init', postData: 'id=' + p_vidArr.id  + '&rating=@@ratingValue@@', saveUrl:pathRatings});
	
	}
	
	function createEpisodeRating(p_int){
	
		var rateNameStr = "videolistrating_" + videoList[p_int].id;
		var rateNameStr2 = "videolistrating_" + videoList[p_int].id + "_2";
	
		var rateVal		= videoList[p_int].ranking;
	
		var widgetname = new Spry.Widget.Rating(rateNameStr,{ratingValue:rateVal, readOnly:true}); 
		//var widgetname = new Spry.Widget.Rating(rateNameStr2,{ratingValue:rateVal, readOnly:true}); 
	}
	
	function createEpisodeRatingMoreSection(p_id, p_rate){

		var rateNameStr = p_id;
		var rateVal		= p_rate;
		
		//var widgetname = new Spry.Widget.Rating(rateNameStr,{ratingValue:rateVal, readOnly:true}); 
	}
	
	function ratingMsg(){	
		
		document.getElementById('rating_thanks').style.display = "block";
		
		setTimeout("clearRatingMsg()", 5000);
	}
		
	function clearRatingMsg(){
		document.getElementById('rating_thanks').style.display = "none" 
	}
	
	function showViralButton(p_show){
		if(p_show){
			document.getElementById("cnv_html_copy").className = "cnv_copyFB"; 
			document.getElementById("cnv_html_title").className = "cnv_video_titleFB"; 
			document.getElementById("html_viralbtns").className = "cnv_viralbtnsFB"; 
			document.getElementById("html_fbbtn").style.display = "block"; 
			document.getElementById("html_sendbtn").style.display = "block"; 
		}else{
			document.getElementById("cnv_html_copy").className = "cnv_copy";
			document.getElementById("cnv_html_title").className = "cnv_video_title"; 
			document.getElementById("html_viralbtns").className = "cnv_viralbtns"; 
			document.getElementById("html_fbbtn").style.display = "none"; 
			document.getElementById("html_sendbtn").style.display = "block"; 
		}
	}
	
	function sendViralLink(){
	 	var windowURL = "http://www.cartoonnetwork.com/fb/video_share.html?episodeID=" + viralID;

		window.open(windowURL,'fbBufferWin','width=627,height=310');

	}

	function viralBtnHover(p_id, p_over){

		var imgSrc = "";
		var hoverState = "";
		
		if(p_over){
			hoverState = "_hover";	
		}
				
		imgSrc = "/video/tools/img/sharevideo/" + p_id + hoverState + ".jpg";
		
		document.getElementById(p_id).src = imgSrc;
	}

	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// END Various Navigational functions ////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	

	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Flash/JS Communication ////////////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	flashVideoCommunication.onVideoStateChange = function (val){

		if(val == "ENDED" && reachedPlayListEnd == false && continuousPlayEnabled){
			playVideo(autoPlayList, "next");
		}else if(val == "ENDED"){
			flashVideoCommunication.onShowEndSlate();	
		}
	}
	
	flashVideoCommunication.onOpenFacebook = function (){
		sendViralLink();
	}
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// END Flash/JS Communication ////////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function VideoPresentation(){
		
	}

	VideoPresentation.trackVideo = function(p_type, p_title, p_segmentID, p_episodeID, p_segmentIndex){
		
		var videoTrackingData = {};
		
		videoTrackingData.id 		= p_segmentID;
		videoTrackingData.title 	= p_title;
		videoTrackingData.episode	= p_episodeID;
		videoTrackingData.segment	= p_segmentIndex;
		
		for(var x=0; x <= videoList.length -1; x++){
			if(videoList[x].id == p_episodeID){
				videoTrackingData.type		= videoList[x].episodeType;
				videoTrackingData.season	= videoList[x].epiSeasonName;
				videoTrackingData.franchise	= videoList[x].collectionTitle;			
				break;
			}
		}

		trackVideo(p_type, videoTrackingData);	
		
		videoTrackingData 	= null;
		
	}	
	

