/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetfrommouse=[30,30]; //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 = 500;	// maximum image size.
currentimageheight = 480

if (document.getElementById || document.all){
	document.write('<div class="trailimage" id="trailimageid">');
	document.write('</div>');
}

function gettrailobj(id){
if (document.getElementById)
return document.getElementById(id).style
else if (document.all)
return document.all.trailimagid.style
}

function gettrailobjnostyle(id){
if (document.getElementById)
return document.getElementById(id)
else if (document.all)
return document.all.trailimagid
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showtrail(imagename,title,description,ratingaverage,ratingnumber,showthumb,height,width,className,stockCode){

	//if (height < currentimageheight){
		currentimageheight = height;
	//}
	//if (width < currentimageheight){
		currentimageheight = width;
	//}

	document.onmousemove=followmouse;

	cameraHTML = '';

	if (ratingnumber == 0){
		ratingaverage = 0;
	}

	for(x = 1; x <= 5; x++){

		if (ratingaverage >= 1){
			cameraHTML = cameraHTML + '<img src="/images/camera_1.gif" alt="" />';
		} else if (ratingaverage >= 0.5){
			cameraHTML = cameraHTML + '<img src="/images/camera_05.gif" alt="" />';
		} else {
			cameraHTML = cameraHTML + '<img src="/images/camera_0.gif" alt="" />';
		}
	
		ratingaverage = ratingaverage - 1;

	}

	cameraHTML = cameraHTML + ' (' + ratingnumber + ' Review';
	if ( ratingnumber != 1 ) cameraHTML += 's';
	cameraHTML = cameraHTML + ')';
	
	
	newHTML = '<div class="'+className+'TrailBox">';
	newHTML = newHTML + '<div class="'+className+'TrailHeading">'
	newHTML = newHTML + '<h1>' + title + '</h1>';
	newHTML = newHTML + '</div>'	

	if (showthumb > 0){
		newHTML = newHTML + '<div class="'+className+'TrailImgBox"><img src="' + imagename + '" border="0" alt="" />';
	}
	newHTML = newHTML + '<br />' + description;
	if( stockCode != ''){
		newHTML = newHTML + '<br /><br /><div align=right>Product Code ' + stockCode + '</div>';
	}
	newHTML = newHTML + '</div>';
	newHTML = newHTML + '</div>';

	gettrailobjnostyle("trailimageid").innerHTML = newHTML;

	gettrailobj("trailimageid").visibility="visible";
	
}


function showtrailClick(id, imagename,title,description,ratingaverage,ratingnumber,showthumb,height,width,className,stockCode){	
	if(gettrailobj("trailimageidClick"+id).visibility != "visible"){
	
		currentimageheight = height;
		currentimageheight = width;
	
		cameraHTML = '';
	
		if (ratingnumber == 0){
			ratingaverage = 0;
		}
	
		for(x = 1; x <= 5; x++){
	
			if (ratingaverage >= 1){
				cameraHTML = cameraHTML + '<img src="/images/camera_1.gif" alt="" />';
			} else if (ratingaverage >= 0.5){
				cameraHTML = cameraHTML + '<img src="/images/camera_05.gif" alt="" />';
			} else {
				cameraHTML = cameraHTML + '<img src="/images/camera_0.gif" alt="" />';
			}
		
			ratingaverage = ratingaverage - 1;
	
		}
	
		cameraHTML = cameraHTML + ' (' + ratingnumber + ' Review';
		if ( ratingnumber != 1 ) cameraHTML += 's';
		cameraHTML = cameraHTML + ')';
		
		
		newHTML = '<div class="'+className+'TrailBox" id='+id+' onmousedown="dragStart(event, \'trailimageidClick'+id+'\')">';
		newHTML = newHTML + '<div  class="'+className+'TrailHeading">'
		newHTML = newHTML + '<h1>' + title + '</h1>';
		newHTML = newHTML + '<div style="text-align:right;"><a href="javascript:hidetrailClick('+id+');">close</a></div>'
		newHTML = newHTML + '</div>'	
	
		if (showthumb > 0){
			newHTML = newHTML + '<div class="'+className+'TrailImgBox">'
			
			newHTML = newHTML + '<img src="' + imagename + '" border="0" alt="" />';
		}
		newHTML = newHTML + '<br />' + description;
		if( stockCode != ''){
			newHTML = newHTML + '<br /><br /><div align=right>Product Code ' + stockCode + '</div>';
		}
		newHTML = newHTML + '</div>';
		newHTML = newHTML + '</div>';
	
		gettrailobjnostyle("trailimageidClick"+id).innerHTML = newHTML;
		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 (docwidth - 450 < currentimageheight){
			xcoord = 450 + truebody().scrollLeft - xcoord - currentimageheight; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+450
		}
		if (docheight - 250 < (currentimageheight)){
			ycoord += 250 + truebody().scrollTop - Math.max(0,(currentimageheight + 250 - docheight));
		} else {
			ycoord += truebody().scrollTop + 250;
			//ycoord += event.clientY;
		}
		
		gettrailobj("trailimageidClick"+id).left=xcoord+"px"
		gettrailobj("trailimageidClick"+id).top=ycoord+"px"				
		gettrailobj("trailimageidClick"+id).zIndex = UpUp;
		
		gettrailobj("trailimageidClick"+id).visibility="visible";
		
		UpUp++;
	}else{
		gettrailobj("trailimageidClick"+id).zIndex = UpUp;	
		UpUp++;
	}
}
function hidetrailClick(id){
	gettrailobj("trailimageidClick"+id).visibility="hidden"
	document.onmousemove=""
	gettrailobj(id).left="-1500px"
}

function hidetrail(){
	gettrailobj("trailimageid").visibility="hidden"
	document.onmousemove=""
	gettrailobj("trailimageid").left="-1500px"

}

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 (document.all){
	//	gettrailobjnostyle().innerHTML = 'A = ' + truebody().scrollHeight + '<br />B = ' + truebody().clientHeight;
	//} else {
	//	gettrailobjnostyle().innerHTML = 'C = ' + document.body.offsetHeight + '<br />D = ' + window.innerHeight;
	//}
	if (typeof e != "undefined"){
		if (docwidth - e.pageX < currentimageheight){
			xcoord = e.pageX - xcoord - currentimageheight; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight)){
			ycoord += e.pageY - Math.max(0,(currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < currentimageheight){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - currentimageheight; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
			//ycoord += 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; }
	gettrailobj("trailimageid").left=xcoord+"px"
	gettrailobj("trailimageid").top=(ycoord-50)+"px"
}

function showtrailFlash(id, height, width, title){	
	if(gettrailobj("trailimageidFlash"+id).visibility != "visible"){
		
		GrayBody("trailimageidFlash"+id);	
		
		currentimageheight = height;
		currentimageheight = width;
		
		newHTML = '<div class="FlashTrailBox" id='+id+'>';
	
		//newHTML = newHTML + '<div class="FlashTrailImgBox" onmousedown="dragStart(event, \'trailimageidFlash'+id+'\')">'
		newHTML = newHTML + '<div class="FlashTrailImgBox">'
		newHTML = newHTML + '<div  class="FlashTrailHeading">'
		newHTML = newHTML + '<h1>' + title + '</h1>';
		newHTML = newHTML + '<div style="text-align:right;"><a href="javascript:hidetrailFlash('+id+');">close</a>'
		newHTML = newHTML + '</div>'	
		
		newHTML = newHTML + '</div>';
		
		newHTML = newHTML + '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="764" height="520">'
		newHTML = newHTML + '  <param name="movie" value="3d-flash/3d-flash-'+id+'.swf" />'
		newHTML = newHTML + '  <param name="quality" value="high" />'
		newHTML = newHTML + '  <embed src="3d-flash/3d-flash-'+id+'.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="764" height="520"></embed>'
		newHTML = newHTML + '</object>'
	
		newHTML = newHTML + '</div>';
		newHTML = newHTML + '</div>';
	
		gettrailobjnostyle("trailimageidFlash"+id).innerHTML = newHTML;
		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 arrayPageSize = getPageSize();
		//xcoord += truebody().scrollLeft-30;
		ycoord += truebody().scrollTop-15;
		xcoord = ((arrayPageSize[2]/2)-width-25)
		
	
		gettrailobj("trailimageidFlash"+id).left=  xcoord + "px";
		gettrailobj("trailimageidFlash"+id).top= 235 + "px"
	
		gettrailobj("trailimageidFlash"+id).visibility="visible";	
		gettrailobj("trailimageidFlash"+id).zIndex = 9999;	
		gettrailobj("trailimageidFlash"+id).height = "317px";
		document.getElementById("trailimageidFlash"+id).zindex=9999;
	}else{
		gettrailobj("trailimageidFlash"+id).zIndex = 9999;
		document.getElementById("trailimageidFlash"+id).zindex=9999;
	}	
}
function hidetrailFlash(id){
	gettrailobj("trailimageidFlash"+id).visibility="hidden"
	document.onmousemove=""
	gettrailobj(id).left="-1500px"
	document.getElementById("over").style.display = 'none';
}
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
function GrayBody(FlashId){
	var objBody = document.getElementsByTagName("body").item(0);
	var arrayPageSize = getPageSize();
	var id = "over";
	
	if(!document.getElementById(id)){
		var ov = document.createElement("div");
		
		ov.setAttribute('id',id);
		ov.className = 'overlay';
		ov.style.height = document.getElementById("Content").clientHeight + 196 + "px";
		ov.style.width = arrayPageSize[0]+'px';
		ov.zindex = 1;
		objBody.appendChild(ov);
	}else{
		document.getElementById("over").style.display = 'block';
		document.getElementById("over").style.height = document.getElementById("Content").clientHeight + 196 + "px";
		document.getElementById("over").style.width = arrayPageSize[0]+'px';
	}
}
