//structure that holds all data for videos
var video = {};
// called when template loads, this function stores a reference to the player and modules.
function onTemplateLoaded(experienceID) {
		bcExp = brightcove.getExperience(experienceID);
		video[experienceID] = {
			videoPlayer:bcExp.getModule(APIModules.VIDEO_PLAYER),
			exerience:bcExp.getModule(APIModules.EXPERIENCE),
			content:bcExp.getModule(APIModules.CONTENT)
		}
		video[experienceID].videoPlayer.addEventListener(BCVideoEvent.VIDEO_START, onVideoStart);
}
function onVideoStart(config){
	jQuery('#top-story-list').cycle('stop'); 
}
function onAfterPreviousNextUpdate(curr, next, opts){
	if(opts.currSlide == 0)$(opts.prev).removeClass('enabled');
	else $(opts.prev).addClass('enabled');
	if(opts.currSlide == opts.slideCount - 1)$(opts.next).removeClass('enabled');
	else $(opts.next).addClass('enabled');
}
jQuery(document).ready(function(){
	jQuery('a').focus(function(){jQuery(this).blur();})
	jQuery("#top-story-list").children(":not(:eq(0))").css({display:'none'})
	jQuery("<div></div>").animate({opacity:1}, 200, function(){
		jQuery("#top-story-list").cycle({
			fx: 'fadeMask',
			speed: 0,
			prev: '#top-story-prev-next .previous',
			next: '#top-story-prev-next .next',
			pause: 1,
			nowrap:true,
			end:function(opts){
				jQuery("#top-story-list").cycle(0);
			},
			after: function(curr, next, opts){
				onAfterPreviousNextUpdate(curr, next, opts);
				for(i in video)if(video[i].videoPlayer.isPlaying())video[i].videoPlayer.pause();
			},
			timeout: 8000
  		});
			
		jQuery("#in-other-news-list").cycle( {
  	fx: 'fade',
	cleartype:true,
	nowrap:true,
	end:function(){
		console.log('called');
	},
	after: onAfterPreviousNextUpdate,
  	prev: '#in-other-news-prev-next .previous',
  	next: '#in-other-news-prev-next .next',
		timeout: 0 
  });
	jQuery("#highlight-list").cycle( {
  	fx: 'scrollHorz',
	nowrap:true,
	after: onAfterPreviousNextUpdate,
  	prev: '#highlights-prev-next .previous',
  	next: '#highlights-prev-next .next',
		timeout: 0 
  });
	jQuery("#country-list").cycle({
  	fx: 'scrollHorz',
	nowrap:true,
	after: onAfterPreviousNextUpdate,
  	prev: '#traveling-prev-next .previous',
  	next: '#traveling-prev-next .next',
	/*
		pager: '#scroller-content',
		pagerAnchorBuilder: function(idx, slide) { 
        return '<li><a href="#"><a class="" target="_self" title="'+ slide.id +'" href="#">- '+ slide.id +'</a></li>'; 
    },*/
		before:function(curr, next, opts){
			var next = jQuery(next);
			var id = next.attr("id");
			var html = next.html().replace(/\s+/, "")
			// load from a static file - not needed with only 5 showing
			//if(html == "")
			//	next.load("/traveling/"+ id.replace(/\s/g, "_").replace(/\./g, "") + ".htm");
		},
		timeout: 0 
  });
	});
	
	jQuery("#top-story-list, #in-other-news-list,#highlight-list, #country-list").children(":first-child").show();
	jQuery('#scroller-content li, #dipnote-blog li, #multimedia li, #find-it li, #quick-links li, #t2-press li, #t2-travel li, #t2-careers li, #t2-business li, #t2-youth-and-education li, #t2-about-state li').prepend('- ');
});
