jQuery(document).ready(function() {
	// hides the slickbox as soon as the DOM is ready
	jQuery('#overlayclosed').show();
	jQuery('#overlayopen').hide();
	jQuery('#slideshowoverlayopen').hide();
	
	var alt = $('.largeslideshow IMG.active').attr('alt');
	$('#slideshowtitle').find('h3').text(alt);
  
	jQuery('.largeimg').hover(function() {
		$("#overlayopen").fadeIn("slow");
		$('#overlayclosed').fadeOut("slow");
	}, function() {
		$("#overlayopen").fadeOut("slow");
		$('#overlayclosed').fadeIn("slow");
	});
	
	jQuery('.largeslideshow').hover(function() {
		$("#slideshowoverlayopen").fadeIn("slow");
	}, function() {
		$("#slideshowoverlayopen").fadeOut("slow");
	});
	
	jQuery("#s").each(function(){

		this.value = $(this).attr('title');

		$(this).focus(function(){
			if(this.value == $(this).attr('title')) {
				this.value = '';
			}
		});

		$(this).blur(function(){
			if(this.value == '') {
				this.value = $(this).attr('title');
			}
		});
	});
	
	
			$('.portfolioinfo ul li').hover( 
				function() { 
					$(this).find('a').append('<div class="portfolioborder"></div>');
					$('.portfolioborder', this).hide().fadeIn('slow');
				}, 
				function() {
					$('.portfolioborder', this).fadeOut('slow', function() {
						$(this).remove();
					});
				}
			);
			
			$('.flickr ul li').hover( 
				function() { 
					$(this).find('a').prepend('<div class="flickrborder"></div>');
					$('.flickrborder', this).hide().fadeIn('slow');
				}, 
				function() {
					$('.flickrborder', this).fadeOut('slow', function() {
						$(this).remove();
					});
				}
			);
			
			
			$('#slideshownext').click(function() {
				var $active = $('.largeslideshow IMG.active');
				
				if ( $active.length == 0 ) $active = $('.largeslideshow IMG:last');

				var $next = $active.next().length ? $active.next()
				: $('.largeslideshow IMG:first');

				$active.addClass('last-active');

				$next.css({opacity: 0.0})
					.addClass('active')
					.animate({opacity: 1.0}, 1000, function() {
						$active.removeClass('active last-active');  
						var alt = $next.attr('alt');
						$('#slideshowtitle').find('h3').text(alt);       
					});

				//cancel the link behavior            
				return false;   
			});
			
			$('#slideshowprev').click(function() {
				var $active = $('.largeslideshow IMG.active');
				
				if ( $active.length == 0 ) $active = $('.largeslideshow IMG:first');

				var $prev = $active.prev().length ? $active.prev()
				: $('.largeslideshow IMG:last');

				$active.addClass('last-active');

				$prev.css({opacity: 0.0})
					.addClass('active')
					.animate({opacity: 1.0}, 1000, function() {
						$active.removeClass('active last-active');  
						var alt = $prev.attr('alt');
						$('#slideshowtitle').find('h3').text(alt);       
					});

				//cancel the link behavior            
				return false;   
			});
			
	$(function() {
	    setInterval( "slideSwitch()", 5000 );
	});

});

function slideSwitch() {
    var $active = $('.largeslideshow IMG.active');

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

    var $next =  $active.next().length ? $active.next()
        : $('.largeslideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');  
            var alt = $next.attr('alt');
    		$('#slideshowtitle').find('h3').text(alt);       
        });
}