/*
* Класс работы с вкладками.
* Урушев Владимир (c) ООО "Магия золота", 2009-2010
* urushev@yandex.ru
* Последняя модификация: 2010-11-01
*
* 2010-11-01
*   убрана анимация открытия вкладки
*   теперь активной вкладке добавляется класс 'active'
* 2011-04-16
*   
*/

jQuery.fn.tabManager = function(options) {
	var container = $("<div class='tabs t_" + options.align + "'></div>");


	this.hide();
	

	var thall=this;
	var first = (options.active ? 0: 1);
	
	$("#" + options.container).html('');
	
	if (options.stepByStep){
		/*активировать вкладку*/
		
	}
	
	
	this.each(function(){
		var oTab_main =$("<div class='" + (options.tabstyle ? options.tabstyle : "style1") + "'></div>"); /*first?*/
		
		var oTab = $("<div" + ($(this).attr('click1') ? ' click1="' + $(this).attr('click1') + '"' : "") + ($(this).attr('ga_click') ? " ga_click='" + $(this).attr('ga_click') + "'" : "") + " class='" + (first || this.id == options.active ? "active" : "inactive") + "'></div>");
		
		if (first || this.id == options.active){
			$("#"+  this.id  ).show().addClass('active');
			oTab.css("margin-top", 1);
		}
		

		first = 0;

		oTab.append("<div class='start'></div>");
		oTab.append("<div class='caption' id='opendivid" + this.id + "'>" + $(this).attr('tabname') + "</div>");
		oTab.append("<div class='end'></div>");
		
		oTab_main.append(oTab);
		container.append(oTab_main);
		
		if (! options.stepByStep){
			oTab.click(function(){
	  			thall.hide().removeClass('active');
	  			container.inactiveAll();
	  			
	  			
	  			$(this).removeClass('inactive');
				$(this).addClass('active');
				$(this).css("margin-top", 1);

	  			$("#"+  $("div.caption", this)[0].id.split('opendivid')[1]  ).show().addClass('active');//.animate({height: "show"}, 300);
	  			
	  			try{
                    var ga_click = $(this).attr('ga_click');
	  			
                    if (ga_click)
 				       pageTracker._trackEvent(ga_click, 'Click');
                }catch(e){}
                
                if ($(this).attr('click1'))
                    eval($(this).attr('click1'));
	  		});
		}
		
		

	
		
	});
	


	container.inactiveAll = function(){
		$("div.active", this).addClass('inactive');
		$("div.inactive", this).removeClass('active');
		$("div.inactive", this).css("margin-top", 0);
		
	};
		
	container.appendTo($("#" + options.container));

	return this;
};
