var $rotateoptions = new Array();
$rotateoptions[2] = new Array();
$rotateoptions[2]["style"] = "fhm-tabs";
$rotateoptions[2]["rotate"] = 0;
$rotateoptions[2]["random_start"] = 0;
$rotateoptions[2]["start_tab"] = 0;
$rotateoptions[2]["interval"] = 10000;
$rotateoptions[3] = new Array();
$rotateoptions[3]["style"] = "fhm-tabs";
$rotateoptions[3]["rotate"] = 0;
$rotateoptions[3]["random_start"] = 0;
$rotateoptions[3]["start_tab"] = 0;
$rotateoptions[3]["interval"] = 10000;


$tw = jQuery.noConflict();

$tw(document).ready(function() {

	$tw('.fhm-tabbed-widget').each(function() {
		var $widgetid = $tw(this).attr("id"); // fhm-tabbed-widget-1
		$widgetid = $widgetid.split("-", 4)[3];

		
		var $widgetstyle = $rotateoptions[$widgetid]["style"];
		var $do_rotate = $rotateoptions[$widgetid]["rotate"];
		var $rotate_interval = $rotateoptions[$widgetid]["interval"];
		var $random_start = $rotateoptions[$widgetid]["random_start"];
		var $start_tab = $rotateoptions[$widgetid]["start_tab"];
		
		if ($widgetstyle == 'fhm-tabs') {
			var $tab_count = 0;
			
			// Build  tab navigation
			var $tabbed_nav = '<ul class="tw-tabbed-nav">';
			$tw('.tw-title', this).each(function(i) {
				$tabbed_nav += '<li><a href="#tw-content-'+ $widgetid +'-'+ i +'">' + $tw(this).text() + '</a></li>';
				$tab_count++;
			}).hide();
			$tabbed_nav += '</ul>';
			
			$tw('.tw-tabs', this).prepend($tabbed_nav);
			
			var $options = { cookie: { expires: 30 } };
			
			if ($random_start)
				$start_tab = Math.floor($tab_count * Math.random());
			
			jQuery.extend($options, { active: $start_tab });
			
			//console.log($options);
			//console.log($rotate_interval);
			
			if ($do_rotate)
				$tw('.tw-tabs', this).tabs($options).tabs('rotate', $rotate_interval);
			else
				$tw('.tw-tabs', this).tabs($options);
			
		}		
	});	
	
});