	/************************************************************************************************************
	(C) www.dhtmlgoodies.com, November 2005
	
	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact. However, you may not
	redistribute, sell or repost it without our permission.
	
	Thank you!
	
	www.dhtmlgoodies.com
	Alf Magne Kalleland
	
	************************************************************************************************************/
	var arrowImageHeight = 35;	// Height of arrow image in pixels;
	var displayWaitMessage=false;	// Display a please wait message while images are loading?	
	var previewImage = false;
	var previewImageParent = false;
	var slideSpeed = 1000;
	var previewImagePane = false;
	var slideEndMarker = false;
	var galleryContainer = false;
	var movieStopped="false";
	var cineType = 0;
	var Frame=0;
	var zoomfactor=100;
	var xPan=0;
	var yPan=0;
	var trueFisp=new Array('Long Axis','Short Axis','Aorta','RVOT');
	var tagging=new Array('Long Axis','Short Axis');
	var flow=new Array('Aorta','RP','LPA','PA');

	var cineSel="trueFisp";
	var axisSel="Long";
	var numOfMovies=12;
	var noOfMovies=12;
	thumbnails=new Array();

	function getAxis(Movie){
		//clear out current axis
		document.form1.AxisBox.options.length=0;
		
		Cine=Movie.options[Movie.selectedIndex].value;
		if (Cine != ""){
			if (Cine=='0'){
				for(i=0;i<=trueFisp.length-1;i++)
				{
					document.form1.AxisBox.options[i]=new Option(trueFisp[i]);
					document.form1.AxisBox.options[i].value=i
				}
				cineSel="trueFisp";
				document.form1.AxisBox.selectedIndex=0;
			}
			if (Cine=='1'){
				for(i=0;i<=tagging.length-1;i++)
				{
					document.form1.AxisBox.options[i]=new Option(tagging[i]);
					document.form1.AxisBox.options[i].value=i
				}
				cineSel="Tag";
				document.form1.AxisBox.selectedIndex=0;
			}
			if (Cine=='2'){
				for(i=0;i<=flow.length-1;i++)
				{
					document.form1.AxisBox.options[i]=new Option(flow[i]);
					document.form1.AxisBox.options[i].value=i
				}
				cineSel="Flow"
				document.form1.AxisBox.selectedIndex=0;
			}
			cineType=Cine;
			axisSelected(document.form1.AxisBox)
		}
	}
	function axisSelected(axis){
		axisValue=axis.options[axis.selectedIndex].value;
		if (axisValue != ""){
			if (cineType=='0'){
				if (axisValue=='0'){
					axisSel="Long";
					noOfMovies=12;					
				}
				if (axisValue=='1'){
					axisSel="Short";
					noOfMovies=30;
				}
				if (axisValue=='2'){
					axisSel="Aorta";
					noOfMovies=3;
				}
				if (axisValue=='3'){
					axisSel="Rvot";
					noOfMovies=1;
				}
			}
			if (cineType=='1'){
				if (axisValue=='0'){
					axisSel="Long";
					noOfMovies=11;
				}
				if (axisValue=='1'){
					axisSel="Short";
					noOfMovies=15;
				}
			}
			if (cineType=='2'){
				if (axisValue=='0'){
					axisSel="Aorta";
					noOfMovies=2;
				}
				if (axisValue=='1'){
					axisSel="RP";
					noOfMovies=2;
				}
				if (axisValue=='2'){
					axisSel="LPA";
					noOfMovies=2;
				}
				if (axisValue=='3'){
					axisSel="PA";
					noOfMovies=4;
				}
			}
			changeThumbnails();
		}
		
	}
	function getTopPos(inputObj)
	{		
	
	  var returnValue = inputObj.offsetTop;
	  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
	  return returnValue;
	}
	
	function getLeftPos(inputObj)
	{

	  var returnValue = inputObj.offsetLeft;
	  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
	  return returnValue;
	}

	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 changeMovie(imageIndex)
	{
		if (imageIndex<=noOfMovies){
			document.getElementById('largeImageCaption').innerHTML = '<H3>Loading image, please wait...</H3>';
			var flashMovie=getFlashMovieObject("flashfile");
			var tempstr="movies/" + cineSel +axisSel + imageIndex + ".swf";
			flashMovie.LoadMovie(0, tempstr);
			locationPane = document.getElementById('locationImg')
			var images = locationPane.getElementsByTagName('IMG');
			var tmpstr="img/cineplayer/" + cineSel +axisSel + imageIndex + "Loc.jpg";
			images[0].src = tmpstr;
			document.getElementById('largeImageCaption').innerHTML = '<H3>Loaded ' + ' ' + cineSel + ' ' + axisSel + ' ' + imageIndex + '</H3>';
			flashMovie.Zoom(zoomfactor);
			flashMovie.Pan(xPan,yPan,0);
		}
	}
	function initSlide(e)
	{
		if(document.all)e = event;
		
		
		slideSpeed = e.clientY + Math.max(document.body.scrollTop,document.documentElement.scrollTop) - getTopPos(this);
		if(this.src.indexOf('down')>=0){
			slideSpeed = (slideSpeed)*-1;	
		}else{
			slideSpeed = arrowImageHeight - slideSpeed;
		}
		slideSpeed = Math.round(slideSpeed * 10 / arrowImageHeight);
	}
	
	function stopSlide()
	{		
		slideSpeed = 0;
		this.src = this.src.replace('-over','');
	}
	
	function slidePreviewPane()
	{
		if(slideSpeed!=0){
			var topPos = previewImagePane.style.top.replace(/[^\-0-9]/g,'')/1;	
		
			if(slideSpeed<0 && slideEndMarker.offsetTop<(previewImageParent.offsetHeight - topPos)){
				slideSpeed=0;
			
			}
			topPos = topPos + slideSpeed;
			if(topPos>0)topPos=0;

		 	previewImagePane.style.top = topPos + 'px';
	 	
		}
	 	setTimeout('slidePreviewPane()',30);		
	}
	
	function revealThumbnail()
	{
		this.style.filter = 'alpha(opacity=100)';
		this.style.opacity = 1;
	}
	
	function hideThumbnail()
	{
		this.style.filter = 'alpha(opacity=0)';
		this.style.opacity = 0;
	}
	
	function initGalleryScript()
	{
		previewImageParent = document.getElementById('theImages');
		previewImagePane = document.getElementById('theImages').getElementsByTagName('DIV')[0];
		previewImagePane.style.top = '0px';
		galleryContainer  = document.getElementById('galleryContainer');
		var images = previewImagePane.getElementsByTagName('IMG');
	
		slideEndMarker = document.getElementById('slideEnd');
		
		document.getElementById('arrow_up_image').onmousemove = initSlide;
		document.getElementById('arrow_up_image').onmouseout = stopSlide;
		
		document.getElementById('arrow_down_image').onmousemove = initSlide;
		document.getElementById('arrow_down_image').onmouseout = stopSlide;
	
		slidePreviewPane();

		cineSel="trueFisp";
		axisSel="Long";
		numOfMovies=12;

		document.form1.CineBox.selectedIndex=0;
		document.form1.AxisBox.selectedIndex=0;
	}

	function changeThumbnails(){
		previewImagePane = document.getElementById('theImages').getElementsByTagName('DIV')[0];
		var images = previewImagePane.getElementsByTagName('IMG');
		for(var no=0;no<noOfMovies;no++){
			num=no+1;
			images[no].src = 'img/cineplayer/' + cineSel + axisSel + num + '.jpg';
		}
		for(var no=noOfMovies;no<images.length;no++){
			images[no].src ='img/cineplayer/blank.png';
		}
		previewImagePane.style.top = 0;	
		changeMovie(1); 
	}
	function positionSliderTop(n){
		if(n=="top"){
			previewImagePane.style.top =0;
		}
		if(n=="bottom"){
			previewImagePane.style.top =-(noOfMovies-3)*110 + 'px';
		}
	}
	function stopMovie() {
		var flashMovie=getFlashMovieObject("flashfile");
		flashMovie.StopPlay();
		flashMovie.GotoFrame(Frame);
		movieStopped="true";
	}
	function playMovie() {
		var flashMovie=getFlashMovieObject("flashfile");
		flashMovie.Play();
		movieStopped="false";
	}
	function rewindMovie() {
		var flashMovie=getFlashMovieObject("flashfile");
		flashMovie.StopPlay();
		flashMovie.Rewind();
		Frame=0;
		movieStopped="true";
	}
	function prevMovie() {
		var flashMovie=getFlashMovieObject("flashfile");
		if(movieStopped="true"){
			if(Frame>0){		
				flashMovie.GotoFrame(Frame-1);
				Frame=Frame-1;
			}
		}
	}
	function nextMovie() {
		var flashMovie=getFlashMovieObject("flashfile");
		if(movieStopped="true"){
			flashMovie.GotoFrame(Frame+1);
			Frame=Frame+1;
		}
	}	
	function zoomMovie(x) {
		var flashMovie=getFlashMovieObject("flashfile");
		if (x=='in' && zoomfactor>50){
			zoomfactor=zoomfactor-5;
			flashMovie.Zoom(0)		
			flashMovie.Zoom(zoomfactor);
			flashMovie.Pan(xPan,yPan,0);
		}
		if (x=='out' && zoomfactor<100){
			zoomfactor=zoomfactor+5;
			flashMovie.Zoom(0)
			flashMovie.Zoom(zoomfactor);
			flashMovie.Pan(xPan,yPan,0);
		}
		if (x=='reset') {
			zoomfactor=100;
			flashMovie.Zoom(0)
			xPan=0;
			yPan=0;
		}

		
	}
	function panMovie(x,y) {
		var flashMovie=getFlashMovieObject("flashfile");
		xscaled=x*zoomfactor/100;
		yscaled=y*zoomfactor/100;
		flashMovie.Pan(xscaled,yscaled,0);
		xPan=xPan+xscaled;
		yPan=yPan+yscaled;
	}
	window.onload = initGalleryScript;
