(function($){ 
	var t = 1;
	function changeBanner(aTimes)
	{
		var tabs = aTimes.Lenght - 1;
		t = ++t <= tabs ? t : 1;

		$.post('sleep.php', {'milliSeconds': aTimes[t]}, function(sOdp){
			if(sOdp == 'done')
			{
				$('#adv1 div.list_tabs').idTabs({'next': t});
				t++
			}
		});

	}

	$.fn.idTabs = function(){ 

		var s = { "start":null, "return":false, "click":null, "next": null }; 

		for(var i=0; i<arguments.length; ++i) 
		{ 
			var n = {}, a=arguments[i]; 

			switch(typeof a)
			{ 
				case "object": $.extend(n,a); break; 
				case "number": n["next"] = a; break; 
				case "string": n.start = a; break; 
				case "boolean": n["return"] = a; break; 
				case "function": n.click = a; break; 
			}; 
			
			$.extend(s,n); 
		} 

		var self = this;
		
		$("a", this).click(function(){
			var sLinkDoStrony = $(this).attr('href');
			if(sLinkDoStrony != 'javascript:void(null)')
				window.location = sLinkDoStrony;
		});

		var aTimes = [];
		var aTabs = [];
      var aList = []; //save tabs 
  	   var idList = []; //save possible elements 
		
		var list = $("a", this).click(function(){ 

			var sId = $(this).attr('id');
			var aSplitTmp = $(this).attr('id').split('_');
			
	      $("a", self).each(function(){ 
				var aSplit = $(this).attr('id').split('_');
				aList[aList.length]  = this; 
				aTabs[idList.length] = "#tab_"+aSplit[1]; 
				idList[idList.length] = "#t_"+aSplit[1]; 
				aTimes[idList.length] = $(this).attr('rel');
      	}); 
			
	      if(s.click && !s.click(sId,idList,self))
				return s["return"]; 
				
	      //Clear tabs, and hide all 
   	   for(i in aList)
				$(aList[i]).removeClass("Selected");
			
	      for(i in idList) 
			{
				if(typeof idList[i] == "string")
			 		$(idList[i]).hide(); 
			}
				
	      //Select clicked tab and show content 
   	   $(this).addClass("Selected"); 
			$('#t_'+aSplitTmp[1]).show(); 
			
			// changeBanner(aTimes[aSplitTmp[1]]);
			
	      return s["return"]; //Option for changing url 
		}); 

		tabs = aTabs.Lenght - 1;
		t = s["next"];
		t = ++t <= tabs ? t : 1;
		
		$('#adv1 div.list_tabs').idTabs.zaznacz({'next': t});
		
		s["next"] = t++;

		return this;
	}; 
	
	$.fn.idTabs.zaznacz = function(){
		var s = { "next": 1 }; 

		for(var i=0; i<arguments.length; ++i) 
		{ 
			var n = {}, a=arguments[i]; 

			switch(typeof a)
			{ 
				case "object": $.extend(n,a); break; 
				case "number": n["next"] = a; break; 
				case "string": n.start = a; break; 
				case "boolean": n["return"] = a; break; 
				case "function": n.click = a; break; 
			}; 
			
			$.extend(s,n); 
		} 
		
		if(typeof s.start == "number" && (test=list.filter(":eq("+s["next"]+")")).length) 
			test.click(); //Select num tab 
		else if(typeof s["next"] == "string" && (test=list.filter("[@id='"+s["next"]+"']")).length) 
			test.click(); //Select tab linking to id 
		else if((test=list.filter(".selected")).length) 
			test.removeClass("selected").click(); //Select tab with class 'selected' 
		else
			list.filter(":first").click(); //Select first tab 
	}
})(jQuery)




