/* 
 * funkce k jQuery
 *
 * verze 0.1
 */

 /**
  * String @selector eg #myCheckbox or .allCheckboxes
  * boolean @check
  */
function jqSetCheckbox(selector, check) {
	jQuery("input:checkbox" + selector).attr('checked', check);
}

function jqToggleCheckbox(selector) {
	// inspirovano http://www.texotela.co.uk

	var checked = jQuery("input:checkbox" + selector).each(
				function()
				{
					this.checked = !this.checked;
				}
			)
}

function checkboxAllByClass(className) {
	jQuery("input:checkbox." + className).attr('checked', true);
}

function checkboxNoneByClass(className) {
	jQuery("input:checkbox." + className).attr('checked', false);
}

function setGlobalMessagesToHide()
{
	if (jQuery("#globalMessageRemove").length>0) {
		jQuery("#globalMessageRemove").click(function () {
			jQuery("#globalMessages").hide(1000);
			return true;
		});

		setTimeout(function(){
			jQuery("#globalMessages").hide(1000);
		}, 10000);

	}
}

function setGlobalMessages(htmlInsert) {
	jQuery("#globalMessages").hide();
	jQuery("#globalMessages").html(htmlInsert);
	jQuery("#globalMessages").show(1000);

	setGlobalMessagesToHide();
}

// zavola php a naparsuje vracena data
/*
	jQuery("#ajaxtextClick").click(function() {
				myAjax('AJAX_TYP_TEST', 'pole1=ahoj&pole2=vole');
			})
*/
function myAjax(typ, myData, file) {
	if (file == '' || file == null) file = 'ajax.php';
	jQuery.ajax({
		url : file + '?typ=' + typ,
		type : "POST",
		//data : "employee=" + jQuery("#employee_id").attr("id"),
		data : myData,
		dataType : "json",
		error : function (xhr, desc, exception) {
			alert("Chyba: " + xhr.responseText + desc + exception);
		},
		success : function (data) {
			//assuming an Array of objects was retreived
			for (var x=0; x < data.length; x++) {
				var dataItem = data[x];

				var element = dataItem.element;
				var output = dataItem.output;

				// pokud je to message, pak se vola jina funkce
				if (element == "#globalMessages") setGlobalMessages(output);
				else if (element == "sessionError") top.location = output;
				else if (jQuery(element).length>0) {
					jQuery(element).fadeOut(1000, function () {
						jQuery(element).html(output).fadeIn(1000)
					});
				}
			}
		}
	});
}

/*
http://jquery.open2space.com/node/56

jQuery.ajax({
url : "employee_sales_json.php",
type : "POST",
data : "employee=" + jQuery("#employee_id").attr("id"),
dataType : "json",
error : function (xhr, desc, exception) { alert(xhr.responseText); },
success : function (data) {
//assuming an Array of objects was retreived
var output = "<ul>";
for (var x=0; x < data.length; x++) {
var sale = data[x];
output += "<li>";
output += "Type: " + sale.type + ", ";
output += "QTY : " + sale.qty + ", ";
output += "Total: " + sale.total;
output += "</li>";
}
output += "</ul>";
jQuery("#employee_sales").html(output);
}
});


 */


/*--------------------------------------------------------------------
 * JQuery Plugin: "EqualHeights"
 * by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
 *
 * Copyright (c) 2008 Filament Group
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Description: Compares the heights or widths of the top-level children of a provided element
 		and sets their min-height to the tallest height (or width to widest width). Sets in em units
 		by default if pxToEm() method is available.
 * Dependencies: jQuery library, pxToEm method	(article:
		http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/)
 * Usage Example: jQuery(element).equalHeights();
  		Optional: to set min-height in px, pass a true argument: jQuery(element).equalHeights(true);
 * Version: 2.0, 08.01.2008
--------------------------------------------------------------------*/

jQuery.fn.equalHeights = function(px) {
	jQuery(this).each(function(){
		var currentTallest = 0;
		jQuery(this).children().each(function(i){
			if (jQuery(this).height() > currentTallest) { currentTallest = jQuery(this).height(); }
		});
		if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		// for ie6, set height since min-height isn't supported
		if (jQuery.browser.msie && jQuery.browser.version == 6.0) { jQuery(this).children().css({'height': currentTallest}); }
		jQuery(this).children().css({'min-height': currentTallest});
	});
	return this;
};

