/**
 * this function is for simulation the bind() function like in mootools 
 */ 
$j.extend({
	  shove: function(fn, object) {
	    return function() {
	      return fn.apply(object, arguments);
	    }
	  }
});

/**
 * this function hides all Tabs
 */
function jquery_hideAllTabElements() {
	var headers = $j('.tx-nfcfootermenu-pi1 .footer-menu-header');
	var contents = $j('.tx-nfcfootermenu-pi1 .footer-menu-content');
	contents.each(function (index) {
		$j(this).hide();
	});
	headers.each(function (index) {
		$j(this).removeClass('active');
	});
}

/**
 * this function shows tab with index i
 */
function jquery_showTabByIndex(i) {
	var headers = $j('.tx-nfcfootermenu-pi1 .footer-menu-header');
	var header = $j(headers[i]);
	var contents = $j('.tx-nfcfootermenu-pi1 .footer-menu-content');
	var content = $j(contents[i]);
	header.addClass('active');
	content.show();
}

/**
 * start tab functionality for
 * headers: .tx-nfcfootermenu-pi1 .footer-menu-header
 * contents: .tx-nfcfootermenu-pi1 .footer-menu-content
 *	-> for manipulation also edit in jquery_hideAllTabElements and jquery_showTabByIndex
 */
$j(document).ready(function () {

	// get headers and contents
	var headers = $j('.tx-nfcfootermenu-pi1 .footer-menu-header');
	var contents = $j('.tx-nfcfootermenu-pi1 .footer-menu-content');
	//console.log(headers);
	//console.log(contents);
	
	// initial hiding
	jquery_hideAllTabElements();
	
	// click event for tab headers
	headers.each($j.shove(function(index, domElement) {
		$j(domElement).click($j.shove(function () {
			var visibleElement = false;
			var clickedElement = $j(this.contents[index]);
			if(clickedElement.is(":visible")) { visibleElement = true; }
			jquery_hideAllTabElements();
			if(!visibleElement) { jquery_showTabByIndex(this.index); }
		},{index:index,contents:this.contents}));
	},{contents:contents}));
});
