// JavaScript Document
// AJAX for player and tab area
// -------------------
// Player
// -------------------
// This is a javascript handler for the player and is always needed.
// some variables to save
var currentItem = 0;
var previousItem = -1;
// this function is caught by the JavascriptView object of the player.
//function sendEvent(typ,prm) { try{thisMovie("pfs_player").sendEvent(typ,prm)}catch(e) {}; };
//function sendEvent(typ,prm) { thisMovie("pfs_player").sendEvent(typ,prm) };
function sendEvent(typ,prm) { thisMovie("mypodplayer").sendEvent(typ,prm)	 };

// these functions is called by the JavascriptView object of the player.
 function getUpdate(typ,pr1,pr2,swf) {
	 alert("getUpdate " + typ + ' pre:' + previousItem + ' cur:' + currentItem );
 	if(typ == "item") { currentItem = pr1;	
	   setTimeout("getItemData(currentItem)",100);
	}
	//else if(typ == "state") { currentState = pr1; setTimeout("getStateData(currentItem)",10)}
};

// WORKING FOR MPV2
function getItemData(idx1) {
  var obj = null;
   // Not working in IE
   currentItem = idx1;
   //alert("This has worked " + idx1 + ' pre:' + previousItem + ' cur:' + currentItem );
  
    if(previousItem != currentItem)
   {	        	
		previousItem = currentItem;
		//$("#tabcontainer").load('/common/tabs/'+idx1);
		$("#tabcontainer").load('/common/tabs/'+idx1, function(response, status, xhr) {
  if (status == "error") {
        var msg = "Sorry but there was an error: ";
       alert(msg + xhr.status + " " + xhr.statusText);
  }
});     
   }
}; 
// WORKING FOR MPV2

function getStateData(idx2) {
  var obj = null;
   // Not working in IE
   //obj = thisMovie("mypodplayer").itemData(idx2);
   
   alert("Checking State " + idx1 + ' pre:' + previousItem + ' cur:' + currentItem );
   if(previousItem != currentItem && (currentState == 2 || currentState == 1)  )
   {	
		 previousItem = currentItem; 
		//$("#tabcontainer").load('/common/tabs/'+obj["id"]);  
		$("#tabcontainer").load('/common/tabs/'+obj["id"], function(response, status, xhr) {
  if (status == "error") {
        var msg = "Sorry but there was an error: ";
       alert(msg + xhr.status + " " + xhr.statusText);
  }
});     
   }
}; 
// This is a javascript handler for the player and is always needed.
function thisMovie(movieName) {
		return document.getElementsByName(movieName)[0];
};
/* function thisMovie(movieName) {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
             //  return document.getElementsByName(movieName)[0];
	}
};
*/
function stp_plyr(){
	var player = getelementbyid('mypodplayer');
	if (player){
	sendEvent('stop');
	};
}

/*
function displayCompanionBanners(banners, tracking) {
	 tmDisplayBanner(banners, "adarea", 300, 250, null, tracking);
	 tmDisplayBanner(banners, "bottom_ad", 728, 90);
}   

function displayCompanionBanners_300x250(banners) {
          tmDisplayBanner(banners, "adarea", 300, 250);
      }
function displayCompanionBanners_728x90(banners) {
          tmDisplayBanner(banners, "bottom_ad", 728, 90);
      }
*/
