var sliders = new Array();
var controls = new Array();
var count_sliders = 1;
var current_slider = 0;
var doing_timer = 1;

jQuery(document).ready(function(){

	jQuery('.slide').each(function(){
		//jQuery(this).css('display','none');
		sliders[count_sliders]=this;
		jQuery(sliders[count_sliders]).css('display','none');
		count_sliders ++;
	});

	var c =1;
	jQuery('#controllers-main a').each(function(){
		controls[c]=this;
		c++;
	});

//		alert(jQuery('show_'+count_sliders));
//		jQuery('show_'+count_sliders).click(function(){alert('hello');});


	//show_slider(1);

	do_timer(4000);

});


function do_timer(time){
	if(doing_timer){
		if((current_slider+1)<count_sliders){ show_slider(current_slider+1,false); }
		else{ show_slider(1,false);}
		return setTimeout("do_timer("+time+");",time);
	}
	return false;
}

function next_slide(){
	doing_timer=0;	
	return (current_slider+1)<count_sliders? show_slider(current_slider+1,true): show_slider(1,true);
}
function prev_slide(){
	doing_timer=0;	
	return current_slider>1? show_slider(current_slider-1,true): show_slider(count_sliders-1,true);
}

function show_slider(id,stop_timer){
	if(stop_timer)doing_timer=0;
	for(i=1;i<count_sliders;i++){
		if(i != current_slider)
			jQuery(sliders[i]).css('display','none');
		jQuery(sliders[i]).css('z-index','1');
		jQuery(controls[i]).removeClass('active');
	}
	//jQuery(sliders[id]).css('display','');
	jQuery(sliders[id]).css('z-index','2');
	jQuery(sliders[id]).fadeIn(1500);
	current_slider=id;
	return false;
}
