/**
* Variable to hold the floating div element
* @var object
*/
var floatingDiv = false;
var onMouseOverUnderImage = false;
var image_id = 0;

/**
* Variable to hold the preloaded preview images for current page of gallery
* @var array
*/
var previewImages = new Array();

var active_img_mark = null;

window.onerror = function() {
	return true;
}

window.onerror = function() {
	return true;
}

window.onload = function(e) {
	//					preloadPreviewImages();

	if ( document.getElementById && document.createElement) {
		tooltip.define();
	}
}

function run_after_body_ajax() {
	//document.write('<textarea id="gate_to_clipboard_ajax" style="display:none;z-index:99999999"></textarea>');
	document.onmousemove = document_onmousemove;
	//if (window.onscroll) window.onscroll = hideDiv();
	//document.write('<div class="float" id="div_200_ajax" style="left: -3000px; background: #ffffff;overflow:visible;"><img id="img_200_ajax" class="border_b" width="200" height="150"></div>');
}


/**
* Function to get the html element by id
* @var string id - id of the html element
*/
function getElement( id) {
	if ( document.getElementById) {
		return document.getElementById( id);
	} else if ( document.all) {
		return document.all[id];
	} else {
		return null;
	}
}

/**
* Function to get the html element by id
* @var string id - id of the html element
*/
function getparElement( id) {
	if ( parent.document.getElementById) {
		return parent.document.getElementById( id);
	} else if ( parent.document.all) {
		return parent.document.all[id];
	} else {
		return null;
	}
}

function document_onmousemove(e) {
			
	if ( !floatingDiv ) return;
	
	var img = getparElement('img_200_ajax');
	var img_height = img.style.height/1.3;
	
	var pos_X = 0, pos_Y = 0;
	if ( !e ) e = window.event;
	//if ( e ) {
		if ( typeof(e.pageX) == "number" ) {
			pos_X = e.pageX+510; pos_Y = e.pageY+250;
		} else if ( typeof(e.clientX) == "number" ) {
			pos_X = e.clientX+510; pos_Y = e.clientY+250;
			if ( document.body && ( document.body.scrollTop || document.body.scrollLeft ) && !( window.opera || window.debug || navigator.vendor == "KDE" ) ) {
				pos_X += document.body.scrollLeft; pos_Y += document.body.scrollTop;
			} else if ( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft ) && !( window.opera || window.debug || navigator.vendor == "KDE" ) ) {
				pos_X += document.documentElement.scrollLeft; pos_Y += document.documentElement.scrollTop;
			}
		}
	/*}
*/
	var scroll_X = 0, scroll_Y = 0;
	if ( parent.document.body && ( parent.document.body.scrollTop || parent.document.body.scrollLeft ) && !( parent.debug || navigator.vendor == "KDE" ) ) {
		scroll_X = parent.document.body.scrollLeft; scroll_Y = parent.document.body.scrollTop;
	} else if ( parent.document.documentElement && ( parent.document.documentElement.scrollTop || parent.document.documentElement.scrollLeft ) && !( parent.debug || navigator.vendor == "KDE" ) ) {
		scroll_X = parent.document.documentElement.scrollLeft; scroll_Y = parent.document.documentElement.scrollTop;
	}

	var win_size_X = 0, win_size_Y = 0;
	if (parent.innerWidth && parent.innerHeight) {
		win_size_X = parent.innerWidth; win_size_Y = parent.innerHeight;
	} else if (parent.document.documentElement && parent.document.documentElement.clientWidth && parent.document.documentElement.clientHeight) {
		win_size_X = parent.document.documentElement.clientWidth; win_size_Y = parent.document.documentElement.clientHeight;
	} else if (parent.document.body && parent.document.body.clientWidth && parent.document.body.clientHeight) {
		win_size_X = parent.document.body.clientWidth; win_size_Y = parent.document.body.clientHeight;
	}

//	pos_X += 15; pos_Y += 15 - img_height;

/*	if (floatingDiv.offsetWidth && floatingDiv.offsetHeight) {
		
		if (pos_X - scroll_X + floatingDiv.offsetWidth + 5 > win_size_X) pos_X -= (floatingDiv.offsetWidth + 25);
		
		if ((pos_Y - scroll_Y + floatingDiv.offsetHeight + 5 > win_size_Y) && (pos_Y - floatingDiv.offsetHeight > 265) ) pos_Y -= (floatingDiv.offsetHeight + 20);
		
		
	}
	*/
	if(pos_X + 500 > win_size_X)  pos_X -= 540;
	else pos_X += 50;
	//alert(pos_X);
	//alert(win_size_X);

//	if(pos_Y - img_height < 0) pos_Y = 0;
	
	floatingDiv.style.left = pos_X + "px"; floatingDiv.style.top = pos_Y + "px";

}


/**
* Function to show the floating preview image
* @var integer id - Index of the preview image in previewImages array
*/
function showPreviewImage( id) {
	onMouseOverUnderImage = true;
	
	if(!previewImages[id]) {
		var ind = GetImageIndex(id);
		
		if(ind > -1) {
			previewImages[id] = new Image();
			previewImages[id].src = largeList[ind];
		} 	
	}
	
	SetImage(id);
	image_id = id;
	callImage();
}

function callImage() {
	if(!onMouseOverUnderImage) {clearTimeout(counter);return}
	SetImage(image_id);
	counter = setTimeout("callImage()",1000);
}


function SetImage(id) {
	setPreviewImage(id);
	showDiv("div_200_ajax");
}


function GetImageIndex(id) {
	var i;
	var find = 0;
	
	for(i = 0; i < noiseList.length; i++)
		if(noiseList[i] == id) {find = 1;break;}
	if(find) return i; 
	return -1;	
}

/**
* Function to set the current preview image
* @var string id - index of preview image in previewImages array
*/
function setPreviewImage( id){
	var previewImage = getparElement("img_200_ajax");

	if ( previewImage) {
		previewImage.src    = previewImages[id].src;
		previewImage.width  = previewImages[id].width;
		previewImage.height = previewImages[id].height;
	}
}

/**
* Function to make the DIV, containing preview image, visible
* @var string id - id of the DIV element
*/
function showDiv( id) {
	if ( floatingDiv = getparElement( id)) {
		
		if ( floatingDiv.offsetWidth) {
			floatingDiv.style.width = "auto";
			floatingDiv.style.height = "auto";

			if ( floatingDiv.offsetWidth > 300) {
				floatingDiv.style.width = "300px";
			}
		}

		document_onmousemove;
		floatingDiv.style.visibility = "visible";
	}
}

/**
* Function to hide the DIV containing preview image
*/
function hideDiv() {
/*	var previewImage = getElement("img_200");
	if ( previewImage) {
		previewImage.src    = '';
	} */
	if ( floatingDiv) {
		floatingDiv.style.visibility = "hidden";
		floatingDiv.style.left = "-3000px";
		floatingDiv = false;
		onMouseOverUnderImage = false;
	}
}