//Greg Ecklund
//gecklund@orlive.com
//code for the popup maker and the randomization
AJS.BASE_URL = "http://www.clinicalwebcasts.com";

function rolloverTooltip(linkRef, e){	
	
	var tooltip = AJS.DIV({id:"infoToolTip"}, AJS.A({className:"moreInfoBarButton"}, "Click to learn more about this program"));
	var mPos = AJS.getMousePos(e);
	AJS.setStyle(tooltip, {position:"absolute",top:mPos.y - 16,left:mPos.x + 20});
	
	AJS.appendToTop(AJS.getBody(), tooltip );//write it in the body
	
	var content = AJS.getNextSiblingBytc(linkRef, "div", "moreInfoData");
	if(content != null)
		AJS.setHTML( AJS.$("infoToolTip") , content.innerHTML);
	
	AJS.appendToTop( AJS.$("infoToolTip"), AJS.IMG({src:"/images/Masthead-315x211.jpg"}) );
	
}
function updateToolTip(e){
	var mPos = AJS.getMousePos(e);
	AJS.setStyle(AJS.$("infoToolTip"), {top:mPos.y - 16,left:mPos.x + 20});
}
function hideToolTip(){	
	AJS.removeElement( AJS.$("infoToolTip") );
}

function showMoreInfo(linkRef, params){	

	var ajxRef = AJS.getNextSiblingBytc(linkRef, "a", "moreInfoLink");//link to go to in summaries dir
	//var ajxRef = linkRef;
	//console.log(ajxRef);

	if(typeof(bPageLoaded) != "undefined" && bPageLoaded){
		AJS.setHTML( AJS.$("moreInfoContent"), "Loading.." );
			
		var page = /[^/]+$/i.exec(ajxRef.href);	
		var ajx = AJS.getRequest("/summaries/"+page, null, "GET")
		ajx.addCallback(function(res_txt, req) { AJS.setHTML( AJS.$("moreInfoContent") , res_txt); })
		ajx.addErrback(function(res_txt, req) { AJS.setHTML( AJS.$("moreInfoContent") , "Unable to load page"+page); })
		ajx.sendReq()
		
		//set the link for the view program button
		AJS.$("viewProgramButton").href = ajxRef.href;
		
		//set the link for the print
		AJS.$("printButton").href = AJS.BASE_URL+"/summaries/"+page+"#print";
		
		//set the link for the more button
		AJS.$("morePerButton").href = AJS.BASE_URL+"/summaries/"+page;
		
		//var content = AJS.getNextSiblingBytc(linkRef, "div", "moreInfoData");									
		var page_size = AJS.getWindowSize();//size of the visible space
		
		//disable scrolling on body, have to do html tag to because of ie7 bug
		AJS.setStyle(AJS.getBody(), AJS.$bytc("html"), {overflow:"hidden"});
							
		//make sure inner box is visible
		if( AJS.isElementHidden(AJS.$("moreInfoInner")) == true )
			AJS.showElement(AJS.$("moreInfoInner"));
					
		//calculate center of the page		
		var ft = ((page_size.h - params.height) /2) - 20 + AJS.getScrollTop();
		if(ft < 0)
			ft = 0;
		
		//set the inner box's size and position
		AJS.setStyle(AJS.$("moreInfoInner"), {width:params.width, height:params.height, top:ft, left:((page_size.w - params.width) /2)} );
		AJS.setStyle(AJS.$("moreInfoContent"), {height:params.height - 30} );
		
		//AJS.setHTML( AJS.$("moreInfoContent") , content.innerHTML);
		
		//make the overlay
		initOverlay();
	}else{
		window.location.href=ajxRef;
	}
}

function initOverlay() {	

	var page_size = AJS.getWindowSize();//size of the visible space

	AJS.setStyle(AJS.$("moreInfo"), {width:page_size.w, height:page_size.h, top: AJS.getScrollTop()});

	if( AJS.isElementHidden(AJS.$("moreInfo")) == true )
		AJS.showElement(AJS.$("moreInfo"));
							
	AJS.setOpacity(AJS.$("moreInfo"), 0.5);
}

function closeAll(){
	AJS.hideElement(AJS.$('moreInfo'));
	AJS.hideElement(AJS.$('moreInfoInner'));
	
	//enable scrolling on body again
	AJS.setStyle(AJS.getBody(), AJS.$bytc("html"), {overflow:"auto"});
}


