//animation fix... disable button clickability for brief animation period
var is_enabledBVPBtns = true;
var cnnBreakCache = 'cnnBreakCache=1';
var nitnCurrentVid = false;
var bvpConfig = {
	channelFeedRootUrl: '/.element/ssi/www/auto/2.0/video/xml/',
	tabs: [
		{
			id: 'top_stories',
			title: 'CATEGORIES',
			default_channel: 'ts_latest',
			default_adSection: 'cnn.com_videos_latestnews',
			preferredEdition: 'us',
			channels: [
				{id: 'ts_latest', title: 'Latest News', xml_url: 'top_stories.xml', section: '/video/nitn', adSection: 'cnn.com_videos_latestnews'},
				{id: 'ts_most_popular', title: 'Most Popular', xml_url: 'most_popular.xml', adSection: 'cnn.com_videos_mostpopular'},
				{id: 'ts_us', title: 'U.S.', xml_url: 'by_section_us.xml', section: '/video/us', adSection: 'cnn.com_us_misc', edition:'us' },
				{id: 'ts_world', title: 'World', xml_url: 'by_section_world.xml', section: '/video/world', adSection: 'cnn.com_world_misc', edition:'us' },
				{id: 'ts_politics', title: 'Politics', xml_url: 'by_section_politics.xml', section: '/video/politics', adSection: 'cnn.com_politics_section_misc', edition:'us'},
				{id: 'ts_entertainment', title: 'Entertainment', xml_url: 'by_section_showbiz.xml', section: '/video/showbiz', adSection: 'cnn.com_entertainment_section_misc', edition:'us'},
				{id: 'ts_crime', title: 'Justice', xml_url: 'by_section_crime.xml', section: '/video/crime', adSection: 'cnn.com_justice_misc', edition:'us' },
				{id: 'ts_offbeat', title: 'Offbeat', xml_url: 'by_section_funny_news.xml', section: '/video/offbeat', adSection: 'cnn.com_videos_offbeat', edition:'us'},
				{id: 'ts_tech', title: 'Tech', xml_url: 'by_section_tech.xml', section: '/video/tech', adSection: 'cnn.com_technology_misc', edition:'us' },
				{id: 'ts_living', title: 'Living', xml_url: 'by_section_living.xml', section: '/video/living', adSection: 'cnn.com_living_misc', edition:'us' },
				{id: 'ts_health', title: 'Health', xml_url: 'by_section_health.xml', section: '/video/health', adSection: 'cnn.com_health_section_misc', edition:'us' },
				{id: 'ts_student_news', title: 'Student News', xml_url: 'education.xml', section: '/video/education', adSection: 'cnn.com_living_student_news', edition:'us' },
				{id: 'ts_business', title: 'Business', xml_url: 'by_section_business.xml', section:'/video/business', adSection: 'cnn.com_videos_business', edition:'us' },
				{id: 'ts_sports', title: 'Sports', xml_url: 'by_section_sports.xml', section: '/video/sports', adSection: 'cnn.com_sports_misc', edition:'us' },
				{id: 'ts_weather', title: 'Weather', xml_url: 'by_section_weather.xml', section: '/video/weather', adSection: 'cnn.com_weather_misc', edition:'us' }
			]
		},
		{
			id: 'international',
			title: 'INTERNATIONAL',
			default_channel: 'intl_world',
			default_adSection: 'cnn.com_videos_international',
			preferredEdition: 'intl',
			channels: [
				{id: 'intl_world', title: 'World News', section: '/video/world', xml_url: 'by_section_world.xml', edition:'intl'},
				{id: 'intl_us', title: 'U.S.', section:'/video/us', xml_url: 'by_section_us.xml',edition:'intl' },
				{id: 'intl_politics', title: 'Politics', section:'/video/politics', xml_url: 'by_section_politics.xml',edition:'intl' },
				{id: 'intl_business', title: 'World Business', section:'/video/business', xml_url: 'by_section_business.xml',edition:'intl' },
				{id: 'intl_sports', title: 'World Sport', section: '/video/sports', xml_url: 'by_section_sports.xml',edition:'intl' },
				{id: 'intl_entertainment', title: 'Entertainment', section:'/video/showbiz', xml_url: 'by_section_showbiz.xml',edition:'intl' },	
				{id: 'intl_tech', title: 'Tech', section:'/video/tech', xml_url: 'by_section_tech.xml' },				
				{id: 'intl_health', title: 'Health', section:'/video/health', xml_url: 'by_section_health.xml',edition:'intl' },
				{id: 'intl_living', title: 'Living', section:'/video/living', xml_url:'by_section_living.xml',edition:'intl' },
				{id: 'intl_crime', title: 'Justice', section:'/video/crime', xml_url:'by_section_crime.xml',edition:'intl' },
				{id: 'intl_offbeat', title: 'Offbeat', section:'/video/offbeat', xml_url: 'by_section_funny_news.xml',edition:'intl' },
				{id: 'intl_weather', title: 'Weather', section:'/video/weather', edition:'intl', xml_url:'by_section_weather.xml'},
				{id: 'intl_most_popular', title: 'Most Popular', xml_url: 'intl_most_popular.xml'},
				{id: 'intl_hot_topic_1', title: 'Environment', xml_url: 'specials_2009_news_environment.xml', edition:'intl'}
			]
		},
		{
			id: 'on_tv',
			title: 'ON TV',
			default_channel: 'ontv_american_morning',
			default_adSection: 'cnn.com_on_cnntv',
			selectedEdition: 'us',
			channels: [
				{id: 'label_cnn_us', title: 'CNN U.S.', xml_url: ''},			
				{id: 'ontv_cnn_newsroom', title: 'CNN Newsroom', xml_url: 'cnn_programs_cnn_newsroom.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>CNN Newsroom</span><span class="cnnVidPromoSched">Monday - Friday 9am ET<span>|</span>6am PT</span><a href="http://www.cnn.com/CNN/Programs/cnn.newsroom/">Showpage</a> | <a href="http://newsroom.blogs.cnn.com/">Blog</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},
				{id: 'ontv_the_situation_room', title: 'The Situation Room', xml_url: 'cnn_programs_situation_room.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>The Situation Room</span><span class="cnnVidPromoSched">Monday - Friday 4pm ET<span>|</span>1pm PT</span><a href="http://www.cnn.com/CNN/Programs/situation.room/">Showpage</a> | <a href="http://caffertyfile.blogs.cnn.com/">Blog</a> | <a href="http://www.cnn.com/services/podcasting/">Podcast</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},
				
				{id: 'ontv_cnn_john_king', title: 'John King USA', xml_url: 'cnn_programs_john_king.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>John King USA</span><span class="cnnVidPromoSched">Weeknights 7 p.m. ET</span><a href="http://johnkingusa.blogs.cnn.com/">Blog</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},
				{id: 'ontv_cnn_piers_morgan', title: 'Piers Morgan Tonight', xml_url: 'cnn_programs_piers_morgan.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Piers Morgan Tonight</span><span class="cnnVidPromoSched">Monday - Friday 9pm ET<span>|</span>6pm PT</span><a href="http://piersmorgan.blogs.cnn.com">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},
				{id: 'ontv_anderson_cooper_360', title: 'Anderson Cooper 360', xml_url: 'cnn_programs_anderson_cooper_360.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Anderson Cooper 360</span><span class="cnnVidPromoSched">Monday - Friday 10pm ET<span>|</span>7pm PT</span><a href="http://www.cnn.com/CNN/Programs/anderson.cooper.360/">Showpage</a> | <a href="http://ac360.blogs.cnn.com/blog/">Blog</a> | <a href="http://www.cnn.com/services/podcasting/">Podcast</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},
				{id: 'ontv_cnn_sotu', title: 'State of the Union', xml_url: 'cnn_programs_state_of_the_union.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>State of the Union</span><span class="cnnVidPromoSched">Sunday 9am ET<span>|</span>6am PT</span><a href="http://www.cnn.com/CNN/Programs/state.of.the.union/">Showpage</a> | <a href="http://www.cnn.com/services/podcasting/">Podcast</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},
				{id: 'ontv_cnn_Zakaria', title: 'Fareed Zakaria GPS', xml_url: 'world_fareed_zakaria_qa.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Fareed Zakaria GPS</span><span class="cnnVidPromoSched">Sundays at 1pm and 5pm ET<span><a href="http://www.cnn.com/CNN/Programs/fareed.zakaria.gps/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},
				{id:'ontv_weekend',title:'CNN Weekend Shows',xml_url:'cnn_programs_weekend_shows.xml'},
				{id:'ontv_specials',title:'Special Programming',xml_url:'cnn_programs_specialprogramming.xml'},

				{id: 'label_hln', title: 'HLN', xml_url: '' },
				{id: 'ontv_morning_express', title: 'Morning Express', xml_url: 'cnn_programs_robin_and_company.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Morning Express</span><span class="cnnVidPromoSched">Monday - Friday 6am ET<span>|</span>3am PT</span><a href="http://www.cnn.com/CNN/Programs/morning.express/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},
				{id: 'ontv_PrimeNews', title: 'Prime News', xml_url: 'cnn_programs_prime_news.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Prime News</span><span class="cnnVidPromoSched">Monday - Friday 5pm ET<span>|</span>2pm PT</span><a href="http://www.cnn.com/CNN/Programs/showbiz.tonight/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},
				{id: 'ontv_janevelezmitchell', title: 'Issues w/Jane Velez-Mitchell', xml_url: 'cnn_programs_issues_with_jane.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Issues w/ Jane Velez-Mitchell</span><span class="cnnVidPromoSched">Monday - Friday 7pm ET<span>|</span>4pm PT</span><a href="http://www.cnn.com/CNN/Programs/issues.with.jane/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},
				{id: 'ontv_NancyGrace', title: 'Nancy Grace', xml_url: 'cnn_programs_nancy_grace.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Nancy Grace</span><span class="cnnVidPromoSched">Monday - Friday 8pm ET<span>|</span>5pm PT</span><a href="http://www.cnn.com/CNN/Programs/nancy.grace/">Showpage</a> | <a href="http://www.cnn.com/2008/CRIME/09/08/NGfindcayleeblog/index.html">Blog</a> | <a href="http://www.cnn.com/services/podcasting/">Podcast</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},
				{id: 'ontv_DrDrew', title: 'Dr. Drew', xml_url: 'cnn_programs_dr_drew.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Dr. Drew</span><span class="cnnVidPromoSched">Monday - Friday 9pm ET<span>|</span>9pm PT</span><a href="http://www.cnn.com/drdrew/">Blog</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},
				{id: 'ontv_JoyBehar', title: 'Joy Behar', xml_url: 'cnn_programs_joy_behar.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Joy Behar</span><span class="cnnVidPromoSched">Monday - Sunday 9pm ET<span>|</span>6pm PT</span><a href="http://joybehar.blogs.cnn.com/">Blog</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},
				{id: 'ontv_ShowbizTonight', title: 'Showbiz Tonight', xml_url: 'cnn_programs_showbiz_tonight.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Showbiz Tonight</span><span class="cnnVidPromoSched">Daily 11pm ET<span>|</span>8pm PT</span><a href="http://www.cnn.com/CNN/Programs/showbiz.tonight/">Showpage</a> | <a href="http://marquee.blogs.cnn.com/">Blog</a> | <a href="http://www.cnn.com/services/podcasting/">Podcast</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},
				{id: 'ontv_clarkHoward', title: 'Clark Howard', xml_url: 'howard_tips.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Clark Howard</span><span class="cnnVidPromoSched">Weekends 12pm ET<span>|</span>9am PT</span><a href="http://www.cnn.com/CNN/Programs/clark.howard/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				}
			]
		},
		{
			//id: 'on_tv_intl',
			id: 'on_tv',
			title: 'ON TV',
			default_channel: 'ontv_intl_AfricanVoices',
			default_adSection: 'edition.cnn.com_on_cnntv',
			selectedEdition: 'intl',
			channels: [
				{id: 'ontv_intl_AfricanVoices', title: 'African Voices', xml_url: 'cnni_programs_africanvoices.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>African Voices</span><a href="http://edition.cnn.com/CNNI/Programs/africanvoices/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},			
				{id: 'ontv_intl_BusinessTraveller', title: 'Business Traveller', xml_url: 'cnni_programs_business_traveller.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0px 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Business Traveller</span><a href="http://edition.cnn.com/CNNI/Programs/business.traveller/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},			
				{id: 'ontv_intl_CNNGo', title: 'CNNGo', xml_url: 'cnni_programs_cnngo.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0px 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>CNNGo</span><a href="http://edition.cnn.com/CNNI/Programs/cnngo/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},
				{id: 'ontv_intl_EarthsFrontiers', title: 'Earth\'s Frontiers', xml_url: 'cnni_programs_earths_frontiers.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Earth\'s Frontiers</span><a href="http://edition.cnn.com/CNNI/Programs/earths.frontiers/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},
				{id: 'ontv_intl_EcoSolutions', title: 'Eco Solutions', xml_url: 'cnni_programs_eco_solutions.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Eco Solutions</span><a href="http://edition.cnn.com/CNNI/Programs/eco.solutions/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},			
				{id: 'ontv_intl_Icon', title: 'Icon', xml_url: 'cnni_programs_icon.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Icon</span><a href="http://edition.cnn.com/CNNI/Programs/icon/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},
				{id: 'ontv_intl_i-List', title: 'i-List', xml_url: 'specials_2010_ilist.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>i-List</span><a href="http://edition.cnn.com/SPECIALS/2010/ilist/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},
				{id: 'ontv_intl_InsideAfrica', title: 'Inside Africa', xml_url: 'cnni_programs_insideafrica.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Inside Africa</span><a href="http://edition.cnn.com/CNNI/Programs/insideafrica/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},
				{id: 'ontv_intl_InsidetheMiddle', title: 'Inside the Middle East', xml_url: 'cnni_programs_middle_east.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Inside the Middle East</span><a href="http://edition.cnn.com/CNNI/Programs/middle.east/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},			
				{id: 'ontv_intl_LivingGolf', title: 'Living Golf', xml_url: 'cnni_programs_living_golf.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Living Golf</span><a href="http://edition.cnn.com/CNNI/Programs/living.golf/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},			
				{id: 'ontv_intl_MainSail', title: 'MainSail', xml_url: 'cnni_programs_main_sail.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Main Sail</span><a href="http://edition.cnn.com/CNNI/Programs/main.sail/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},			
				{id: 'ontv_intl_MarketplaceAfrica', title: 'Marketplace Africa', xml_url: 'cnni_programs_marketplace_africa.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Marketplace Africa</span><a href="http://edition.cnn.com/CNNI/Programs/marketplace.africa/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},
				{id: 'ontv_intl_MarketplaceMiddleEast', title: 'Marketplace Middle East', xml_url: 'cnni_programs_mme.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Marketplace Middle East</span><a href="http://edition.cnn.com/CNNI/Programs/mme/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},			
				{id: 'ontv_intl_OpenCourt', title: 'Open Court', xml_url: 'sport_tennis.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Open Court</span><a href="http://edition.cnn.com/SPORT/tennis/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},
				{id: 'ontv_intl_Revealed', title: 'Revealed', xml_url: 'cnni_programs_revealed.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Revealed</span><a href="http://edition.cnn.com/CNNI/Programs/revealed/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},	
				{id: 'ontv_intl_TalkAsia', title: 'Talk Asia', xml_url: 'asia_talkasia.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>Talk Asia</span><a href="http://edition.cnn.com/ASIA/talkasia/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				},			
				{id: 'ontv_intl_WorldsUntoldStories', title: 'World\'s Untold Stories', xml_url: 'cnni_programs_untoldstories_blog.xml',
					banner_html: '<div id="On_Tv_Content"><div class="cnnWireLtgBox" style="margin: 0 16px 15px 10px;"><div class="cnnBoxHeader"><div></div></div><div class="cnnBoxContent"><div class="cnnVidPromo"><span>World\'s Untold Stories</span><a href="http://edition.cnn.com/CNNI/Programs/untoldstories/">Showpage</a></div></div><div class="cnnBoxFooter"><div></div></div></div></div>'
				}
			]
		},

		{id: 'ireports',
			title: 'iREPORTS',
			default_channel: 'ir_NewsiestNow',
			default_adSection: 'cnn.com_ireport_main',
			channels: [
				{id: 'ir_NewsiestNow', title: 'Newsiest Now', section:'/video/ireports', xml_url: 'ireport_newsiest_now.xml'},
				{id: 'ir_OnCNN', title: 'On CNN', xml_url: 'ireport_on_cnn.xml'},
				{id: 'ir_SoundOff', title: 'Sound Off', xml_url: 'ireport_sound_off.xml'},
				{id: 'ir_Offbeat', title: 'Offbeat', xml_url: 'ireport_off_beat.xml'},
				{id: 'ir_iReportOnCNN', title: 'iReport for CNN show', xml_url: 'cnni_programs_ireport.xml'}
			]
		},
		{id: 'spanish',
			//title: 'ESPANOL',
			title: 'ESPA&Ntilde;OL',
			default_channel: 'spanish_AmericaLatina',
			default_adSection: 'cnn.com_espanol_misc',
			channels: [
				{id: 'spanish_Ahoras', title: 'Ahoras', section:'/video/spanish', xml_url: 'spanish_ahoras.xml'},
				{id: 'spanish_Mundo', title: 'Mundo', xml_url: 'spanish_mundo.xml'},
				{id: 'spanish_AmericaLatina', title: 'Am&eacute;rica Latina', xml_url: 'spanish_america_latina.xml'},
				{id: 'spanish_EstadosUnidos', title: 'Estados Unidos', xml_url: 'spanish_estados_unidos.xml'},
				{id: 'spanish_Economia', title: 'Econom&iacute;a', xml_url: 'spanish_economia.xml'},
				{id: 'spanish_TuDinero', title: 'Tu Dinero', xml_url: 'spanish_tu_dinero.xml'},
				{id: 'spanish_Entretenimiento', title: 'Entretenimiento', xml_url: 'spanish_entretenimiento.xml'},
				{id: 'spanish_Tecnologia', title: 'Tecnolog&iacute;a', xml_url: 'spanish_tecnologia.xml'},
				{id: 'spanish_Vida', title: 'Vida', xml_url: 'spanish_vida.xml'},
				{id: 'spanish_Elecciones', title: 'Elecciones', xml_url: 'spanish_eleccions.xml'}
			]
		}
		/*,
		{id: 'live',
			title: 'LIVE',
			default_channel: 'livelist',
			default_adSection: 'cnn.com_videos_bvp',
			channels: [
				{id: 'live_live', title: 'LIVE', xml_url: 'pipeline.xml?' + cnnBreakCache, video_box_class: 'sec_video_box_live', no_content_name: 'live streams'}
			]
		} */
		/*{id: 'hotTopic1',
			title: 'FLEX TAB',
			default_channel: 'ht1_AmericaLatina',
			channels: [
				{id: 'ht1_AmericaLatina', title: 'Am&eacute;rica Latina', xml_url: 'by_section_espanol.xml?AmericaLatina'}
			]
		}*/
	]	
};

var bvpSpecialsConfig = {
	'autumn_of_change': {
		url:'/SPECIALS/2009/autumn.of.change/',
		name:'Autumn of Change',
		xml: 'specials_2009_autumn_of_change.xml'
	},
	'cnn_heroes': {
		url:'/SPECIALS/cnn.heroes/',
		name:'CNN Heroes',
		xml: 'specials_cnn_heroes.xml'
	},
	'edge_of_discovery': {
		url: '/SPECIALS/2008/edge.of.discovery/',
		name: 'Edge of Discovery',
		xml: 'specials_2008_edge_of_discovery.xml'
	},
	'fit_nation': {
		url: '/SPECIALS/2009/fit.nation/',
		name: 'Fit Nation',
		xml: 'specials_fit_nation.xml'
	},
	'help_desk': {
		url: '/SPECIALS/helpdesk/',
		name: 'Help Desk',
		xml: 'specials_news_help_desk.xml'
	},
	'impact_your_world': {
		url:'/SPECIALS/2007/impact/',
		name:'Impact Your World',
		xml: 'specials_2007_impact.xml'
	},
	'living_with_allergies': {
		url:'/SPECIALS/2009/living.with.allergies/',
		name:'Living with Allergies',
		xml: 'specials_2009_living_with_allergies.xml'
	},
	'luxury_week': {
		url:'/SPECIALS/2009/news/luxury.week/',
		name:'Luxury Week',
		xml:'specials_2009_news_luxury_week.xml'
	},
	'money_and_main_street': {
		url:'/SPECIALS/2009/money.and.main.street/',
		name:'Money &amp; Main St.',
		xml: 'specials_archives_money_and_main_street.xml'
	},
	'solutions': {
		url: '/SPECIALS/2009/solutions/',
		name: 'Solutions',
		xml: 'tech_miles_obrien_solutions.xml'
	},
	'travel_companion': {
		url: '/SPECIALS/2009/travel.companion/',
		name: 'Travel Companion',
		xml: 'specials_2008_news_travel_companion.xml'
	}
};

var bvpHistoryConfig = {
	'/SPECIALS/2009/autumn.of.change/':'autumn_of_change',
	'/SPECIALS/cnn.heroes/':'cnn_heroes',
	'/SPECIALS/2008/edge.of.discovery/': 'edge_of_discovery',
	'/SPECIALS/2008/edge.of.discovery/archive/': 'edge_of_discovery',
	'/SPECIALS/2008/edge.of.discovery/archive/video/': 'edge_of_discovery',
	'/SPECIALS/2009/news/luxury.week/': 'luxury_week',
	'/SPECIALS/2009/news/luxury.week/archive/video/': 'luxury_week',
	'/SPECIALS/2009/fit.nation/': 'fit_nation',
	'/SPECIALS/fit.nation/archive/': 'fit_nation',
	'/SPECIALS/helpdesk/': 'help_desk',
	'/SPECIALS/news/help.desk/archive/': 'help_desk',
	'/SPECIALS/2007/impact/': 'impact_your_world',
	'/SPECIALS/2009/living.with.allergies/': 'living_with_allergies',
	'/SPECIALS/2009/money.and.main.street/': 'money_and_main_street',
	'/SPECIALS/archives/money.and.main.street/archive/' :'money_and_main_street',
	'/SPECIALS/2009/solutions/': 'solutions',
	'/TECH/miles.obrien.solutions/archive/': 'solutions',
	'/SPECIALS/2009/travel.companion/' : 'travel_companion',
	'/SPECIALS/2008/news/travel.companion/archive/': 'travel_companion',
	'/SPECIALS/2008/news/travel.companion/archive/video/': 'travel_companion'
};

var bvpManager = {
	selectedTab: {},
	isDeepLinked: false,
	selectedChannel: {},
	currentVideoPlayingChannelXML: '',
	selectedChannelId: 'ts_most_popular',
	prevSelectedTabId: '',
	channelVideos: [],
	playlist: [],
	my_playlist:[],
	videos_per_playlist: 12,
	isInitialized: false,
	tabsLoaded: false,
	// playlist stuff
	currPlaylist: 'navNext_Up',
	playlistDisplay: {
		navNext_Up: '112px',
		navMyPlay_List: '112px'
	},
	imgObj: new Image(),
	getImg: function(src)
	{
		//this.imgObj.src = src;
		return src;
	},

	/**
	 * marks tab UI as selected - will draw tabs if not initialized yet
	 */
	setSelectedTab: function(id, channelID, isSpecial) {
		if(is_enabledBVPBtns) {
		this.selectedTab = this.getTab(id);
		bvpManager.drawTabs();
		// if user is trying to get to a non-default channel first
		var defChannel = (typeof channelID == 'undefined' || channelID === null) ? bvpManager.selectedTab.default_channel : channelID;
		bvpManager.selectedChannel = bvpManager.getChannel(defChannel);
		// set selected
		if(bvpManager.prevSelectedTabId != bvpManager.selectedTab.id) {
			window.cnnCVPAdSection = this.selectedTab.default_adSection || 'undefined';
			window.cnnCVPAdSection = editionizeAdTab(window.cnnCVPAdSection);
			// unselect previous
			if (bvpManager.prevSelectedTabId != '') {
				$('nav' + bvpManager.prevSelectedTabId).style.width = '98px';
				$('nav' + bvpManager.prevSelectedTabId).className = 'cnnNav_Button_ext_med';
			}

			var selected_tab = $('nav' + bvpManager.selectedTab.id);
			var selected_tab_r = $('nav' + bvpManager.selectedTab.id + 'R');
			selected_tab.className = 'cnnNav_Button_ret_med_active';
			selected_tab_r.style.background = 'transparent url(http://i.cdn.turner.com/cnn/.element/img/3.0/video/bvp/nav_buttons/active_right_corner.gif) no-repeat scroll right top';
			
			var selectedTabWidth = 204;
			if(this.tabsLoaded === true ){ /* Only do effect after the page is loaded and the tabs are loaded the first time */
				var defaultWidth = selected_tab.getWidth();
				var percent = Math.round((selectedTabWidth / selected_tab.getWidth()) * 100);
				selected_tab.style.width = defaultWidth + 'px';
				var scale_options = {
					scaleX: true,
					scaleY: false,
					scaleContent: false, 
					scaleFromCenter: false,
					transition: Effect.Transitions.linear,
					duration: 0.3,
					beforeStart: function() {
						is_enabledBVPBtns = false;
					},
					afterFinish: function() {
						is_enabledBVPBtns = true;
					}
				};
				var scaleAnim = new Effect.Scale(selected_tab, percent, scale_options);
			} else {
				selected_tab.style.width = selectedTabWidth + 'px';
			}
			bvpManager.prevSelectedTabId = bvpManager.selectedTab.id;
			this.drawChannels(isSpecial);
		}
		this.tabsLoaded = true;
	}
	},

	setSelectedChannel: function(channel_id) {
		if( this.selectedChannel.id === channel_id && this.isInitialized === true) { return; }
		$('By_Section_Content').innerHTML = 'Loading...';
		$('section_'+this.selectedChannel.id).className = 'cnnSec_Cell';
		$('section_'+channel_id).className = 'cnnSec_Cell_active';
		bvpManager.selectedChannel = bvpManager.getChannel(channel_id);
		var channels = bvpManager.selectedTab.channels;
		for (var i=0, end=channels.length; i<end; i++)
		{
			var channel = channels[i];
			if(channel.id && channel.id===bvpManager.selectedChannel.id) { 
				bvpManager.loadChannel(channel);
			}
		}
	},

	loadChannel: function(channel) {
		$('By_Section_Content').innerHTML = '';
		var targetURL = bvpConfig.channelFeedRootUrl + channel.xml_url;
		if(targetURL.indexOf(cnnBreakCache) > -1){
			var cnnToday = new Date();
			var cnnCurrTimeTmp = cnnToday.getTime()%3600; 
			targetURL = targetURL.replace(cnnBreakCache,'time='+cnnCurrTimeTmp); 
		}
		var video_box_class = channel.video_box_class?channel.video_box_class:'sec_video_box';
		var no_content_name = channel.no_content_name?channel.no_content_name:'videos';
		AjaxManager.sendCommand(targetURL, function(resp) { bvpManager.onChannelLoaded(resp,video_box_class, no_content_name); } );
	},

	/**
	 * populates the videos within a channel
	 * @param {Object} response
	 */
	onChannelLoaded: function(response, video_box_class, no_content_name) {
		var html = [];
		var feed = response.video;
		var loadingSection = bvpManager.selectedChannel.id;

		window.cnnCVPAdSection = bvpManager.selectedChannel.adSection || bvpManager.selectedTab.default_adSection;
		window.cnnCVPAdSection = editionizeAdTab(window.cnnCVPAdSection);

		bvpManager.selectedChannelId = loadingSection;
		bvpManager.channelVideos = [];

		if (typeof(bvpManager.selectedChannel.banner_html) != 'undefined' && (bvpManager.selectedChannel.banner_html.length > 0)) {
			html.push(bvpManager.selectedChannel.banner_html);
		}
		for (var i= 0, end=feed.length; i<end; i++) {
			try {
				if(feed[i].video_url  && feed[i].video_url  != 'undef'){ //see ajaxManager.js for how 'undef' is set
					var anchorTag;
					var re = new RegExp(/Stream\s+(\d)$/);
					var streamNum = re.exec(feed[i].video_url);
					if(streamNum != null && typeof streamNum == 'object' && streamNum.length == 2){
						anchorTag = '<a href="javascript:cnnCVPPlayer.pause();cnnLiveVideo(\''+streamNum[1]+'\');">';
					} else {
						feed[i].video_url = feed[i].video_url.replace(/\/video\/data\/2\.0/,'');
						bvpManager.channelVideos[i] = feed[i].video_id;
						anchorTag = '<a href="#" onclick="hasAChannelVidBeenClicked=true; bvpLoadSpecificVid(\''+feed[i].video_id+'\',\''+bvpManager.selectedChannel.id+'\'); return false;">';
					}

					html.push( 
						'<div id="vid_'+feed[i].video_id+'" class="'+video_box_class,
						'"><div style="height:70px;padding-top:9px;">'+anchorTag,
						'<img src="'+this.getImg(feed[i].image_url)+'" width="125" height="70" alt="" border="0">',
						'</a></div><div style="padding:0px;height:50px;height:auto;height:50px;" class="vid_play">',
						'<div style="margin:0px;height:36px;height:auto; height:36px;word-spacing:0px;">',
						anchorTag,
						feed[i].tease_txt+'</a><span class="vid_duration"> ',
						feed[i].vid_duration+'</span></div>',
						''
					);

					html.push( '</div></div></div>');
				}
			}
			catch(e) {}
		}
		if(html.length == 0){
			html.push( 
				'<div id="vid_none" class="'+video_box_class+'">',
					'<div style="height:70px;padding-top:9px;">&nbsp;','</div>',
					'<div style="padding:0px;height:50px;height:auto;height:50px;" class="vid_play">',
						'<div style="margin:0px;height:36px;height:auto; height:36px;word-spacing:0px;">',
							'There are no ' + no_content_name + ' currently available.',
						'</div>',
					'</div>',
				'</div>'
			);
		}
		$('By_Section_Content').innerHTML = html.join('');
		if(!(this.isInitialized)) {
			// load default playlist
//#			CNNPlaylistManager.getInstance().BVPMGetSplashPlaylist(loadingSection);
			
			// load first video
			this.isInitialized = true;
			if ( this.isDeepLinked == false && bvpManager.channelVideos[0] ) {
				if(bvpManager.selectedChannelId)
				{
					// CNN-13113
					var specificVid2Load = (bvpManager.channelVideos[0].indexOf('/nitn/') >= 0 && bvpManager.channelVideos[1])?bvpManager.channelVideos[1]:bvpManager.channelVideos[0];
					bvpLoadSpecificVid( specificVid2Load, bvpManager.selectedChannelId );
				}
				else
				{
					bvpLoadSpecificVid( bvpManager.channelVideos[0] );
				}
			}
			this.isDeepLinked = false;			
		}

	},

	/**
	 * changes video display to show user video isn't in 'my playlist' anymore
	 * @param {String} json_id
	 */
	removeFromMyPlaylist: function(json_id) {
		try {
			var video_id = json_id.replace(/\.json$/, '');
			if (video_id.indexOf('nitn')>-1){
				video_id = video_id.replace(/\/video/,'');
			}
			$('vid_' + video_id).className = 'sec_video_box';
//#			$('playListAdder'+json_id).innerHTML = '<div onclick="CNNPlaylistManager.getInstance().MYPMAddToPlaylist(\''+json_id+'\',\'' + Math.round(Math.random() * 1000) +'\');" style="margin-top:-10px;height:100px;cursor:pointer; width:50px;"><img src="http://i.cdn.turner.com/cnn/images/1.gif" alt="" style="width:100px; height:100%;"/></div>';
		}
		catch (e) {
			// video not in currently displaying channel
		}
	},

	/**
	 * changes video display to show user video is in 'my playlist'
	 * @param {String} json_id
	 */
	addToMyPlaylist: function(json_id) {
		try {
			var video_id = json_id.replace(/\.json$/, '');
			if (video_id.indexOf('nitn')>-1){
				video_id = video_id.replace(/\/video/,'');
			}
			$('vid_' + video_id).className = 'sec_video_box_saved';
			$('playListAdder'+json_id).innerHTML = '';
		}
		catch (e) {
			// video not in currently displaying channel
		}
	},

	/**
	 * switches the Playlist tab between "Now Playing" and "My Playlist",
	 * adds little animation
	 * @param {String} nav_section_id
	 */
	showPlaylist: function(nav_section_id) {
		if (bvpManager.currPlaylist != nav_section_id) {

			$('navMyPlay_List').className = $('navMyPlay_List').className.replace('_active', '');
			$('navMyPlay_List_R').style.width = bvpManager.playlistDisplay['navMyPlay_List'];
			$('navNext_Up').className = $('navNext_Up').className.replace('_active', '');
			$('navNext_Up_R').style.width = bvpManager.playlistDisplay['navNext_Up'];
			$(nav_section_id).className += "_active";

			var percent = (154 / $(nav_section_id + '_R').getWidth()) * 100;
			var scale_options = {
				scaleX: true,
				scaleY: false,
				scaleContent: false, 
				scaleFromCenter: false,
				duration: 0.4,
				from:0.4
			};
			var scaleAnim = new Effect.Scale($(nav_section_id + '_R'), percent, scale_options);
		}

		if (nav_section_id == 'navNext_Up') {
			$('My_Play_Box').style.display = 'none';
			$('Play_Box').style.display = 'block';
			$('PlayList_Nav').className = $('PlayList_Nav').className.replace('_alt','');
		} else {
			$('Play_Box').style.display = 'none';
			$('My_Play_Box').style.display = 'block';
			$('PlayList_Nav').className += '_alt';
		}
		bvpManager.currPlaylist = nav_section_id;
	},
	drawTabs: function() {
		if(this.tabsLoaded === false)
		{
			var tabDiv = document.getElementById('tab_list');
			tabDiv.innerHTML ='';
			var tabs = bvpConfig.tabs;
			var html = [];
			for (var i=0,end=tabs.length; i < end; i++) {
				// takes care of editionized tabs
				if ((tabs[i].selectedEdition) && (tabs[i].selectedEdition != cnnSelectedEdition)) {
					continue;
				}
				html.push('<div id="nav'+tabs[i].id+'" class="cnnNav_Button_ext_med">',
					'<div id="nav'+tabs[i].id+'R">',
					'<a href="#" onclick="bvpManager.setSelectedTab(\''+tabs[i].id+'\'); return false;">',
					'<div>'+tabs[i].title+'</div></a>&nbsp;</div></div>'
				);
			}
			tabDiv.innerHTML = html.join('');
		}
	},
	drawChannels: function(isSpecial) {
		var channelDiv = document.getElementById('By_Section_Nav');
		channelDiv.innerHTML = '';
		var channels = bvpManager.selectedTab.channels;
		var html = [];

		var toLoad = (bvpManager.selectedChannel.id === 'intl_world' || !isSpecial) ? true : false;
		// Only need to list channels in left nav when there is more than one.  There are three columns in
		// the section box on the bottom.  Collapse the first 2 and widen the third when there's only one
		// channel in the tab.  Show the 1st two columns and make the third narrower when there's more than one
		var sectionBoxDivs = $$('#By_Section_Box div');
		if(channels.length > 1){
			$('By_Section_Content').style.width = '800px';
			sectionBoxDivs.each( function(div) { 
				div.style.display=''; 
			});
		} else {
			try {
				$('By_Section_Nav').style.display = 'none';
				$('By_Section_Spacer').style.display = 'none';
				$('By_Section_Content').style.width = '957px';
			} catch (e) {}
		}
		if(channels.length > 1){
			for (var i=0, end=channels.length; i<end; i++)
			{
				var channel = channels[i];
				if(channel.xml_url && channel.xml_url.length > 0)
				{
					html.push('<div id="section_'+channel.id+'" class="cnnSec_Cell',
						(channel.id && channel.id == bvpManager.selectedChannel.id) ? '_active' : '',
						'"><a style="font-weight:bold;" href="#" onclick="bvpManager.setSelectedChannel(\''+channel.id+'\'); return false;">',
						channel.title+'</a></div>'
					);
					if(toLoad && channel.id && channel.id===bvpManager.selectedChannel.id) {
						bvpManager.loadChannel(channel);
					}
				}
				else 
				{
					if(html.length > 0) {
						html.push('<div style="background-color:#dadada;height:1px;overflow:hidden;"></div>');
					}
					html.push('<div style="padding:8px 0 3px 6px;"><b>' + channel.title + '</b></div>');				
				}
			}
			channelDiv.innerHTML = html.join('');
		} else if(toLoad && channels.length == 1) {
			var theChannel = channels[0];
			if(theChannel.id===bvpManager.selectedChannel.id){
				bvpManager.loadChannel(theChannel);
			}
		}
	},
	/**
	 * return tab object for a given tab ID
	 * @param {String} tab_id
	 */
	getTab: function(tab_id) {
		var tabs = bvpConfig.tabs;
		for (var i=0,end=tabs.length; i<end; i++) {
			// takes care of editionized tabs
			if ((tabs[i].selectedEdition) && (tabs[i].selectedEdition != cnnSelectedEdition)) {
				continue;
			}
			if(tabs[i].id == tab_id) {
				return tabs[i];
			}
		}
	},

	/**
	 * get channel object for given channel ID
	 * @param {String} channel_id
	 */
	getChannel: function(channel_id) {
		var channels = bvpManager.selectedTab.channels;
		var ct = channels.length;
		var defaultChannel = channels[0];
		for (var i = 0; i < ct; i++) {
			var channelID_item = channels[i].id;
			if(channelID_item == bvpManager.selectedTab.default_channel) {
				defaultChannel = channels[i];
			}
			// for backward compatibility test config id ts_tech (translate to /tech) against the channel passed in
			var tmpChannel = (channelID_item.indexOf('_') > -1)?'/' + channelID_item.slice(channelID_item.indexOf('_') + 1):'';
			if (channelID_item == channel_id || tmpChannel == channel_id ) {
				return channels[i];
			}
		}
		return defaultChannel;
	},

	// helper functions

	/**
	 * returns the position of the selected video in the channel list
	 * @param {Object} video_id
	 */
	getPositionForId: function(video_id) {
		var ct = bvpManager.channelVideos.length;
		for (var i=0; i < ct; i++) {
			if (bvpManager.channelVideos[i] == video_id) {
				return i;
			}
		}
		return 0;
	},

	/**
	 * returns position of video inside playlist - not sure this is used anymore
	 * @param {Object} video_id
	getPlaylistPositionForId: function(video_id) {
		//alert('getPlaylistPositionForId');
		for (var i=0, end=this.playlist.length; i < end; i++) {
			//if (bvpManager.playlist[i] == video_id) {
			if (this.playlist[i] == video_id) {
				return i;
			}
		}
		return 0;
	},
	 */
	/**
	 * tab {Object}
	 * @param {String} tab_id
	 */
	findTab : function(tab_id) {
		var ret = 0;
		for(var i=0, end=bvpConfig.tabs.length; i<end; i++)
		{
			var tab = bvpConfig.tabs[i];
			if( tab.id == tab_id ) { ret = tab_id; }
		}
		return ret;
	},
	/**
	 * tab_id for a given channel_id
	 * @param {String} channel_id
	 */
	findTabByChannel : function(channel) {
		for(var s=0; s<2; s++){
			var searchByEdition = (s==0)?true:false;
			for(var i=0, end=bvpConfig.tabs.length; i<end; i++)
			{
				var tab = bvpConfig.tabs[i];
				// takes care of editionized tabs and looks in preferred tabs(based on edition) first
				if ((tab.selectedEdition && tab.selectedEdition != cnnSelectedEdition) || (searchByEdition == true && tab.preferredEdition && tab.preferredEdition != cnnSelectedEdition)) {
					continue;
				}
				var tabID_item = tab.id;
				// for backward compatibility test config id spanish (translate to /spanish) against the channel passed in
				var tmpTab = '/' + tabID_item;
				if (tab.id == channel || tmpTab == channel ) {
					return tab.id;
				}
				for(var j=0,endj=tab.channels.length; j< endj; j++) {
					var tabChannelID_item = tab.channels[j].id;
					// for backward compatibility test config id ts_tech (translate to /tech) against the channel passed in
					var tmpChannel = (tabChannelID_item.indexOf('_') > -1)?'/' + tabChannelID_item.slice(tabChannelID_item.indexOf('_') + 1):'';
					if (tabChannelID_item == channel || tmpChannel == channel) {
						return tab.id;
					}
				}
			}
		}
		return '';
	},

	/**
	 * channel_id for a given section (from video json)
	 * @param {String} section
	 */
	findChannelBySection : function(section) {
		var fallBackChannel = '';
		for (var i=0, end=bvpConfig.tabs.length; i<end; i++) {
			var tab = bvpConfig.tabs[i];
			// takes care of editionized tabs
			if (tab.selectedEdition && tab.selectedEdition != cnnSelectedEdition) {
				continue;
			}
			for (var j=0,endj=tab.channels.length; j<endj; j++) {
				if(tab.channels[j].section && tab.channels[j].section == section) {
					if(tab.channels[j].edition && tab.channels[j].edition !== cnnSelectedEdition )
					{
						fallBackChannel = tab.channels[j].id;
					}
					else {
						return tab.channels[j].id;
					}
				}
			}
		}
		return fallBackChannel;
	},
	// parse URL for initial state, load / draw the tab/channel interface
	loadFirstSection: function() {
		var qs = (window.location.hash.length > 0) ? window.location.hash : window.location.search;
		var isIntlUser = (location.hostname.indexOf('edition.') > -1 || location.port === '94');
		var dfltTab = (isIntlUser) ? 'international' : 'top_stories';
		var dfltChannel = (isIntlUser) ? '' : 'ts_latest';
		var search = qs.slice(qs.indexOf('#')+1);
		if(search == '?adTest=1'){search = '';}
		search.replace('&adTest=1','');
		var hasVid = false;
		var refregexp = /\?.ref=.*&*#*/i; // Fix Search: http://www.cnn.com/video/#/video/politics/2010/03/05/bts.obama.clean.energy.jobs.cnn?iref=videosearch
		if(refregexp.test(search)){search = search.replace(refregexp,'');}
		// Fix Homepage: http://www.cnn.com/video/#/video/ireports/2010/03/02/ireport.oscar.best.picture.picks.cnn?hpt=C2
		// Fix Homepage: http://www.cnn.com/video/?/video/us/2010/03/05/vo.fl.scuba.shark.rescue.new.scubaworks&hpt=P1
		var cleanQSregexp = /[?&]hpt=.*$/i; 
		if(cleanQSregexp.test(search)){search = search.replace(cleanQSregexp,'');}
		if (typeof loadThisVideo != 'undefined') {
			this.isDeepLinked = true;
			sec = (loadThisVideo.split('/'))[2];
			bvpLoadSpecificVid(loadThisVideo);
		} else if (search.length > 0) {
			this.isDeepLinked = true;
			if(search.indexOf('?') > -1) {
				var vidID;
				var sec = '';
				if (search.indexOf('launchLivePlayer') > -1) {
					var str = search;
					var openedWindow = window.open(('/video/live/live.html?stream=stream'+str.charAt(str.length - 1)),'liveplayer','scrollbars=yes,resizable=yes,width=672,height=540',true);
					if (openedWindow) { bvpManager.setSelectedTab(dfltTab); } else {
						document.getElementById('cnnCVPLargeContainer').innerHTML = "<div class=\"cnnVideoMessageContainer\" style=\"width: 100%; height: 100%;\"><div class=\"cnnVideoMessage\"><p class=\"cnnTopGraf\"><b>LIVE VIDEO PLAYER BLOCKED</b><br><br>Your popup blocker has blocked access to the CNN Video Player.<br> To view your video, please launch the CNN Live Video Player below.<br><br><input type=\"button\" value=\"Launch CNN Live Video Player\" onclick=\"window.open(('http://www.cnn.com/video/live/live.html?stream=stream" + str.charAt(str.length - 1) + "'),'liveplayer','scrollbars=yes,resizable=yes,width=672,height=540',true);\"><\/div><\/div>";
					}
				}
				else if (search.indexOf('JSONLINK') > -1) {
					var str = location.href;
					str = (str.indexOf('.html') > -1) ? str.slice(str.indexOf('.html?')+6,str.length) : str.slice(str.indexOf('/video/?')+8,str.length);
					var args = str.split('&');
					for (var i = 0; i < args.length; i++) {
						args[i] = args[i].split('=');
					}
					for (var i = 0; i < args.length; i++) {
						if (args[i][0] == 'JSONLINK') {
							vidID = args[i][1];
							sec = (args[i][1].split('/'))[1];
						} else if (args[i][0] == 'DPFPR' && args[i][1] == 'true') {
//#							CNNPlaylistManager.getInstance().forceSensitive = true;
						}
					}
				} else {
					vidID = search.slice(search.indexOf('?')+1);
				}
				if( vidID && /^\/video\//.test(vidID) )
				{
					//Strip out any other params, get just the video id
					vidID = vidID.replace(/\?.*/,'').replace(/&.*/,'');
					hasVid = true;
					bvpLoadSpecificVid(vidID);
//#					CNNPlaylistManager.getInstance().loadFirstVideo = vidID+'.json';
//#					BVPPlaylistManager.prototype.BVPMVideoSelected(vidID+'.json');
				}
				else if( search.indexOf('#') === -1 )
				{
					bvpManager.setSelectedTab(dfltTab);
				}
			}
			if( !hasVid )
			{
				// Dealing with #
				search = search.replace(/\?.*/,'');
				var init_tab = bvpManager.findTabByChannel(search);
				if( init_tab.length > 0) {
					// Load a specific channel from hash value
					this.isDeepLinked = false;
					bvpManager.selectedTab = bvpManager.getTab(init_tab);
					bvpManager.selectedChannel = bvpManager.getChannel(search);
					bvpManager.setSelectedTab(init_tab, search);
				} else if( bvpManager.findTab(search) ) {
					// Load a specific tab from hash value
					this.isDeepLinked = false;
					bvpManager.selectedTab = bvpManager.getTab(search);
					bvpManager.selectedChannel = bvpManager.selectedTab.default_channel;
					bvpManager.setSelectedTab(search);
				} else if (/^\/video\//.test(search)) {
					// Load a specific video from hash value
					var json_url = search + '.json';
					bvpLoadSpecificVid(search);
					//CNNPlaylistManager.getInstance().loadFirstVideo = json_url;
					//BVPPlaylistManager.prototype.BVPMVideoSelected(json_url);

					var specialReferrer = bvpHistoryConfig[ getReferrer() ];
					if( specialReferrer && bvpSpecialsConfig[ specialReferrer ] && bvpSpecialsConfig[ specialReferrer ].xml ) {
						var cfgObj = bvpSpecialsConfig[ specialReferrer ];
						var specialPlaylist = '/.element/ssi/www/auto/2.0/video/xml/'+cfgObj.xml;
						AjaxManager.sendCommand(specialPlaylist, function(resp) { writeSpecialsPlaylist(resp,cfgObj); });
					
					}
				} else {
					// if loading special playlist
					var cfgObj = bvpSpecialsConfig[search];
					if(cfgObj){
						var specialPlaylist = '/.element/ssi/www/auto/2.0/video/xml/'+cfgObj.xml;
						AjaxManager.sendCommand(specialPlaylist, function(resp) { writeSpecialsPlaylist(resp,cfgObj); });
					} else {
						bvpManager.setSelectedTab(dfltTab);
					}
				}
				
			}
		} else {
			this.isDeepLinked = false;

			// load default channel
			if(dfltChannel!='')
			{
				bvpManager.setSelectedTab(dfltTab, dfltChannel);
			}
			else
			{
				bvpManager.setSelectedTab(dfltTab);
			}
		}
	}
};

function getReferrer()
{
	var r = document.referrer.replace(/^http:\/\/[^\/]*\//,'/');
	r = r.replace(/index\.html?.*/,'');
	return r;
}

function editionizeAdTab(adTab) {
	var isIntlUser = (location.hostname.indexOf('edition.') > -1 || location.port === '94');
	if (isIntlUser && adTab.indexOf('edition') < 0) {
		adTab = "edition." + adTab;
	}
	return adTab;
}

function writeSpecialsPlaylist(resp,cfgObj) {
	if( resp ) {
		var videoArray = [];
		var vids = resp.video;
		var isIntlUser = (location.hostname.indexOf('edition.') > -1 || location.port === '94');
		var dfltTab = (isIntlUser) ? 'international' : 'top_stories';

		for (var i=0, end=vids.length; i<end; i++) {
			//removing '/video/data/2.0' from url, getting duplicated in ajax request
			videoArray[i] = vids[i].video_id;
		}

		bvpManager.channelVideos = videoArray;
//#		var bvpPlaylistManager = CNNPlaylistManager.getInstance();
//#		bvpPlaylistManager.nextUpTitle = cfgObj.name || 'Next Up';
//#		bvpPlaylistManager.BVPMGetSplashPlaylist('specials_playlist',videoArray);
		bvpManager.isInitialized = true;

		if(cfgObj.channel && cfgObj.channel.length > 0) {
			var tab_id = bvpManager.findTabByChannel(cfgObj.channel);
			bvpManager.setSelectedTab(tab_id);
			bvpManager.setSelectedChannel(cfgObj.channel);
		}
		else if(cfgObj.tab && cfgObj.tab.length > 0) {
			bvpManager.setSelectedTab(cfgObj.tab);
		}
		else {
			//bvpManager.setSelectedTab(dfltTab,null,'specials_playlist');
			bvpManager.setSelectedTab(dfltTab);
		}
	}
	else {
		bvpManager.setSelectedTab(dfltTab);
	}
}

var currentPlayListListing = new Array();
function loadInPlayList(resp)
// Used on BVP and on pages using a playlist like /POLITICS
{
	currentPlayListListing = new Array();
	if(cnnIsGoodVideo('/video/'+currentPlayListId)){
			currentPlayListListing.push(currentPlayListId);
	}

	var videoIdList = new Array();
	var startoffset = -1;
	var foundList = new Array();
	var foundTheVideo = false;
	var searchForVideo = '/video/'+currentPlayListId;
	loopVideos: for(var i=0;i<resp.video.length;i++)
	{
		var videourl = resp.video[i].video_id;
		if(!cnnIsGoodVideo(videourl)){
			continue loopVideos;
		}

		videoIdList.push(resp.video[i].video_id);
		if((videourl==searchForVideo) || foundTheVideo)
		{
			// the order here is important - flipping this will cause the video to be added twice.
			if(foundTheVideo)
			{
				foundList.push( videourl );
			}
			foundTheVideo = true;
		}
	}
	var maxNum = videoIdList.length;
	if(foundTheVideo) {
		var maxNum = foundList.length;
		videoIdList = foundList;
	}
	if(maxNum>playListLength)
	{
		maxNum = playListLength;
	}
	for(var i=0;i<maxNum;i++)
	{
		var cvpVideoId = videoIdList[i].substring(7);
		// Have to 'play' the first video after a error.  Queue'd videos won't play.  Queue them when we are
		// waiting for the 7 second timeout to finish(onPlayerReady loadPlayList call) for the deep-linked case.
		// We can populate the playlist while we wait.
		if(typeof(cnnCVPPlayer) != 'object' || (cnnCVPPlayer.options.lastVideoErrored && i==0 && typeof cnnClearTimeoutAfterError != "number")){
			cnnNextVideoToPlay = cvpVideoId;
			cnnCVPPlay(cvpVideoId, 'cnnCVPLargeContainer', '640x406_start_bvp');
		} else {
			cnnCVPQueue(cvpVideoId,'cnnCVPLargeContainer', '640x406_start_bvp');
		}
		currentPlayListListing.push(cvpVideoId);
	}
}

function renderPlayList()
{
	var html = new Array();
	var havesomedata = false;
	for(var i=0;i<currentPlayListListing.length;i++)
	{
		var currId = currentPlayListListing[i];
		var currVideojson = cnnCVPPlayer.getContentEntry( currId );
		var currVideoObj = false;
		if(currVideojson && currVideojson!='{}' && currVideojson!='')
		{
			currVideoObj = eval( '('+currVideojson+')');
		} else {
			return;
		}
		havesomedata = true;

		if(currVideoObj)
		{
			var teaseImageUrl = '';
			var numImages = currVideoObj.images.length;
			if(numImages>0)
			{
				teaseImageUrl = currVideoObj.images[1].image.text;
			}
			for(var x=0;x<numImages;x++)
			{
				if(currVideoObj.images[x] && currVideoObj.images[x].image && currVideoObj.images[x].image.name && currVideoObj.images[x].image.name == 'pl')
				{
					teaseImageUrl = currVideoObj.images[x].image.text;
				}
			}
			var vidid = currVideoObj.id;

			var specialbrandingKey = currVideoObj.subcategory.toLowerCase().replace(' ','_');
			var specialConfigObj = bvpSpecialsConfig[ specialbrandingKey ];

			var bln_specialbranded = false;
			var special_url = '';
			var title_class = 'box_item_link';
			var special_title = '';
			var extraclass = '';

			if(specialConfigObj)
			{
				bln_specialbranded = true;
				special_url = specialConfigObj.url;
				title_class = 'box_item_link bIwTitle';
				special_title = specialConfigObj.name;
			}


			var isnowplaying = false;
			var nowplaying = '';

			if(vidid==currentPlayListId)
			{
				teaseImageUrl = 'http://i.cdn.turner.com/cnn/.element/img/3.0/video/bvp/2008/play_btn.gif';
				nowplaying = '<div id="_nowplaying_' + i + '"><span class="box_item_np">NOW PLAYING</span><br></div>';
				extraclass = '_play';
				isnowplaying = true;
				title_class = 'box_item_link bIwTitle';
				bln_specialbranded = false;
			}
			else
			{

			}

			var t_hdln = currVideoObj.headline + '';
			if(t_hdln.length > 32) { t_hdln = t_hdln.substr(0,32) + '...'; }

			html.push('<div class="box_item'+extraclass+'" id="nextup_' + i + '"><div class="box_item_tz">',
			// don't know if this is good or not. Need to discuss how to moving around within a playlist. Is it actually possible?
	//				'<a href="#" onclick="CNNPlaylistManager.getInstance().advanceTo(\'bvpplaylist\','+i+'); return false;">',
					'<a href="#" onclick="skipAheadInPlayList(',
					"'"+vidid+"');return false;",
					'">',
					'<img id="nextup_img_'+i+'" src="',
					teaseImageUrl,
					'" width="45" height="25" border="0" alt="">',
					'</a>',
					'</div><div id="_title_'+i+'" class="'+title_class,
					'">',nowplaying,
					(bln_specialbranded) ? '<div id="_specials_'+i+'"><a href="'+special_url+'"><span><span>'+special_title+'</span> &raquo;</span></a><br></div>' : '<div id="_specials_'+i+'"></div>',
//see above
					'<a href="#" onclick="skipAheadInPlayList(',
					"'"+vidid+"');return false;",
					'">' + t_hdln + '</a>',
					'<span class="duration">' + currVideoObj.length + '</span>',
					'</div></div>'
				);
		}


	}
	if(havesomedata)
		{
			var newhtml = html.join('');
			if(newhtml!=previousPlayListHTML)
			{
				document.getElementById('Play_Box').innerHTML = newhtml;
				previousPlayListHTML = newhtml;
			}
		}
}

function skipAheadInPlayList(id)
{
	cnnGoClearTimeoutIfAfterError();
	cnnNextVideoToPlay = id;
	currentPlayListId = id;
	hasAPlayListVidBeenClicked = true;
	var startqueing = false;
	cnnCVPPlay(id, 'cnnCVPLargeContainer', '640x406_start_bvp');
	var retStr="";
	for(var i=0;i<currentPlayListListing.length;i++)
	{
		if(startqueing)
		{
		retStr=retStr+currentPlayListListing[i]+"\n";
			cnnCVPQueue(currentPlayListListing[i]);
		}
		if(currentPlayListListing[i]==id)
		{
			startqueing = true;
		}
	}
	renderPlayList();
}

var previousPlayListHTML='';

var previousMetaDataHTML = '';
function renderVideoMetaData(id)
{
	var html = new Array();
	var currVideojson = cnnCVPPlayer.getContentEntry( id);
	var currVideoObj = false;
	if(currVideojson && currVideojson!='{}' && currVideojson!='')
	{
		currVideoObj = eval( '('+currVideojson+')');
	}

	if(currVideoObj && currVideoObj.description)
	{
		var specialbrandingKey = currVideoObj.subcategory.toLowerCase().replace(' ','_');
		var specialConfigObj = bvpSpecialsConfig[ specialbrandingKey ];

			var bln_specialbranded = false;
			var special_url = '';
			var special_title = '';

			if(specialConfigObj)
			{
				bln_specialbranded = true;
				special_url = specialConfigObj.url;
				special_title = specialConfigObj.name;
			}


		var videoDescription = currVideoObj.description;
		if(currVideoObj.lastModified && currVideoObj.lastModified.text){
			var monthNames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
			var dateArr = currVideoObj.lastModified.text.split('/');
			if(dateArr && typeof(dateArr) == 'object' && dateArr.length && dateArr.length >=2){
				var dateModified = new Date(dateArr[0],(dateArr[1]-1),dateArr[2]);
				var theDate = dateModified.getDate();
				var theMonth = monthNames[dateModified.getMonth()];
				var theYear = dateModified.getFullYear();
				html.push('<div id="commentsPadding"><div id="addedOnL"><b>Added On</b> '+theMonth+' '+theDate+', '+theYear+'</div></div>');
			}
		}
		html.push('<div id="contentL"><div class="bvp_desctext">'+videoDescription);
		html.push('<div class="bvp_desclinks">',
			(bln_specialbranded) ? '<div class="bvp_desclhead"><a href="'+special_url+'"><span><span>'+special_title+'</span> &raquo;</span></a><br></div>' : '',
		'<ul class="cnn_bulletbin">');
		if(currVideoObj.urls && currVideoObj.urls.relateds && typeof(currVideoObj.urls.relateds) == 'object') {
			try {
				var storyObj;
				if (currVideoObj.urls.relateds.length >=0) {
					for (var i=0, end=currVideoObj.urls.relateds.length; i<end; i++)
					{
						storyObj = currVideoObj.urls.relateds[i].story;
						html.push('<li><a href="'+storyObj.url.html+'">'+storyObj.headline+'</a></li>');
					}
				} else if (currVideoObj.urls.relateds.story) {
						storyObj = currVideoObj.urls.relateds.story;
						html.push('<li><a href="'+storyObj.url.html+'">'+storyObj.headline+'</a></li>');
				}
			} catch(err) {
				// do nothing, live your live, be free
			}
		}
		html.push('</ul></div></div></div>');

		document.getElementById('cnnVPInfoLeftCol').innerHTML = html.join('');
	}
}

/**
 * used when individual video is requested, so video's image will load before the rest
 * of the BVP
 * @param {Array} imgs: images array from video json object
 */
function getBackgroundImage(imgs) {
	for (var i=0,end=imgs.length; i<end; i++) {
		if ((imgs[i].h == 324) && (imgs[i].w == 576)) {
			return imgs[i].resource;
		}
	}
	return '';
}

var hasAChannelVidBeenClicked = false;

var bvpLoadSpecificVid = function( vidID, sectionID )
{
	cnnGoClearTimeoutIfAfterError();
	cnnNextVideoToPlay = vidID.substring(7);
	var videoJsonUrl;
	if( vidID.startsWith('/video/')) {				
		if( typeof bvpManager.selectedChannel.xml_url !== 'undefined' )
		{
			bvpManager.currentVideoPlayingChannelXML = bvpManager.selectedChannel.xml_url;
		}

		var isIntlUser = (location.hostname.indexOf('edition.') > -1 || location.port === '94');
		var dfltTab = (isIntlUser) ? 'international' : 'top_stories';
		var cvpVideoId = vidID.substring(7);
		var channelSection = '/video/'+cvpVideoId.substring(0, cvpVideoId.indexOf('/'));
		var initChannelID = sectionID || bvpManager.findChannelBySection(channelSection);
		if (initChannelID.length > 0) {
			var tab_id = bvpManager.findTabByChannel(initChannelID);
			bvpManager.setSelectedTab(tab_id, initChannelID, true);
			bvpManager.setSelectedChannel(initChannelID);
		} else {
			bvpManager.setSelectedTab(dfltTab);
		}
		cnnCVPPlay(cvpVideoId, 'cnnCVPLargeContainer', '640x406_start_bvp');
	}
};

