/*
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 = 350;	// maximum image size.

var defaultimageheight = 40;	// maximum image size.
var defaultimagewidth = 40;	// maximum image size.

if (document.getElementById || document.all){
	document.write('<div id="trailimageid">');
	document.write('</div>');
	document.write('<div id="trailimageidcap">');
	document.write('</div>');
}

function gettrailobj(){
	if (document.getElementById)
		return document.getElementById("trailimageid").style
	else if (document.all)
		return document.all.trailimagid.style
}

function gettrailobjnostyle(){
	if (document.getElementById)
		return document.getElementById("trailimageid")
	else if (document.all)
		return document.all.trailimagid
}
function gettrailobjcap(){
	if (document.getElementById)
		return document.getElementById("trailimageidcap").style
	else if (document.all)
		return document.all.trailimagidcap.style
}

function gettrailobjnostylecap(){
	if (document.getElementById)
		return document.getElementById("trailimageidcap")
	else if (document.all)
		return document.all.trailimagidcap
}

function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
var  newHTML;
function showtrail(title,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,page){

	
	document.onmousemove=followmouse;
	//add switch statement here for 
	switch (page){
		
		case "designfinalist": 
			newHTML = '<div class="jukeboxDesignHoverStyle" style="z-index:3000">';
			newHTML = newHTML + '<span class="">' + decodeMyHtml(title) + '</span>  ';
			if(f1!='')
			{
				newHTML = newHTML + '<span class=""> - ' + decodeMyHtml(f1) + '</span>';
			}
			if(f2!='')
			{
			newHTML = newHTML + '<img src="' + decodeMyHtml(f2) + '" alt="' + decodeMyHtml(f1)+'" />';
			}
			
				
			newHTML = newHTML + '</div>';
			break;
			
		default : newHTML = newHTML + '<div style="padding: 5px; background-color: #FFF; border: 1px solid #888;"></div>';
}
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().visibility="visible";
}


function hidetrail(){
	gettrailobj().visibility="hidden"
	document.onmousemove=""
	gettrailobj().left="-500px"

}

function showtrailcap(img,cls,title){
	
	document.onmousemove=followmousecap;
			
	newHTML = '<div style="padding: 0px; background-color: #000000; border: 1px solid #888;" class="track">';
	newHTML = newHTML + '<img src=\'' + img + '\' class=\''+cls+'\' align=\'absmiddle\' />&nbsp;';			
	newHTML = newHTML +  decodeMyHtml(title);			
	newHTML = newHTML + '</div>';
		
	gettrailobjnostylecap().innerHTML = newHTML;
	gettrailobjcap().visibility="visible";
}

function hidetrailcap(){
	gettrailobjcap().visibility="hidden"
	document.onmousemove=""
	gettrailobjcap().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)
    if (typeof e != "undefined") {
        if (docwidth - e.pageX < 380) {
            xcoord = e.pageX - xcoord - 400;
        } else {
            xcoord += e.pageX;
        }
        if (docheight - e.pageY < (currentimageheight + 110)) {
            if (document.body) {
                scrollTop = Math.max(truebody().scrollTop, document.body.scrollTop);
            } else {
                scrollTop = truebody().scrollTop;
            }
            ycoord += e.pageY - Math.max(0, (110 + currentimageheight + e.pageY - docheight - scrollTop));
        } else {
            ycoord += e.pageY;
        }
    } else if (typeof window.event != "undefined") {
        if (docwidth - event.clientX < 380) {
            xcoord = event.clientX + truebody().scrollLeft - xcoord - 400;
        } 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;
        }
    }
    if (ycoord < 0) {
        ycoord = ycoord * -1;
    }
    gettrailobj().left = xcoord + "px"
    gettrailobj().top = ycoord + "px"
}


function followmouseBatch(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 trailInnerDiv = $('trailInnerDiv');
	var currentimageheight = trailInnerDiv.offsetHeight;
	var currentimagewidth = trailInnerDiv.offsetWidth;

	scrollPos = Position.realOffset(truebody());
	
	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 380){
			xcoord = e.pageX - xcoord - 400; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if ((e.pageY - scrollPos[1]) + currentimageheight > docheight){
			ycoord = -ycoord + (e.pageY - currentimageheight);
		} else {
			ycoord += e.pageY;
		}
	} else if (typeof window.event != "undefined"){
		if (event.clientX + currentimagewidth > docwidth){
			xcoord = -xcoord + ((event.clientX + scrollPos[0]) - currentimagewidth); // Move to the left side of the cursor
		} else {
			xcoord += (event.clientX + scrollPos[0]);
		}
		if (event.clientY + currentimageheight > docheight){
			ycoord = -ycoord + ((event.clientY + scrollPos[1]) - currentimageheight);
		} else {
			ycoord += (event.clientY + scrollPos[1]);
		}
	}

	if(ycoord < 0) { ycoord = ycoord*-1; }

	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}


	function followmousecap(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)

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = e.pageX - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < defaultimageheight + 2*offsetfrommouse[1]){
			ycoord += e.pageY - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (defaultimageheight + 2*offsetfrommouse[1])){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	
			gettrailobjcap().left=xcoord+"px";
			gettrailobjcap().top=ycoord+"px";
			


}
function encodeMyHtml(s) {
	encodedHtml = escape(s);
	encodedHtml = encodedHtml.replace(/\//g,"%2F");
	encodedHtml = encodedHtml.replace(/\?/g,"%3F");
	encodedHtml = encodedHtml.replace(/=/g,"%3D");
	encodedHtml = encodedHtml.replace(/&/g,"%26");
	encodedHtml = encodedHtml.replace(/@/g,"%40");
	return encodedHtml;
}
function decodeMyHtml(s) {
	s=s.replace("&apos;","'")
	s=s.replace("&apos;","'")
	s=s.replace("&apos;","'")
	s=s.replace("&apos;","'")
	s=s.replace("&apos;","'")
	s=s.replace("&apos;","'")
	s=s.replace("&apos;","'")
	return unescape(s);
}





if (document.layers)
document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)

