var frontplayingInterval; //variable for scrolling through the front page stuff
var actionArray = new Array("rsna2009","rsnanews",	"radiology","radiographics", "education", "myrsna","RadInfo"); // array of front page events
var currentEvent;

/*
FLASH JAVASCRIPT
*/
function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}



function flashStopMovie(movieName){
	
	movie = getFlashMovieObject(movieName);
	movie.StopPlay() ;
	
}

function flashPlayMovie(movieName){
	
	movie = getFlashMovieObject(movieName);
	movie.Play();
	
}

function flashRewindMovie(movieName){
	
	movie = getFlashMovieObject(movieName);
	//movie.Rewind();
	movie.GotoFrame(1)
	
}

 function sendToActionScript(value) {
	 
	 getFlashMovieObject("RSNAFRONTVIDEO").sendToActionScript(value);
	 
 }


function flashIsLoaded(movieName) {
  movie = getFlashMovieObject(movieName);
  if (typeof(movie) != "undefined") {
    try {return movie.PercentLoaded() == 100; } catch(e) { return false;}
  } else {
    return false;
  }
}



var flashLoadedInterval;
function checkflashLoaded(movieName){
		
		if(flashIsLoaded(movieName)){
				 movie = getFlashMovieObject(movieName);
				 movie.GotoFrame(1);
				 clearInterval(flashLoadedInterval);
		}

	
}


/*
END FLASH JAVASCRIPT
*/


function rotateFrontpageItems(){
	turnoff();
	
	
	if(currentEvent == (actionArray.length - 1)){
		currentEvent = 0
	}else{
		currentEvent = currentEvent + 1
	}
	load_rightnav_ON('/customcf/frontpage/rightpane.cfm?ACTION=' + actionArray[currentEvent] ,actionArray[currentEvent],false);
	//alert('ken, do not freak out, i am testing. BK');	
}


function randomStart(){
	try{clearInterval(frontplayingInterval);}catch(e){}
	var randomnumber=Math.floor(Math.random()*actionArray.length);
	currentEvent = randomnumber;
	load_rightnav_ON('/customcf/frontpage/rightpane.cfm?ACTION=' + actionArray[currentEvent] ,actionArray[currentEvent],false);
	//alert(randomnumber);
}


function executeJavascript(divid){
			var d=document.getElementById(divid).getElementsByTagName("script");
			//if(d.length > 0){alert(d.length);}
			for(var x=0;x<d.length;x++) {
				//with(window) {
					eval(d[x].text);
				//}// end with
			}// end for		
}

function load_rightnav_ON(url,target,clear) {
	turnoff();
	if(clear){try{clearInterval(frontplayingInterval);}catch(e){}}
	
	//alert('do')
	AjaxRequest.get(
	    {
	      'url':url
	      ,'onSuccess':function(req)
		  		{
					turnoff();try{
					document.getElementById(target + '_image').innerHTML = '<img src="/customcf/frontpage/images/' + target + 'ON.gif" name="' + target + '" border="0" id="'+ target + '" />';		
					
					document.getElementById(target + '_bg').className = 'left_highlight';
					document.getElementById('rightpane').innerHTML =  req.responseText;
					//alert(document.getElementById('rightpane'));
					executeJavascript('rightpane');
					//document.getElementById(background).className = 'row2';
					}catch(e){}
					
				}
	    }
	  );
	
	for (var i = 0; i < actionArray.length ; i++) {
    	if(actionArray[i] == target){currentEvent = i}
	}
//	alert('Action Array: ' + actionArray.length);
	
}	


function turnoff(){
	try{
	document.getElementById(actionArray[currentEvent] + '_image').innerHTML = '<img src="/customcf/frontpage/images/' +  actionArray[currentEvent] + 'OFF.gif" name="' + actionArray[currentEvent] + '" border="0" id="' + actionArray[currentEvent] + '" />';
	document.getElementById(actionArray[currentEvent] + '_bg').className = 'left_normal';
	}catch(e){}
	//alert(currentEvent);
}




function toggleRadiologySection(section){
	if (document.getElementById(section).style.display == 'none'){
		document.getElementById(section).style.display = '';
		document.getElementById('toggle_' + section).innerHTML='<img src="/customcf/myrsna/plugins/radiology/images/bullet_toggle_minus.png" border="0">';
	} else {
		document.getElementById(section).style.display = 'none';
		document.getElementById('toggle_' + section).innerHTML='<img src="/customcf/myrsna/plugins/radiology/images/bullet_toggle_plus.png" border="0">';
	}

}




///Radiographics Section
function toggleRadiographicsSection(section){
	if (document.getElementById(section).style.display == 'none'){
		document.getElementById(section).style.display = '';
		document.getElementById('toggle_' + section).innerHTML='<img src="/customcf/myrsna/plugins/radiographics/images/bullet_toggle_minus.png" border="0">';
	} else {
		document.getElementById(section).style.display = 'none';
		document.getElementById('toggle_' + section).innerHTML='<img src="/customcf/myrsna/plugins/radiographics/images/bullet_toggle_plus.png" border="0">';
	}

}


function detectHeight() {
        var wh = 0;
        if (typeof(window.innerHeight)=="number") {
                wh = window.innerHeight;
        }
        else {
                if (document.documentElement && document.documentElement.clientHeight) {
                        wh = document.documentElement.clientHeight;
                }
                else {
                        if (document.body && document.body.clientHeight) {
                                wh = document.body.clientHeight;
                        }
                }
        }
        return wh;

} 


function detectWidth() {
        var wh = 0;
        if (typeof(window.innerWidth)=="number") {
                wh = window.innerWidth;
        }
        else {
                if (document.documentElement && document.documentElement.clientWidth) {
                        wh = document.documentElement.clientWidth;
                }
                else {
                        if (document.body && document.body.clientWidth) {
                                wh = document.body.clientWidth;
                        }
                }
        }
        return wh;

} 


function getRSNAVideo(target, rtmp_stream, w, h) {
	 
	 if(w == undefined){var w = 320}
	 if(h == undefined) { var h = 240 }
	 
	 var hasversion = 'N';
	 if(DetectFlashVer(9, 0, 115)){hasversion = 'Y'}
	 
	
	 
	 var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	 var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
	 var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
	 if (isIE && isWin && !isOpera){
		 	 var embedtype = 'object';
	 }else {
		 var embedtype = 'embed'; 
	 }
	 
		 
	 //alert(hasversion);
	 
	 AjaxRequest.get(
	    {
	      'url':'/customcf/frontpage/drawRSNAmediaplayer.cfm?hasversion=' + hasversion + '&rtmp_stream=' + rtmp_stream + '&embedtype=' + embedtype + '&h=' + h + '&w=' + w
	      ,'onSuccess':function(req){
				document.getElementById(target).innerHTML = req.responseText;
		  	}
	    }
	  );	  
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function initFront(){
	
MM_preloadImages('#fullpath#images/RSNA2008ON.gif');MM_preloadImages('#fullpath#images/rsnanewsON.gif');MM_preloadImages('#fullpath#images/radiologyON.gif');MM_preloadImages('#fullpath#images/radiographicsON.gif');MM_preloadImages('#fullpath#images/educationON.gif');MM_preloadImages('#fullpath#images/myrsnaON.gif');	MM_preloadImages('#fullpath#images/RadInfoON.gif')
	
document.getElementById('rightpane').style.height = detectHeight() - 150 + 'px';
//document.getElementById('rightpane').style.height = detectHeight() - 150 + 'px';
//alert(detectHeight() - 75 + 'px');
//set the left empty space to the height of the rightpane minus any "tabs"  the left_normal style has the hieght in px of the tab

//document.getElementById('leftspace').style.height = detectHeight() + 'px';
document.getElementById('leftspace').style.height = detectHeight() - 200 - 240 + 'px';


randomStart();
//frontplayingInterval = setInterval(function(){rotateFrontpageItems();}, 10000);
}



function getRSNAVideoSWF(file_name) {
	 
	 AjaxRequest.get(
	    {
	      'url':'/customcf/frontpage/education_swf.cfm?file_name=' + file_name
	      ,'onSuccess':function(req){
				document.getElementById('eflash').innerHTML = req.responseText;
		  	}
	    }
	  );	  
}


function launchJournalWindow(url,title,h,w){
		
		new Ajax.Request(url, {
		  method: 'get',
		  forceJS:true,
		  onSuccess: function(transport) {
				launchwin = new Ext.Window(
					{
					
						title:title,
						width:w,
						//height:h,
						//autoWidth:true,
						autoHeight:true,
						autoScroll:true,
						html: transport.responseText
					}
				).show();
		  }
		  
		});	
		

	
	
}

function launchSpotlightWindow(url,title,h,w){
	
		launchwin = new Ext.Window(
			{
			
				title:title,
				width:w,
				height:h,
				autoScroll:true,
				body:  new Ext.ux.ManagedIFrame({autoCreate:{id:'dynamicIframe1',cls:'x-window-body',width:'100%',height:'100%',src:url}})
			}
		).show();
	
	
}