/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

/*
Dramaticaly enhanced by UC Technology (Pepita.fr)
Visit http://www.pepita.fr for a demo (and become a member !! You deserve it !)
This notice must also stay intact
*/

var offsetfrommouse=[10,10];	//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 bottommargin = 20; // The bottom margin if the sample not entry in the background
var shown = 0;
var test = 0;
var current_style = 0;

hasReqestedFlashVersion = true; //DetectFlashVer(7,0,0);

function init_showtrail()
{
    if (document.getElementById || document.all)
  {
    document.write('<div id="trailimageid" style="visibility:hidden;z-index:4;">');
    document.write('</div>');
    document.write('<div id="trailmusicid" style="visibility:hidden;z-index:4;">');
    document.write('<div id="trailmusictext" style="visibility:hidden;z-index:4;"></div></div>');

/*
    if ( hasReqestedFlashVersion)
    {
    document.write( '<div align="center" style="padding:2px;"></div><div id="lector"><object type="application/x-shockwave-flash" data="lib/player/player_mp3.swf" width="200" height="20" id="playermp3"><param name="movie" value="lib/player/player_mp3.swf" /><param name="FlashVars" value="mp3=' + '' + '&amp;bgcolor1=ffffff&amp;bgcolor2=cccccc&amp;buttoncolor=999999&amp;buttonovercolor=0&amp;slidercolor1=cccccc&amp;slidercolor2=999999&amp;sliderovercolor=666666&amp;textcolor=0&amp;autoplay=1" /></object></div></div>');
    }
    else
    {
    document.write( '<div align="center" style="padding:2px;"></div><div id="lector" style="padding: 5px; background-color: #FFF; border: 1px solid #888;"><p>Pour &eacute;couter cette musique, Flash 7 ou sup&eacute;rieur est n&eacute;cessaire vous pouvez l\'installer sur href="http://www.adobe.com/go/getflash/"</p></div></div>');
    }
*/
  }
}

init_showtrail();

function gettrailobj( id)
{
  if ( id == 0)
  {
  if (document.getElementById)
    return document.getElementById("trailimageid").style;
  else if (document.all)
    return document.all.trailimagid.style;
  }
  else if ( id == 10)
  {
  if (document.getElementById)
    return document.getElementById("lector").style;
  else if (document.all)
    return document.all.lector.style;
  }  
  else
  {
  if (document.getElementById)
    return document.getElementById("trailmusicid").style;
  else if (document.all)
    return document.all.trailmusicid.style;
  }  
}

function gettrailobjnostyle( type)
{
 if ( type == 0)
 {
  if (document.getElementById)
    return document.getElementById("trailimageid");
  else if (document.all)
    return document.all.trailimagid;
  }
  else
 {
  if (document.getElementById)
    return document.getElementById("trailmusicid");
  else if (document.all)
    return document.all.trailmusicid;
 }
}

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

function showtrail_img_2(imagename,author,title,type,description,category,img_width,img_height,file_ext,object_id,showthumb,height,a_width, a_height)
{
  nb_pix = img_width * img_height;
  nb_pix = nb_pix / 1000000;
  nb_pix = Math.round(nb_pix*10)/10; 

  size_x_72 = Math.round(img_width / 72 * 2.54 * 10)/10;
  size_y_72 = Math.round(img_height / 72 * 2.54 * 10)/10;
  size_x_300 = Math.round(img_width / 300 * 2.54 * 10)/10;
  size_y_300 = Math.round(img_height / 300 * 2.54 * 10)/10;

  newHTML = '<div style="text-align: left;padding: 5px; background-color: #FFF; border: 1px solid #888;">';
  newHTML = newHTML + '<div style="max-width:300px;"><h2>' + title + '&nbsp;&nbsp;&copy;' + author + '</h2>';
  newHTML = newHTML + '<p>' + type + ' (' + file_ext + ') ' + img_width + ' x ' + img_height + ' (' + nb_pix + ' MP)' + '<br/>';
  newHTML = newHTML + '72 dpi: ' + size_x_72 + 'x' + size_y_72 + 'cm' + ' / ';
  newHTML = newHTML + '300 dpi: ' + size_x_300 + 'x' + size_y_300 + 'cm' + '</p><br/>';
  newHTML = newHTML + '<p>' + description + '</p><br/>';
  newHTML = newHTML + '<h3>' + category + '</h3></div>';  

  if (showthumb > 0)
    newHTML = newHTML + '<div align="center" style="width:auto;padding: 8px 2px 2px 2px;"><img src="' + imagename + '" border="0"></div>';
  
  newHTML = newHTML + '</div>';

  gettrailobjnostyle(0).innerHTML = newHTML;

 if ( navigator.appName == 'Netscape')
 {
   gettrailobj(0).width = 'auto';
   gettrailobj(0).height = 'auto';
 }
else
{
   gettrailobj(0).width = (a_width + 16) + 'px';
   gettrailobj(0).height = 'auto';
}

  gettrailobj(0).visibility="visible";
  current_style = 0;

  document.onmousemove=followmouse;
}

function showtrail_music(musicname,author,title,type,description,category,file_ext,object_id,showthumb,height,msg, with_music, a_width, a_height)
{
 newHTML = '<div style="text-align: left;padding: 5px; background-color: #FFF; border: 1px solid #888;">';
 newHTML = newHTML + '<h2>' + title + '&nbsp;&nbsp;&copy;' + author + '</h2>';
 newHTML = newHTML + '<p>' + type + ' (' + file_ext + ') ' + '</p><br/>';
 newHTML = newHTML + '<p>' + description + '</p><br/>';
 newHTML = newHTML + '<h3>' + category + '</h3>';  

 if ( with_music == 1)
  newHTML = newHTML + msg;

 document.getElementById("trailmusictext").innerHTML = newHTML;

 shown = 1;

 if ( navigator.appName == 'Netscape')
 gettrailobj(1).height = 'auto';

 gettrailobj(1).width = 300+'px';
 gettrailobj(1).visibility="visible";

 gettrailobj(10).visibility="hidden";
 gettrailobj(10).visibility="visible";
 gettrailobj(10).visibility="hidden";
 gettrailobj(10).visibility="visible";
 gettrailobj(10).visibility="hidden";

if ( (musicname == "") || ( with_music == 0))
 gettrailobj(10).visibility="hidden";
else
gettrailobj(10).visibility="visible";

if (( hasReqestedFlashVersion) && (musicname != "") && (with_music == 1))
{
 window.document.playermp3.SetVariable("file", musicname);
 window.document.playermp3.SetVariable("stop", "false");
 window.document.playermp3.SetVariable("stop", "true");
 window.document.playermp3.SetVariable("stop", "false");
}

 current_style = 1;

 document.onmousemove= followmouse;
}

function showtrail_text(author,title,type,description,category, file_ext)
{
  document.onmousemove=followmouse;

  newHTML = '<div style="text-align: left;padding: 5px; background-color: #FFF; border: 1px solid #888; height: auto">';
  newHTML = newHTML + '<h2>' + title + '&nbsp;&nbsp;&copy;' + author + '</h2>';
  newHTML = newHTML + '<p>' + type + ' (' + file_ext + ') ' + '</p><br/>';
  newHTML = newHTML + '<p>' + description + '</p><br/>';
  newHTML = newHTML + '<h3>' + category + '</h3>';  
  newHTML = newHTML + '</div>';

  gettrailobjnostyle(0).innerHTML = newHTML;
  gettrailobj(0).width = 300+'px';
  gettrailobj(0).height = 'auto';
  gettrailobj(0).visibility="visible";
}

function showtrail_zip(author,title,type,description, category, file_ext)
{
  document.onmousemove=followmouse;

  newHTML = '<div style="text-align: left;padding: 5px; background-color: #FFF; border: 1px solid #888; height: auto;">';
  newHTML = newHTML + '<h2>' + title + '&nbsp;&nbsp;&copy;' + author + '</h2>';
  newHTML = newHTML + '<p>' + type + ' (' + file_ext + ') ' + '</p><br/>';
  newHTML = newHTML + '<p>' + description + '</p><br/>';
  newHTML = newHTML + '<h3>' + category + '</h3>';  
  newHTML = newHTML + '</div>';

  gettrailobjnostyle(0).innerHTML = newHTML;
  gettrailobj(0).width = 300+'px';
  gettrailobj(0).height = 'auto';
  gettrailobj(0).visibility="visible";
}

function showtrail_video(comment,author,title,type,description,category,file_ext,object_id,showthumb,height)
{
//alert( imagename);
  //if (height > 0)
  //  currentimageheight = height;

  document.onmousemove=followmouse;

//alert(imagename);

  newHTML = '<div style="text-align: left;padding: 5px; background-color: #FFF; border: 1px solid #888;">';
  newHTML = newHTML + '<h2>' + title + '&nbsp;&nbsp;&copy;' + author + '</h2>';
  newHTML = newHTML + '<p>' + type + ' (' + file_ext + ') ' + '</p><br/>';
  newHTML = newHTML + '<p>' + description + '</p><br/>';
  newHTML = newHTML + '<h3>' + category + '</h3>';    

  if ( comment != "")
    newHTML = newHTML + '<div style="padding: 8px 2px 2px 2px;"><p>' + comment + '</p></div>';
  
  newHTML = newHTML + '</div>';

  gettrailobjnostyle(0).innerHTML = newHTML;
  gettrailobj(0).width = 300+'px';
  gettrailobj(0).height = 'auto';
  gettrailobj(0).visibility="visible";
}


function showtrail_soft(imagename,author,title,type,description,category,file_ext,object_id,showthumb,height)
{
  document.onmousemove=followmouse;

  newHTML = '<div style="text-align: left;padding: 5px; background-color: #FFF; border: 1px solid #888;">';
  newHTML = newHTML + '<h2>' + title + '&nbsp;&nbsp;&copy;' + author + '</h2>';
  newHTML = newHTML + '<p>' + type + ' (' + file_ext + ') ' + '</p><br/>';
  newHTML = newHTML + '<p>' + description + '</p><br/>';
  newHTML = newHTML + '<h3>' + category + '</h3>';  
  
  if (showthumb > 0)
    newHTML = newHTML + '<div align="center" style="padding: 8px 2px 2px 2px;"><img src="' + imagename + '" border="0"></div>';
  
  newHTML = newHTML + '</div>';

  gettrailobjnostyle(0).innerHTML = newHTML;
  gettrailobj(0).width = 300+'px';
  gettrailobj(0).height = 'auto';
  gettrailobj(0).visibility="visible";
}

function hidemusic()
{
 if (gettrailobj(1).visibility == "visible")
 {
  gettrailobj(1).visibility="hidden";
  gettrailobj(1).left="-500px";
 }
}

function hidetrail()
{
if (gettrailobj(0).visibility == "visible")
{
  gettrailobj(0).visibility="hidden";
  document.onmousemove=null;
  gettrailobj(0).left="-500px";
}
else if (gettrailobj(1).visibility == "visible")
{
if ( shown == 1)
 if ( hasReqestedFlashVersion)
  window.document.playermp3.SetVariable("stop", "true");
  gettrailobj(1).visibility="hidden";
  document.onmousemove=null;
  gettrailobj(1).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(window.innerHeight);

  var trailwidth = gettrailobjnostyle( current_style).offsetWidth;
  var trailheight = gettrailobjnostyle( current_style).offsetHeight;

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

    } 
  else if (typeof window.event != "undefined")
    {
      if (docwidth - event.clientX < trailwidth)
	{
		xcoord = event.clientX + truebody().scrollLeft - xcoord - trailwidth; // Move to the left side of the cursor
      	} 
      else 
	{	
		xcoord += truebody().scrollLeft+event.clientX
	}
      if (docheight - event.clientY < (trailheight + bottommargin))
	{
		ycoord += event.clientY + truebody().scrollTop - Math.max(0,(bottommargin + trailheight + 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);

  if(ycoord < 0) 
    { 
      ycoord = ycoord*-1; 
    }

if ( gettrailobj(0).visibility == "visible")
{
  gettrailobj(0).left=xcoord+"px";
  gettrailobj(0).top=ycoord+"px";
}
else
{
  gettrailobj(1).left=xcoord+"px";
  gettrailobj(1).top=ycoord+"px";
}
}
