var navTime; 
var scrollTime;
var thumbDisplayWidth;

function echo(str){
	$('debug').innerHTML += str + "<br>";
}

function getWidthOfObject(id){
	return $(id).offsetWidth;
}

//--- AJAX -------------------
function ajaxUpdateFullImage(outputId, gid, imgId, page){
	var url = 'ajax.php?AJAX_PROC=' + outputId + '&page=' + page;
	new ajax(url, {postBody: 'gid=' + gid + '&imgId=' + imgId, update: $(outputId)});
}

// ---- SCROLL FUNCTION ----------------------
/**
* will set an interval that will continually call the scroll function
* until the interval is cleared.
*/
function stopScroll(){
	window.clearInterval(scrollTime);	
}

function continuousScroll(id, direction){
	if (direction == 'left'){
		scrollTime = window.setInterval(scrollLeft, 50);	
	} else if (direction =='right'){
		scrollTime = window.setInterval(scrollRight, 50);	
	}
}


/**
* These ridiculous functions had to be implemented
* because IE does not take arguments in it's setInterval command.
*/
function scrollLeft(){
	scrollThis('left');	
}

function scrollRight(){
	scrollThis('right');
}

function scrollThis(direction){
	var mNum = 0;
	var id = 'thumbDisplay';
	var increment = 10;
	var viewWidth = 320;
	
	var currentLeftMargin = $(id).style.marginLeft; 
	
	if (currentLeftMargin){
		mNum = parseInt(currentLeftMargin);
	} 

//	$('DEBUG').innerHTML = thumbDisplayWidth; 
	
	if ((direction == 'right') && (Math.abs(mNum) < Math.abs(thumbDisplayWidth - viewWidth))){
		mNum -= increment;			
	} else if((direction == 'left') && (mNum < 0)){
		mNum += increment;			
	}
	currentLeftMargin = mNum + 'px';

	$(id).style.marginLeft = currentLeftMargin;	
}


function showFullImage(fullBox, imgSrc){
	var imgStr;
	imgStr = '<img src="' + imgSrc + '" />';
	$(fullBox).innerHTML = imgStr;	
}
					   
					   
function fadeIn(id){
	hideAllOtherSubMenus('submenu', id);
	clearTimeout(navTime);
	if ($(id).style.display == 'none'){ 
		$(id).style.visibility = 'hidden';
		$(id).style.display = '';
		var myEffect = new fx.Opacity(id, {duration: 300});
		myEffect.toggle();	
	}
}


function hideAllOtherSubMenus(className, id){
	var ids = document.getElementsByClassName(className);
	var i;
	for (i = 0; i < ids.length; i++){
		if (ids[i] != $(id)){
			hide(ids[i]);
		}
	}
}

function hide(id){
	$(id).style.display = 'none';
}

function timedDisplay(id){
	var functionStr = "hide('" + id + "')";
	navTime = setTimeout(functionStr, 1500);	
}


function recordPosition(e) {
	// sets the values of the mouse pointer in the global mouse variables.
	MOUSE_X = Event.pointerX(e);
	MOUSE_Y = Event.pointerY(e);
}

function resizeWindowToImage(elementId, xBuffer, yBuffer) {
	elementWidth = $(elementId).width + xBuffer;
	elementHeight = $(elementId).height + yBuffer;
	if (elementWidth < 450){
		elementWidth = 450;	
	}

	
   self.resizeTo(elementWidth, elementHeight);
} 

function resizeWindow(x, y){
   self.resizeTo(x, y);
}

function confirmDelete(mesg){
	var agree;
	if (!mesg){
		mesg = "Are you sure you want to delete this?";
	} 
	agree = confirm(mesg);
	if (agree){
		return true ;
	} else {
		return false ;
	}	
}




