$(document).ready(function() {
	// find the div.fade elements and hook the hover event
	$('.fadeThis').hover(function() {
		// on hovering over find the element we want to fade *up*
		var fade = $('> .hover', this);
 
		// if the element is currently being animated (to fadeOut)...
		if (fade.is(':animated')) {
			// ...stop the current animation, and fade it to 1 from current position
			fade.stop().fadeTo(500, 1);
		} else {
			fade.fadeTo(500, 1);
		}
	}, function () {
		var fade = $('> .hover', this);
		if (fade.is(':animated')) {
			fade.stop().fadeTo(500, 0);
		} else {
			fade.fadeTo(500, 0);
		}
	});
 
	// get rid of the text
	$('.fadeThis > .hover').empty();
});

var sliderbar = 0;
var num = 1;
function slideTimer(){
	num++;
	if (num>3)
		num = 1;
	var margin = (num-1)*(-980);
	$("#img_slide_wrapper").stop();
	$("#img_slide_wrapper").animate({"margin-left": margin+"px"}, "slow");
}

function slideBar(){
	$("#timer").stop();
	$("#timer").css("width","0px");
	$("#timer").animate({"width": "100%"}, 5000, "linear", slideTimer());
}
$(document).ready(function(){
	$("#timer").css("width","0px");
	$("#timer").animate({"width": "100%"}, 5000, "linear");
	sliderbar = setInterval("slideBar()", 5000);
	$("#previews img").hover(
		function(){
			clearInterval(sliderbar);
			$("#timer").stop();
			$("#timer").css("width","0px");
			num = $(this).attr("title");
			margin = (num-1)*(-980);
			$("#img_slide_wrapper").stop();
			$("#img_slide_wrapper").animate({"margin-left": margin+"px"}, "slow");
		},
		function(){
			$("#timer").animate({"width": "100%"}, 5000, "linear");
			sliderbar = setInterval('slideBar()', 5000);
	});
});
