$.fn.mytabs = function(Active, settings) {
	if (typeof Active == 'object') settings = Active;
	var settings = $.extend({
		Active: Active ? Active : 1,
		highlightClass: 'tabs-selected',
		Tabs: '.tabs-nav a',
		extraClass: 'reference'
	}, settings || {});
	var me = $(this);
	var active = settings.Active;
	var tabs = settings.Tabs;
	var nowActive = '.tabActive';
	var date = new Date();
	var cookie = readCookie('activeTab');
    var autoScrollToTab="";
	date.setTime(date.getTime()+(7*60*1000));
	function init() {
		if (window.default_tab !== undefined) {
			active=default_tab;
		} 
		else if (cookie && $(cookie).attr('class') == $(me).attr('class')) {
			active = cookie;
		} else {
			active = (typeof(active) == 'number') ? $(tabs).slice((active - 1), active).attr('href') : active;
		}
		show();
	}
	function show () {
		if (!$(active).size()) {
			active = $(me).slice(0,1).attr('href');
		}
		$(nowActive).hide();
		$(active).show();
		$(active+'_tab').addClass(settings.highlightClass);
		$(nowActive+'_tab').removeClass(settings.highlightClass);
		nowActive = active;
        if (autoScrollToTab!="#undefined" && autoScrollToTab!="") window.location=active;
	}
	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	init();
	$(tabs).click(function () {
		active = $(this).attr('href');
        autoScrollToTab= '#'+$(this).attr('autoScroll');
		show();
		document.cookie = 'activeTab='+active+'; expires='+date.toGMTString()+'; path='+location.pathname;
		return false;
	});
	$('a.'+settings.extraClass).click(function () {
		active = '#'+$(this).attr('rel');
        autoScrollToTab= '#'+$(this).attr('autoScroll');
		show();
		return false;
	});
}