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);
	//Load the slideshow
	theRotator();
	$j('div.rotator').fadeIn(1000);
	    $j('div.rotator ul li').fadeIn(1000); // tweek for IE

	$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('#partners2').fadeOut(1000);
//	} else {
//		$j('#partners2').fadeIn(1000);
//	}
        if($j('#partners1').is(":visible")){
                $j('#partners1').hide();
		$j('#partners2').fadeIn(1000);
        } else if($j('#partners2').is(":visible")) {
                $j('#partners2').hide();
		$j('#partners1').fadeIn(1000);
        } else {
                $j('#partners2').fadeIn(1000);
	}

	
	setTimeout(fadePartners, 6500);
}

function theRotator() {
	//Set the opacity of all images to 0
	$j('div.rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$j('div.rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	
	setInterval('rotate()',6000);
	
}

function rotate() {	
	//Get the first image
	var current = ($j('div.rotator ul li.show')?  $j('div.rotator ul li.show') : $j('div.rotator ul li:first'));

    if ( current.length == 0 ) current = $j('div.rotator ul li:first');

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $j('div.rotator ul li:first') :current.next()) : $j('div.rotator ul li:first'));
	
	//Un-comment the 3 lines below to get the images in random order
	
	//var sibs = current.siblings();
        //var rndNum = Math.floor(Math.random() * sibs.length );
        //var next = $( sibs[ rndNum ] );
			

	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};

