// add to html <a href="#" onclick="dontscroll=true;"><font color="#FF0000">X</font></a>


// the offset that the floater is from origin at (top_padding)
//lastScrollY = 0;
lastScrollY = 2000;

readyToScroll = false;


dontscroll = true;


var intervalID = 0;

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;
	}	
	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function setTop(y){
	floaterEl = document.getElementById("floater");
	if(document.all){
		floaterEl.style.pixelTop = y;
	}else{
		floaterEl.style.top = y;
	}		
}
/*
			c= 'right';   // left or right
			left_right_padding = 100;   /// pixels
			top_padding = 100;  
*/
// set Start Location
function startUp(){
	var floaterEl = document.getElementById("floater");
		if (position=='right'){
			floaterEl.style.right=left_right_padding;
		}
		if (position=='left'){
			floaterEl.style.left=left_right_padding;
		}
		if (position=='center'){
			t=getPageSize(); t=Math.ceil(t[2]/2);
			floaterEl.style.left=t;
		}
	setTop(lastScrollY + top_padding);
	intervalID = window.setInterval('scrollToStartUp()',1)
} // end startUp

// scroll to startup position from bottom
function scrollToStartUp() {
	floaterEl = document.getElementById("floater");
	diffY = document.body.scrollTop;
	// while the page hasn't been scrolled and the image is not in the startup position
	// then scroll the image to startup position
	atOrigin = lastScrollY == 0;
	if((diffY == 0) && (!atOrigin)){
		// if floater not at top_padding position yet
		if(lastScrollY != 0) {
			percent = .1 * (0 - lastScrollY);
			if(percent > 0){
				percent = Math.ceil(percent);
			}else{
				percent = Math.floor(percent);
			}
			setTop(parseInt(floaterEl.style.top) + percent);
			lastScrollY = lastScrollY + percent;
		}// endif
	}else{
		readyToScroll = true;
		window.clearInterval(intervalID);
		// set image to constant location,
		// just in case user doesn't let the image finish scrolling to startup position
		setTop(top_padding);
		lastScrollY = 0;
		// run scrollImage every millisecond
		intervalID = window.setInterval('scrollImage()',1);
		if(dontscroll == false) {
}
	}// end if
} // end scrollToStartUp

function scrollImage() {
	if (readyToScroll == true){
		diffY = document.body.scrollTop;

		// if page has been scrolled down or up since last run through
		if(diffY != lastScrollY){
			percent = .1 * (diffY - lastScrollY);
			if(percent > 0){
				percent = Math.ceil(percent);
			}else{
				percent = Math.floor(percent);
			}
			setTop(parseInt(floaterEl.style.top) + percent);
			lastScrollY = lastScrollY + percent;
		}
	}
} // end scrollImage

function stopSroll(){
 window.clearInterval(intervalID);
}


function falsefunc() { return false; }

//isOpera=isOpera5=window.opera&&isDOM; //Opera 5+
if(navigator.userAgent.indexOf("Opera")!=-1) isOpera=true;
else isOpera=false;

isMSIE=document.all&&document.all.item&&!isOpera; //MSIE 4+
isMozilla=navigator.appName=="Netscape"; //Mozilla

var mousex = 0;
var mousey = 0;

var start_drag=false;

if (isMSIE || isOpera){
document.onmousemove = function(){
mousex = event.clientX + document.body.scrollLeft;
mousey = event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
return true;
}
}
else if (isMozilla){
document.onmousemove=function(e){
mousex = e.pageX;
mousey = e.pageY;
return true;
}
}

function showMenu(){
 if(start_drag==true){
  document.getElementById("floater").style.left = mousex-(150/2)+"px";
  document.getElementById("floater").style.top = mousey-(131/2)+"px";
 }
 //return false;
}

function startDrag(){
  start_drag=true;
  document.onmousedown = falsefunc; // in NS this prevents cascading of events, thus disabling text selection
  //dragobj = context;
  //dragobj.style.zIndex = 10; // move it to the top
  //document.onmousemove = showMenu;
  //document.onmouseup = stopDrag;
  ocument.onmouseup = null;
  document.onmousedown = null; 
}

function stopDrag(){
 start_drag=false;
 document.onmouseup = null;
 document.onmousedown = null;
 return false;
}

