/*
function collapseMenu(node) {return false; if (!document.getElementById) return false;if (!document.getElementById("tree1")) return false;if (!node) node = document.getElementById("tree1");if (node.childNodes.length > 0) {for (var i=0; i<node.childNodes.length; i++) {var child = node.childNodes[i];if (child.nodeName == "UL" && child.parentNode.className != "curr") {child.style.display = "none";}collapseMenu(child);}}}
function justHide(node, activ) {if (!node) node = document.getElementById("tree1");if(node.childNodes) {if (node.childNodes.length > 0) {for (var i=0; i<node.childNodes.length; i++) {var child = node.childNodes[i];if (child.nodeName == "UL" && child != activ && node != activ) {child.style.display = "none";}justHide(child, activ);}}}}
function prepareMenu() {return false;if (!document.getElementById || !document.getElementsByTagName) return false;if (!document.getElementById("tree1")) return false;var links = document.getElementById("tree1").getElementsByTagName("a");for (var i=0; i<links.length; i++) {links[i].onclick = function() {toggleMenu(this.parentNode.getElementsByTagName("UL")[0], this.href);return false;}}}
function toggleMenu(node, link) {return false;if (!document.getElementById) return false;if (!link) return false;if (!node) {location.href = link;} else {if (node.style.display == '') {node.style.display = 'none';} else {node.style.display = '';}}}
*/

/* STYLE SWITCHER */

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}


$(document).ready(function() {

	$('.toggleaddress').click(function(){
		$('.address').toggle();
		if ($('#address').attr('checked')) {
			$('#address').attr('checked', false);
		} else {
			$('#address').attr('checked', true);
		}
		return false;
	});
	
	$('#address').click(function(){$('.address').toggle();});
	$('a[href="#tree1"]').click(function() {
		$.cookie("tree","tree1", {expires: 365, path: '/'});
		$("#tree1").show();
		$("#tree2").hide();
		$('.switch a').removeClass('curr');
		$(this).addClass('curr');
		return false;
	});
	$('a[href="#tree2"]').click(function() {
		$.cookie("tree","tree2", {expires: 365, path: '/'});
		$("#tree1").hide();
		$("#tree2").show();
		$('.switch a').removeClass('curr');
		$(this).addClass('curr');
		return false;
	});


	if($.cookie("tree")=='tree2') {
		$("#tree1").hide();
		$("#tree2").show();
		$('a[href="#tree2"]').addClass('curr');
	} else {
		$("#tree1").show();
		$("#tree2").hide();
		$('a[href="#tree1"]').addClass('curr');
	}
	
  $.ajaxSetup({
    'beforeSend' : function(xhr) {
        xhr.overrideMimeType('text/html; charset=windows-1250');
    }
  });	
	
  filterload();





	jQuery.browser.version = jQuery.browser.msie && parseInt(jQuery.browser.version) >= 6 && window["XMLHttpRequest"] ? "7.0" : jQuery.browser.version;

	$('.bubble').wrapInner('<div class="bubblein" />');

	$('.bubble').hover(
		function(){
			if ($(this).hasClass('p2line') || ($(this).next().length == 0)) {
				el = $(this).prev('td');
				var x = '-21px'
                  if ($.browser.msie && $.browser.version <= 6) { x = "-37px" };
			} else {
				el = $(this).next('td');
				var x = $(this).width()- 21 + 'px';
                  if ($.browser.msie && $.browser.version <= 6) { x = $(this).width()- 36 + 'px' };
			}

			el.addClass('bubblehover');
			$(this).addClass('bubblehover');
			$(this).children('.bubblein').append('<div class="bubblebox"><div class="bubbleinner">' + $(this).attr('title') + '</div></div>');
			var bottom =    $(window).height() + $(window).scrollTop();
			var y = $(this).offset().top;
			if ((bottom - y) < ($('.bubblebox').height()+55)) {
				$('.bubblebox').addClass('bubbleflip');
			}
			$('.bubblebox').css({'left':x,'visibility':'visible','display':'none'}).fadeIn('fast');
		},
		function(){

			if ($(this).hasClass('p2line') || ($(this).next().length == 0)) {
				el = $(this).prev('td');
			} else {
				el = $(this).next('td');
			}
			$('.bubblebox').remove();
			$(this).removeClass('bubblehover');
			el.removeClass('bubblehover');
		}
	);





});


function filterload(){

	$('#filter form').prepend('<input type="hidden" name="jquery" value="1" />');
	var domain = window.location.href.split("/");
	//alert(domain[2]);
	$('#filter input').change(function(){
    $('#filter').prepend('<div id="waiting">ČEKEJTE PROSÍM<br /><br /></div>');
    $("#itemlist").load("http://"+domain[2]+"/"+"component.php", $('#filter form').find('input').serialize(),function(){
      filterload();
    });    
   
  });
  


}