var product_tabs_cat	= 1;
var product_tabs_prod	= 1;
var persona_box			= 1;
var brandbox_tabs		= 1;

$j = jQuery.noConflict();
$j(document).ready(function(){
	setTimeout(fadePartners, 6500);

	$j("#product-tabs").tabs({
		event: 'mouseover',
		selected: product_tabs_cat
	});

	$j("#pfam-1, #pfam-2, #pfam-3, #pfam-4, #pfam-5").tabs({
		event: 'mouseover'
	});

	$j("#pfam-"+(product_tabs_cat+1)).tabs("select",product_tabs_prod);

	$j(".persona-box").tabs({
		event: 'mouseover',
		selected: persona_box
	});
	
	$j(".brandbox-tabs").tabs({ 
		event: 'click',
		selected: brandbox_tabs,
		fx: {opacity: 'toggle'}
		//rotate: 16000
	});
	$j("div.brandbox-tab-backdrop").css('opacity',0.5); //set opacity of layer behind the tabs to 65%
	
	//Feature Tabs
	$j(".feature-tabs").tabs({ //construct tabs and capture clicks, assign transition effect
		event: 'click',
		fx: {opacity: 'toggle'},
		rotate: 10000
	});
	$j("div.feature-tab-backdrop").css('opacity',0.65); //set opacity of layer behind the tabs to 65%

	//Info-Box tabs
	$j("div.info-box").tabs({ //construct tabs and capture clicks, assign transition effect
		event: 'mouseover'
	});

	$j(".jump-right").click(function() { //handle next button - mouseovers handled with script for ie6
		jump('next');
	}).mouseover(function() {
		$j(this).addClass("jump-over");
	}).mouseout(function() {
		$j(this).removeClass("jump-over"); 
	});
	
	$j(".jump-left").click(function() { //handle previous button - mouseovers handled with script for ie6
		jump('prev');
	}).mouseover(function() {
		$j(this).addClass("jump-over");
	}).mouseout(function() {
		$j(this).removeClass("jump-over"); 
	});
	
	new TWTR.Widget({
	version: 2,
	type: 'profile',
	id: 'twitter_widget',
	rpp: 4,
	interval: 6000,
	width: 400,
	height: 300,
	theme: {
		shell: {
			background: '#ffffff',
			color: '#1a1a1a'
		},
		tweets: {
			background: '#ffffff',
			color: '#050505',
			links: '#66ad3d'
		}
	},
	features: {
		scrollbar: false,
		loop: false,
		live: false,
		hashtags: true,
		timestamp: true,
		avatars: false,
		behavior: 'all'
	}
}).render().setUser('mongoosemetrics').start();
});


function jump(direction){ //next and previous function
	if(document.getElementById('home-branding')) {
		var $jtabs = $j(".brandbox-tabs").tabs();
	} else {				
		var $jtabs = $j(".feature-tabs").tabs();
	}
	t = $jtabs.tabs().data("selected.tabs");	
	tlength = $jtabs.tabs('length');
	if(t == 'undefined'){t = 0}
	if(direction == "next"){
		t = ++t < tlength ? t : 0;	
	} else {
		t = --t > -1 ? t : (tlength - 1);
	}
	$jtabs.tabs('select',t);
}


function fadePartners() {
	if($j('#partners2').is(":visible") && $j('#partners3').is(":hidden")){
		$j('#partners2').fadeOut(1);
		$j('#partners3').fadeIn(1000);
		
	} else if ($j('#partners3').is(":visible") && $j('#partners2').is(":hidden")) {
		$j('#partners3').fadeOut(1000);
	} else {
		$j('#partners2').fadeIn(1000);
	}
	
	setTimeout(fadePartners, 6500);
}