var mouseX;
var mouseY;
var IE = document.all ? true:false;
var pos_x;
var pos_y;
var is_moving = false;
var posX = 0;
var posY = 0;

function move_full_image() {
	if (is_moving) {
		if (IE) {
			document.getElementById('image_show').style.marginLeft = (mouseX - 142) + posX;
			document.getElementById('image_show').style.marginTop = (mouseY - 15) + posY;
		}
		else {
			document.getElementById('image_show').style.marginLeft = (mouseX - 10) + posX;
			document.getElementById('image_show').style.marginTop = (mouseY - 10) + posY;
		}
	document.getElementById('test').value = document.getElementById('image_show').style.marginLeft;
	}
}

function change_moving(special) {
	if (is_moving) {
		is_moving = false;
	}
	else {
		is_moving = true;
		if (IE && !special) {
			posX = (parseInt(document.getElementById('image_show').style.marginLeft) - mouseX) + 142;
			posY = (parseInt(document.getElementById('image_show').style.marginTop) - mouseY) + 15;
		}
		else if (!special) {
			posX = parseInt(document.getElementById('image_show').style.marginLeft) - mouseX;
			posY = (parseInt(document.getElementById('image_show').style.marginTop) - mouseY) + 10;
		}
		else {
			posY = -100;
		}
	}
}

function show_full_image(image_path, width, height) {
	hide_full_image()
	new_image = new Image();
	new_image.src = image_path;
	new_image.width = width;
	new_image.height = height;
	new_image.onload = function() {
		document.getElementById('show_image').src = new_image.src;
		document.getElementById('show_image').width = new_image.width;
		document.getElementById('show_image').height = new_image.height;
		document.getElementById('image_show').style.width = (new_image.width) + 'px';
		document.getElementById('image_show').style.height = (new_image.height + 20) + 'px';
	  change_moving(true);
		setTimeout('change_moving(true);', 500);
		delete new_image;

	}
	document.getElementById('show_image').src = loading_image.src;
	document.getElementById('show_image').width = loading_image.width;
	document.getElementById('show_image').height = loading_image.height;
	document.getElementById('image_show').style.width = (loading_image.width) + 'px';
	document.getElementById('image_show').style.height = (loading_image.height) + 'px';
	document.getElementById('image_show').style.display = 'block';
}

function hide_full_image() {
	document.getElementById('show_image').src = '';
	document.getElementById('image_show').style.display = 'none';
}

function getMouseXY(e) {
	if (IE) {
		mouseX = event.clientX + document.body.scrollLeft;
		mouseY = event.clientY + document.body.scrollTop;
	}
	else {
		mouseX = e.pageX;
		if (mouseX < 0) { mouseX = 0; }
		mouseY = e.pageY;
		if (mouseY < 0) { mouseY = 0; }
	}
}

document.onmousemove = getMouseXY;

var loading_image = new Image();
loading_image.src = 'images/loading.gif';
loading_image.width = '75';
loading_image.height = '75';


hs.graphicsDir = '../images/custom_images/gallery/';
hs.transitions = ['expand', 'crossfade'];
hs.restoreCursor = null;
hs.lang.restoreTitle = 'Click for next image';

// Add the slideshow providing the controlbar and the thumbstrip
hs.addSlideshow({
	//slideshowGroup: 'group1',
	interval: 5000,
	repeat: true,
	useControls: true,
	overlayOptions: {
		position: 'bottom right',
		offsetY: 50
	},
	thumbstrip: {
		position: 'above',
		mode: 'horizontal',
		relativeTo: 'expander'
	}
});

// Options for the in-page items
var inPageOptions = {
	//slideshowGroup: 'group1',
	outlineType: null,
	allowSizeReduction: false,
	wrapperClassName: 'in-page controls-in-heading',
	useBox: true,
	width: 600,
	height: 400,
	targetX: 'gallery-area 10px',
	targetY: 'gallery-area',
	captionEval: 'this.thumb.alt',
	numberPosition: 'caption'
}

// Open the first thumb on page load
hs.addEventListener(window, 'load', function() {
	if (document.getElementById('thumb1')) {
		document.getElementById('thumb1').onclick();
	}
});

// Cancel the default action for image click and do next instead
hs.Expander.prototype.onImageClick = function() {
	if (/in-page/.test(this.wrapper.className))	return hs.next();
}

// Under no circumstances should the static popup be closed
hs.Expander.prototype.onBeforeClose = function() {
	if (/in-page/.test(this.wrapper.className))	return false;
}
// ... nor dragged
hs.Expander.prototype.onDrag = function() {
	if (/in-page/.test(this.wrapper.className))	return false;
}

// Keep the position after window resize
hs.addEventListener(window, 'resize', function() {
	var i, exp;
	hs.getPageSize();

	for (i = 0; i < hs.expanders.length; i++) {
		exp = hs.expanders[i];
		if (exp) {
			var x = exp.x,
				y = exp.y;

			// get new thumb positions
			exp.tpos = hs.getPosition(exp.el);
			x.calcThumb();
			y.calcThumb();

			// calculate new popup position
		 	x.pos = x.tpos - x.cb + x.tb;
			x.scroll = hs.page.scrollLeft;
			x.clientSize = hs.page.width;
			y.pos = y.tpos - y.cb + y.tb;
			y.scroll = hs.page.scrollTop;
			y.clientSize = hs.page.height;
			exp.justify(x, true);
			exp.justify(y, true);

			// set new left and top to wrapper and outline
			exp.moveTo(x.pos, y.pos);
		}
	}
});

