/* REQUIRES jQuery */

(function(){
	var C = {
		defaults: {
			divVideo: "#videoplayer, #techContent",
			divContent: "#topSpan, #btmContent",
						
			divTop: "#container_header",
			linkVideo: "#btnPlay, a.linkVideo",
			linkClose: "#close",
			useFade: true
		},

		getDefaults: function() {
			for(key in C.defaults) {
				if(!C[key]) {
					C[key] = C.defaults[key];
					if(C.options && C.options[key]) C[key] = C.options[key];
				}
			}
		},

		clearFilter: function() {
			if(this.style.removeAttribute) this.style.removeAttribute("filter");
		},

		initStart: function() {
			C.getDefaults();
			$(C.divVideo).hide();
			$(C.linkVideo).click(function(ev){
				ev.preventDefault();
				$(C.divVideo).slideDown("slow");
				$(C.divContent).fadeOut();
				
				if($(window).scrollTop() > $(C.divTop).offset().top) {
					$("html, body").animate({
						scrollTop: $(C.divTop).offset().top
					}, "fast");
				}
			});
			$(C.linkClose).click(function(ev){
				$(C.divVideo).slideUp("slow");
				$(C.divContent).fadeIn("fast", C.clearFilter);
								
				if(videoPlayer) videoPlayer.stop();
			});
		},

		init: function () {
			if (typeof jQuery != "undefined") {
				$(document).ready(C.initStart);
			}
		}
	}
	window['ClientFunctions'] = C;
})();

ClientFunctions.init();

/* Brightcove */
var experienceModule;	//a reference to brightcove experience module
var videoPlayer;	//a reference to the videoPlayer module

// called when template loads, we use this to store a reference to the player and modules
// and add event listeners for the video load (when the user clicks on a video)
function onTemplateLoaded(experienceId) {
	experienceModule = brightcove.getExperience(experienceId);
	videoPlayer = experienceModule.getModule(APIModules.VIDEO_PLAYER);
}
