var c;
var i = 0;
var timeout = false;
var delay = 3000;

function show( wid, id ) {
   //  if ( t ) clearTimeout( t );
	setTimeout( _show(wid,id), 1000 );
}

function _show(wid, id) {
	$( "#"+wid+" .tabs ul li a").css('background-color','#eee');
	$( "#"+wid+" .tabs ul li a").css('border','1px solid #ccc');
	// $( "#"+wid+" .tabs ul li a").css('border-bottom','1px solid #c96');
	
	$( "#tab-"+id+" a" ).css('background-color','#fff');
	$( "#tab-"+id+" a" ).css('border-bottom','2px solid #fff');
	$( "#tab-"+id+" a" ).css('border-top','2px solid #f00');
	
	$( "#"+wid+" .xoxo .widget-container" ).hide();
	$( "#"+id ).show();
}


function next() {
	p = i;
	i++;
	if ( i==c ) i=0;
	n = i;
	resetTimer();
	$(".sticky").each( function(index) {
		if ( index==p ) {
			$(this).hide();
		}
		if ( index==n ) {
			$(this).fadeToggle('slow');
		}
		
	});
}

function prev() {
	p = i;
	i--;
	if ( i<0 ) i=c-1;
	n = i;
	resetTimer();
	$(".sticky").each( function(index) {
		if ( index==p ) {
			$(this).hide();
		}
		if ( index==n ) {
			$(this).fadeToggle('slow');
		}
		
	});
}

function pause() {
	resetTimer();
	$('#slider').children().css('display','inline');
	$('.pause').css('display','none');
}

function resetTimer(){
	if (timeout)
		clearTimeout(timeout);    
	$('#slide').html( i+1 );
}

function play() {
	resetTimer();
	$('#slider').children('a').css('display','none');
	$('.pause').css('display','inline');
	timeout = setTimeout(slide, delay);
}

function slide() {
	next();
	play();
}

jQuery(document).ready(function($){
	c = $('.sticky:last').index() +1;
	$("#slideshow").css("border","1px solid #ccc");
	$(".sticky").css("display","none");
	$(".sticky").css("border","0");
	$(".sticky:first").show();
	$("#slider").css("display","inline");	
	play();
});

