(function($){
	$.fn.vatCount = function(options){
		return this.each(function(i){
			var container = this;
			container.jqthis = $(this);
			container.defaults = $.extend({}, vatCount.defaults, options );
			
			
			container.taxValues = new Array();
			$(container.defaults.taxValues).each(function(){
				var value = this;
				container.taxValues[value.iVat] = 
				{ 
					iVat : value.iVat,
					fVatValue : value.fVatValue,
					sVatText : value.sVatText
				}
			
			});
			
			if (container.taxValues.length > 0){
				$(container).focusout(function(){
						selectedVat = container.defaults.taxValuesSelect.val();
						taxValue = container.taxValues[selectedVat].fVatValue;
						netValue = parseFloat(container.defaults.taxGrossField.attr("value"))/(parseFloat(taxValue)+1);
						container.defaults.taxNetField.attr("value",netValue.toFixed(2));
					
				});
				
				container.defaults.taxValuesSelect.change(function(){
					$(container).trigger("focusout");
				});
				
				$(container).trigger("focusout");
			}
		});
	}
	
	vatCount =	{
		defaults : 
		{
			taxValuesSelect : null,
			taxValues : null,
			taxGrossField : null,
			taxNetField : null
		},
		countFromGross: function()
		{
			

		}		
	}

})(jQuery);


(function($){
	
	var methods = {	};

	methods.init = function(options){
		return this.each(function(i){
			
			var container = this;
			container.jqthis = $(this);
			container.options = $.extend({}, libTabs.defaults, options);
		
			
			//alert(container.attr("id"));
			container.tabHeadersList = container.jqthis.children("ul").addClass("lib-tabs-nav");
			container.tabHeadersItems = container.jqthis.children("ul").find("li");
			container.tabHeadersItemsArray = new Array();
			container.tabHeadersAnchors = container.tabHeadersItems.find("a:first");
			container.visible_item = null;
			container.visibleHover_item = null;
	
			container.tabHeadersAnchors.each(function(i){
				var tabItem = $(this).parent("li")[0];
				container.tabHeadersItemsArray[i] = tabItem;
				
				$(this).click(function(){
					return false;
				});
				tabItem.an = this;				
				tabItem.pid = i;
				tabItem.stringref = $(tabItem.an).attr("href");	
				
				tabItem.panel = container.jqthis.children(tabItem.stringref).addClass("lib-tabs-panel").hide();	
				
				if (container.options.wrapper)
				{
					tabItem.panel.wrapInner('<div class="lib-tab-wrapper" />');
				}
				
				
				if (container.options.click)
				{
					// przełączenie zakładki
					$(tabItem.an).click(function(){
						container.tabHeadersItems.removeClass("lib-tabs-selected");
						$(tabItem).addClass("lib-tabs-selected");
						if (container.options.hoverSwitch)
						{
							container.tabHeadersItems.removeClass("lib-state-hover-dynamic");
							$(tabItem).addClass("lib-state-hover-dynamic");
						}
						libTabs.showTab(container, container.visible_item, tabItem);
						container.visible_item = tabItem;
						
						return false;
		
					});
				}
				else
				{	
					// brak akcji
					$(tabItem.an).click(function(){

					});
				}
				
				
				if (container.options.activeAnchor)
				{	
					$(tabItem.an).mouseover(function(){
						$(tabItem).addClass("lib-state-hover");
						if (container.visibleHover_item == null && container.options.hoverSwitch == true)
						{
							container.tabHeadersItems.removeClass("lib-state-hover-dynamic");
							$(tabItem).addClass("lib-state-hover-dynamic");
							libTabs.showTab(container, container.visible_item, tabItem);
							container.visibleHover_item = tabItem;
							
						}
					})
					.mouseout(function(){
						$(tabItem).removeClass("lib-state-hover");
						if (container.visibleHover_item != null && container.options.hoverSwitch == true)
						{
							container.tabHeadersItems.removeClass("lib-state-hover-dynamic");
							$(container.visible_item).addClass("lib-state-hover-dynamic");
							libTabs.showTab(container, container.visibleHover_item, container.visible_item);
							container.visibleHover_item = null;
						}
					});
				}
				
				if (container.options.activeList && !container.options.activeAnchor)
				{
					$(tabItem).mouseover(function(){
						$(tabItem).addClass("lib-state-hover");
						if (container.visibleHover_item == null && container.options.hoverSwitch == true)
						{
							container.tabHeadersItems.removeClass("lib-state-hover-dynamic");
							$(tabItem).addClass("lib-state-hover-dynamic");
							libTabs.showTab(container, container.visible_item, tabItem);
							container.visibleHover_item = tabItem;
							
						}
					})
					.mouseout(function(){
						$(tabItem).removeClass("lib-state-hover");
						if (container.visibleHover_item != null && container.options.hoverSwitch == true)
						{
							container.tabHeadersItems.removeClass("lib-state-hover-dynamic");
							$(container.visible_item).addClass("lib-state-hover-dynamic");
							libTabs.showTab(container, container.visibleHover_item, container.visible_item);
							container.visibleHover_item = null;
						}
					});
				}
				
	
		
				if (tabItem.pid == 0)
				{	
				//alert("go");
					container.visible_item = tabItem;
					$(tabItem.panel).show();
					$(tabItem).addClass("lib-tabs-selected");		
					if (container.options.hoverSwitch)
					{
						$(tabItem).addClass("lib-state-hover-dynamic");
					}
					
				}
				
			});
		});	
	};
	
	methods.showTab = function(options){
		return this.each(function(i){
			var container = this;
			var item = container.tabHeadersItemsArray[options];
			$(item.an).trigger("click");			
		});
	}
	
	$.fn.libTabs = function( method )
	{
		if ( methods[method] ) {
			return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
		} else if ( typeof method === 'object' || ! method ) {
			return methods.init.apply( this, arguments );
		} else {
			$.error( 'Method ' +  method + ' does not exist on jQuery.tooltip' );
		}
	};
	
	
	libTabs = { 
		showTab: function(container, tabFrom, tabTo)
		{
			if (container.options.animate)
				{
					tabFrom.panel.slideUp(function(){
						tabTo.panel.slideDown();
					});
				}
				else 
				{
					tabFrom.panel.hide();
					tabTo.panel.show();
				}
			
			return tabTo;		
		},
		rotate: function(delay)
		{
			
		},
		defaults: 
		{
			wrap: true, // dodaje wrapper na zawartość zakładki
			animate: false, //animuje zanikanie zakładek
			hoverSwitch: false, // powoduje pojawienie się zakładki po najechaniu kursora na anchor - znika po zjechaniu
			activeList: false, // wywołuje akcję hover i zmianę panelu uzywajac znacznika li
			activeAnchor: true, // wywołuje akcję hover i zmianę panelu używając znacznika a
			
			click: true, // zmiana panelu po kliknięciu
			
			rotate: false, // uruchamia rotator - nie zaimplementowane
			rotateDelay: 2000 // czas przełaczenia rotatora j.w.
			
		}
		
	}
	
})(jQuery);




