/* load flash videos */
 // set up unobtrusive JS
 window.onload = initPage;
 
 function initPage() {
  getvideo();
  openNewWindowNow();
}
 
 function getvideo() {
			// check to see that the browser supports the getElementsByTagName method
			// if not, exit the loop 
			if (!document.getElementsByTagName) {
		return false; 
	} 
	// create an array of objects of each link in the document 
	var videovalue = document.getElementsByTagName("a");
	// loop through each of these links (anchor tags) 	
	for (var i=0; i < videovalue.length; i++) {	
		// if the link has a class of "popup"...	
		if (videovalue[i].className == "video") {	
			// add an onclick event on the fly to pass the href attribute	
			// of the link to our second function, openPopUp 	
			videovalue[i].onclick = function() {	
			getWidePlayer(this.getAttribute("href"));	
			return false; 	
			} 	
		}
	} 
} 


function openNewWindowNow() {
			// check to see that the browser supports the getElementsByTagName method
			// if not, exit the loop 
			if (!document.getElementsByTagName) {
		return false; 
	} 
	// create an array of objects of each link in the document 
	var videovalue = document.getElementsByTagName("a");
	// loop through each of these links (anchor tags) 	
	for (var i=0; i < videovalue.length; i++) {	
		// if the link has a class of "popup"...	
		if (videovalue[i].className == "compliance") {	
			// add an onclick event on the fly to pass the href attribute	
			// of the link to our second function, openPopUp 	
			videovalue[i].onclick = function() {	
			openPopUp(this.getAttribute("href"));	
			return false; 	
			} 	
		}
	} 
}
 
 //get wide player
var http = createRequestObject();
function createRequestObject() {
   var objAjax;
   var browser = navigator.appName;
   if(browser == "Microsoft Internet Explorer"){
      objAjax = new ActiveXObject("Microsoft.XMLHTTP");
   }else{
      objAjax = new XMLHttpRequest();
   }
   return objAjax;
}

function getWidePlayer($video){
   http.open('get','/players/player.php?video=' + $video + '.flv');
   http.onreadystatechange = updateNewContent;
   http.send(null);
   return false;
}

function updateNewContent(){
   if(http.readyState == 4){
      document.getElementById('player').innerHTML = http.responseText;
   }
}

//get list player
var http = createRequestObject();
function createRequestObject() {
   var objAjax;
   var browser = navigator.appName;
   if(browser == "Microsoft Internet Explorer"){
      objAjax = new ActiveXObject("Microsoft.XMLHTTP");
   }else{
      objAjax = new XMLHttpRequest();
   }
   return objAjax;
}

function getListPlayer(){
   http.open('get','/players/list.html');
   http.onreadystatechange = updateNewContent;
   http.send(null);
   return false;
}

function updateNewContent(){
   if(http.readyState == 4){
      document.getElementById('player').innerHTML = http.responseText;
   }
}

//pop up window for compliance
function openPopUp(linkURL) {
	window.open(linkURL,'popup','width=622,height=400')
}