function reloadSimpleBasket(){
	var simpleBasket = $('#header-login-basket a[id^=header-basket]');
	simpleBasket.elAjax({
		url: GLOBAL.basketSimpleUrl,
		success: function(data){
			simpleBasket.text(data);
		},
		error: function(){
			window.location.reload();
		}
	});
}

	
$(function(){
	// doprovodne obrazky v detailu clanku
	$.Lightbox.construct({
		show_helper_text:	false,
		show_linkback: false,
		show_extended_info: true,
		text: {
			image:		'Obrázek',
			of:			'z',
			close:		'<strong>Zavřít X</strong>',
			closeInfo:	'Obrázek můžete zavřít kliknutím kamkoli mimo něj.',
			download:	'Stáhnout.',
			help: {
				close:		'Klikněte pro zavření',
				interact:	'Přejeďte myší pro ovládání'
			}
		}
	});
	
	// vychozi nastaveni validatoru
	
	$.validator.addMethod("regexp", function(value, element, param) {
		return !value.length || (new RegExp("^" + param + "$")).test(value);
	});
	
	$.extend(jQuery.validator.messages, {
		required: "Údaj je povinný.",
		email: "E-mail je neplatný.",
		regexp: "Údaj je ve špatném formátu.",
		url: "URL adresa je neplatná."
	});

	
	//search input
	var SEARCH_DEFAULT = 'Najít na stránkách...';
	if($('#search-input').val() == ''){
		$('#search-input').val(SEARCH_DEFAULT);
	}
	$('#search-input').focus(function(){
		if($(this).val() == SEARCH_DEFAULT){
			$(this).val('');
		}
	}).blur(function(){
		if($(this).val() == ''){
			$('#search-input').val(SEARCH_DEFAULT);
		}
	});
	
	// top odkazy hover
	$('#header-top-menu a').hover(function(){
		if($(this).hasClass('active')){
			return;
		}
		var img = $('img', this);
		if(img.length == 1){
			img.attr('src' , img.attr('src').replace('.jpg', '-active.jpg'));
		}
	},
	function(){
		if($(this).hasClass('active')){
			return;
		}
		var img = $('img', this);
		if(img.length == 1){
			img.attr('src' , img.attr('src').replace('-active.', '.'));
		}
	});
	
	
	// login form
	/*
	var loginformEntered = false;
	$('#header-login-blue, #header-login').mouseenter(function(){
		$(this).addClass('active');
		$('#header-loginform').show();
	});
	$('#header-loginform').mouseleave(function(){
		$('#header-login-blue, #header-login').removeClass('active');
		$('#header-loginform').hide();
		loginformEntered = false;
	});
	
	$('#header-loginform').mouseenter(function(){
		loginformEntered = true;
	})
	
	$('#header-login-blue, #header-login').mouseleave(function(){
		setTimeout(function(){
			if(!loginformEntered){
				$('#header-login-blue, #header-login').removeClass('active');
				$('#header-loginform').hide();
				loginformEntered = false;
			}
		}, 200);
	});
	*/
	$('#header-login-blue, #header-login').click(function(){
		if($(this).hasClass('active')){
			$(this).removeClass('active');
			$('#header-loginform').hide();
		} else {
			$(this).addClass('active');
			$('#header-loginform').show();
		}
		return false;
	});
	
	
	// registrace
	$(':button.registrace_reset').click(function(){
		$(':text, textarea, select', $(this).closest('form')).val('');
	});
	
	
	// tabs
	$('ul.tabs').superSimpleTabs();

	
	// e-shop kosik
	$('form.order_form').submit(function(){
		var form = this;
		$(form).elAjax({
			url: $(form).attr('action'),
			type: 'post',
			data: {
				ajax: true,
				id: $('input[name=id]', form).val(),
				count: $('input[name=count]', form).val()
			},
			dataType: 'json',
			success: function(data){
				reloadSimpleBasket();
				jqDialog.notify('<p>' + $('input[name=name]', form).val() + ' v ceně ' + $('input[name=price]', form).val() + ',- Kč</p><div><a href="'+ GLOBAL.basketUrl +'">přejít k objednávce</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" class="jqDialog_hide">pokračovat v nákupu</a></div>', 10, 'dialog_basket_add');
			},
			error: function(){
				//window.location = $(form).attr('action');
			}
		});
		return false;
	});
	
	$('a.jqDialog_hide').live('click', function(){
		jqDialog.close();
		return false;
	});
	
	
	// registrace dokoncena
	
	if($('#content-head').length == 1 && $('#content-head').hasClass('registration_registered')){
		jqDialog.notify('<p></p><div><a href="'+GLOBAL.loginUrl+'">přihlásit se</a></div>', 4, 'dialog_registered');
	}
	
	
	// ie form styling
	if($.browser.msie){
		$(':radio').addClass('noBorder');
	}
});
