function removeCKEonClose() {
	for ( var key in CKEDITOR.instances) {
		CKEDITOR.remove(CKEDITOR.instances[key]);
	}
}

function tb_remove() {
	$("#TB_imageOff").unbind("click");
	$("#TB_closeWindowButton").unbind("click");
	$("#TB_window").fadeOut(
			"fast",
			function() {
				$("#TB_window,#TB_overlay,#TB_HideSelect").trigger("unload")
						.unbind().remove();
			});
	$("#TB_load").remove();
	if (typeof document.body.style.maxHeight == "undefined") {// if IE 6
		$("body", "html").css({
			height : "auto",
			width : "auto"
		});
		$("html").css("overflow", "");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	removeCKEonClose();
	return false;
}

$(document).ready(function() {
	Shadowbox.init({
		 handleOversize:     "drag",
		 viewportPadding: 0
	});
	bindConfirms();
	bindNewWindow();
	zamestnanecEON();
	if ($("a#mainReg").length > 0) { 
		$("a#mainReg").tooltip({
			effect : 'fade',
			relative : true,
			position : 'bottom center',
			offset : [ 0, 0 ]
		// offset: [-100, 0]
		}).dynamic({
			bottom : {
				direction : 'down',
				bounce : true
			}
		});
	}
});

function zamestnanecEON() {
	if ($("#zamestnanecEON").attr('checked') == false)
		$("#kid").hide();
	$("#zamestnanecEON").change(function() {
		if ($(this).attr("checked") == true)
			$("#kid").show();
		else
			$("#kid").hide();
	});
}

function postForm(form, div) {
	$.ajax({
		type : "POST",
		url : $(form).attr("action"),
		data : $(form).serialize(),
		success : function(data) {
			if (div)
				$(div).html(data);
		}
	});
	return false;
}

function print_r(theObj) {
	if (theObj.constructor == Array || theObj.constructor == Object) {
		document.write("<ul>")
		for ( var p in theObj) {
			if (theObj[p].constructor == Array
					|| theObj[p].constructor == Object) {
				document.write("<li>[" + p + "] => " + typeof (theObj)
						+ "</li>");
				document.write("<ul>")
				print_r(theObj[p]);
				document.write("</ul>")
			} else {
				document.write("<li>[" + p + "] => " + theObj[p] + "</li>");
			}
		}
		document.write("</ul>")
	}
}

function useFinder() {
	for ( var key in CKEDITOR.instances) {
		CKFinder.SetupCKEditor(CKEDITOR.instances[key], HTTP_PATH
				+ "resources/ckfinder/");
	}
}

function useCKE(where) {
	for ( var key in CKEDITOR.instances) {
		CKEDITOR.remove(CKEDITOR.instances[key]);
	}
	if ($.isArray(where)) {
		for ( var key2 in where) {
			CKEDITOR.replace(where[key2]);
		}
	} else if (where) {
		CKEDITOR.replace(where);
	} else {
		CKEDITOR.replaceAll();
	}
}

function shiftContent(block, contents, id) {
	if (id == undefined) {
		id = 0;
		for ( var c in contents) {
			if (c != id)
				$(contents[c]).hide();
			// $(contents[c]).css('position', 'absolute');
		}
		$(block).css('position', 'relative');
	}

	var newID = id + 1;
	if (newID >= contents.length)
		newID = 0;
	$(contents[id]).delay(8000).fadeOut(100, function() {
		$(contents[newID]).fadeIn(100, function() {
			shiftContent(block, contents, newID);
		});
	});
}

$(function() {
	$("#hledatButton").button();
});

$(function() {
	if ($("#zarazeniProduktu").length > 0) {
		$("#zarazeniProduktu").jstree({
			"themes" : {
				"theme" : "classic",
				"dots" : true,
				"icons" : false
			},
			"plugins" : [ "themes", "html_data" ]
		});
	}
});

$(document)
		.ready(
				function() {
					$('a.fb_share_button')
							.click(
									function() {
										window
												.open(
														'http://www.facebook.com/sharer.php?u='
																+ encodeURIComponent($(
																		this)
																		.attr(
																				'href'))
																+ '&t='
																+ encodeURIComponent(document.title),
														'sharer',
														'toolbar=0,status=0,width=626,height=436');
										return false;
									});

					$(".wallComment form, #postOnTheWall")
							.submit(
									function() {
										var str = $(this).find("textarea")
												.val();
										if (str.length > 1000) {
											alert("Zpráva je příliš dlouhá a bude automaticky zkrácena na 1000 znaků.");
										}
									});
				});
/*
 * function fbs_click() { u=location.href;t=document.title;
 * window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
 * return false; }
 */
