var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

var images = new Array();
var cur_img = 0;
var hImages1 = new Array();
var hImages2 = new Array();

function change_img( container, id )
{
	c = document.getElementById( container );
	c.src = images[id];
	cur_img = id;
	for( i = 0; i < hImages1.length; i++ ) {
		hImages1[i].className = 'pager_link';
		hImages2[i].className = 'pager_link';
	}
	hImages1[id].className = 'pager_link pager_active';
	hImages2[id].className = 'pager_link pager_active';
}

function write_pager( container )
{
	for( i = 0; i < images.length; i++ ) {
		if( i == images.length - 1 ) {
			spacer = "";
		} else {
			spacer = "&nbsp;<span class=\"spacer\">|</span>&nbsp;";
		}
		if( i in hImages1 ) {
			document.write( '<a href="#" id="link2' + i + '" class="pager_link" onclick="change_img( \'' + container + '\', ' + i + ' ); return false;" >' + ( i + 1 ) + '</a>' + spacer  );
			hImages2[i] = document.getElementById( 'link2' + i );
		} else {
			document.write( '<a href="#" id="link' + i + '" class="pager_link" onclick="change_img( \'' + container + '\', ' + i + ' ); return false;" >' + ( i + 1 ) + '</a>' + spacer  );
			hImages1[i] = document.getElementById( 'link' + i );
		}
	}
}

function prev_img( container )
{
	if( cur_img )
		change_img( container, cur_img - 1 );
}

function next_img( container )
{
	if( cur_img < images.length - 1 )
		change_img( container, cur_img + 1 );
}

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  return true
}




function correctPNG()
{
	for(var i=0; i<document.images.length; i++)
	{
		var img = document.images[i]
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			{
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
					var imgClass = (img.className) ? "class='" + img.className + "' " : ""
					var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
					var imgStyle = "display:inline-block;" + img.style.cssText
					if (img.align == "left") imgStyle = "float:left;" + imgStyle
						if (img.align == "right") imgStyle = "float:right;" + imgStyle
							if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle  
								var strNewHTML = "<span " + imgID + imgClass + imgTitle
									+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
									+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
									+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
									img.outerHTML = strNewHTML
									i = i-1
			}
	}
}

var preload = new Array();
preload.push( 'images/sitemap_txt_hov.png' );

function onLoad()
{
	preloadMenuImages();
	var divs = document.getElementsByTagName( 'div' );
	if( divs.length )
		for( i = 0; i < divs.length; i++ )
			if( divs[i].getAttribute( 'class' ) == 'left_top_gradient' ) {
				var myDIV = divs[i];
				break;
			}
	if ( !myDIV || myDIV == null ) return false;
	myDIV.setAttribute( 'class', '' );
	myDIV.setAttribute( 'class', 'left_top_gradient' );
	var textNode = document.createElement( 'br' );
	myDIV.appendChild( textNode );
	var preloadDiv = document.createElement( 'div' );
	preloadDiv.setAttribute( 'style', 'display: none;' );
	if( preload.length )
		for( var i = 0; i < preload.length; i++ )
			preloadDiv.innerHTML += '<img src="' + preload[i] + '">';
	if( images.length )
		for( var i = 0; i < images.length; i++ )
			preloadDiv.innerHTML += '<img src="' + images[i] + '">';
	container = document.getElementsByTagName( 'body' );
	container[0].appendChild( preloadDiv );
	if( IE )
		correctPNG();
}

if( IE )
	window.attachEvent("onload", onLoad);
else
	window.onload = onLoad;

/*
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 = 270;	// maximum image size.

function gettrailobj(){
if (document.getElementById)
return document.getElementById("big_img").style
else if (document.all)
return document.all.big_img.style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("big_img")
else if (document.all)
return document.all.big_img
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showtrail(imagename,title,description,ratingaverage,ratingnumber,showthumb,height,filetype){
	if (height > 0){
		currentimageheight = height;
	}

	document.onmousemove=followmouse;

	cameraHTML = '';

	if ( !ratingnumber ){
		ratingnumber = 0;
		ratingaverage = 0;
	}

	newHTML = '<div style="z-index: 999;">';
	newHTML = newHTML + '<img id="image_" src="' + imagename + '" border="0"></div>';

	newHTML = newHTML + '</div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().display="inline";
}

function hidetrail(){
	gettrailobj().innerHTML = " ";
	gettrailobj().display="none"
	document.onmousemove=""
	gettrailobj().left="-500px"

}

function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]
	img = document.getElementById( 'image_' );

	currentimageheight = img.height;
	currentimagewidth = img.width;

	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 < currentimagewidth){
			xcoord = e.pageX - xcoord - currentimagewidth - 20; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight + 30)){
			ycoord += e.pageY - Math.max(0,(30 + 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 - 20; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 30)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(30 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}
/* images popup stop */

var menuPreload = new Array(
	'images/home.jpg', 			'images/home_hov.jpg', 			'images/home_act.jpg',
	'images/about_us.jpg', 		'images/about_us_hov.jpg', 		'images/about_us_act.jpg',
	'images/projects.jpg', 		'images/projects_hov.jpg', 		'images/projects_act.jpg',
	'images/services.jpg', 		'images/services_hov.jpg', 		'images/services_act.jpg',
	'images/products.jpg', 		'images/products_hov.jpg', 		'images/products_act.jpg',
	'images/contact_us.jpg',	'images/contact_us_hov.jpg', 	'images/contact_us_act.jpg',
	'images/driving.jpg', 		'images/driving_hov.jpg', 		'images/driving_act.jpg'
);

function preloadMenuImages()
{
	for( var i = 0; i < menuPreload.length; i++ ) {
		var img_src = menuPreload[i];
		if ( img_src != null && img_src != "" ) {
			var oImage = new Image();
			oImage.src = img_src;
			menuPreload[i] = oImage;
		}
	}
}
