// SLIDESHOW FUNCTION:
function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');
	    $active.addClass('last-active');

	var $sibs  = $active.siblings();
	var rndNum = Math.floor(Math.random() * $sibs.length );
	var $next  = $( $sibs[ rndNum ] );

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 4000 );
});

// DISPLAY FUCNTIONS:

// Edit the height of container to always go to the absolute bottom of the page:
$(document).ready(function(){
	resizeContainer();
	
	$('#menulist').mouseenter(function(){
		$('#submenu').slideDown('fast');
	});
	
	$('#menu').mouseleave(function(){
		$('#submenu').slideUp('fast');
	})
	
	
	$('.next').click(function(){
		var id = $(this).attr('id').substring(2);
		$('#gal_'+id).stop().animate({'marginLeft':'-=54'},50);
	})
	
	$('.prev').click(function(){
		var id = $(this).attr('id').substring(2);
		$('#gal_'+id).stop().animate({'marginLeft':'+=54'},50);
	})
	
});

$(window).resize(function(){
	resizeContainer();
})


function resizeContainer(){
	var headerConstant = 173;
	var rightHeight = $('#right').height();
	
	if(rightHeight + headerConstant > $(window).height()){
		var newHeight = rightHeight + headerConstant +'px';
		$('#container').css('height', newHeight);
	}else{
		$('#container').css('height', '100%');
	}	
}
