/* $Id: plugin-general.js,v 1.1 2009/02/18 09:29:53 chris Exp $ */

/* NATIVE-LIKE ENHANCEMENT & SUPPLEMENTS  *************************************/


/**	Debug function				// TODO: sprawdzić jak to właściwie działa
 *	http://markc.renta.net/jquery/, 206-06-11
 */
$.fn.dbg = function(obj) {
  var buf = '';
  var o = obj || this;
  if (o) {
    for (var i in o) {
      if ((o[i] instanceof Function)
       || (o[i] == null)
       || (i.toUpperCase() == i)) continue;
      buf += i + '=' + o[i] + ', ';
    }
  } else buf = 'Null Object';
  alert(buf);
  return o;
};


/**	Checks if given selector has found anything
 * 	by chris, 2006-06-15
 */
$.fn.exists = function()
{
	return this.size() > 0;
};


 
/** Replaces Old class with New one in all found elements
 * 	by chris, 2006-06-15 
 */
$.fn.replaceClass = function(sANewClass, sAOldClass)
{
	this.addClass(sANewClass).removeClass(sAOldClass);
};


/**	Wrapper for DOM getAttribute method, returns attribute value for first element found
 * 	by chris, 2006-06-11
 */
$.fn.getAttribute = function(sAttrName) 
{
	var aR = new Array();
	this.each(function() { aR[aR.length] = this.getAttribute(sAttrName); });
	return aR[0];
};

/**	Wrapper for DOM getAttribute method, returns an array of attribute values for all elements found
 * 	by chris, 2006-06-11
 */
$.fn.getAttributes = function(sAttrName) 
{
	var aR = new Array();
	this.each(function() { aR[aR.length] = this.getAttribute(sAttrName); });
	return aR;
};


/** Workaround for DOM getAttribute('class') method (IE bug), returns 'class' value for fisrt found element
 * 	by chris, 2006-06-15
 */
$.fn.getClass = function()
{
	var aR = new Array();
	this.each(function() { aR[aR.length] = this.attributes['class'].value; });
	return aR[0];
};

/**	Workaround for DOM getAttribute method (IE bug), returns an array of 'class' values for all elements found
 * 	by chris, 2006-06-15
 */
$.fn.getClasses = function() 
{
	var aR = new Array();
	this.each(function() { aR[aR.length] = this.attributes['class'].value; });
	return aR;
};


$.fn.hasClass = function(sAClassName) 
{
	var sClasses = this.getClasses().join();
	var bResult = (sClasses.match(sAClassName) != null);
//	alert(bResult)
	return bResult;
};


$.fn.getContents = function() 
{
	var aR = new Array();
	this.each(function() { aR[aR.length] = this.innerHTML; });
	return aR;
};

$.fn.getContent = function() 
{
	var aR = new Array();
	this.each(function() { aR[aR.length] = this.innerHTML; });
	return aR[0];
};


/* ADDONS & OTHER PLUGINS *****************************************************/

/*	Tabs - jquery plugin for accessible, unobtrusive tabs 
 *	Free beer and free speech. Enjoy!
 * 	by Klaus Hartl, http://stilbuero.de/tabs/, added 2006-06-11
 */
$.tabs = function(containerId, start) {		// TODO: jakiś kod jeszcze został na tej stronie; 2006-06-11, chris
    var ON_CLASS = 'on';
    var id = '#' + containerId;
    var i = (typeof start == "number") ? start - 1 : 0;
    $(id + '>div:lt(' + i + ')').add(id + '>div:gt(' + i + ')').hide();
    $(id + '>ul>li:nth-child(' + i + ')').addClass(ON_CLASS);
    $(id + '>ul>li>a').click(function() {
        if (!$(this.parentNode).is('.' + ON_CLASS)) {
            var re = /([_\-\w]+$)/i;
            var target = $('#' + re.exec(this.href)[1]);
            if (target.size() > 0) {
                $(id + '>div:visible').hide();
                target.show();
                $(id + '>ul>li').removeClass(ON_CLASS);
                $(this.parentNode).addClass(ON_CLASS);
            } else {
                alert('There is no such container.');
            }
        }
        return false;
    });
};





