function initData(context) {
	$('input.focusToggle, textarea.focusToggle, .textToggle').make('searchInput');
	$('a.printMe').make('myPrint');
	$('a.sendMe').make('sendMe');
	$('.sendMeForm').make('sendMeForm');
	$('div.rychlaNavigace').make('rychlaNavigace');
	$('#mainMenu li.unfold.hasChildren').make('submenu');
	$('.suggestForm').make('suggest', {url: langURL+'ajax/suggest/', form: true});
	$('div.carousel').make('carousel');
	$('.formUI').make('formUI');
	$('div.map').make('googleMap');
	$('.systemEdit').make('systemEdit');
	$('body').make('overlay');
	$('.tabWrapper').make('mytabs');
}

$(document).ready(function() {
	$('input.resetMe').click(function () {
		$(this).closest('form').find('select').val(0);
		return false;
	});

	//tooltip
	$("cite").tooltip({
		//showURL: false,
		track: true,
		showURL: true,
		positionRight: true,
		top: 5
		//left: 30
	}); 

	//zájemce o akci
	$('a.applicantFormTrigger').click(function () {
		
		$(this).append('<span class="loadingStatic"></span>');
		$.ajax({
			type: 'GET',
			url: langURL +'ajax/eventApplicant/',
			dataType: 'json', 
			context: this,
			error: function (a,b,c) {
				//alert(c);
			},
			success: function (data) {
				$('span.loadingStatic', this).remove();
				window.overlay.pushData(data.form).showOverlay();
				$('#applicantForm').find('input[name=event_id]').val( $(this).data('id') );
				
				$('#applicantForm').submit(function (e) {
					$(this).append('<span class="loadingStatic"></span>');
					$.ajax({
						type: 'POST',
						url: langURL +'ajax/eventApplicant/',
						data: $(this).serialize(),
						dataType: 'json', 
						context: this,
						error: function (a,b,c) {
							//alert(c);
						},
						success: function (data) {
							$('span.loadingStatic', this).remove();
							$('div.messageKo', this).remove();
							if (data.result) {
								$(this).empty().append(data.form)
							}
							else {
								$('legend', this).eq(0).after(data.form);
							}
						}
					})
					
					//e.preventDefault();
					return false;
				});
				
			}
		})
		return false
	});

	//zájem o partnerství/sponzoring
	$('a.partnerFormTrigger').click(function () {
		
		$(this).append('<span class="loadingStatic"></span>');
		$.ajax({
			type: 'GET',
			url: langURL +'ajax/eventPartner/',
			dataType: 'json', 
			context: this,
			error: function (a,b,c) {
				//alert(c);
			},
			success: function (data) {
				$('span.loadingStatic', this).remove();
				window.overlay.pushData(data.form).showOverlay();
				$('#partnerForm').find('input[name=event_name]').val( $(this).closest('div.eventContainer').data('name') );
				$('#partnerForm').find('input[name=event_id]').val( $(this).closest('div.eventContainer').data('id') );
				
				$('#partnerForm').submit(function (e) {
					$(this).append('<span class="loadingStatic"></span>');
					$.ajax({
						type: 'POST',
						url: langURL +'ajax/eventPartner/',
						data: $(this).serialize(),
						dataType: 'json', 
						context: this,
						error: function (a,b,c) {
							//alert(c);
						},
						success: function (data) {
							$('span.loadingStatic', this).remove();
							$('div.messageKo', this).remove();
							if (data.result) {
								$(this).empty().append(data.form)
							}
							else {
								$('legend', this).eq(0).after(data.form);
							}
						}
					})
					
					//e.preventDefault();
					return false;
				});
				
			}
		})
		return false
	});
	
	//discounts
	$('#eventDetail a.loadDiscounts').click(function () {
		$(this).append('<span class="loadingStatic"></span>');
		$.ajax({
			type: 'POST', 
			url: langURL +'ajax/eventDiscounts/', 
			data: {id: $(this).data('id')},
			dataType: 'html', 
			context: this,
			error: function (a,b,c) {
				//alert(c);
			},
			success: function (data) {
				$('span.loadingStatic', this).remove();
				window.overlay.pushData(data).showOverlay();
			}
		}); 
	});
	
	//tabs
	$('div.tabs').each(function () {
		$('div.tab', this).hide();
		$('div.menu a', this).removeClass('active');
		var hash =  window.location.hash.replace('#', '').toLowerCase();
		
		if (hash == '') {
			$('div.tab', this).eq(0).show();
			$('div.menu a', this).eq(0).addClass('active');
		}
		else if ( $('div.'+ hash, this).length ) {
			$('div.tab.'+ hash, this).show();
			$('div.menu a[href=#'+ hash + ']', this).addClass('active');
			//console.log( $('div.menu a[href='+ hash + ']', this).length, 'div.menu a[href=#'+ hash + ']');
		}
		else {
			$('div.tab', this).eq(0).show();
			$('div.menu a', this).eq(0).addClass('active');
		}
		//click
		$('div.menu a', this).click($.proxy(function (e) {
			$('div.tab', this).hide();
			$('div.menu a', this).removeClass('active');
			var hash = $(e.target).attr('href').replace('#', '').toLowerCase();
			$('div.tab.'+ hash, this).show();
			$('div.menu a[href=#'+ hash + ']', this).addClass('active');
			window.location.hash = '#'+ hash;
			return false;
		}, this));
	});
	
	//ie button
	$('form button').click(function () {
		$(this).closest('form').submit();
	});
	
	//contacts module
	$('div.quickContactModule a.more').click(function () {
		$(this).toggleClass('open');
		$(this).closest('div.quickContactModule').find('div.allContacts').toggle();
	});
	
	//captcha
	$('form input.cInput').hide();
	
	//top title text
	/*
	$('#topTitlesModule div.item div.img img').bind('load', function () {
		$(this).closest('div.item').find('div.text').width( $(this).width() - 20 );
	});
	*/
	$('#topTitlesModule div.item div.img').hover(
		function () {
			$('div.text', this).css({'bottom': (-1 * (36 + $('div.text', this).height()))+'px'}).animate({'bottom': 0}, {duration: 800, queue: false});
		}, 
		function () {
			$('div.text', this).animate({'bottom': (-1 * (36+$('div.text', this).height()))+'px'}, {duration: 800, queue: false});
		} 
	);
	
	//tlačítka předplatného
	$('#titleDetailTop div.buttons a.info').click(function (e) {
		e.preventDefault();
		var closure = $(this).closest('div.item');
		$('div.text_more', closure).slideToggle(400);
		return false;
	});
	
	//info o titulu
	$('div.titlesSubscriptionModule div.submenu a.local').click(function (e) {
		e.preventDefault();
		var closure = $(this).closest('div.detail').find('div.textInfo');
		var toFind = $(this).data('reveal');
		if ( $(document).scrollTop() == 0 ) {
			$(document).scrollTop(350);
		}
		$('div.item', closure).hide().removeClass('show');
		$('div.'+ toFind, closure).fadeIn(400);
		return false;
	});

	//login
	$('#loginTrigger button').click(function () {
		$(this).hide();
		$('#loginFormMini').show();
		//alert(1)
	});

	//lang nastavení
	langURL = "/"+lang.lang_url;

	//initialize modules
	initData();

	//dictionary
	$('div.dictionarySideLetters a').click(function () {
		this.xcontext = $(this).closest('div.webSideDictionary');
		$(this.xcontext).find('div.content').empty();
		$(this.xcontext).find('a').removeClass('active');
		$(this).addClass('active');
		$(this.xcontext).append('<div class="loadingAjax center"><img src="/images/loading.gif" alt="" /></div>');
		$.ajax({
			type: 'POST', 
			url: langURL +'ajax/dictionary/', 
			data: {letter: $(this).attr('rel') },
			dataType: 'html', 
			context: this,
			success: function (data) {
				$(this.xcontext).find('div.loadingAjax').remove();
				$(this.xcontext).find('div.content').append(data);
			}
		});
		return false;
	});
	$('div.webSideDictionary dt').live('hover',
		function () {
			$(this).closest('dl').find('dd').hide();
			$(this).next('dd').show();
		}
	);

	//zobrazit znaky hesla
	$('input.showPassword').showPassword('input.showPasswordInput');

	//link to open in new window
	$('a[rel=external]').attr('target', '_blank');

	//go back
	$('a.takeMeBack, a.goBack').click(function () {
		window.history.go(-1);
	});

	//newsletter
	$('form.newsletterAjax').submit( function() {
		$(this).append('<div class="loading"></div>');
		$.ajax({
			url: langURL + "ajax/newsletter/",
			type: "POST", 
			data: {email: $('input[name=email]', this).attr('value')},
			dataType: 'html',
			success: myScope(function(data) {
				$('input[name=email]', this).attr('value', '');
				$('div.message, div.loading', this).remove();
				$(this).prepend('<div class="message">'+data+'</div>');
				$('.message', this).click(function(){$(this).fadeOut(200);});
			}, this)
		});
		return false;
	});

	//gallery
	$('a[rel=gallery], a.gallery').fancybox({
		'mouse-wheel': false,
		'swing': false,
		'titleShow'	: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'showNavArrows'	: false,
		'speedIn':400, 
		'speedOut':200 
	});

	//gallery group
	$('a[rel=galleryGroup], a.galleryGroup').fancybox({
		'mouse-wheel': true,
		'swing': true,
		'transitionIn':'elastic',
		'transitionOut':'elastic',
		'speedIn':400, 
		'speedOut':200, 
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) { 
			return '<span id="fancybox-title-over">'+ lang.fotogalerie_Image +' '+ (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}

	});

});

