
function bc_global(bc_mBaseUrl)
{
	this.bc_mBaseUrl = bc_mBaseUrl;
	this.bc_mCurrentPageId = 0;
	
	
	this.doSearch = function() {
	    location.href = bc_mBaseUrl + "search/" + document.getElementById("searchField").value;
	}
	
	function init()
	{
		var searchText = document.getElementById("searchField").value;
		var searchBox = document.getElementById("searchField");

		searchBox.onfocus = function(){
	        if (searchBox.value == searchText) searchBox.value = "";
		};
		
		searchBox.onblur = function() {
			if (searchBox.value == "") {
				searchBox.value = searchText;
			}
		};
	}
	
	this.searchBox = function(e)
	{	
		var keynum;
		
		if(window.event) // IE
			{
				keynum = e.keyCode;
			}
		else if(e.which) // Netscape/Firefox/Opera
		{
			keynum = e.which;
		}
		if(keynum==13) {
			this.doSearch();
		}
	}
	
	this.page = function(pPageId, numberOfPages) {
	    document.getElementById('page_' + this.bc_mCurrentPageId).style.display = "none";
		document.getElementById('page_' + pPageId).style.display = "block";
		
		//Fix the css and html for the paging links.
		document.getElementById("bc_number_" + pPageId).className = "bc_activeNumber";
		document.getElementById("bc_number_" + pPageId).innerHTML = (pPageId + 1);
		
		document.getElementById("bc_number_" + this.bc_mCurrentPageId).className = "bc_pageNumbers";
		document.getElementById("bc_number_" + this.bc_mCurrentPageId).onlick = 'javascript:bcGlobal.page(" + this.bc_mCurrentPageId + "," + numberOfPages + ")';
		document.getElementById("bc_number_" + this.bc_mCurrentPageId).innerHTML = (this.bc_mCurrentPageId + 1);
		if(this.bc_mCurrentPageId == 0) 
		   document.getElementById("bc_number_" + this.bc_mCurrentPageId).borderLeftWidth = "0px";
		if(pPageId == 0) {
			document.getElementById('prev').style.display = "none";
			document.getElementById('next').style.display = "inline";
		} else if(pPageId == numberOfPages - 1) {
			document.getElementById('next').style.display = "none";
			document.getElementById('prev').style.display = "inline";
		} else {
			document.getElementById('next').style.display = "inline";
			document.getElementById('prev').style.display = "inline";
		}
		this.bc_mCurrentPageId = pPageId;
	}
	
	this.next = function(numberOfPages) {
		this.page(this.bc_mCurrentPageId + 1, numberOfPages);
	}
	
	this.previous = function(numberOfPages) {
		this.page(this.bc_mCurrentPageId - 1, numberOfPages);
	}
	
	init();
	
}

function onTemplateLoaded() {
    player = brightcove.getExperience("myPlayer");
    experience = player.getModule(APIModules.EXPERIENCE);
    experience.addEventListener(BCExperienceEvent.CONTENT_LOAD, onContentLoad);
    social = player.getModule(APIModules.SOCIAL);
}

function onContentLoad() {
    social.setLink(experience.getExperienceURL());
}

