//Requires scriptaculous and prototype libraries loaded on the page as well



var defaultWidth = 671;
var defaultHeight = 600;
var movieWidth = 560;
var movieHeight = 350;
var movieCellHeight = 370;
var movieType = 0;
var gDebug = false;

var movieName = "";
var bgImgSmall = new Image;
//bgImgSmall.src = "../images/moviebox_bg_small.png";
var bgImgLarge = new Image;
//bgImgLarge.src = "../images/moviebox_bg_large.png";
var bgImgTall = new Image;
//bgImgTall.src = "images/moviebox_bg_tall.png";

//Size and position functions
function setMoviePos() {
	var left, top = null;

	left = this.windowSize().x+(this.windowSize().width-this.defaultWidth)/2;
	if (this.windowSize().width<this.defaultWidth) left = this.windowSize().x;

	top = this.windowSize().y+(this.windowSize().height-this.defaultHeight)/2;
	if (this.windowSize().height<this.defaultHeight) top = this.windowSize().y;	
	if (gDebug) alert("left: " + left + " top: " + top);
	return { left:left, top:top };
}

function windowSize() {
	var width = window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
	var height = window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight);
	var x = window.pageXOffset || (window.document.documentElement.scrollLeft || window.document.body.scrollLeft);
	var y = window.pageYOffset || (window.document.documentElement.scrollTop || window.document.body.scrollTop);
		
	return {'width':width, 'height':height, 'x':x, 'y':y}
}

//Show the movie
function showMovie(mName,w,h,mType){
	if (mName && mName != ""){
		movieName = mName;
		if (movieName.indexOf(".swf") == -1){
			movieName += ".swf";
			if (gDebug) alert("added swf file extension");
		}
	}else{
		return false;
	}
	var bg = $('movieBackground');
	bg.style.top = setMoviePos().top + "px";
	bg.style.left = setMoviePos().left + "px";
	
	if (w && w != 0){
		movieWidth = w;
	}
	if (h && h !=0){
		movieHeight = h;
		$('movieCell').style.height = (h + 30) + "px";		
		$('movie').style.height = h + "px";
	}	
	if (mType){ movieType = mType;	}
	
	
	new Effect.Grow(bg,{duration:0.5,direction:'top-left',afterFinish:finishMovieOpen});
//	new Effect.Appear(bg,{duration:0.5,afterFinish:finishMovieOpen});	 
}
function finishMovieOpen(){
	var bg = $('movieBackground');
	if (IE7 || !isIE){
		bg.addClassName('popped');
		if (movieType == 1){ //odd size movie
			bg.style.background = "url(../images/moviebox_bg_med.png) no-repeat";
		}
	}else{ 
		bg.addClassName('poppedIE6');
	}

	if (gDebug) alert("movieName: " + movieName);
	
	var params = {}; 
	params.allowScriptAccess = "always";
	params.quality = "high";
	swfobject.embedSWF(movieName,'movie',movieWidth,movieHeight,'9','expressinstall.swf',{},params,{});
	/*
	var so = new SWFObject(movieName, "movieBox", movieWidth, movieHeight, "9", "#ffffff");
	so.addParam("AllowScriptAccess","always");
	so.addParam("quality","high");
	so.write("movie");
	*/
	
	var m = $('movie');
	m.style.visibility = "hidden";
	if (isIE){ location="#SlideFrame_1"; }
	if (gDebug) alert("movie html: " + $('movie').parentNode.innerHTML);
	setTimeout('rewindMovie()',300);
}

function rewindMovie(){
	var m = $('movie');
	m.Rewind();
	$('movie').style.visibility = "visible";
	m.Play();
}

//Hide the movie and reset everything
function hideMovie(){
	var bg = $('movieBackground');
	bg.removeClassName("popped");
	bg.removeClassName("poppedIE6");

	new Effect.Shrink(bg, {direction:'top-left',duration:0.5});
	$('movie').update();
	resetMovieDims();
}

function resetMovieDims(){
	movieWidth = 560;
	movieHeight = 350;
	$('movieCell').style.height = movieCellHeight + "px";		
}




//********* OLD CODE - CANDIDATE FOR DELETION ********************
function showMovieOld(movieBoxId,path,mWidth,mHeight){
	var moviebox = document.getElementById(movieBoxId);
	if (moviebox){
		var l = moviebox.style.left;
		var w = moviebox.style.width;
		if (w.indexOf("px") >= 0){
			w = w.substring(0,w.indexOf("px"));
		}
		var fullW = 918;
		var cw = document.getElementById("pageWrapper"); //every page should have a master contentwrapper div
		if (cw && cw.offsetWidth) fullW = cw.offsetWidth;
		l = Math.floor((fullW - w)/2);
		moviebox.style.left = l + "px";	
		var cell = document.getElementById(movieBoxId + "Cell");
		if (cell){
			cell.innerHTML = QT_GenerateOBJECTText_XHTML(path , mWidth, mHeight , '','CONTROLLER','TRUE');
		}
		new Effect.Appear(moviebox, {duration:0.3, afterFinish: showShadow});	
	}
}
function showShadow(obj){
//	var m = document.getElementById("movieBox");
	var mShadow = document.getElementById(obj.element.id + "Shadow");
	if (mShadow){
		mShadow.style.visibility = "visible";
//		mShadow.className = "movieBox";
	}
}

function showScreen(imgId,h,w){
	var screenbox = document.getElementById(imgId);
	if (screenbox){
		var l = screenbox.style.left;
		var w = screenbox.style.width;
		if (w.indexOf("px") >= 0){
			w = w.substring(0,w.indexOf("px"));
		}
		var fullW = 918;
		var cw = document.getElementById("pageWrapper"); //every page should have a master contentwrapper div
		if (cw && cw.offsetWidth) fullW = cw.offsetWidth;
		l = Math.floor((fullW - w)/2);
		screenbox.style.left = l + "px";	

		new Effect.Appear(screenbox, {duration:0.3, afterFinish: showShadow});	
	}	
}
function closeScreen(m){
	var moviebox = document.getElementById(m);
	var mShadow = document.getElementById(m + "Shadow");
	if (moviebox && mShadow){
		new Effect.Fade(moviebox, {duration:0.5});
	}
}