	function redirect(url)
	{
		window.location=url;
	}

	function preparedoc()
	{  
		$('a[rel="external"]').attr('target','_external');  
		$('a.thickbox, area.thickbox, input.thickbox').fancybox();
	}

	var origContent = "";

	function loadContent(hash) {	
	
		if(hash != "") {
			if(origContent == "") {
				origContent = $('#content').html();
			}
			
			$.get('index.php', {'method':'renderdoc', 'document':hash}, function(text) {		
				document.title = text.split('\n', 2)[0].replace(/<h1>\s*(.*)\s*<\/h1>/, '$1');
				$('#loading').hide();
				$('#content').empty().append(text).show();	  

				preparedoc();
			});

			$('#content').hide();    
			$('#loading').show()
			
		} else if(origContent != "") {
			$('#content').html(origContent);
		}
	}

	$(function() {		
		switch(lang) {
			case 'sk':
				$('<div id="loading"><img src="images/loadingAnimation.gif" alt="nahráva sa obsah"/><br/>Stránka sa nahráva</div>').insertBefore('#content').hide();
			break;
			case 'en':
				$('<div id="loading"><img src="images/loadingAnimation.gif" alt="loading"/><br/>Loading page</div>').insertBefore('#content').hide();
			break;
			case 'de':
				$('<div id="loading"><img src="images/loadingAnimation.gif" alt="nahráva sa obsah"/><br/>Stránka sa nahráva</div>').insertBefore('#content').hide();
			break;
		}
		
		$.history.init(loadContent);
		  
		$('#header .flash').flash({
			src: 'swf/top.swf?lang='+lang,
			width: 833,
			height: 225,
			wmode: 'transparent'
		});

		$('#gallery .content').flash({
			src: 'swf/gal.swf?lang='+lang,
			width: 130,
			height: 130,
			wmode: 'transparent'
		});
		
		var menuid = 1;

		$('#mainmenu ul').each(function(){			
			this.id='submenu'+(menuid++);

			$(this).hide();
			if($.cookie(this.id) == 'true')
			{
				$(this).show();
			}
		});

		$('#mainmenu li a').click(function()
		{			
			var submenu = $(this).next('ul');   
			if(submenu.length)
			{
				if(submenu.css('display') == 'none')
				{
					submenu.show(500);
					$.cookie(submenu.attr('id'), 'true');
				}
				else
				{
					submenu.hide(500);
					$.cookie(submenu.attr('id'), null);
				}     
				return false;
			}
			else
			{
				$.history.load(/\?document=(.*)/.exec(this.href)[1]);
				return false;
			}
		});
		
		preparedoc();
		
	});

