var quote_timers = new Array();
var image_cache = new Array();

$(function() {

	$(".hover").hover(function() {
		$(this).attr("src", $(this).attr("src").split(".").join("-hover."));
	}, function() {
		$(this).attr("src", $(this).attr("src").split("-hover.").join("."));
	}); 
		
	$(".hover").each(function(index, value) {
		var image = document.createElement("img");
		image.src = value.getAttribute("src").split(".").join("-hover.");
		image_cache.push(image);
	});	
		
	$(".quotes").hover(function() {
		clearTimeout(quote_timers[$(this).attr("id")]["timer"]);
	}, function() {
		quote_timers[$(this).attr("id")]["timer"] = setInterval("quote_switch(" +  quote_timers[$(this).attr("id")]["index"] + ")", 7000);
	});
  
	$(".quotes").each(function(index, value) {
		quote_timers[value.id] = {"index": index, "timer": setInterval("quote_switch(" +  index + ")", 7000)}
	});
  
});

function quote_switch(index) {
	var id = $('.quotes')[index].id;
	var active = $('#' + id + ' div.active').length ? $('#' + id + ' div.active') : $('#' + id + ' div:last');
	var next = active.next().length ? active.next() : $('#' + id + ' div:first');
	active.addClass('last-active');
	next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 2000, function() {
		//active.removeClass('active last-active');
	});
	active.css({opacity: 1.0}).animate({opacity: 0.0}, 2000, function() {
		active.removeClass('active last-active');
	});
}

function preLoadImages() {	
    var args_len = arguments.length;
    for(var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      image_cache.push(cacheImage);
    }
}
