//	to get jQuery to play nice with prototype, change $ to jQuery

fsTabs = new Object();

fsTabs = {
	contentDivIDs: new String,
	showhidetabsContainer: new String,

	// init the Tabs, attach events
	initTabs: function(tabs_wrapper) {
		jQuery.noConflict(); // just to make sure :)

		if (typeof tabs_wrapper == 'undefined') tabs_wrapper = 'default';
		if (tabs_wrapper != 'default') {
			var is_array = this.isArray(tabs_wrapper);
			if (is_array == true) { // multiple tabs (still in development
				//for (i = 0; i < tabs_wrapper.length; i++) {
				//blah
				//}
			} else { // only one tab area
				// add  the click event
				jQuery("#" + tabs_wrapper + " li").click(function() {
					var index = jQuery("#" + tabs_wrapper + " li").index(this);

					fsTabs.showTab(index, tabs_wrapper);
				});
			}
		}
	},

	// show the tab
	showTab: function(id, wrapper_id) {
		div_id = this.contentDivIDs[id]; // get the id
		if (jQuery('#' + div_id).length > 0) {
			for (i = 0; i < this.contentDivIDs.length; i++) { // hide all other content
				singe_id = jQuery('#' + this.contentDivIDs[i]);
				if (singe_id.length > 0) {
					singe_id.css({ 'display': 'none' });
					jQuery("#" + wrapper_id + " li:eq(" + i + ")").addClass("tab-inactive");

					if (i > 0) { // remove left corner
						jQuery("#" + wrapper_id + " li:eq(" + i + ")").removeClass("tab-leftcorner");
					}
				}
			}

			jQuery('#' + this.contentDivIDs[id]).css({ 'display': 'block' }); // show div
			jQuery("#" + wrapper_id + " li:eq(" + id + ")").removeClass("tab-inactive");

			if (id > 0) { // adding left corner
				jQuery("#" + wrapper_id + " li:eq(" + id + ")").addClass("tab-leftcorner");
			}
		}
	},

	// adding the event listeners on the links
	addShowHideTabs: function(wrapper) {
		this.showhidetabsContainer = wrapper;
		if (jQuery('.' + wrapper).length > 0) {
			var elements = jQuery('.' + wrapper + ' .show-hide-tab a');
			jQuery(elements).click(function() {
				var index = elements.index(this);
				fsTabs.showContainerContent(index, wrapper);
				return false;
			});
		}
	},

	// show individual divs
	showContainerContent: function(index, wrapper) {
		var content = jQuery('.' + wrapper + ' .show-hide-tab .show-hide-content:eq(' + index + ')');
		if (content.length > 0) {
			var link = jQuery('.' + wrapper + ' .show-hide-tab a.tab-link:eq(' + index + ')');
			if (content.css("display") == "none") {

				if ((content).is(":hidden")) { content.slideDown("normal"); } // effect

				//content.css({ 'display': 'block' });
				if (link.length > 0) { link.addClass("show-hide-tab-active"); }

			}
			else {
				if (link.length > 0) { link.removeClass("show-hide-tab-active"); }
				content.slideUp("fast"); // effect :)

				//content.css({ 'display': 'none' });
			}
		}
	},

	// show'em all 
	showAllContainerContent: function(wrapper) {
		var content = jQuery('.' + wrapper + ' .show-hide-tab .show-hide-content');
		if (content.length > 0) {
			content.each(function(i) {
				this.style.display = "block";
			});
			var link = jQuery('.' + wrapper + ' .show-hide-tab a.tab-link');

			if (link.length > 0) {
				link.each(function(i) {
					link.addClass("show-hide-tab-active");
				});
			}
		}
	},

	// jumpt to specific tab and show it
	openShowHideTab: function(tab_id) {
		var link = jQuery('.' + this.showhidetabsContainer + ' .show-hide-tab a.tab-link:eq(' + tab_id + ')');
		if (link.length > 0) {
			var position = link.offset();
			window.scrollTo(0, position.top);
			this.showContainerContent(tab_id, this.showhidetabsContainer);
		}
	},


	/* check if its an array*/
	isArray: function(obj) {
		return (obj.constructor.toString().indexOf("Array") != -1);
	}
}

// This part gets handled by MiniTabs.php class
// init the footer
$(document).ready(function() {

	// define all content-divs
	if (typeof fs_minitabs_array == 'undefined') fs_minitabs_array = 'default';

	// the <UL>-container with the <LI>-Tabs
	if (typeof fs_minitabs_wrapper == 'undefined') fs_minitabs_wrapper = 'default';
	if (typeof fs_showhidetabs == 'undefined') fs_showhidetabs = 'default';
	if (typeof fs_open_showhidetab == 'undefined') fs_open_showhidetab = 'default';


	if (fs_minitabs_array != 'default') {
		fsTabs.contentDivIDs = fs_minitabs_array;
	}
	if (fs_minitabs_wrapper != 'default') {
		fsTabs.initTabs(fs_minitabs_wrapper);
	}

	// add the show-hide-tabs
	if (fs_showhidetabs != 'default') {
		fsTabs.addShowHideTabs(fs_showhidetabs);
		//fsTabs.showAllContainerContent(fs_showhidetabs);
	}

	// open specific tab from the beginning and jump to it
	if (fs_open_showhidetab != 'default') {
		fsTabs.openShowHideTab(fs_open_showhidetab);
	}


	// add showHideTab
	//fsTabs.addShowHideTabs('help-tab-content');
	// in case you wanna show all tabs at once
	//fsTabs.showAllContainerContent('help-tab-content');

	//fsTabs.contentDivIDs = Array("aboutBox", "pluginsBox");
	//fsTabs.initTabs("fontcase-tabs");
});


