
var t;
var inscroll;
inscroll = false

function slide(source){
	if(!inscroll){
		inscroll = true;
		if (source != "auto" && source != "mouse"){
			$("#main_cluster_scroll").animate({"left": -(source * move_amount) + "px"}, "slow",  function() {
				inscroll = false;
			});
		}else{
			var move = "-=" + move_amount + "px";
			if ($("#main_cluster_scroll").css("left") == (-(slide_count * move_amount) + "px")) 
					$("#main_cluster_scroll").css("left", "0px");
				$("#main_cluster_scroll").animate({"left": move}, "slow",  function() {
				inscroll = false;});
		}
		move_slider();
		if(source == "auto"){
			t=setTimeout('slide("auto")', time);
		}
		
	}
}

function reverse_slide(source){
	if(!inscroll){
		inscroll = true;
		move =  "+=" + move_amount + "px";
		if ($("#main_cluster_scroll").css("left") == "0px") 
			move = -(slide_count * move_amount) + "px" ;
		$("#main_cluster_scroll").animate({"left": move}, "slow",  function() {
		inscroll = false;});
		move_slider();
		if(source == "auto"){
			t=setTimeout('slide("auto")', time);
		}
	}
}

function init() {
	$(".cluster_control_right").attr("onclick", "call_slide('right');");
	$(".cluster_control_left").attr("onclick", "call_slide('left');");
	$("#home_main_cluster").bind("mouseenter", function(event){
		but_show();
	});
	$("#home_main_cluster").bind("mouseleave", function(event){
		but_hide();
	});
//$("#home_main_cluster div").attr("onmouseover", "but_show();");
//$("#home_main_cluster div").attr("onmouseout", "but_hide();");
	$( "#main_cluster_control_a" ).slider({
		min: 0,
		max: slide_count - 1,
		step: 1,
		slide: function( event, ui ) {
			slide( ui.value );
		},
		start: function(event, ui) { 
			clearTimeout(t);
		},
		stop: function(event, ui) { 
			t=setTimeout('slide("auto")', time);
		}
	});

	t=setTimeout('slide("auto")', time);
}

function but_show(){
	clearTimeout(t);
	$(".cluster_control_right, .cluster_control_left").fadeIn("fast");
}

function but_hide(){
	t=setTimeout('slide("auto")', time);
	$(".cluster_control_right, .cluster_control_left").fadeOut("fast");
}

function call_slide(dirc){
	if (!inscroll){
		if(dirc == "right"){
			slide("mouse");
		}else{
			reverse_slide("mouse");
		}
	}
}

function move_slider(){
num = $("#main_cluster_scroll").css("left").replace(/[^-\d\.]/g, '');
num -= (num*2);
counter = (num / move_amount)+1;
counter = (counter == 5?0:counter);
$( "#main_cluster_control_a" ).slider( "value", counter );
}

