﻿

var WotGallery =
{
	init : function()
	{
		this.layer = document.getElementById('ImageLayer');
		this.image = document.getElementById('ViewImage');
		this.desc = document.getElementById('ImageDesc');
		this.lastimage = document.getElementById('ShowLastImage');
		this.nextimage = document.getElementById('ShowNextImage');
		this.thumbbox = document.getElementById('ThumbBox');
		this.thumbs = this.thumbbox.getElementsByTagName('a');
		this.count = 0;
		this.maxcount = this.thumbs.length;
		this.open = false;
		this.lastimage.onclick = function() { WotGallery.lastImage(); };
		this.nextimage.onclick = function() { WotGallery.nextImage(); };
	},

	showImage : function(url,title,index)
	{
		for (var i = 0; i < this.thumbs.length; i++)
		{
			this.thumbs[i].className = '';

			if (i == index)
				this.thumbs[i].className = 'active';
		}

		this.image.src = url;
		this.image.alt = title;
		this.image.title = title;
		this.desc.innerHTML = title;
		this.count = index;
		return false;
	},

	nextImage : function()
	{
		if (this.count < this.maxcount-1)
		{
			var index = this.count + 1
		}
		else
		{
			var index = 0
		}

		var url = this.thumbs[index].href;
		var title = this.thumbs[index].title;

		this.showImage(url,title,index);
	},

	lastImage : function()
	{
		if (this.count > 0)
		{
			var index = this.count - 1
		}
		else
		{
			var index = this.maxcount - 1;
		}

		var url = this.thumbs[index].href;
		var title = this.thumbs[index].title;

		this.showImage(url,title,index);
	},

	showHide : function()
	{
		if (this.open)
		{
			this.layer.style.display = 'none';
			this.open = false;
		}
		else
		{
			this.layer.style.display = 'block';
			this.open = true;
		}
	}
}

var ziehenZ = 10000;
TMZieheElement = function(mdelem,elem,startX,startY,startZ) {
	this.mdelem = TMSucheElem(mdelem);
	TMCSS(this.mdelem).cursor = 'move';
	this.elem = TMSucheElem(elem);
	this.startX = startX;
	this.startY = startY;
	this.startZ = startZ ? startZ : null;
	var obj = this;
	TMErstelleEvent(this.mdelem,'mousedown',function(e) { obj.ziehenbeginnen(e); });
};

TMZieheElement.prototype = {

	ziehenbeginnen : function(e) {
		if (isDOM) {
			this.elemPosX = parseInt(this.elem.style.left) || this.startX;
			this.elemPosY = parseInt(this.elem.style.top) || this.startY;
			this.mausPos = TMSucheMaus(e);
			this.ziehenPosX = this.mausPos.xo - this.elemPosX;
			this.ziehenPosY = this.mausPos.yo - this.elemPosY;
			this.ablegenZ = this.startZ ? this.startZ : ziehenZ;
			TMCSSZindex(this.elem,ziehenZ);
			var obj = this;
			TMErstelleEvent(document,'mousemove',function(e) { obj.ziehen(e); });
			TMErstelleEvent(document,'mouseup',function(e) { obj.ablegen(); });
			TMUnterbindeStandard(e);
		}
	},

	ziehen : function(e) {
		this.mausPos = TMSucheMaus(e);
		this.elemPosX = this.mausPos.xo - this.ziehenPosX;
		this.elemPosY = this.mausPos.yo - this.ziehenPosY;
		this.elemPosX = (this.elemPosX > 0) ? this.elemPosX : 0;
		this.elemPosY = (this.elemPosY > 0) ? this.elemPosY : 0;
		TMCSSPosition(this.elem,this.elemPosX,this.elemPosY);
		TMUnterbindeStandard(e);
	},

	ablegen : function() {
		TMEntferneEvent(document,'mousemove');
		TMEntferneEvent(document,'mouseup');
		TMCSSZindex(this.elem,this.ablegenZ);
		ziehenZ++;
	}
};


