// auto show/hide input value
var swap_text_boxes = [];
function init_swap_text_boxes(){
  //Store the default value for each box
  $('input[type=text][value].swaptextbox').each(function() {
    swap_text_boxes[$(this).attr('id')] = $(this).attr('value');
  });
  //Add focus and blur events to set or clear the value
  $('input[type=text][value].swaptextbox').bind('focus', function() {
    if($(this).val() == swap_text_boxes[$(this).attr('id')]) {
      $(this).val('');
    }
  });
  $('input[type=text][value].swaptextbox').bind('blur', function() {
    if($(this).val() == '') {
      $(this).val(swap_text_boxes[$(this).attr('id')]);
    }
  });
}

function initMenus() {
	$('ul.menu ul').hide();
	$.each($('ul.menu'), function() {
		var cookie = $.cookie(this.id);
		if (cookie === null || String(cookie).length < 1) {
			$('#' + this.id + '.expandfirst ul:first').show();
		}
		else {			
			$('#' + this.id + ' .' + cookie).next().show();
		}
	});
	
	$('ul.menu li a').click(
		function() {
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;

      /*
			if ($('#' + parent).hasClass('noaccordion')) {
				if ((String(parent).length > 0) && (String(this.className).length > 0)) {
					if ($(this).next().is(':visible')) {
						$.cookie(parent, null);
					}
					else {
						$.cookie(parent, this.className);
					}
					$(this).next().slideToggle('normal');
				}				
			}
			*/
			
			if ((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if ($('#' + parent).hasClass('collapsible')) {
					$('#' + parent + ' ul:visible').slideUp('normal');
				}
				return false;
			}
			
			if ((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp('normal');
				if ((String(parent).length > 0) && (String(this.className).length > 0)) {
					$.cookie(parent, this.className);
				}
				checkElement.slideDown('normal');
				return false;
			}
		}
	);
}

$(document).ready(
  function() {
    /*
    <script type="text/javascript" src="<?=$levelseo;?>scripts/jquery/jquery.cookie.min.js"></script>
    <script type="text/javascript" src="<?=$levelseo;?>scripts/jquery/jquery.bgpos.js"></script>
    // initMenus();
    */
    init_swap_text_boxes();
    
    $('.piktogramy img').tooltip({ 
      track: true, 
      delay: 0, 
      showURL: false, 
      showBody: " - ", 
      fade: 250 
    });
  }
);
