	/*
$(document).mousedown(function(e) { 

	if (!$(e.target).parents('#emm-left').length) {
			var elem = $('li#emm-left > a');
					elem.next().slideUp(100);
					elem.removeAttr('id');
		}

};
	*/
$(document).ready(function(){

	/* simple workaround to switch off focus-blur effect on search pages */
	if($('#search').val() == "Szukaj na stronie") {
	$('#search').focus(function() {
							if (this.value == this.defaultValue){
								this.value = '';
							} else {
								this.select();
							}
						})
				.blur(function() {
							if ($.trim(this.value) == ''){
								this.value = (this.defaultValue ? this.defaultValue : '');
							}
						});
	}

	// drop-down menu
	var menu = [ "emm-left", "emm-center", "emm-right" ];
	$('li#emm-left > a, li#emm-center > a, li#emm-right > a').click(function() {
		var menuId = $(this).parent().attr('id');
		var menuClicked = $('#'+menuId+' > ul');
		menuClicked.stop(true,true);
		menuClicked.slideToggle('fast', function() {
			jQuery.each(menu, function() {
				if (menuId != this) {
					var elem = $('li#'+this+' > a');
					elem.next().slideUp(100);
					elem.removeAttr('id');
				}
			});
			if ($(this).is(':hidden')) {
				$('li#'+menuId+' > a').removeAttr('id');
			} else {		
				$('li#'+menuId+' > a').attr('id','selected');
			}	
		});
		return false;			
	});
	$(document).mousedown(function(e) {
		jQuery.each(menu, function() {
			var parent = 'li#'+this;
			if (!$(e.target).parents(parent).length)
			{
				var elem = $(parent + ' > a');
				elem.next().slideUp(100);
				elem.removeAttr('id');
			}
		});
		
	});
		

	// bannerek
	var timeoutId = 0;
	$('#mb').hover(function() {
		$('#mb span').stop(true,true);
		if ($('#mb span').is(':hidden')) {
			timeoutId = setTimeout(function(){
							$('#mb span').slideDown('fast');
						},500);
		}
		
	}, function() {
		clearTimeout(timeoutId);
		$('#mb span').slideUp('fast');
	});


	// tabs
	if ($.isFunction($("body").tabs)) {
		
		// calculate the maxHeight of tabs` content
		var maxHeight=0;
		$(".c_box_content").each(function(){
			if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;}
		});

		// set maxHeight as a default height of each tab
		$('div.c_box_nav ul').bind('tabsshow', function(event, ui) {
			$('.c_box_content').height(maxHeight+"px");
			if (this.offsetHeight>maxHeight) {
				$(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
			}	
		});	

		// configure & display tabs
		$('div.c_box_nav ul').tabs({
			//cookie: { expires: 7 },		
			fx: {opacity: 'toggle', duration: 'fast'}
			//selected : 1
		});

		$('.c_box_content_more_link').css('right','14px');	
	
	}

	if ($.isFunction($("body").prettyPhoto)) {
		$("a[rel^='prettyPhoto']").prettyPhoto({
			animationSpeed: 'normal', /* fast/slow/normal */
			padding: 30, /* padding for each side of the picture */
			opacity: 0.35, /* Value betwee 0 and 1 */
			showTitle: false, /* true/false */
			allowresize: true, /* true/false */
			counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
			theme: 'light_square' /* light_rounded / dark_rounded / light_square / dark_square */
		});
	}

});

