/* FLOATING IMAGE */

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

var offsetfrommouse=[10,20]; //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 = 0;    // maximum image size.
var currentimagewidth = 0;    // maximum image size.

/*
if (document.getElementById || document.all){
    document.write('<div id="trailimageid" style=\"position:absolute;z-index:5000;\">');
    document.write('</div>');
}
*/

function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}



function gettrailobj(){
//sleep(10)
if (document.getElementById && document.getElementById("trailimageid"))
return document.getElementById("trailimageid").style
else if (document.all)
return document.all.trailimagid.style
}

function gettrailobjnostyle(){
//sleep(10)
if (document.getElementById && document.getElementById("trailimageid"))
return document.getElementById("trailimageid")
else if (document.all)
return document.all.trailimagid
}


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

function showtrail1(){
    var browser=navigator.appName;
        var b_version=navigator.appVersion;
        var version=parseFloat(b_version);
       
        if ((browser=="Microsoft Internet Explorer") && (version>=4)){
            extra1 = "";
            extra2 = "";
        }else{
            extra1 = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+width+'" height="'+height+'">';
            extra2 = '</object>';
        }
             		
        temp =     '<div style="border:solid 5px #fff;width:'+width+'px;height:'+height+'">'+extra1+'<embed'
        +'			flashvars="file='+imagename+'&autostart=true&controlbar=none&repeat=always"'
		+'			src="/js/player.swf"'
		+'			width="'+width+'"'
		+'			height="'+height+'"';
        +'        />'+extra2+'</div>'; 
}

function showtrail(imagename,type,title,width,height,catid,copyright,description){
   
	var windowheight1 = document.all? truebody().clientHeight : window.innerHeight 
    var docwidth1=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth

   	//alert(windowheight1+' / '+docwidth1);
	if ( height > 0.90*windowheight1 ){ 
		if ( width > 0.50*docwidth1 && width > height ){ 
			currentimageheight = Math.floor(0.50*(docwidth1/width)*height);
			currentimagewidth  = Math.floor(0.50*(docwidth1/width)*width);
		} else { 
			currentimageheight = Math.floor(0.90*(windowheight1/height)*height);
			currentimagewidth  = Math.floor(0.90*(windowheight1/height)*width);
		}
	}
   	else
   	{
	   if ( width > 0.50*docwidth1 ){ 
			currentimageheight = Math.floor(0.50*(docwidth1/width)*height);
			currentimagewidth  = Math.floor(0.50*(docwidth1/width)*width);
		} else {
			currentimageheight=height;
			currentimagewidth = width;
		}
	}

    document.onmousemove=followmouse;

    var newHTML = '<table border="0" width="240" cellpadding="3" cellspacing="3">';
    newHTML = newHTML + '<tr><td width="100%" valign="top">';
    newHTML = newHTML + '<table class="thin" width="222">';
    newHTML = newHTML + '<tr><td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">';
    newHTML = newHTML + '<tr><td width="100%"><p align="center">';

    if(type=='photo'){
        newHTML = newHTML + '<div align="center" style="padding:6px;background:#000;">';
        newHTML = newHTML + '<img src="' + imagename + '" border="0" width="'+currentimagewidth+'" height="'+currentimageheight+'">';
        newHTML = newHTML + '</div><div align="center" style="margin-top:-25px;z-index:5000;color:grey;">'+description+'</div>';
    }
    
    if(type=='video') {
        
        var browser=navigator.appName;
        var b_version=navigator.appVersion;
        var version=parseFloat(b_version);
       
        if ((browser=="Microsoft Internet Explorer") && (version>=4)){
            extra1 = "";
            extra2 = "";
        }else{
            extra1 = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+width+'" height="'+height+'">';
            extra2 = '</object>';
        }
             		
        temp =     '<div style="border:solid 5px #000;width:'+width+'px;height:'+height+'">'+extra1+'<embed'
        +'			flashvars="file='+imagename+'&autostart=true&controlbar=none&repeat=always"'
		+'			src="/js/player.swf"'
		+'			width="'+width+'"'
		+'			height="'+height+'"';
        +'        />'+extra2+'</div>';
		
       
		newHTML = newHTML + '<div align="center" style="">';
        newHTML = newHTML += temp;
        newHTML = newHTML + '</div>';
    }

    gettrailobjnostyle().innerHTML = newHTML;

    gettrailobj().visibility="visible";
}


function hidetrail(){
    gettrailobj().visibility="hidden"
    gettrailobjnostyle().innerHTML=""
    document.onmousemove=""
    gettrailobj().left="-1000px"
}


function followmouse(e){

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

    if (typeof e != "undefined"){
       	var xPos = e.pageX
        var yPos = e.pageY
        
        var cliposX = e.clientX
        var cliposY = e.clientY

    } else if (typeof window.event != "undefined"){
        var xPos = truebody().scrollLeft+event.clientX
        var yPos = truebody().scrollTop+event.clientY
        
		var cliposX = event.clientX
        var cliposY = event.clientY
        
        
    }
    
    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth
    var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
 	var windowheight = document.all? truebody().clientHeight : window.innerHeight 
    
    if (cliposY < windowheight/2)
    {
        ycoord = yPos + offsetfrommouse[1]
        
        if(cliposY+currentimageheight > windowheight)
       	{
	       	ycoord = yPos - cliposY + windowheight - currentimageheight - 20
       	}    	
    }
    else
    {
        ycoord  = yPos - currentimageheight - offsetfrommouse[1]
        if(cliposY-currentimageheight < 0)
       	{
	       	ycoord = yPos - cliposY + 5
       	}
	}
    
    if (cliposX < docwidth/2)
    {
	    xcoord = xPos + offsetfrommouse[0]
    }
    else
    {
	    xcoord  = xPos - currentimagewidth - offsetfrommouse[0]-30
	  
    }
 
    gettrailobj().left=xcoord+1+"px"
    gettrailobj().top=ycoord-15+"px"

}

