// functions

function slideSwitch() {
	var $divs = $('#slideshow div');
	if ($divs.length > 1) {
		var $active = $('#slideshow div.active');
		if ( $active.length == 0 ) $active = $('#slideshow div:last');
		var $next =  $active.next().length ? $active.next() : $('#slideshow div:first');
		$active.addClass('last-active');
		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {
				$active.removeClass('active last-active');
			});
	}
}

function scrollDiv(x) {
	$(".scrollable").scrollTop($(".scrollable").scrollTop() + x);
}

function quote_rotate() {
	current_quote = (old_quote + 1) % quote_count; 
	$("div.quote:eq(" + old_quote + ")")
		.animate({top: -110},"slow", function() {
	  		$(this).css('top', '110px');
		});
	$("div.quote:eq(" + current_quote + ")")
		.animate({top: 5},"slow");  
	old_quote = current_quote;
}


// slideshow tracker variable
var rep;

// quotes scroller vars
var quote_count;
var quote_interval;
var old_quote = 0;
var current_quote = 0;



// startup
$(function()
{
//main menu
	$("#mainmenu li A").mouseover(function () { $(this).effect("bounce", { times: 3 }, 300); });

// family pictures
	$("#family li a").mouseover(function()
        {
	        var content = $(this).children("div").html();
			var original = $("#family_text").html();
      		$("#family_text").html(content);
			$("#spare").html(original);
			
			var src = $(this).children("img").attr("src");
			var newsrc = $(this).attr("href");

			$(this).children("img").attr("src",newsrc);
			$("#spareimg").attr("src",src);
		});

    $("#family li a").mouseout(function()
        {
	        var content = $("#spare").html();
      		$("#family_text").html(content);

			var src = $("#spareimg").attr("src");
			$(this).children("img").attr("src",src);
	});
	
	$("#family li a").click(function()
		{
			return false;
		});
	
// scrollable

	$(".scrollable")
			.css("overflow", "hidden")
			.after("<div style='text-align: center'><img class='scrolldown' src='images/down.gif' alt='Scroll down' border='0' /> <img class='scrollup' src='images/up.gif' alt='Scroll up' border='0' /></div>");

	$(".scrolldown").mouseover(function()
		{
			rep = setInterval("scrollDiv(15)", 200);
		});
	$(".scrolldown").mouseout(function()
		{
			clearInterval(rep);
		});

	$(".scrollup").mouseover(function()
		{
			rep = setInterval("scrollDiv(-15)", 200);
		});
	$(".scrollup").mouseout(function()
		{
			clearInterval(rep);
		});


// slideshow
    setInterval( "slideSwitch()", 4000 );
	
	
// quotes
	quote_count = $("div.quote").size();
	$('#quotes').css({position: 'absolute', overflow: 'hidden'})
	$('div.quote')
		.css({position: 'absolute', height: '90px'})
		.not(current_quote)
			.css('top','110px');
  
 	quote_rotate();
	quote_interval = setInterval(quote_rotate,5000); 
});



