// JavaScript Document
function showTV(event,contentID){ 
/**
* IBM TV is 322 pix width and 291 pix height
* */
   //the position of mouse
	var posx=0,posy=0;

	//the IBMTV container id
	var divID;
	if(arguments[2]==undefined) divID = "ibm-overlay-top"; //If the IBMTV container div id is not provided, we use default one
	else divID = arguments[2]; // otherwise we use the given one
	
	//initialize the variable 'event'
	event=event || window.event;
	//the height of IBMTV is 291 and the height of blue bar is 30
    posy = event.clientY + document.documentElement.scrollTop - 291 - 30;
	if(posy<0) posy = 0;
	
	var divWidth = document.getElementById('ibm-top').offsetWidth;
	var bodyWidth=document.body.clientWidth;   
	posx = (bodyWidth-divWidth)/2;
	if(posx<0) posx = 0;

	//set the left position
	document.getElementById(divID).style.left = (posx + 400) + 'px'; 
 
	//calculate the top position
	document.getElementById(divID).style.top = posy + 'px';
	document.getElementById(divID).style.width = '322px';
	
	/*detect the browser type*/
	if (document.all){
     	var ua = navigator.userAgent;
		/*For IE7*/
		if (/msie 7/i.test(ua)) {}
		/*For IE6*/
		else if(/msie 6/i.test(ua)) {
			document.getElementById(divID).style.left = (posx + 410) + 'px'; 
		}
  	} else {
     	if (document.layers){
       		//Netscape
    	} else {
		   /*Firefox*/
		   document.getElementById(divID).style.height = '291px';
        }
  }

	document.getElementById("ibm-tv-bar-bg").style.top = document.getElementById('ibm-tv-bar').style.top;
	document.getElementById("ibm-tv-bar-bg").style.left = document.getElementById('ibm-tv-bar').style.left;
	document.getElementById(divID).style.display='block';
	
	idArray = contentID.split(',');
	contentID = idArray[0];
	for(var i=1; i<idArray.length; i++){
		contentID += "%26item" + i + "=" + idArray[i];	
	}
	
   var so = new SWFObject("http://www.ibm.com/ibmtv/320player", "ibm_tv_320", "322", "291", "8", "#ffffff");
   //so.addParam("wmode", "transparent");
   so.addParam("allowfullscreen","true");
   so.addParam("base","http://www.ibm.com/software/info/television/");
   so.addVariable("config","http://www.ibm.com/ibmtv/320config?item="+contentID);
   so.write("ibm-tv-body");  		
}

function hideTV(divID){
	//hide this popup
	document.getElementById(divID).style.display='none';
}

/*
* Because id is unique, and this id "ibm-overlay-top" contains some CSS attributes,
* we don't want to rewrite it, and set two popups share the same id. When one of them is displayed, 
* it will use this id, and when it is hiden, it will release this id.
*/
	//display the popup
	function showOverlay(event,divID){	
		//show the popup
		document.getElementById(divID).style.display='block';
		
		//the position of mouse
		var posx=0,posy=0;
		//how many pixels the user scroll the browser
		var scrollTop = 0;
		
		//initialize the variable 'event'
		event=event || window.event;
    	posx = event.clientX;
    	posy = event.clientY;
		scrollTop = document.documentElement.scrollTop;	

		//set the left position
		document.getElementById(divID).style.left = posx + 'px'; 
		//calculate the top position
		posy = posy - document.getElementById(divID).offsetHeight;
		
		if(posy<0) posy = 0; //if the popup is out of the top, move it back to top
		
		document.getElementById(divID).style.top = (scrollTop+posy) + 'px'; //if the user scroll the browser, we need consider it

		
		//if it is the second link, then increase the top offset
		if(divID=="ibm-overlay-top2"){
			//document.getElementById(divID).style.top = '200px'; 
			//if the first popup is still there, then hide it and release the id
			if(document.getElementById("ibm-overlay-top")!=null){
				document.getElementById("ibm-overlay-top").style.display = "none";
				document.getElementById("ibm-overlay-top").id = "ibm-overlay-top1";
			}
		}else if(divID=="ibm-overlay-top1"){
			//if the second popup is still there, then hide it and release the id
			if(document.getElementById("ibm-overlay-top")!=null){
				document.getElementById("ibm-overlay-top").style.display = "none";
				document.getElementById("ibm-overlay-top").id = "ibm-overlay-top2";
			}
		}
		
		document.getElementById(divID).id = "ibm-overlay-top"; 
	}
	
	function hideOverlay(divID){
		//hide this popup and release the id
		document.getElementById(divID.substr(0,divID.length-1)).style.display='none';
		document.getElementById(divID.substr(0,divID.length-1)).id = divID;
	}