/**
* Variable to hold the floating div element
* @var object
*/
var floatingDiv = false;

/**
* 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() {
	document.write('<textarea id="gate_to_clipboard" style="display:none;"></textarea>');
	document.onmousemove = document_onmousemove;
	if (window.onscroll) window.onscroll = hideDiv();
	document.write('<div class="float" id="div_200" style="left: -3000px; background: #ffffff;"><img id="img_200" 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 document_onmousemove(e) {

	if ( !floatingDiv ) return;

	var pos_X = 0, pos_Y = 0;
	if ( !e ) e = window.event;
	if ( e ) {
		if ( typeof(e.pageX) == "number" ) {
			pos_X = e.pageX; pos_Y = e.pageY;
		} else if ( typeof(e.clientX) == "number" ) {
			pos_X = e.clientX; pos_Y = e.clientY;
			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 ( document.body && ( document.body.scrollTop || document.body.scrollLeft ) && !( window.debug || navigator.vendor == "KDE" ) ) {
		scroll_X = document.body.scrollLeft; scroll_Y = document.body.scrollTop;
	} else if ( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft ) && !( window.debug || navigator.vendor == "KDE" ) ) {
		scroll_X = document.documentElement.scrollLeft; scroll_Y = document.documentElement.scrollTop;
	}

	var win_size_X = 0, win_size_Y = -0;
	if (window.innerWidth && window.innerHeight) {
		win_size_X = window.innerWidth; win_size_Y = window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientWidth && document.documentElement.clientHeight) {
		win_size_X = document.documentElement.clientWidth; win_size_Y = document.documentElement.clientHeight;
	} else if (document.body && document.body.clientWidth && document.body.clientHeight) {
		win_size_X = document.body.clientWidth; win_size_Y = document.body.clientHeight;
	}

	pos_X += 15; pos_Y += 15;

	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);
	}

	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) {
	setPreviewImage( id);
	showDiv("div_200");
}

/**
* Function to set the current preview image
* @var string id - index of preview image in previewImages array
*/
function setPreviewImage( id){
	var previewImage = getElement("img_200");

	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 = getElement( 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() {
	if ( floatingDiv) {
		floatingDiv.style.visibility = "hidden";
		floatingDiv.style.left = "-3000px";
		floatingDiv = false;
	}
}