/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

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 = 410;	// maximum image size.
var currentimageheight =230;	// maximum image size.
var currentimagewidth = 300;	// maximum image size.
//var currentimagewidth = 490;	// maximum image size.
var timer;

function applyTransition (oImg)
{
    oImg.filters(0).Apply();
    oImg.style.visibility = "visible";
    oImg.filters(0).Play();
}



function gettrailobj(){
if (document.getElementById)
return document.getElementById("preview_div").style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("preview_div")
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function hidetrail(){	
	gettrailobj().display= "none";
	document.onmousemove=""
	gettrailobj().left="-500px"
	var frmobj = document.getElementById('ifrm');
	frmobj.style.display='none';
	frmobj.style.left="-500px";
	clearTimeout(timer);
}



function showtrail(imagename,title,showthumb){
	
	i = imagename
	t = title
	s = showthumb
	
	timer = setTimeout("show('"+i+"',t,s);",200);
}
function show(imagename,title,showthumb){
	
    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

if( (navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1)) && (docwidth>650 && docheight>500)) {

		document.onmousemove=followmouse; 
		//document.onmousemove=getX; 
	
		newHTML = '<div  style="width:274px;height:285" height="285px" width="274px" ><div width="100%" id="loader_container" style="z-index:120px;"><div id="loader"><div align="center">Loading ...</div><div id="loader_bg"><div id="progress"> </div></div></div></div>';
		
		if( title != "" )
		{
		   newHTML = newHTML + '<div width="100%" ><span class="highlited-section-heading">' + title + '</span></div>'
		}
		
		if (showthumb > 0){
    		newHTML = newHTML + '<div class="preview_temp_load" style="filter: progid:DXImageTransform.Microsoft.MotionBlur(strength=13, direction=310)    progid:DXImageTransform.Microsoft.Blur(pixelradius=2)    progid:DXImageTransform.Microsoft.Wheel(duration=7);"  ><img id="myimg" align="absmiddle"  onload="javascript:remove_loading();"  src="' + imagename + '" border="0"></div>';
			//newHTML = newHTML + '<div class="preview_temp_load"><img onload="javascript:remove_loading();" src="' + 'http://www.awimaway.com/images/preview1.jpg' + '" border="0"></div>';
		}

		newHTML = newHTML + '</div>';
		if(navigator.userAgent.indexOf("Firefox")==-1){
			//newHTML = newHTML+'<iframe src="about:blank" scrolling="no"  width="1"  hight="1" frameborder="0" ></iframe>';
	
		}
		gettrailobjnostyle().innerHTML = newHTML;
		gettrailobj().display="block";
 		//gettrailobj().position ="relative";
	
     	//gettrailobj().left = getX() +"px" ;
	  //gettrailobj().top= getY() +"px" ;
		
		//gettrailobj() =  "display: block; position:relative; z-index: 110; left: -500px; background-color: #FFFFFF ; vertical-align:middle" ; 
	}
}

function getX(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < currentimagewidth){
			if(navigator.userAgent.indexOf("Firefox")!=-1)	{xcoord = e.pageX - xcoord - currentimagewidth + 2*offsetfrommouse[0]} else{ xcoord = e.pageX - xcoord - currentimagewidth + 6*offsetfrommouse[0] ;} // Move to the left side of the cursor
			} else {
				xcoord += e.pageX;
			}
			if (docheight - e.pageY < (currentimageheight + 10)){
				ycoord += e.pageY - Math.max(0,(10 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
			} else {
			ycoord += e.pageY;
			}
	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < currentimagewidth){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - currentimagewidth + 2*offsetfrommouse[0]; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 10)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(10 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-offsetfrommouse[0]
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
	if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
	
}

function getY(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < currentimagewidth){
			if(navigator.userAgent.indexOf("Firefox")!=-1)	{xcoord = e.pageX - xcoord - currentimagewidth + 2*offsetfrommouse[0]} else{ xcoord = e.pageX - xcoord - currentimagewidth + 6*offsetfrommouse[0] ;} // Move to the left side of the cursor
			} else {
				xcoord += e.pageX;
			}
			if (docheight - e.pageY < (currentimageheight + 110)){
				ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
			} else {
			ycoord += e.pageY;
			}
	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < currentimagewidth){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - currentimagewidth + 2*offsetfrommouse[0]; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 110)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-offsetfrommouse[0]
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
	if(ycoord < 0) { ycoord = ycoord*-1; }
	return ycoord ; 
	
}


function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]
	var mousex = event.screenX;
	var mousey = event.screenY;
	
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)
	
	if (typeof e != "undefined"){
		if (docwidth - e.pageX < currentimagewidth){
			if(navigator.userAgent.indexOf("Firefox")!=-1)	{xcoord = e.pageX - xcoord - currentimagewidth + 2*offsetfrommouse[0]} else{ xcoord = e.pageX - xcoord - currentimagewidth + 2*offsetfrommouse[0] ;} // Move to the left side of the cursor
			} else {
				xcoord += e.pageX;
			}
			if (docheight - e.pageY < (currentimageheight + 110)){
				ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
			} else {
			ycoord += e.pageY;
			}
	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < currentimagewidth){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - currentimagewidth + 2*offsetfrommouse[0]; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 110)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-offsetfrommouse[0]
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
	

	/*if((docwidth - mousex) < currentimagewidth)
	{
			xcoord = mousex - (currentimagewidth + ;
	}
	else
	{
	}*/
	
	if(ycoord < 0) { ycoord = ycoord*-1; }


	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
	
	var frmobj = document.getElementById('ifrm');
	frmobj.style.display='';
	frmobj.style.width = '275px';
	frmobj.style.height = '284px';
	frmobj.style.left = xcoord+"px";
	frmobj.style.top = ycoord+"px";
	
	//alert(frmobj.style.left);
	
	
}
var ie5=(document.getElementById && document.all);
var ns6=(document.getElementById && !document.all);

nPlus = 5   //the % of fading for each step
speed = 50  //the speed

// You don't have to edit below this line
nOpac = 100
function FadeImg()
{
    if(document.getElementById)
	{
        document.getElementById('img1').style.visibility="visible";
        imgs = document.getElementById('img2');
	opacity = nOpac+nPlus;
	nOpac = opacity;
	setTimeout('FadeImg()',speed);
    if(opacity>100 || opacity<0)
	{
        nPlus=-nPlus;
    }
    if(ie5)
	{
        imgs.style.filter="alpha(opacity=0)";
	imgs.filters.alpha.opacity = opacity;
    }
    if(ns6)
	{
        imgs.style.MozOpacity = 0 + '%';
	imgs.style.MozOpacity = opacity + '%';
    }
  }
}
