$.extend($lang);

function search()
{
	return true;
}

function load_image(i)
{			
	var img = $('<img />');

	img.load(function()
	{
		$(this).addClass('ready');
	});
	
	img.attr('src', i.img);
	return img;
}

function show_full_image(num, all)
{	
	var foto = $('#f' + num);
	
	if (foto.attr('href') == '')
	{
		$('div#foto-full').click();
		return false;
	}
	
	$('html').css('overflow', 'hidden');
	$('div#mask').show();
	$('div#foto-bg .next').hide();
	$('div#foto-bg .prev').hide();
	$('div#foto-full').hide();
	$(document).unbind('keydown');

	$('div#foto-bg').css('background', 'url(pub/img/loading.gif) center no-repeat');
	$('div#foto-bg').css('margin-top', (-($('div#foto-bg').height()) / 2)+$('html').scrollTop());
	$('div#foto-bg').fadeIn(50);
	
	if (foto.attr('href').substr(-4) == 'null')
	{
		if (num < all)
		{
			show_full_image(++num, all)
		}
		else if (num == all)
		{
			//img.remove();
			$(document).unbind('keydown');
			$('div#foto-bg').css('background-image', '').hide();
			$('div#foto-full').css('background-image', '').fadeOut(50);
			$('div#mask').hide();
			$('html').css('overflow', '');
		}
			
		return false;
	}	

	var img = load_image({img:foto.attr('href')});
	var obj = {};
	var load_time = 0;
	
	$('body').everyTime(100, function ()
	{
		load_time++;
		
		if (load_time > 30000)
		{
			$('body').stopTime();
			$(img).remove();
			$('div#foto-full').click();
		}
		
		if ($(img).attr('class') == 'ready')
		{
			$('body').stopTime();
			
			obj = {src: $(img).attr('src'), width: $(img).attr('width'), height: $(img).attr('height')};

			$(img).remove();
			
			if ($('div#foto-full').width() == obj.width && $('div#foto-full').height() == obj.height)
			{
				$('div#foto-bg').css('background', '');
				
				if (num < all)
				{
					$('div#foto-bg .next').fadeIn(300);
				}

				if (num > 1)
				{
					$('div#foto-bg .prev').fadeIn(300);
				}
				
				$('div#foto-full').css('background', 'url(' + obj.src + ') center no-repeat');
				$('div#foto-full').fadeIn(300, function()
				{
					$(this).pngFix({blankgif:'pub/img/blank.gif'});
					$('div#close').show();
					
				});
			}
			else
			{
				$('div#foto-full').width(obj.width).height(obj.height);
				$('div#foto-bg').animate(
				{
					width: obj.width,
					height: obj.height+35,
					marginTop: (-(obj.height+35) / 2)+$('html').scrollTop(),
					marginLeft: -(obj.width) / 2
				}, 400, function ()
				{
					$('div#foto-bg').css('background', '');
					
					if (num < all)
					{
						$('div#foto-bg .next').fadeIn(300);
					}

					if (num > 1)
					{
						$('div#foto-bg .prev').fadeIn(300);
					}
				
					$('div#foto-full').css('background', 'url(' + obj.src + ') center no-repeat');
					$('div#foto-full').fadeIn(300, function()
					{
						$(this).pngFix({blankgif:'pub/img/blank.gif'});
						$('div#close').show();
					});
				});
			}
		}
	});

	$(document).keydown(function (e)
	{
		$(img).remove();
		
		switch (e.keyCode)
		{
			case 27:
				$('div#foto-full').click();
				break;

			case 37:
				if (num > 1) $('div#foto-bg .prev').click();
				break;

			case 39:
				if (num < all) $('div#foto-bg .next').click();
				break;		
		}
	});
	
	$('div#close').unbind('click').click(function ()
	{
		$('div#foto-full').click();
	});

	$('div#foto-full').unbind('click').click(function ()
	{
		$(document).unbind('keydown');
		$('div#close').hide();
		$('div#foto-bg').css('background-image', '').hide();
		$('div#foto-full').css('background-image', '').fadeOut(50);
		$('div#mask').hide();
		$('html').css('overflow', '');
	});
	
	$('div#foto-bg .prev').unbind('click').click(function ()
	{
		$('div#foto-full').css('background-image', '').fadeOut(50);
		show_full_image(--num, all);
	});

	$('div#foto-bg .next').unbind('click').click(function ()
	{
		$('div#foto-full').css('background-image', '').fadeOut(50);
		show_full_image(++num, all);
	});
}
	
	$(document).ready(function ()
	{
		$('.pngfix').pngFix({blankgif:'templates/img/blank.gif'});
		
		var thumbs = $('.gallery a').length;

		$('.gallery a').click(function ()
		{		
			if ($(this).attr('href').substr(-4) == 'null')
				return false;

			show_full_image($(this).attr('rel'), thumbs);
			
			return false;
		});

		$('div#search-btn-mask').click(function ()
		{
			$('form#search-fm').submit();
		});
		
		$('form#search-fm').submit(function ()
		{
			return search();
		});
		
		$('#flags a').easyTooltip({yOffset : -5});
			
		$('div.menu-bg a').mouseover(function ()
		{
			$('div.menu-bg:has(a[href='+this.href+'])').css('background-position', '0px 45px');
		});
		
		$('div.menu-bg a').mouseout(function ()
		{
			$('div.menu-bg:has(a[href='+this.href+'])').css('background-position', '0px 0px');
		});
		
		$('form[name=kontakt] input[type=button]').click(function ()
		{
			var $alert = false;
			
			$('form[name=kontakt] .req').each(function ()
			{
				if ($(this).val() == '') $alert = true;
			});
			
			if ($alert)
				alert($lang['mess']);
			else
				$('form[name=kontakt]').submit();			
		});
		
		$('a[rel=ext]').live('click', function ()
		{
			this.target = "_blank";
		});
	});
	
function showWindow(url, width, height)
{
	var top = (screen.height-height)/2;
	var left = (screen.width-width)/2;
	
	var d = new Date();
	
	window.open(url,d.getTime(),'status=yes,top='+top+',left='+left+',width='+width+',height='+height);	
}
		/**
		 / THIRD FUNCTION
		 * getPageScroll() by quirksmode.com
		 *
		 * @return Array Return an array with x,y page scroll values.
		 */
		function ___getPageScroll() {
			var xScroll, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;	
			}
			arrayPageScroll = new Array(xScroll,yScroll);
			return arrayPageScroll;
		};
