var mouseDistance=[10,10];
var imgPreview;
var i;
var x=0;
var theViewer=false;
var theVideoViewer=false;
var noTitle= "";
var objOpacity=.96;
var f;
var thumbWidth=450
function createThumbDiv (){
  clearTimeout(f);
	var thumbDiv = createEl("DIV");
  thumbDiv.style.position = "absolute";
  thumbDiv.style.display = "";
  thumbDiv.className = "thumbViewer";
  thumbDiv.id = "thumbViewer";
  thumbDiv.name = "thumbViewer";
  thumbDiv.style.zindex = 2000;
  if (!isExplorer) thumbDiv.style.opacity = .1;
  	else thumbDiv.style.filter="alpha(opacity:"+0+")";
	thumbDiv.style.top=mouseY+mouseDistance[0]+"px";
	thumbDiv.style.left=mouseX+mouseDistance[1]+"px";
	document.body.appendChild(thumbDiv);
	theViewer=obj('thumbViewer');
	x=0;
	faderIn('thumbViewer');
}

function showPreview(theImage,title,imageWidth){
    if(!title)title=noTitle;
  if (imageWidth) thumbWidth = imageWidth;
  if(theViewer) document.body.removeChild(theViewer);
	createThumbDiv();
    	imgPreview ="";
	imgPreview += '<div id "img" align="center" style="padding:10px;padding-bottom:35px; background:white; border:1px solid #cccccc;">';  //width:'+thumbWidth+'px;
	imgPreview += '<img src="' + theImage + '" border="0" >';
	imgPreview += '<br><br>'+title+'</div>';
	theViewer.innerHTML = imgPreview;

	var xcoord=mouseDistance[0];
	var ycoord=mouseDistance[1];
	if ((getWindowDimensionW()+truebody().scrollLeft) - mouseX < theViewer.offsetWidth+25){
		var diff=(mouseX+theViewer.offsetWidth+25)-(getWindowDimensionW() +truebody().scrollLeft);
		//xcoord = mouseX - diff;
		xcoord = mouseX - (theViewer.offsetWidth+mouseDistance[0]) ;
	} else {
		xcoord += mouseX;
	}
	if ((getWindowDimensionH() +truebody().scrollTop) < mouseY+theViewer.offsetHeight+25){
		var diff=(mouseY+theViewer.offsetHeight+25)-(getWindowDimensionH() +truebody().scrollTop);
		ycoord = mouseY - diff;
	} else {
		ycoord +=  mouseY;
	}
	if(ycoord < 0) { ycoord = ycoord*-1; }

	theViewer.style.left=xcoord+"px";
	theViewer.style.top=ycoord+"px";

	addEvent(document,"mousemove",followmouse);
}


function showLargeText(text) {
  if (theViewer) document.body.removeChild(theViewer);
	createThumbDiv();
	imgPreview = "";
	imgPreview += '<div id="img" style="padding:10px;padding-bottom:35px;width:400px; background:white; border:1px solid #cccccc;">';
	imgPreview += text+'</div>';

//  alert(theViewer);
  theViewer.innerHTML = imgPreview;

	var xcoord=mouseDistance[0];
	var ycoord=mouseDistance[1];
	if ((getWindowDimensionW()+truebody().scrollLeft) - mouseX < theViewer.offsetWidth+25){
		var diff=(mouseX+theViewer.offsetWidth+25)-(getWindowDimensionW() +truebody().scrollLeft);
		//xcoord = mouseX - diff;
		xcoord = mouseX - (theViewer.offsetWidth+mouseDistance[0]) ;
	} else {
		xcoord += mouseX;
	}
	if ((getWindowDimensionH() +truebody().scrollTop) < mouseY+theViewer.offsetHeight+25){
		var diff=(mouseY+theViewer.offsetHeight+25)-(getWindowDimensionH() +truebody().scrollTop);
		ycoord = mouseY - diff;
	} else {
		ycoord +=  mouseY;
	}
	if(ycoord < 0) { ycoord = ycoord*-1; }

	theViewer.style.left=xcoord+"px";
	theViewer.style.top=ycoord+"px";

  addEvent(document,"mousemove",followmouse);
}

var videoContent ="";
function showMovie(theMovie,title,autostart){
  //url, nome, w, h, scroll, resiz
	if (!autostart) autostart=false;
	videoContent ="";
	videoContent +='<object type="application/x-shockwave-flash" data="/applications/webwork/parts/flv/flvplayer.swf?autostart='+autostart+'&file='+theMovie+'" width="500" height="420" wmode="transparent">';
  	videoContent +='<param name="movie" value="/applications/webwork/parts/flv/flvplayer.swf?autostart='+autostart+'&file='+theMovie+'" />';
  	videoContent +='<param name="wmode" value="transparent" />';
	videoContent +='</object>';
	videoContent += '<div style="color: white; padding:10px">'+title+'</div>';
	centerPopup("/applications/webwork/parts/flv/videoPlayer.htm","moviePlayer", '500', '500', 'no', 'no' );
}

var fader=.1;
function faderIn(objToFade){
	if (x<=10){
		fader=(objOpacity/10)*x;
		x++
		f=setTimeout("faderIn('"+objToFade+"')",0);
	}else x=0;
	if (obj(objToFade)){
		if (!isExplorer) obj(objToFade).style.opacity=fader;
		else obj(objToFade).style.filter="alpha(opacity:"+fader*100+")";
	}
}

function hidePreview(){
	removeEvent(document,"mousemove",followmouse);
	if (theViewer) document.body.removeChild(theViewer);
	theViewer=false;
}

function followmouse(e){
  
if(theViewer){
	var xcoord=mouseDistance[0];
	var ycoord=mouseDistance[1];
	if ((getWindowDimensionW()+truebody().scrollLeft) - mouseX < theViewer.offsetWidth+25){
		var diff=(mouseX+theViewer.offsetWidth+25)-(getWindowDimensionW() +truebody().scrollLeft);
		//xcoord = mouseX - diff;
		xcoord = mouseX - (theViewer.offsetWidth+mouseDistance[0]) ;
	} else {
		xcoord += mouseX;
	}
	if ((getWindowDimensionH() +truebody().scrollTop) < mouseY+theViewer.offsetHeight+25){
		var diff=(mouseY+theViewer.offsetHeight+25)-(getWindowDimensionH() +truebody().scrollTop);
		ycoord = mouseY - diff;
	} else {
		ycoord +=  mouseY;
	}
	if(ycoord < 0) { ycoord = ycoord*-1; }

	theViewer.style.left=xcoord+"px";
	theViewer.style.top=ycoord+"px";
	if (getTarget(e).tagName!="IMG"){
    hidePreview();
  }
}
}

function truebody(){
    return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function closeList(){
    theListViewer.parentNode.removeChild(theListViewer);
  }
function createListDiv (){
	var thumbDiv = createEl("DIV");
  thumbDiv.style.position = "absolute";
  thumbDiv.style.display = "";
  thumbDiv.className = "listViewer";
  thumbDiv.id = "listViewer";
  thumbDiv.name = "listViewer";
  thumbDiv.style.zindex = 2000;
  thumbDiv.style.backgroundColor = "white";
	thumbDiv.style.top=mouseY+mouseDistance[0]+"px";
	thumbDiv.style.left=mouseX+mouseDistance[1]+"px";
	document.body.appendChild(thumbDiv);
	theListViewer=obj('listViewer');

  addEvent(document,"click",closeList);
  x=0;
}
