// Global JS Document
var xhr = false;
var xPos, yPos;
//Define global variables
var timerID = null;
var timerOn = false;
var timecount = 2000;

// JavaScript Document
function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}

function toggleImg(curimg, newimg, newimgwt, newimght) {
	if (document.getElementById) {
		var thisImg = document.getElementById(curimg);
		var newImg = document.getElementById(newimg);
		changeOpac(0, curimg);
		thisImg.src = newImg.src;
		thisImg.width = newimgwt;
		thisImg.height = newimght;	
		opacity(curimg, 0, 100, 500);	
		return false;
	}
	else {
		return true;
	}
}
//OLd
//		var thisImg = document.getElementById(curimg);
//		var newImg = document.getElementById(newimg);
//		thisImg.src = newImg.src;
//		thisImg.width = newimgwt;
//		thisImg.height = newimght;


function hidediv() { 
	var id = "wait";
    var object = document.getElementById(id).style; 
    object.display = "none"; 
}

function showPreview(theurl) {
	getPreview(theurl);
	return false;
}

function hidePreview() {
	document.getElementById("previewWin").style.visibility = "hidden";
}

function getPreview(theurl) {
		evt = window.event;
		var url = theurl;
	xPos = evt.clientX;
	yPos = evt.clientY;
	
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	}
	else {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) { }
		}
	}

	if (xhr) {
		xhr.onreadystatechange = showContents;
		xhr.open("GET", url, true);
		xhr.send(null);
	}
	else {
		alert("Sorry, but I couldn't create an XMLHttpRequest");
	}
}

function showContents() {
	var prevWin = document.getElementById("previewWin");
	
	if (xhr.readyState == 4) {
		prevWin.innerHTML = (xhr.status == 200) ? xhr.responseText : "There was a problem with the request " + xhr.status;
		prevWin.style.top = parseInt(yPos)+2 + "px";
		prevWin.style.left = parseInt(xPos)+2 + "px";
		prevWin.style.visibility = "visible";
		prevWin.onmouseout = hidePreview;
	}
}

function startTime() {
	if (timerOn == false) {
		timerID=setTimeout( "hidePreview()" , timecount);
		timerOn = true;
	}
} 

function stopTime() {
	if (timerOn) {
		clearTimeout(timerID);
		timerID = null;
		timerOn = false;
	}
} 