var playlist = '';

var VideoData = new Object();
VideoData.loaded = false;
VideoData.mode = 'single';
// max search results
VideoData.maxResults = 40; 
VideoData.lastSearch = '';
// defaultTab
VideoData.current_tab = '';

function $(e) { return document.getElementById(e); }

var Player = {};
Player.overrideVideoAd = true;
Player.overridePreRoll = '/video/preroll_std.ad';
Player.overrideSyncUnit = '/video/sync.300x250.ad';

// sections :
// IMPORTANT: This list is sorted by video paths (highest level), shortest to longest (deepest level)
VideoData.sections = [
{ 
		section: '/video', 
		name: 'PGA TOUR Video',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&page.allowcompete=yes',
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&page.allowcompete=yes',
		sync_ad: '/video/sync.300x250.ad',
		preroll: '/video/preroll_std.ad',
		site_section: 'pgatour.com_main'
	},{ 
		section: '/video/pga-tour', 
		name: 'PGA TOUR ',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=pgatour&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=pgatour&page.allowcompete=yes' ,
		sync_ad: '/video/pga-tour/sync.300x250.ad',
		preroll: '/video/pga-tour/preroll_std.ad',
		site_section: 'pgatour.com_main'
	}, { 
		section: '/video/pga-tour/tour-today',
		name: 'PGA TOUR Today',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=tour_today&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=tour_today&page.allowcompete=yes' ,
		sync_ad: '/video/pga-tour/tour_today/sync.300x250.ad',
		preroll: '/video/pga-tour/tour_today/preroll_std.ad',
		site_section: 'pgatour.com_pgatour_pgatourtoday'
	}, { 
		section: '/audio/interviews',
		name: 'XM Audio',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=audio&pgatour_subsection=interviews&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=audio&pgatour_subsection=interviews&page.allowcompete=yes' ,
		sync_ad: '/video/audio/interviews/sync.300x250.ad',
		preroll: '/video/audio/interviews/preroll_std.ad',
		site_section: 'pgatour.com_audio'
	}, { 
		section: '/audio/news-conferences', 
		name: 'Audio Conferences',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=audio&pgatour_subsection=news-conferences&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=audio&pgatour_subsection=news-conferences&page.allowcompete=yes' ,
		sync_ad: '/video/audio/news-conferences/sync.300x250.ad',
		preroll: '/video/audio/news-conferences/preroll_std.ad',
		site_section: 'pgatour.com_audio'
	}, { 
		section: '/audio/xm', 
		name: 'XM',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=audio&pgatour_subsection=xm&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=audio&pgatour_subsection=xm&page.allowcompete=yes' ,
		sync_ad: '/video/audio/xm/sync.300x250.ad',
		preroll: '/video/audio/xm/preroll_std.ad',
		site_section: 'pgatour.com_audio'
	}, { 
		section: '/video/champions-tour', 
		name: 'Champions Tour',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=champions&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=champions&page.allowcompete=yes' ,
		sync_ad: '/video/champions-tour/sync.300x250.ad',
		preroll: '/video/champions-tour/preroll_std.ad',
		site_section: ''
	}, { 
		section: '/multimedia/channels/champions-tour/features_and_highlights',
		name: 'Champions Features',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=champions&pgatour_subsection=features&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=champions&pgatour_subsection=features&page.allowcompete=yes' ,
		sync_ad: '/video/champions-tour/features/sync.300x250.ad',
		preroll: '/video/champions-tour/features/preroll_std.ad',
		site_section: 'pgatour.com_champions_featureshighlights'
	}, { 
		section: '/video/champions-tour/highlights/winners_interview',
		name: 'Champions Tour Winners Interview',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=champions&pgatour_subsection=highlights&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=champions&pgatour_subsection=highlights&page.allowcompete=yes' ,
		sync_ad: '/video/champions-tour/highlights/sync.300x250.ad',
		preroll: '/video/champions-tour/highlights/preroll_std.ad',
		site_section: 'pgatour.com_champions_featureshighlights'
	}, { 
		section: '/video/flyovers', 
		name: 'Flyovers',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=flyovers&pgatour_subsection=pga-tour&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=flyovers&pgatour_subsection=pga-tour&page.allowcompete=yes' ,
		sync_ad: '/video/flyovers/sync.300x250.ad',
		preroll: '/video/flyovers/preroll_std.ad',
		site_section: 'pgatour.com_pgatour_flyovers'
	}, { 
		section: '/video/pga-tour/features/flyovers',
		name: 'Flyovers',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=flyovers&pgatour_subsection=pgatour&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=flyovers&pgatour_subsection=pgatour&page.allowcompete=yes' ,
		sync_ad: '/video/flyovers/pga-tour/sync.300x250.ad',
		preroll: '/video/flyovers/pga-tour/preroll_std.ad',
		site_section: 'pgatour.com_pgatour_flyovers'
	}, { 
		section: '/video/instruction',
		name: 'Instruction',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=instruction&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=instruction&page.allowcompete=yes' ,
		sync_ad: '/video/instruction/sync.300x250.ad',
		preroll: '/video/instruction/preroll_std.ad',
		site_section: 'pgatour.com_instruction'
	},{ 
		section: '/video/instruction/golf-academy',
		name: 'TOUR Academy',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=instruction&pgatour_subsection=golf-academy&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=instruction&pgatour_subsection=golf-academy&page.allowcompete=yes' ,
		sync_ad: '/video/instruction/golf-academy/sync.300x250.ad',
		preroll: '/video/instruction/golf-academy/preroll_std.ad',
		site_section: 'pgatour.com_instruction'
	}, { 
		section: '/video/instruction/pro-tips',
		name: 'Pro Tips',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=instruction&pgatour_subsection=pro-tips&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=instruction&pgatour_subsection=pro-tips&page.allowcompete=yes' ,
		sync_ad: '/video/instruction/pro-tips/sync.300x250.ad',
		preroll: '/video/instruction/pro-tips/preroll_std.ad',
		site_section: 'pgatour.com_instruction'
	},{
		section: '/video/instruction/pro_fitness',
		name: 'Pro Fitness',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=instruction&pgatour_subsection=pro-fitness&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=instruction&pgatour_subsection=pro-fitness&page.allowcompete=yes' ,
		sync_ad: '/video/instruction/pro-fitness/sync.300x250.ad',
		preroll: '/video/instruction/pro-fitness/preroll_std.ad',
		site_section: 'pgatour.com_instruction'
	}, {
		section: '/video/instruction/team_nationwide', 
		name: 'Team Nationwide',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=instruction&pgatour_subsection=team_nationwide&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=instruction&pgatour_subsection=team_nationwide&page.allowcompete=yes' ,
		sync_ad: '/video/instruction/team_nationwide/sync.300x250.ad',
		preroll: '/video/instruction/team_nationwide/preroll_std.ad',
		site_section: 'pgatour.com_instruction'
	}, { 
		section: '/video/instruction/titleist', 
		name: 'Titleist Performance Institute',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=instruction&pgatour_subsection=performance_institute&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=instruction&pgatour_subsection=performance_institute&page.allowcompete=yes' ,
		sync_ad: '/video/instruction/performance_institute/sync.300x250.ad',
		preroll: '/video/instruction/performance_institute/preroll_std.ad',
		site_section: 'pgatour.com_instruction'
	}, { 
		section: '/video/nationwide-tour', 
		name: 'Nationwide Tour',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=nationwide&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=nationwide&page.allowcompete=yes' ,
		sync_ad: '/video/nationwide-tour/sync.300x250.ad',
		preroll: '/video/nationwide-tour/preroll_std.ad',
		site_section: ''
	}, { 
		section: '/video/nationwide-tour/features', 
		name: 'Nationwide Features',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=nationwide&pgatour_subsection=features&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=nationwide&pgatour_subsection=features&page.allowcompete=yes' ,
		sync_ad: '/video/nationwide-tour/features/sync.300x250.ad',
		preroll: '/video/nationwide-tour/features/preroll_std.ad',
		site_section: 'pgatour.com_nationwide_featureshighlights'
	}, { 
		section: '/multimedia/channels/nationwide-tour/features_and_highlights',
		name: 'Nationwide Tour Highlights',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=nationwide&pgatour_subsection=highlights&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=nationwide&pgatour_subsection=highlights&page.allowcompete=yes' ,
		sync_ad: '/video/nationwide-tour/highlights/sync.300x250.ad',
		preroll: '/video/nationwide-tour/highlights/preroll_std.ad',
		site_section: 'pgatour.com_nationwide_featureshighlights'
	}, { 
		section: '/multimedia/channels/pga-tour/features',
		name: 'PGA TOUR Features',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=features&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=features&page.allowcompete=yes' ,
		sync_ad: '/video/pga-tour/features/sync.300x250.ad',
		preroll: '/video/pga-tour/features/preroll_std.ad',
		site_section: 'pgatour.com_pgatour_features'
	}, { 
		section: '/video/pga-tour/fedexcup',
		name: 'FedExCup',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=fedexcup&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=fedexcup&page.allowcompete=yes' ,
		sync_ad: '/video/fedexcup/sync.300x250.ad',
		preroll: '/video/fedexcup/preroll_std.ad',
		site_section: 'pgatour.com_pgatour_fedexcup'
	}, { 
		section: '/video/pga-tour/features/opening_shot',
		name: 'Opening Shot',	  
		ad234_1: 'site=pgatour&pgatour_pos=234x60_spon&pgatour_rollup=video&pgatour_section=opening_shot&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_spon2&pgatour_rollup=video&pgatour_section=opening_shot&page.allowcompete=yes' ,
		sync_ad: '/video/opening_shot/sync.300x250.ad',
		preroll: '/video/opening_shot/preroll_std.ad',
		site_section: 'pgatour.com_pgatour_openingshot'
	}, { 
		section: '/multimedia/channels/pga-tour/highlights',
		name: 'PGA TOUR Highlights',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=highlights&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=highlights&page.allowcompete=yes' ,
		sync_ad: '/video/pga-tour/highlights/sync.300x250.ad',
		preroll: '/video/pga-tour/highlights/preroll_std.ad',
		site_section: 'pgatour.com_pgatour_highlights'
	}, { 
		section: '/video/pga-tour/highlights/rocksolid', 
		name: 'Rock Solid',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_spon&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=prudential_rock_solid&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_spon2&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=prudential_rock_solid&page.allowcompete=yes' ,
		sync_ad: '/video/pga-tour/prudential_rock_solid/sync.300x250.ad',
		preroll: '/video/pga-tour/prudential_rock_solid/preroll_std.ad',
		site_section: ''
	}, { 
		section: '/video/pga-tour/onsite', 
		name: 'PGA TOUR Highlights',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=onsite&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=onsite&page.allowcompete=yes' ,
		sync_ad: '/video/pga-tour/onsite/sync.300x250.ad',
		preroll: '/video/pga-tour/onsite/preroll_std.ad',
		site_section: ''
	}, {
		section: '/video/pga-tour/sod',
		name: 'Shot of the Day',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=sod&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=sod&page.allowcompete=yes' ,
		sync_ad: '/video/pga-tour/sod/sync.300x250.ad',
		preroll: '/video/pga-tour/sod/preroll_std.ad',
		site_section: 'pgatour.com_pgatour_shotoftheday'
	}, {
		section: '/video/pga-tour/highlights/shot_of_the_day',
		name: 'Shot of the Day',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=sod&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=sod&page.allowcompete=yes' ,
		sync_ad: '/video/pga-tour/sod/sync.300x250.ad',
		preroll: '/video/pga-tour/sod/preroll_std.ad',
		site_section: 'pgatour.com_pgatour_shotoftheday'
	}, { 
		section: '/video/pga-tour/topshots', 
		name: 'Top Shots',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=top_shots&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=top_shots&page.allowcompete=yes' ,
		sync_ad: '/video/pga-tour/topshots/sync.300x250.ad',
		preroll: '/video/pga-tour/topshots/preroll_std.ad',
		site_section: 'pgatour.com_pgatour_memorablemoments'
	}, {
		section: '/video/pga-tour/highlights/memorable_moments',
		name: 'Memorable Moments',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=top_shots&page.allowcompete=yes' ,
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=top_shots&page.allowcompete=yes' ,
		sync_ad: '/video/pga-tour/topshots/sync.300x250.ad',
		preroll: '/video/pga-tour/topshots/preroll_std.ad',
		site_section: 'pgatour.com_pgatour_memorablemoments'
	}, {
		section: '/video/microsites/usopen', 
		name: 'US Open',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=pga-tour&pgatour_subsection=us_open&page.allowcompete=yes',
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=pga-tour&pgatour_subsection=us_open&page.allowcompete=yes',
		sync_ad: '/video/pga-tour/us_open/sync.300x250.ad',
		preroll: '/video/pga-tour/us_open/preroll_std.ad',
		site_section: ''
	}, {
		section: '/video/pga-tour/features/in_the_bag',
		name: 'In The Bag Video',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=in_the_bag&page.allowcompete=yes',
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&pgatour_section=pgatour&pgatour_subsection=in_the_bag&page.allowcompete=yes',
		sync_ad: '/video/pgatour/in_the_bag/sync.300x250.ad',
		preroll: '/video/pgatour/in_the_bag/preroll_std.ad',
		site_section: 'pgatour.com_pgatour_inthebag'
	}, {
		section: '/video/microsites/masters', 
		name: 'The Masters',
		ad234_1: 'site=pgatour&pgatour_pos=234x60_sync&pgatour_rollup=video&page.allowcompete=yes',
		ad234_2: 'site=pgatour&pgatour_pos=234x60_sync2&pgatour_rollup=video&page.allowcompete=yes',
		sync_ad: '/video/sync.300x250.ad',
		preroll: '/video/preroll_std.ad',
		listSource: 'cms',
		site_section: ''
	}
];

// VideoPage Navigation
function HideVideoLinks() {
	var MainLinks = new Array ("tourVideoNav1", "tourVideoNav2", "tourVideoNav3");
	var SubLinks = new Array ("tourVideoLatest", "tourVideoPopular", "tourVideoChannel", "tourVideoSearchResults");
	for (var i=0; i<MainLinks.length; i++) {
		if ($(MainLinks[i])) {
			$(MainLinks[i]).className = "tourTabNavItem";
			$(MainLinks[i]).hideFocus = true;
		}
	}

	for (var i=0; i<SubLinks.length; i++) {	
		if ($(SubLinks[i])) {
			$(SubLinks[i]).className = "tourVideoLatest hide";
		}
	}
}
function ShowVideoLink(MainLinkId, SubLinkId) {
	if ($(MainLinkId)) {
		$(MainLinkId).className = "tourTabNavItem TabNavactive";
	}
	if ($(SubLinkId)) {
		$(SubLinkId).className = "tourVideoLatest show";
	}
}
function VideoMenu(MainLinkId, SubLinkId) {
	HideVideoLinks();
	ShowVideoLink(MainLinkId, SubLinkId);
	VideoData.current_tab = SubLinkId;
}

var currentPlaylist;
var currentChannelIndex = 0; // Defaults to PGATOUR video;

// Video Play function
function play_video(video, override) {
	if(isAdPlaying) {	//prevent changing video during ad playback
		return;
	}
	
	if(typeof video == 'string') {	//if video is a string, it is a single video
		cvp_playVideo(video);
	} else {	//else it's a playlist of videos size 1 to n
		var len = video.length;
		if(len == 0) {	//no playlist, just return
			return;
		}
		
		var currId = video[0].url;
		currId = cvp_prepareVideoId(currId);
		
		cvp_playVideo(currId);	//play the first
		cvp_enqueueVideos(video, currId);	//queue the rest
	}
}

// Channel Changer
function change_channel(channel, autoplay){
	if (autoplay == null) autoplay = true;
	
	if (VideoData.current_tab != 'tourVideoChannel') {
		VideoMenu('tourVideoNav3', 'tourVideoChannel');
		VideoData.current_tab == 'tourVideoChannel';
	}
	
	for (var i=0; i<VideoData.sections.length; i++) {
		if (channel == VideoData.sections[i].section) {
			currentChannelIndex = i;
			break;
		}
	}
	
	var currentChan = VideoData.sections[currentChannelIndex];
	
	// Load top and bottom 234x60 ads
	//if ($('ad234x60_1')) $('ad234x60_1').src="http://ads.pgatour.com/html.ng/"+VideoData.sections[currentChannelIndex].ad234_1 + "&tile="+cnnad_tileID;
	//if ($('ad234x60_2')) $('ad234x60_2').src="http://ads.pgatour.com/html.ng/"+VideoData.sections[currentChannelIndex].ad234_2 + "&tile="+cnnad_tileID;

	// get list source path
	var dotElementBasePath = (currentChan.listSource && currentChan.listSource == 'cms')? 
			'/.element/ssi/auto/3.0/cms/sect/video' : '/.element/ssi/auto/3.0/aps/sect/video';
	
	// change contents of Channel Window
	tourAjaxContentLoader('channels_video_list', dotElementBasePath+channel+'/videos_list.html');
	
	// Update channel Title
	$('video_section_title').innerHTML = currentChan.name.toUpperCase();
	$('channel_name').innerHTML = currentChan.name.toUpperCase();
	
	// change iframe top ten video loader
	if (autoplay) {
		$('top_ten').src = dotElementBasePath+channel+'/top_10_videos.iframe.html';
	}
	
	//set the correct site section for Freewheel
	tourCVPMain.setAdSection(currentChan.site_section);
	
	//make it so an ad prerolls after channel change
	//tourCVPMain.resetAdFrequency();
}

//per ticket: PGATOUR-3116, make the page default to the latest videos, with auto-play option
function defaultToLatestVideos(autoplay) {
	//show latest videos, hide channels
	VideoMenu('tourVideoNav1', 'tourVideoLatest');
	
	//import the top 10 latest videos playlist, and play them starting from the most recent
	if(autoplay) {
		$('top_ten').src = '/.element/ssi/auto/3.0/aps/sect/video/multimedia/latest/top_10_videos.iframe.html';
	}
	
	//var adDiv = $$('div.tour234AdSpace')
	//adDiv[0].innerHTML = '';

	tourCVPMain.setAdSection('pgatour.com_pgatour_latestvideos');	//set site_section to latest videos
}

// What do I do first?
function initialize_video_page () {
	var q = '';
	var search = getParam('s');
	var channel = getParam('c');
	if (search) {
		// Go to video search
		q = search.replace(/\+/g, ' ');
		$('video_search_string').value = q;
		video_search();
		return;
	} else if (channel)	{
		change_channel(channel);
		return;
	}
	else {
		// Process what is being called
		var regex = new RegExp( "[?](.*)$" );
		var results = regex.exec( window.location.href );
		if (results){
			if (results.length == 2) q = results[1];
		}
	}
	
	// Fix for mal-formed urls
	q = q.replace('/video/?','');
	
	//CVP sharing on Facebook requires that the URL be decoded for the link to work correctly
	q = decodeURIComponent(q);
	q = q.replace('/video/video', '/video');	//also remove extra /video, if it exists.
	
	// default
	if (q == '') { defaultToLatestVideos(true); return; }
	
	// q is most popular
	if (q == 'mostpopular' || q == 'popular') {
		VideoMenu('tourVideoPopular'); return;
	}
	// q is latest videos
	if (q == 'latest') {
		VideoMenu('tourVideoLatest'); return;
	}
	// q is a video
	if (q.match(/[a-z]+\/[0-9][0-9][0-9][0-9]\/[0-9][0-9]\/[0-9][0-9]/)) {
		if (!q.match(/^\/video\/video/) && !q.match(/^\/video\/audio/)) q = '/video'+q;
		for (var i=0; i<VideoData.sections.length; i++) {
			if (q.indexOf(VideoData.sections[i].section+'/20') >= 0) { 
				if (q.indexOf('instr_depuy_mitek') > -1) {
					change_channel('/video/instruction/pro_fitness', false);
				}
				else {
					change_channel(VideoData.sections[i].section, false);
				}
				continue;
			}
		}
		if (q.indexOf('openingshot') > -1 )	{
			change_channel('/video/pga-tour/fedexcup/opening_shot', false);
		}
		
		play_video (q); return;

	}
	
	
	// q is a video channel
	for (var i=0; i<VideoData.sections.length; i++) {
		if (q == VideoData.sections[i].section || q == '/video'+VideoData.sections[i].section) {
			change_channel(VideoData.sections[i].section); return
		}
	}
	change_channel('/video/pga-tour/features'); 
}

// Video Search --------------------------------------
function video_search() {
	var q = $('video_search_string').value;
	q = q.replace(/ /g, '+');
	if (q) {
		VideoData.lastSearch = q;
		VideoMenu('x','tourVideoSearchResults');
		
		//function to call updated SearchProcessor to return query results
		$('videoSearchTerm').innerHTML = q;

		coreUpdateQuery(q);
		document.getElementById('video_search_string').value = "";
		
	}
}
// top.populateSearchResults(String query,int totalResults, int remainingResults);

function getpage(page) {
	$('search_results').src = 'http://search.pgatour.com/pages/freeSearch.jsp?query='+VideoData.lastSearch+'&numPerPage='+VideoData.maxResults + '&currentPage=' + page;
}

function populateSearchResults (query, total, remaining) {
	if (total == null || remaining == null) return false;
	var pages = Math.ceil(total / VideoData.maxResults);
	var page = Math.floor((total - remaining) / VideoData.maxResults);
	var j = 0;
	var nav = ''; 
	var nav_head = '<b>Page</b> : &nbsp; ';

	for (var i = 1; i <= pages; i++) {
		if ((i >= (page - 5)|| i >= (pages - 10)) && j < 10) {
			if (i == page) nav += '<u>'+i+'</u> ';
			else nav += '<a href="javascript:getpage(\''+i+'\');">'+i+'</a> ';
			j++;
		} else {
			if (j == 10 && i < pages) { 
				nav += ' ... <a href="javascript:getpage(\''+pages+'\');">'+pages+'</a>'; j++; 
			} else if (nav == '') {
				nav += '<a href="javascript:getpage(\'1\');">1</a> ... ';
			}
		}
	}
	$('search_nav').innerHTML = nav_head+nav;
	// currentPage
}

