var myZoomFx;

function writeReport(to)
{
	if (to > 0) document.location.href = '/bericht/schreiben/'+to;
	else document.location.href = '/bericht/schreiben';
}

function tour()
{
	document.location.href = '/tour';
}

function premium()
{
	tour();
	//document.location.href = '/anmeldung/premium';
}

function detailsearch()
{
	document.location.href = '/detailsuche';
}

function countChars(_this, numLimit)
{
	var numDisplay = _this.id+'Count';
	var numChars   = _this.value.length;
	
	if (numLimit > 0)
	{
		if (numChars >= numLimit)
		{
			_this.value = _this.value.substr(0, numLimit);
			$(numDisplay).set('html', 0);
		}
		else
		{
			$(numDisplay).set('html', numLimit-numChars);
		}
	}
	else
	{
		$(numDisplay).set('html', numChars);
	}
}

function zoomImg(elem)
{
	var pos = elem.getPosition();
		pos.x -= 30;
		pos.y -= 30;
	
	$('imgHover').setPosition(pos);
	
	var targetLink = elem.getParent();
	
	$('imgLink').href = targetLink.href;
	$('imgLink').title = targetLink.title;
	
	$('imgHoverImg').src = elem.src;
	$('imgHoverImg').setStyles({
		width: 140,
		height: 140,
		border: 0
	});
	
	myZoomFx = new Fx.Tween('imgHover', {duration:200});
	myZoomFx.start('opacity', 0, 1);
}

function delImg(id)
{
	if (confirm('Wollen Sie dieses Bild wirklich löschen?'))
	{
		document.location.href = '/images/delete/'+id;
	}
}

window.addEvent('domready', function()
{
	$$('div.parent').each(function(item)
	{
		var elem = item.getElement('a').rel;
				
		item.addEvent('mouseover', function()
		{
			item.setStyle('background','#EBBC27');
			
			if (elem != 'false')
			{
				var pos = item.getPosition();
					pos.x += 1;
					pos.y += 35;
				
				$(elem).setPosition(pos);
				$(elem).setStyle('display','block');
			}
		});
		
		item.addEvent('mouseout', function()
		{
			item.setStyle('background','none');
			
			if (elem != 'false')
			{
				$(elem).setStyle('display','none');
			}
		});
		
		item.addEvent('click', function()
		{
			if (item.getElement('a').href != '')
			{
				document.location.href = item.getElement('a').href;
			}
		});
	});
});

window.addEvent('load', function()
{
	var arr_img = $$('div.regioImgWrap img');
	var img_num = arr_img.length;
	
	for (var i=0; i<img_num; i++)
	{
		if (arr_img[i].getParent().rel != 'undefined' && arr_img[i].getParent().rel != 'noZoom')
		{
			arr_img[i].addEvent('mouseover', function()
			{
				zoomImg(this);
			});
		}
	}
	
	$('imgHover').addEvent('mouseout', function()
	{
		$('imgHover').setStyle('visibility', 'hidden');
		myZoomFx.cancel();
	});
});