	
	var current_movie = 0;
	var target_movie;
	var Debug = 0;
	var count = 0;
	var movWidth = "640";
	var movHeight = "360";
        //var staticFilePath = "/kiosk/lewis/";
	var staticFilePath = "file:///C:/ra/";
	var timerID = null;

        function test() {
		alert("test");
	}

	function initqjs(){
//		alert("Loaded");		
		var ele = document.getElementById("bodydiv");
//		alert(ele.className);
//		window.status = ele.className;
/*
		if(ele.addEventListener) {
			ele.addEventListener('click',bodyEvent,true);
			return true;
		}
		else 

		{
			ele.attachEvent('onclick',bodyEvent);
			return true;
		}

		return false;
*/
	}

	function bodyEvent(e) {
		
		count++;
		//window.status = "bodyEvent("+count+")";
		//window.event.cancelBubble = true;		
		try {

			stopAll();		
		} catch(e) {};
	}

	function pageTrace(str) {
		if(Debug != 0) window.status = str;
	}


        function PlayIt(anObj)
        {
		document.getElementById("leftspaceblock").className="leftspace_opq";
                anObj.Play();
        }

        function StopIt(anObj)
        {
		document.getElementById("leftspaceblock").className="leftspace";
                anObj.Stop();
        }

	function Rewind(anObj)
        {
                anObj.Rewind();
        }

	function setMovSize(width,height) {
		movWidth = width;
		movHeight = height;
	}

	function drawObject(str,num) {
		//if(num == 1) alert(staticFilePath+'./data/video/'+str+num+'.mov');
	        var embed = '<embed name="movie'+num+'" src="'+staticFilePath+'./data/video/'+str+num+'.mov" width="'+movWidth+'" height="'+movHeight+'" autoplay="false" enablejavascript="true" kioskmode="true" controller="false" showlogo="false">';
		document.write('<object id="movie'+num+'" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" align="middle" width="'+movWidth+'" height="'+movHeight+'"><param name="src" value="'+staticFilePath+'./data/video/'+str+num+'.mov" /><param name="autoplay" value="false" /><param name="enablejavascript" value="true" /><param name="controller" value="false" /><param name="kioskmode" value="true" /><param name="width" value="'+movWidth+'" /><param name="height" value="'+movHeight+'" /><param name="showlogo" value="false" />'+embed+'</object>');
	        //ADD EMBED FOR FIREFOX

	}



	function getPagesMovieElement(str,num) {
	       //pageTrace(str+num);
	       //if str = movie and Firefox. Get the embed.
	       var obj = document.getElementById((str+num));
	       //FIREFOX USES EMBEDS
	       var embed_obj = eval("document.embeds["+(num-1)+"]");
	       if(embed_obj && str == "movie") return embed_obj;
	       return obj;
	       
        }

	function hideDiv(obj) {	      
	      obj.style.display = "none";
	      obj.style.visibility = "hidden";
    	      pageTrace(window.status + " HIDE:" + obj.id);
	}

	function showDiv(obj) {
	      obj.style.display = "inline";
	      obj.style.visibility = "visible";
	      pageTrace(window.status + " SHOW:" + obj.id);

        }

	function runCurrentMovie() {
	    if(current_movie != 0) {
		try {
			target_movie.Play();
		} catch (ep) {
			window.clearTimeout(timerID);
			current_movie = 0;
		};
		window.clearTimeout(timerID);
	    }
	    pageTrace(window.status + " " +new Date());
	}

	function showAndPlay(num) {
	    var target_screen;
	    var tmp_screen;
	    var tmp_movie;
	    var load_count = 0;

	    //stop,rewind and hide all movies
	    document.getElementById("leftspaceblock").className="leftspace_opq";

	    if(current_movie != 0) {
	        tmp_screen = getPagesMovieElement("screen",current_movie);
		tmp_movie = getPagesMovieElement("movie",current_movie);
		tmp_movie.Stop();
		tmp_movie.Rewind();
		hideDiv(tmp_screen);
	    }	    
/*
    	    if(num < 0)  {	
		document.getElementById("leftspaceblock").className="leftspace";
		return false;
	    }
	    else {
		window.event.stopPropagation();
	    }
*/
	    target_screen = getPagesMovieElement("screen",num);
	    target_movie = getPagesMovieElement("movie",num);		
   
	    pageTrace("SET:" + target_screen);		
 
	    if(target_movie && target_screen) {
	    	   
	       showDiv(target_screen);
	       current_movie = num;
	       //CHECK MOVIE LOAD STATUS? HOW?
	       //QUICKTIME NEEDS A DELAY BEFORE PLAYING
	       //IS IT THE LOAD TIME? ITS NO TIME AT ALL!
	       //1ms vs simply calling Play works!
	       timerID = window.setTimeout('runCurrentMovie()', 1);	       
	       //timerID = window.setTimeout('runCurrentMovie()', 500);	       
	       //target_movie.Play(); 	        
	       //target_movie.SetAutoPlay(true);
 	       pageTrace(window.status + " Play "+num);
	   }
	   if(num = 0) current_movie = 0;
	}
	
	function stopAll() {
		var tmp_screen;
		//if(window.event.currentTarget.className != "movie_container") return false;
		
		if(current_movie != 0) {
	        	tmp_screen = getPagesMovieElement("screen",current_movie);
			tmp_movie = getPagesMovieElement("movie",current_movie);
			tmp_movie.Stop();
			tmp_movie.Rewind();
			hideDiv(tmp_screen);
				
	    	}
		document.getElementById("leftspaceblock").className="leftspace"		   
	}

	

