var offsetfrommouse=[15,15]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 270;	// maximum image size.

if (document.getElementById || document.all){
	document.write('<div id="tooltipimageid">');
	document.write('</div>');
}

function gettooltipobj(){
if (document.getElementById && document.getElementById("tooltipimageid"))
return document.getElementById("tooltipimageid").style
else if (document.all)
return document.all.tooltipimagid.style
}

function gettooltipobjnostyle(){
if (document.getElementById && document.getElementById("tooltipimageid"))
return document.getElementById("tooltipimageid")
else if (document.all)
return document.all.tooltipimagid
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showtooltip(file,type,title,width,height,media){
	if(type == 'video') {
		if(width <= 0) {
			width = 266;
		}
		if(height > 0) {
			var factor = width / 266;
			if(factor != 0) {
				var new_height = height / factor;
				if(new_height > 100) {
					height = new_height;
				}
				else {
					height = 150;
				}
			}
			else {
				width = 266;
				height = 150;
			}
		}
		else {
			height = 150;
		}
		width = 266;
	}

	if (height > 0){
		currentimageheight = height;
	}


	document.onmousemove=followmouse;

	var html = '<table border="0" width="240" cellpadding="3" cellspacing="3" bgcolor="#777777">';
  html = html + '<tr><td width="100%" valign="top">';
      html = html + '<table class="thin" width="222">';
        html = html + '<tr><td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">';
              html = html + '<tr><td width="100%">';

                if(type=='photo')
                html = html + '<img src="' + file + '" border="0">';
                if(type=='video') {
                        temp = '<div align="center" style="padding: 0px 0px 0px 0px; background-color: black;">'
                                 +'     <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+width+'" height="'+height+'" id="434_player" align="middle">'
                                 +'     <param name="allowScriptAccess" value="sameDomain" />'
                                 +'     <param name="movie" value="videoPlayer.swf" />'
                                 +'     <param name="quality" value="high" />'
                                 +'     <param name="bgcolor" value="#000000" />'
                                 +' <param name="FlashVars" value="path='+file+'" /> '
                                 +'     <embed FlashVars="path='+file+'" src="videoPlayer.swf" quality="high" bgcolor="#000000" width="'+width+'" height="'+height+'" name="player" align="middle"allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
                                 +'     </object>'
                                 +'</div>';

                   html += temp;
				}
				if(type=='audio') {
                        temp = '<div align="center" style="padding: 0px 0px 0px 0px; background-color: white;">'
                                 +'     <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="0" height="0" id="434_player" align="middle">'
                                 +'     <param name="allowScriptAccess" value="sameDomain" />'
                                 +'     <param name="movie" value="players/audio.swf" />'
                                 +'     <param name="quality" value="high" />'
                                 +'     <param name="bgcolor" value="#000000" />'
                                 +' <param name="FlashVars" value="file='+file+'" /> '
                                 +'     <embed FlashVars="file='+file+'" src="players/audio.swf" quality="high" bgcolor="#000000" width="0" height="0" name="player" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
                                 +'     </object>'
                                 +'</div>';

                   html += temp;
				   html = html + '<img src="mediaimage.jpg" width="266">';
				}
				
html = html + '</td></tr><tr><td width="100%" bgcolor="#FFFFFF">';
                  html = html + '<table border="0" width="100%" cellpadding="2"><tr>';
                      html = html + '<td width="100%" style = "color:#333;font-weight:bold;">'+title+'</td>';
                      html = html + '</tr>';
                  html = html + '</table></td></tr>';
            html = html + '</table></td></tr></table></td></tr>';
  html = html + '<tr><td width="100%" valign="top" style = "color:white;">'+media+'</td>';
  html = html + '</tr></table>';



  


        gettooltipobjnostyle().innerHTML = html;

        gettooltipobj().visibility="visible";

}


function hidetooltip(){
	gettooltipobj().visibility="hidden"
	gettooltipobjnostyle().innerHTML=""
	document.onmousemove=""
	gettooltipobj().left="-500px"

}

function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(document.body.offsetHeight, window.innerHeight)
	//if (document.all){
	//	gettooltipobjnostyle().innerHTML = 'A = ' + truebody().scrollHeight + '<br>B = ' + truebody().clientHeight;
	//} else {
	//	gettooltipobjnostyle().innerHTML = 'C = ' + document.body.offsetHeight + '<br>D = ' + window.innerHeight;
	//}

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 460){
			xcoord = e.pageX - xcoord - 420; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX + 10;
		}
		if (docheight - e.pageY < (currentimageheight + 210)){
			ycoord += e.pageY - Math.max(0,(210 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < 460){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 420; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX  + 10;
		}
		if (docheight - event.clientY < (currentimageheight + 210)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(210 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)

	gettooltipobj().left=xcoord+"px"
	gettooltipobj().top=ycoord+"px"

}
