	var requiredMajorVersion 	= 9;
	var requiredMinorVersion 	= 0;
	var requiredRevision 		= 45;
	
	var params = HttpUtils.getQueryAsObject();
	
	var dsregEx;
	var dsreplace;
	var dsconfigPath;
	
	var collectionID;	
	var freeWheelSectionID;
	var pageUrl = "http://www.cartoonnetwork.com/video/index.html";

	var dsConfigInfo;					
	
	var ndsallcollections;
	var ndsEpisodesByCategoryPath;
	var ndsEpisodesByShowPath;
	var ndsMoreEpisodesByShowPath;
	var ndsMoreGetAllEpisodesPath;
	var ndsEpisodesByIDsPath;
	var ndsVideoPlayListPath;
	var ndsRatingsPath;
	var ndsGetTimeStamp;
	
	var dsEpisodesByCategory;
	
	var ndsCategoryByFullEp;
	var ndsCategoryByFullEpSeasons;
	var ndsCategoryRecentlyAdded;
	var ndsCategoryRecentlyAddedIDs;
	var ndsCategoryClips;
	var ndsCategoryTopRated;
	var ndsCategoryTopRatedIDs;
	var ndsCategoryMostViewed;
	var ndsCategoryMostViewedIDs;

	var loadedCategoryByFullEp			= false;
	var loadedCategoryByFullEpSeasons	= false;
	var loadedCategoryRecentlyAdded		= false;
	var loadedCategoryRecentlyAddedIDs	= false; 
	var loadedCategoryClips				= false;	
	var loadedCategoryTopRated			= false;
	var loadedCategoryTopRatedIDs		= false;
	var loadedCategoryMostViewed		= false;
	var loadedCategoryMostViewedIDs		= false;
			
	var dsEpisodesByShow;
	var dsMoreEpisodesByShow;
	var dsMoreGetAllEpisodes;
	var dsEpisodesByEpisodeID;

//	var configObserver = new Object;

	var loadedAllcollections			= false;
	var loadedEpisodesByCategory 		= false;
	var loadedEpisodesByShow 			= false;
	var loadedMoreEpisodesByShow		= false;
	var loadedMoreGetAllEpisodesPath	= false;
	var loadedTimeStamp 				= false;
	var loadedEpisodesByCategoryPath 	= false;
	var loadedEpisodesByIDsPath			= false;
	var loadedVideoPlaylistPath 		= false;
	var loadedRatingsPath 				= false;
	var loadedMoreGetAllEpisodesData	= false;
	var loadedMoreEpisodesByShowData	= false;

	var pathEpisodesByCategory;
	var pathEpisodesByID;
	var pathRatings;
	var pathEpisodeByShow;
	var pathMoreEpisodeByShow;
	var pathMoreGetAllEpisodes;
	var pathVideoPlayList;
	var pathVideoPlayListQueryString;
	var timeStampNextGen;
	var resultsLimit;
	var previous_btn 	= "previous";
	var next_btn 		= "next";
		
	var flashVideoCommunication = new FlashVideoCommunication();
	
	var videoConfigFlashVars	= null;

	var videoList 				= new Array(0);
	var moreFromVideoList 		= new Array(0);
	var moreVideoList 			= new Array(0);
	var allcollections			= new Array(0);
	 
	var videoListIndex 			= 0;
	var allcollectionsIndex		= 0;
	var videoListSegmentIndex 	= 0;

	var reachedPlayListEnd		= false;
	var initialPlay				= true;
	var continuousPlayEnabled 	= true;
	var autoPlayList			= new Array(0);
	
	var categoryData			= new Array(0);
	var categoryList 			= new Array("MOSTVIEWED", "TOPRATED", "CLIPS", "FULLEP", "RECENT");
	var currentCategory			= "";
	var nodeFullEpSeasons		= new Array(0);
	var nodeClipsSeasons		= new Array(0);
	
	var vdSect 					= "RECENT";
	var vdepType 				= "ALL";
	var vdseasonNumber 			= "NONE";

	var associatedContentName	= "";	

	var rankingList				= new Array(0);
	
	var deepLinkID 				= null;
	var deepLinkCollectionID 	= null;
	var thumbnailStart 			= 0;
	var thumbnailEnd			= 0;
	var validDeepLinkEpisode	= false;
	var validVars 				= true;
	var validSeg 				= true;
	var videoTimer;
	
	function resetVars(){
		collectionID					= null;
		freeWheelSectionID 				= null;

		dsConfigInfo 					= null;
	
		ndsallcollections 				= null;
		ndsEpisodesByCategoryPath 		= null;
		ndsEpisodesByShowPath 			= null;
		ndsMoreEpisodesByShowPath		= null;
		ndsMoreGetAllEpisodesPath		= null;
		ndsEpisodesByIDsPath			= null;
		ndsVideoPlayListPath 			= null;
		ndsRatingsPath 					= null;
		ndsGetTimeStamp 				= null;
	
		dsEpisodesByCategory 			= null;
	
		ndsCategoryByFullEp 			= null;
		ndsCategoryByFullEpSeasons 		= null;
		ndsCategoryRecentlyAdded 		= null;
		ndsCategoryRecentlyAddedIDs 	= null;
		ndsCategoryClips 				= null;
		ndsCategoryTopRated 			= null;
		ndsCategoryTopRatedIDs 			= null;
		ndsCategoryMostViewed 			= null;
		ndsCategoryMostViewedIDs 		= null;

		loadedCategoryByFullEp			= false;
		loadedCategoryByFullEpSeasons	= false;
		loadedCategoryRecentlyAdded		= false;
		loadedCategoryRecentlyAddedIDs	= false; 
		loadedCategoryClips				= false;	
		loadedCategoryTopRated			= false;
		loadedCategoryTopRatedIDs		= false;
		loadedCategoryMostViewed		= false;
		loadedCategoryMostViewedIDs		= false;
			
		dsEpisodesByShow 				= null;
		dsMoreEpisodesByShow			= null;
		dsMoreGetAllEpisodes			= null;
		dsEpisodesByEpisodeID			= null;

//		configObserver 					= new Object;

		loadedAllcollections			= false;
		loadedEpisodesByCategory 		= false;
		loadedEpisodesByShow 			= false;
		loadedMoreEpisodesByShow		= false;
		loadedMoreGetAllEpisodesPath	= false;
		loadedTimeStamp 				= false;
		loadedEpisodesByCategoryPath 	= false;
		loadedEpisodesByIDsPath			= false;
		loadedVideoPlaylistPath 		= false;
		loadedRatingsPath 				= false;
		loadedMoreGetAllEpisodesData	= false;
		loadedMoreEpisodesByShowData	= false;
		

		pathEpisodesByCategory 			= null;
		pathEpisodesByID				= null;
		pathRatings 					= null;
		pathEpisodeByShow 				= null;
		pathMoreEpisodeByShow			= null;
		pathMoreGetAllEpisodes			= null;
		pathVideoPlayList 				= null;
		pathVideoPlayListQueryString 	= null;
		timeStampNextGen 				= null;
		resultsLimit 					= null;
		
		videoList 				= new Array(0);
		moreFromVideoList		= new Array(0);
		moreVideoList 			= new Array(0);
		allcollections			= new Array(0);
	 
		videoListIndex 			= 0;
		videoListSegmentIndex 	= 0;
		reachedPlayListEnd		= false;
		autoPlayList			= new Array(0);
		
		categoryData			= new Array(0);
		currentCategory			= "";
		nodeFullEpSeasons		= new Array(0);
		nodeClipsSeasons		= new Array(0);
		
		vdSect 					= "RECENT";
		vdepType 				= "ALL";
		vdseasonNumber 			= "NONE";

		associatedContentName	= "";	
		
		rankingList				= new Array(0);
	
		deepLinkID 				= null;
		deepLinkCollectionID 	= null;
		thumbnailStart 			= 0;
		thumbnailEnd			= 0;
		validDeepLinkEpisode	= false;
		validVars 				= true;
		validSeg 				= true;
	}

	//querystring vars -----------------------------------------------------------------------------------------------------------------------------------------------//

//	if(params.section != null) 		videoConfigFlashVars = "FLASHVARS_defaultSection=" 		+ params.section;
//	if(params.categoryID != null) 	videoConfigFlashVars = "FLASHVARS_defaultCategoryID=" 	+ params.categoryID;
	

//	if(params.segmentID != null) 	videoConfigFlashVars = "FLASHVARS_defaultSegmentID=" 	+ params.segmentID;	
	//end querystring vars -----------------------------------------------------------------------------------------------------------------------------------------------//
	
	
	//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){
		
		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.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;

	}
		
	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);
				}

				
				loadedAllcollections = true;
			}
			
			if(dataSet == ndsEpisodesByShowPath){

				ndsEpisodesByShowPath.removeObserver(configObserverFunc);

				pathEpisodeByShow = getConfigNode(ndsEpisodesByShowPath, "@url");

				pathEpisodeByShow = pathEpisodeByShow.replace(dsregEx, dsreplace);

				resultsLimit = getConfigNode(ndsEpisodesByShowPath, "@limit");

				loadedEpisodesByShow = true;
			}

			if(dataSet == ndsMoreGetAllEpisodesPath){

				ndsMoreGetAllEpisodesPath.removeObserver(configObserverFunc);

				pathMoreGetAllEpisodes = getConfigNode(ndsMoreGetAllEpisodesPath, "@url");

				pathMoreGetAllEpisodes = pathMoreGetAllEpisodes.replace(dsregEx, dsreplace);

				loadedMoreGetAllEpisodesPath = true;
			}


			if(dataSet == ndsMoreEpisodesByShowPath){

				ndsMoreEpisodesByShowPath.removeObserver(configObserverFunc);

				pathMoreEpisodeByShow = getConfigNode(ndsMoreEpisodesByShowPath, "@url");

				pathMoreEpisodeByShow = pathMoreEpisodeByShow.replace(dsregEx, dsreplace);

				pathMoreEpisodeByShow = pathMoreEpisodeByShow.substring(0, pathMoreEpisodeByShow.indexOf("networkName=CN2") + 15);
				
				loadedMoreEpisodesByShow = true;
			}
			
			if(dataSet == ndsVideoPlayListPath){

				ndsVideoPlayListPath.removeObserver(configObserverFunc);
				
				pathVideoPlayList = getConfigNode(ndsVideoPlayListPath, "@url");
				
				pathVideoPlayList = pathVideoPlayList.replace(dsregEx, dsreplace);
				
				loadedVideoPlaylistPath = true;
			}
			
			if(dataSet == ndsRatingsPath){

				ndsRatingsPath.removeObserver(configObserverFunc);
				
				pathRatings = getConfigNode(ndsRatingsPath, "@url");
				
				pathRatings = pathRatings.replace(dsregEx, dsreplace);
				
				loadedRatingsPath = true;
			}
			
			if(dataSet == ndsEpisodesByCategoryPath){

				ndsEpisodesByCategoryPath.removeObserver(configObserverFunc);
				
				pathEpisodesByCategory = getConfigNode(ndsEpisodesByCategoryPath, "@url");
				
				pathEpisodesByCategory = pathEpisodesByCategory.replace(dsregEx, dsreplace);
				
				loadedEpisodesByCategoryPath = true;
			}
			
			if(dataSet == ndsEpisodesByIDsPath){

				ndsEpisodesByIDsPath.removeObserver(configObserverFunc);
				
				pathEpisodesByID = getConfigNode(ndsEpisodesByIDsPath, "@url");
				
				pathEpisodesByID = pathEpisodesByID.replace(dsregEx, dsreplace);
				
				loadedEpisodesByIDsPath = true;
			}

			if(dataSet == ndsGetTimeStamp){

				ndsGetTimeStamp.removeObserver(configObserverFunc);

				timeStampNextGen = getConfigNode(ndsGetTimeStamp, "@value");

				loadedTimeStamp = true;
			}
			
			if(loadedEpisodesByShow && loadedMoreGetAllEpisodesPath && loadedMoreEpisodesByShow && loadedTimeStamp && loadedVideoPlaylistPath && loadedRatingsPath && loadedEpisodesByCategoryPath && loadedEpisodesByIDsPath && loadedAllcollections){

				pathVideoPlayList = pathVideoPlayList + "&r=" + timeStampNextGen; 

				
				if(deepLinkID != null){
					validateDeepLink(deepLinkID);				
				}else{
					getShowData();
				}
			}
		}
		
	}
	
	function showEpisodeObserverFunc(notificationType, dataSet, data){

		if (notificationType == "onLoadError" && dataSet == dsEpisodesByShow){
			alert("Unable to Load Data. Please reload page. Error 200")
		}
		
		if (notificationType == "onLoadError" && dataSet == dsMoreEpisodesByShow){
			alert("Unable to Load Data. Please reload page. Error 201")
		}
		
		if (notificationType == "onLoadError" && dataSet == dsEpisodesByEpisodeID){
			alert("Unable to Load Data. Please reload page. Error 202")
		}

		if (notificationType == "onLoadError" && dataSet == dsMoreGetAllEpisodes){
			alert("Unable to Load Data. Please reload page. Error 203")
		}

		if (notificationType == "onPostLoad"){
			
			if(dataSet == dsEpisodesByShow){

				dsEpisodesByShow.removeObserver(showEpisodeObserverFunc);
			
				var rows = dsEpisodesByShow.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 = dsEpisodesByShow.getData()[i]["ds_RowID"];
					dsEpisodesByShow.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"]);
						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;
				}
				
				if(validSeg){
					getCategoryData();
				}else{
					alert("Missing SegmentID");
				}
			}
			
			//////dsMoreGetAllEpisodes
			if(dataSet == dsMoreGetAllEpisodes){

				dsMoreGetAllEpisodes.removeObserver(showEpisodeObserverFunc);
			
				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"]);
						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;
				}

				writeAssociatedTopContent();

			}
			
			if(dataSet == dsMoreEpisodesByShow){

				dsMoreEpisodesByShow.removeObserver(showEpisodeObserverFunc);
			
				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"]);
						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;
				}

				writeAssociatedBottomContent();

			}
			
			if(dataSet == dsEpisodesByEpisodeID){

				dsEpisodesByEpisodeID.removeObserver(showEpisodeObserverFunc);

				deepLinkID 				= getConfigNode(dsEpisodesByEpisodeID, "@id")
				deepLinkCollectionID 	= getConfigNode(dsEpisodesByEpisodeID, "@collectionId")

				
				if(deepLinkCollectionID == null){
					alert("This Episode is no longer available");
				}else{
					collectionID = deepLinkCollectionID;
					getShowData();
				}
			}
			
		}
	}
	
	function validateDeepLink(p_episodeID){
		
		var s = pathEpisodesByID  + "&ids=" + p_episodeID;

		dsEpisodesByEpisodeID = new Spry.Data.XMLDataSet(s, "/episodes/episode", { entityEncodeStrings: false });
		dsEpisodesByEpisodeID.addObserver(showEpisodeObserverFunc);
		dsEpisodesByEpisodeID.loadData();
		
	}
	
	function getShowData(){
		
		var s = pathEpisodeByShow  + "&id=" + collectionID + "&limit=" + resultsLimit + "&offset=0&r=" + timeStampNextGen;

		dsEpisodesByShow = new Spry.Data.XMLDataSet(s, "/episodes/episode", { subPaths: [ "segments/segment"] });
		dsEpisodesByShow.addObserver(showEpisodeObserverFunc);
		dsEpisodesByShow.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 == ndsCategoryRecentlyAddedIDs){
				parseCategoryIDs(ndsCategoryRecentlyAddedIDs, "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 == ndsCategoryTopRatedIDs){
				parseCategoryIDs(ndsCategoryTopRatedIDs, "TOPRATED");
			}else if(dataSet == ndsCategoryMostViewed){
				parseCategoryData(ndsCategoryMostViewed, "MOSTVIEWED");
			}else if(dataSet == ndsCategoryMostViewedIDs){
				parseCategoryIDs(ndsCategoryMostViewedIDs, "MOSTVIEWED");
			}
			
			if(loadedCategoryByFullEp && loadedCategoryByFullEpSeasons && loadedCategoryRecentlyAdded &&loadedCategoryClips && ndsCategoryClipsSeasons &&	loadedCategoryTopRated && loadedCategoryMostViewed){

				getNestedCategoryData();

			}
		}
	}
	
	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 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;
		}
	
	}
	
	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;
		}		
	}
	
	//////////////////////////////
	
	
	function nestedCategoryObserverFunc(notificationType, dataSet, data){

		if (notificationType == "onLoadError"){
			alert("Unable to Load Data. Please reload page. Error 400");
		}

		if (notificationType == "onPostLoad"){
			
			if(dataSet == ndsCategoryRecentlyAddedIDs){
				ndsCategoryRecentlyAddedIDs.removeObserver(categoryObserverFunc);
				
				var rowsRA = ndsCategoryRecentlyAddedIDs.getData();

				var currentRow;

				for(var i=0; i <= rowsRA.length - 1; i++){

					currentRow = ndsCategoryRecentlyAddedIDs.getData()[i]["ds_RowID"];
					ndsCategoryRecentlyAddedIDs.setCurrentRow(currentRow);
					
					var isRecentlyAdded = rowsRA[i]["@id"];

					for(var n=0; n <= videoList.length - 1; n++){
						if(videoList[n].id == isRecentlyAdded){
							videoList[n].recentlyAdded = true;
						}
					}

				}
				
				loadedCategoryRecentlyAddedIDs = true;
				
			}else if(dataSet == ndsCategoryTopRatedIDs){
				ndsCategoryTopRatedIDs.removeObserver(categoryObserverFunc);
				
				var rowsTRID = ndsCategoryTopRatedIDs.getData();

				var currentRow;

				for(var i=0; i <= rowsTRID.length - 1; i++){

					currentRow = ndsCategoryTopRatedIDs.getData()[i]["ds_RowID"];
					ndsCategoryTopRatedIDs.setCurrentRow(currentRow);
					
					var isTopRated = rowsTRID[i]["@id"];

					for(var n=0; n <= videoList.length - 1; n++){
						if(videoList[n].id == isTopRated){
							videoList[n].topRated = true;
						}
					}

				}
				
				loadedCategoryTopRatedIDs = true;
				
			}else if(dataSet == ndsCategoryMostViewedIDs){
				ndsCategoryMostViewedIDs.removeObserver(categoryObserverFunc);
				
				var rowsMVID = ndsCategoryMostViewedIDs.getData();

				var currentRow;

				for(var i=0; i <= rowsMVID.length - 1; i++){

					currentRow = ndsCategoryMostViewedIDs.getData()[i]["ds_RowID"];
					ndsCategoryMostViewedIDs.setCurrentRow(currentRow);
					
					var isMostViewed = rowsMVID[i]["@id"];

					for(var n=0; n <= videoList.length - 1; n++){
						if(videoList[n].id == isMostViewed){
							videoList[n].mostViewed = true;
						}
					}

				}
				
				loadedCategoryMostViewedIDs = true;
				
			}

			
			if(loadedCategoryRecentlyAddedIDs && loadedCategoryTopRatedIDs && loadedCategoryMostViewedIDs){

				

				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;
								}
							}
						}						
					}
				}

				if(deepLinkID != null){
				
					for(var f=0; f <= videoList.length - 1; f++){
						if(videoList[f].id == deepLinkID){
							videoListIndex = f;
							validDeepLinkEpisode = true;
						}
					}
					
					if(validDeepLinkEpisode){
						vdSect = "DEEPLINK";

						for(var f=0; f <= allcollections.length - 1; f++){
							if(allcollections[f].id == deepLinkCollectionID){
								allcollectionsIndex = f;
							}
						}
					}else{
						alert("Video is no longer available.");
					}

				}
				
				if(params.collectionID != null && initialPlay){

					for(var f=0; f <= allcollections.length - 1; f++){
						if(allcollections[f].id == collectionID){
							allcollectionsIndex = f;
						}
					}

				}
				
				//Inital Play here 
					if(collectionID == "8a25c39218ef808e0118f1012d1a0013"){
						freeWheelSectionID = "cn.com_videos_premieres";
					}

					if(collectionID == "8a25c3921dabeacd011dabfc870c0005"){
						freeWheelSectionID = "cn.com_extras_instores";
					}

					if(collectionID == "8a25c3920d9d36d1010d9ec2ae870016"){
						freeWheelSectionID = "cn.com_extras_movietrailers";
					}
					
					if(collectionID == "8a250ab0230ec20c012334ad4f650371"){
						showHideVidNav(true);
					}else{
						showHideVidNav(false);
						writeVideoSeasonNavigation();
					}
					
					//writeVideoSeasonNavigation();
					writeEpisodeClipNavigation(vdSect, vdepType, vdseasonNumber); 

					if(initialPlay){
						writeVideoNavigation(vdSect, vdepType, vdseasonNumber);
						writeAllVideoNav();
						showSectionPlaying (vdSect);
						initializeAndPlayVideo(videoList[videoListIndex]);
						getMoreFromGenre(videoList[videoListIndex].collectionId, videoList[videoListIndex].genre, videoList[videoListIndex].collectionTitle);
					}
					
				////////////////////
					
				

			}
			
		}
	}
	
	function getMoreFromGenre(p_collectionId, p_genre, p_collectionTitle){
		
		associatedContentName = p_collectionTitle;	

		var gmfv_path = pathMoreEpisodeByShow  + "&filterByCollectionId=" + p_collectionId + "&limit=50&howMany=6&colGenre=" + p_genre + "&"; //r=" + timeStampNextGen;

		dsMoreEpisodesByShow = new Spry.Data.XMLDataSet(gmfv_path, "/episodes/episode", { subPaths: [ "segments/segment"] });
		dsMoreEpisodesByShow.addObserver(showEpisodeObserverFunc);
		dsMoreEpisodesByShow.loadData();
	
	}
	
	function getMoreFromCollectionId(p_collectionId){

		var gmfae_path = pathMoreGetAllEpisodes + "&limit=50&offset=0&sortByEpisodeRanking=DESC&filterByCollectionId=" + p_collectionId;
		
		dsMoreGetAllEpisodes = new Spry.Data.XMLDataSet(gmfae_path, "/episodes/episode", { subPaths: [ "segments/segment"] });
		dsMoreGetAllEpisodes.addObserver(showEpisodeObserverFunc);
		dsMoreGetAllEpisodes.loadData();
		
	}
	
	function getCategoryData(){
		var s = pathEpisodesByCategory  + "&id=multiCat&filterByCollectionId=" + collectionID + "&limit=" + resultsLimit + "&offset=0&r=" + timeStampNextGen

		dsEpisodesByCategory = new Spry.Data.XMLDataSet(s, "/episodes", { entityEncodeStrings: false });
		
		dsEpisodesByCategory.addObserver(categoryObserverFunc);
		dsEpisodesByCategory.loadData();

	}
	
	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 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 getVidConfigData(){

		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 });
		ndsMoreGetAllEpisodesPath	= new Spry.Data.NestedXMLDataSet(dsConfigInfo, "services/getAllEpisodes", { entityEncodeStrings: false });
		ndsMoreEpisodesByShowPath	= 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);
		ndsMoreGetAllEpisodesPath.addObserver(configObserverFunc);
		ndsMoreEpisodesByShowPath.addObserver(configObserverFunc);
		ndsEpisodesByIDsPath.addObserver(configObserverFunc);
		ndsVideoPlayListPath.addObserver(configObserverFunc);
		ndsRatingsPath.addObserver(configObserverFunc);
		ndsGetTimeStamp.addObserver(configObserverFunc);

		ndsallcollections.loadData();
		ndsEpisodesByCategoryPath.loadData();
		ndsEpisodesByShowPath.loadData();
		ndsMoreGetAllEpisodesPath.loadData();
		ndsMoreEpisodesByShowPath.loadData();
		ndsEpisodesByIDsPath.loadData();
		ndsVideoPlayListPath.loadData();
		ndsRatingsPath.loadData();
		ndsGetTimeStamp.loadData();
	
	}
	
	function getConfigNode(dsName, nodeName){

		var rows = dsName.getData(); 
		return rows[0][nodeName];

	}

	function startVideoLoad(){
		var vidEnvironment 	= (document.URL.indexOf("staging.cartoonnetwork.com") > -1) == true ? "stg" : "prd"; 

		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;

		}

		if(params.collectionID != null && initialPlay) {

			collectionID = params.collectionID;
			
			if(collectionID == "8a25c39218ef808e0118f1012d1a0013"){
				freeWheelSectionID = "cn.com_videos_premieres";
			}else if(collectionID == "8a250ab0230ec20c012334ad4f650371"){
				freeWheelSectionID = "cn.com_videos_whatsnew";
			}else if(freeWheelSectionID == "8a25c3921dabeacd011dabfc870c0005"){
				freeWheelSectionID = "cn.com_extras_instores";
			}else if(freeWheelSectionID == "8a25c3920d9d36d1010d9ec2ae870016"){
				freeWheelSectionID = "cn.com_extras_movietrailers";
			}else{
				freeWheelSectionID = "cn.com_videos_archive"; 
			}
			
		}else{

			collectionID = "8a250ab0230ec20c012334ad4f650371";
			freeWheelSectionID 	= "cn.com_videos_whatsnew";

		}

		if(params.episodeID != null){
			deepLinkID = params.episodeID;
		}

		getVidConfigData();
		
	}
	
	function allVideoLoad(p_allIndx, p_collectionID, p_freeWheelSectionID){
		
		if(p_collectionID != collectionID){
			resetVars();
			
			continuousPlayEnabled = false;
			document.getElementById('img_continuousplay').src = "/tools/img/video/contplayoff.gif"

			allcollectionsIndex = p_allIndx;
		
			if(document.getElementById('videoSlidingPanelsContentGroup')){
				document.getElementById('videoSlidingPanelsContentGroup').innerHTML = "<div style='color: #ffffff; padding-left:25px; padding-top:25px; font: bold 20px arial,helvetica,sans-serif;'>Loading...</div>";
			}
			
			//showHideVidNav(false);
			collectionID = p_collectionID;	
		
			freeWheelSectionID = p_freeWheelSectionID;		
			
			getVidConfigData();
			
		}
		
	}
	//end spry and episode data --------------------------------------------------------------------------------------------------------------------------//
	
	//Navigation controls --------------------------------------------------------------------------------------------------------------------------------//
	
	function initializeAndPlayVideo(p_vidArr){
		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];
	
				if(segDuration == ""){
					alert("Missing Duration");
					validVars = false;
				}
	
				if(segID == ""){
					alert("Missing SegmentID");
					validVars = false;
				}
	
	
				flashVideoCommunication.addSegment(segDuration, segID, segThumb);
			}			
			 
			flashVideoCommunication.collectionId		= validateVars(p_vidArr.collectionId, "collectionId") 			? p_vidArr.collectionId 		: null;
			flashVideoCommunication.collectionTitle		= validateVars(p_vidArr.collectionTitle, "collectionTitle") 	? p_vidArr.collectionTitle		: null;
			flashVideoCommunication.episodeId			= validateVars(p_vidArr.id, "id") 								? p_vidArr.id					: null;
			flashVideoCommunication.episodeType 		= validateVars(p_vidArr.episodeType, "episodeType") 			? p_vidArr.episodeType			: null;
			flashVideoCommunication.episodeTitle 		= validateVars(p_vidArr.title, "title") 						? p_vidArr.title				: null;
			flashVideoCommunication.pageUrl 			= pageUrl; 
			flashVideoCommunication.pathVideoPlayList	= validateVars(pathVideoPlayList, "pathVideoPlayList") 			? pathVideoPlayList				: null;
			flashVideoCommunication.playEndSlate 		= false;
			flashVideoCommunication.ranking 			= "0";
			flashVideoCommunication.sectionId 			= validateVars(freeWheelSectionID, "freeWheelSectionID") 		? freeWheelSectionID			: null;

			doDelayinitializeAndPlayVideo()

		}

		getMoreFromCollectionId(flashVideoCommunication.collectionId);

		initialPlay = false;

	}

	
	function doDelayinitializeAndPlayVideo(){
		if(videoPlayerIsReady()){
			flashVideoCommunication.playVideo();
		}else{
			videoTimer = setTimeout("doDelayinitializeAndPlayVideo()",200);
		}
		
	}
	
	function videoPlayerIsReady(){

		if(flashVideoCommunication.swfIsReady == false || flashVideoCommunication.videoAdPlaying){
			return false;
		}else{
			return true;
		}
		
	}
	
	
	function validateVars(p_var, p_name){
		if(p_var == null){
			validVars = false;
			alert("Missing " + p_name);
			return false;
		}else{
			return true;
		}
	}

	function playMoreFromVideo(val, p_fromLikeService){
		if(videoPlayerIsReady()){
			if(p_fromLikeService){
				highlightThumbnail(videoListIndex, false);

				hasReachPlayListEnd();

				initializeAndPlayVideo(moreVideoList[val]);
		
				getMoreFromGenre(moreVideoList[val].collectionId, moreVideoList[val].genre, moreVideoList[val].collectionTitle);
		
				document.tv_rating_img.src = moreVideoList[val].epiRatingImage;
		
				writeTitle(moreVideoList[val]);
				writeDescription(moreVideoList[val]);
				writeMoreButton(moreVideoList[val]);
			
				createRating(moreVideoList[val]);
			}else{
				highlightThumbnail(videoListIndex, false);
	
				hasReachPlayListEnd();

				initializeAndPlayVideo(moreFromVideoList[val]);
		
				getMoreFromGenre(moreFromVideoList[val].collectionId, moreFromVideoList[val].genre, moreFromVideoList[val].collectionTitle);
		
				document.tv_rating_img.src = moreFromVideoList[val].epiRatingImage;
		
				writeTitle(moreFromVideoList[val]);
				writeDescription(moreFromVideoList[val]);
				writeMoreButton(moreFromVideoList[val]);
				
				createRating(moreFromVideoList[val]);
			}				
		}		
	}
	
	
	function playVideo(val){
		if(videoPlayerIsReady()){
	
			highlightThumbnail(videoListIndex, false); 
	
			
			if(val.toString() == "next"){
				videoListIndex = locateNextVideo();
			}else{
				videoListIndex = parseInt(val);
			}
			
			hasReachPlayListEnd();
			initializeAndPlayVideo(videoList[videoListIndex]);
	
			getMoreFromGenre(videoList[videoListIndex].collectionId, videoList[videoListIndex].genre, videoList[videoListIndex].collectionTitle);
	
			highlightThumbnail(videoListIndex, true);
	
			document.tv_rating_img.src = videoList[videoListIndex].epiRatingImage;
	
			writeTitle(videoList[videoListIndex]);
			writeDescription(videoList[videoListIndex]);
			writeMoreButton(videoList[videoListIndex]);
			
			createRating(videoList[videoListIndex]);
		}		
	}
	
	function locateNextVideo(){
		
		var nextAutoPlayIndex = autoPlayList[0];
		
		for(var x=0; x <= autoPlayList.length - 1; x++){

			if(videoListIndex == autoPlayList[x]){			
				nextAutoPlayIndex = x == autoPlayList.length - 1 ? autoPlayList[x] : autoPlayList[x + 1];
			}
		
		}
		
		return nextAutoPlayIndex;
		
	}
	
	function hasReachPlayListEnd(){
			
		var nextAutoPlayIndex = autoPlayList[0];
		
		for(var x=0; x <= autoPlayList.length - 1; x++){
			
			if(videoListIndex == autoPlayList[x]){

				if(x == autoPlayList.length - 1){
					reachedPlayListEnd = true;
				}else{
					reachedPlayListEnd = false;
				}
			}
		}			
	}

	function writeVideoNavigation(p_cat, p_epType, p_seasonNumber){
		
		writeTitle(videoList[videoListIndex]);
		writeDescription(videoList[videoListIndex]);
		writeMoreButton(videoList[videoListIndex]);
		
		createRating(videoList[videoListIndex]);
		
		highlightThumbnail(videoListIndex, true);
		
		document.tv_rating_img.src = videoList[videoListIndex].epiRatingImage;

		reachedPlayListEnd = autoPlayList.length == 1 ? true : false;

	}

	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 += "<div><a class='videoNavLinks' href=" + '"' + "JavaScript:showHideVideoNavDiv('dsVidNav_"+ categoryData[x].categoryShortName +"'); writeEpisodeClipNavigation('"+ categoryData[x].categoryShortName +"', '"+ linkVarClipType +"','"+linkVarSeason +"');" + '" ';
				content += "id='videolink" + categoryData[x].categoryShortName + "'>";
				content += categoryData[x].categoryName  + " (" + categoryData[x].totalItems + ")";
				content += "</a></div>";
				
				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:writeEpisodeClipNavigation('"+ categoryData[x].categoryShortName +"', '"+linkVarClipType+"','" + nodeFullEpSeasons[n].seasonNumber +  "');" + '"' + "  >";
						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:writeEpisodeClipNavigation('"+ categoryData[x].categoryShortName +"', '" +linkVarClipType+ "','" + nodeClipsSeasons[n].seasonNumber +  "');" + '"' + "  >";
						content += nodeClipsSeasons[n].seasonName ;
						content += "</a></div>";		
					}
		
					document.getElementById("dsVidNav_"+categoryData[x].categoryShortName+"Seasons").innerHTML = content;
				}
			}
		}
	}
	
	
	function writeEpisodeClipNavigation(p_cat, p_epType, p_seasonNumber){

		var content = "";

		autoPlayList = null;
		autoPlayList = new Array(0);
		
		content += "<div><img src='http://i.cdn.turner.com/toon/tools/img/pixel.gif' border='0' height='15' width='400'></div>" 


		switch (p_cat) {
		
			case "RECENT" :

				for(n=0; n <= videoList.length - 1; n++){
					if(videoList[n].recentlyAdded){
						autoPlayList.push(n);
						content += returnNavigationString(n, p_cat);
					}
				}
				autoPlayList.reverse
			
			break;

			case "FULLEP" :
				
				for(n=0; n <= videoList.length - 1; n++){
					if(p_seasonNumber == videoList[n].epiSeasonNumber && p_epType == videoList[n].episodeType){
						autoPlayList.push(n);
						content += returnNavigationString(n, p_cat);
					}
				}
				autoPlayList.reverse
				
			break;

			case "CLIPS" :
				
				for(n=0; n <= videoList.length - 1; n++){
					if(p_seasonNumber == videoList[n].epiSeasonNumber && p_epType == videoList[n].episodeType){
						autoPlayList.push(n);
						content += returnNavigationString(n, p_cat);
					}
				}
				autoPlayList.reverse
			
			break;

			case "TOPRATED" :

				for(n=0; n <= videoList.length - 1; n++){
					if(videoList[n].topRated){
						autoPlayList.push(n);
						content += returnNavigationString(n, p_cat);
					}
				}
				autoPlayList.reverse
			
			break;
			
			case "MOSTVIEWED" :
			
				for(n=0; n <= videoList.length - 1; n++){
					if(videoList[n].mostViewed){
						autoPlayList.push(n);
						content += returnNavigationString(n, p_cat);
					}
				}
				autoPlayList.reverse
			
			break;
			
			case "DEEPLINK" :
			
				for(n=0; n <= videoList.length - 1; n++){
					if(videoList[n].id == params.episodeID){
						autoPlayList.push(n);
						content += returnNavigationString(n, p_cat);
					}
				}
				autoPlayList.reverse
			
			break;
			
			default:
				
				for(n=0; n <= videoList.length - 1; n++){
					autoPlayList.push(n);
					content += returnNavigationString(n, p_cat);
				}
				autoPlayList.reverse
				
			break;
		
		}

		content += "<div><img src='http://i.cdn.turner.com/toon/tools/img/pixel.gif' border='0' height='45' width='400'></div>" 

		document.getElementById('videoSlidingPanelsContentGroup').innerHTML = content;

		
		for(i=0; i<= autoPlayList.length - 1; i++){
 			
			var rateNameStr = "videolistrating_" + videoList[autoPlayList[i]].id;
			var rateNameStr2 = "videolistrating_" + videoList[autoPlayList[i]].id + "_2";

			var rateVal		= videoList[autoPlayList[i]].ranking;

			var widgetname = new Spry.Widget.Rating(rateNameStr,{ratingValue:rateVal, readOnly:true}); 
			var widgetname = new Spry.Widget.Rating(rateNameStr2,{ratingValue:rateVal, readOnly:true}); 

		}
		
		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>" ;
			}
		}
		
		if(p_cat == currentCategory || p_cat == ""){
			highlightThumbnail(videoListIndex, true);
		}
		
		doUpdateVideoScrollBars("videoListAreaComplete");

	}
	
	function writeAllVideoNav(){

		var content = "";
			
		content += "<div><img src='http://i.cdn.turner.com/toon/tools/img/pixel.gif' border='0' height='8' width='265'></div>" 
		
		for(i=0; i<=allcollections.length -1; i++){
			content += returnAllVideoNavigationString(i, allcollections[i].category);
		}

		content += "<div><img src='http://i.cdn.turner.com/toon/tools/img/pixel.gif' border='0' height='15' width='265'></div>" 
			
		document.getElementById('video_allVideo').innerHTML = content;

		doUpdateVideoScrollBars("allVideoAreaComplete");
		
	}
	
	
	function writeTitle(p_vidArr){

		var content = p_vidArr.title;
		
		document.getElementById('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_morebutton' href='" + allcollections[indexNum].contextpageurl + "'>" + upperStr.toUpperCase() + "</a>";
		}else{
			content = "";
		}

		document.getElementById('html_morebutton').innerHTML = content; 

	}
	
	function writeDescription(p_vidArr){

		var content = p_vidArr.description;
		
		document.getElementById('rating_init').value = p_vidArr.ranking;
		
		document.getElementById('html_description').innerHTML = content; 

	}
	
	function writeAssociatedBottomContent(){
		
		var content = "";

			content += '	<div id="videoAC3">MORE VIDEOS LIKE THIS:</div>';
			content += '	<div id="videoAC4">';

		for(var n=0; n <= 2; n++){


			content += 		"	<div class='video_association_clip' style='background: url(";

			if(moreVideoList[n]){
				content += 	moreVideoList[n].thumb;
			}else{
				content += 	"http://i.cdn.turner.com/toon/tools/img/pixel.gif";
			}

			content += 		") no-repeat;'>";
			content += 		"		<a href='javascript:playMoreFromVideo(" + n + ", true);'><img class='video_thumb_overlay_sash' width='45' height='80' border='0' src='"

			if(moreFromVideoList[n]){
				content += moreVideoList[n].epiOverlayURL == "" ? "http://i.cdn.turner.com/toon/tools/img/pixel.gif" : moreVideoList[n].epiOverlayURL;
			}else{
				content += "http://i.cdn.turner.com/toon/tools/img/pixel.gif";
			}

			content += 				"'/></a>";
			content += 		"	</div>";
		}

			content += '	</div>';
		
		document.getElementById('video_association_bottom').innerHTML = content; 
	
	}
	
	
	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' style='background: url(";
			content += 	moreFromVideoList[indexArray[n]].thumb;
			content += 		") no-repeat;'>";
			content += 		"<a href='javascript:playMoreFromVideo(" + indexArray[n] + ", false);'><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>";
			content += 		"	</div>";
		}

			content += '	</div>';
		
		document.getElementById('video_association_top').innerHTML = content; 
	
	}
	

	
	function returnNavigationString(n, p_section){

		var s = "";
		s += "<div id='vid" + videoList[n].id + "VidHover' style='display:none;'>";
		s += "	<div class='vidHoverStyleVert'>";
		s += "		<div class='vidHoverImgWrapperVert' >";

		s += "	<div  style='background: url("+ videoList[n].thumb +") no-repeat; overflow:hidden; height:45px; width:80px; float:left; position: absolute;'>";
		s += "		<img width='80' height='45' border='0' src='"
		s += videoList[n].epiOverlayURL == "" ? "http://i.cdn.turner.com/toon/tools/img/pixel.gif" : videoList[n].epiOverlayURL;
		s += "'/>";
		s += "	</div>";

		
		s += "		</div>";
		s += "		<div class='vidHoverTextWrapperVert'>";
		s += "			<div class='vidHoverTitleVert'>" + videoList[n].title + "</div>";
		s += "			<div class='vidHoverDescriptionVert'>" + videoList[n].description + "</div>";
		s += "			<div class='vidHoverStatsVert'>"+ returnRatingsString(videoList[n].ranking, videoList[n].id + "_2") + " <br clear='all' /><br clear='all' /> " + videoList[n].numberOfViews + " VIEWS</div>";
		s += "		</div>";
		s += "		<br clear='all' />";
		s += "	</div>";
		s += "</div>";

		
		s += "<div class='videoSlidingPanelsContent' id='videoContentPanel" + n + "'  >";

		s += "	<div class='video_thumb_img' id='thumbroll" + n + "' name='thumbroll" + n + "'  style='background: url("+ videoList[n].thumb +") 2px no-repeat;'>";
		s += "		<img class='video_thumb_overlay_sash' width='45' height='80' border='0' src='"
		s += videoList[n].epiOverlayURL == "" ? "http://i.cdn.turner.com/toon/tools/img/pixel.gif" : videoList[n].epiOverlayURL;
		s += "'/>";
		s += "		<img class='video_thumb_overlay' id='videothumb" + n + "' width='45' height='80' border='0' src='"
		s += "http://i.cdn.turner.com/toon/tools/img/pixel.gif";
		s += "'/>";
		s += "	</div>";

		s += "	<div id='video_thumb_view'> " + videoList[n].numberOfViews + " VIEWS </div>";	
		s += "	<div id='video_thumb_rank'><div>" + returnRatingsString(videoList[n].ranking, videoList[n].id) + "</div></div>";

		s += "	<div id='video_thumb_inv_btn'>";
		s += "		<a href='javascript:playVideo(" + n + "); showSectionPlaying(" + '"' + p_section + '"' + ");' class='showTip vid" + videoList[n].id +"VidHover' ><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, p_section){

		var s = "";
		
		var fwSection = allcollections[n].category == "Extras" ? "cn.com_extras_homepage" : "cn.com_videos_archive";
		
		if(allcollections[n].id == "8a25c39218ef808e0118f1012d1a0013"){
			fwSection = "cn.com_videos_premieres";
		}
		
		if(allcollections[n].id == "8a250ab0230ec20c012334ad4f650371"){
			fwSection = "cn.com_videos_whatsnew";
		}

		if(allcollections[n].id == "8a25c3921dabeacd011dabfc870c0005"){
			fwSection = "cn.com_extras_instores";
		}
		
		if(allcollections[n].id == "8a25c3920d9d36d1010d9ec2ae870016"){
			fwSection = "cn.com_extras_movietrailers";
		}
		
		s += "<div class='allVideoImg'>";
		s += "		<a href='javascript:allVideoLoad(" + n + ',"' + allcollections[n].id + '","' + fwSection + '");' + "'>";
		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;
		
	}
	
	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 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(num, state){
	
		var elmID = "videothumb" + num.toString();
			
		if(document.getElementById(elmID)){
			document.getElementById(elmID).src = (state) ? "/video/tools/img/playing.gif" : "http://i.cdn.turner.com/toon/tools/img/pixel.gif";
			document.getElementById(elmID).className = (state) ? "video_thumb_overlay_playing" : "video_thumb_overlay";
		}
		
		var elm2ID = "videoContentPanel" + num.toString();
		
		if(document.getElementById(elm2ID)){
//			document.getElementById(elm2ID).className = (state) ? "videoSlidingPanelsContentPlaying" : "videoSlidingPanelsContent";
		}
		
	}


	function doUpdateVideoScrollBars(p_area){

		switch(p_area){
			case "allVideoAreaComplete" :
				resetVAVScroller();
			break;
			
			case "videoListAreaComplete" :
				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 ratingMsg(){	
		
		document.getElementById('rating_thanks').style.display = "block";
		
		setTimeout("clearRatingMsg()", 5000);
	}
		
	function clearRatingMsg(){
		document.getElementById('rating_thanks').style.display = "none" 
	}
	
	//end navigation controls ------------------------------------------------------------------------------------------------------------------------------//

	//flash communication ----------------------------------------------------------------------------------------------------------------------------------//

	flashVideoCommunication.onVideoStateChange = function (val){

		if(val == "ENDED" && reachedPlayListEnd == false && continuousPlayEnabled){
			playVideo("next");
		}else if(val == "ENDED"){
			flashVideoCommunication.onShowEndSlate();	
		}

	}
	
	//end flash communication --------------------------------------------------------------------------------------------------------------------------------//
