
/* initialize slide for intro slideshow */
$(function() {

	var introCookie = $.cookie("introplayed");
    
    if(introCookie == 'true'){
    	removeIntro();
    	callNivo();
    } else {
    	callIntro();
    }
});

function callIntro(){
	$.cookie("introplayed", "true");
	
	$('#intro-slider').nivoSlider({
    	effect:'fade',
    	directionNav:false,
    	controlNav:false,
    	animSpeed:500,
        pauseTime:3500,
        pauseOnHover:false,
        startSlide:0,
        lastSlide: fadeIntro
    });
}

function fadeIntro(){
	$('#intro-slider').data('nivo:vars').stop = true;
	$('#intro').fadeOut('slow',removeIntro);
	callNivo();
}

function removeIntro(){
	$('#intro').remove();
}

/* initialize slide for homepage slideshow */
function callNivo(){
	$('#slider').nivoSlider({
    	effect:'fade',
    	directionNav:false,
    	controlNav:false,
    	animSpeed:500,
        pauseTime:5000,
        pauseOnHover:true
    });    
};

/* initialize shadowbox for linthicum living page (lots) */
Shadowbox.init({
	overlayOpacity: .90
});

/* control li display elements */
$('.publications ul li:nth-child(3n)').addClass('centerpad')
$('.contact-us #company-info dl dd:nth-child(3n)').addClass('adjust');


/* gallery functionality */
var selectedID = 'club-at-kukuiula';
//var selectedID = 'club-at-kukuiula';
//var gallToLoad = '/gallery/galleries.php #' + selectedID;

// add on click events to gallery list
$('#gallery-nav dl dd a').click(function(){
	
	selectedID = $(this).attr('href');
	//var gallToLoad = '/gallery/galleries.php #' + selectedID;	
	$('#gallery-loader div').fadeOut('slow',loadContent);
	
	$('#gallery-loader').removeClass('spinner');
	
	return false;
	
});

function loadContent() 
{
	$('#gallery-loader').load('/gallery/galleries.php #' + selectedID).hide().fadeIn('slow',showNewContent());
	$('#gallery-loader').addClass('spinner');	
}
loadContent();


function showNewContent() 
{
	$('#gallery-loader').hide().fadeIn('slow', function(){
			
//		$('#' + selectedID + ' p').addClass('spinner');		
			
		$('#image-nav a').click(function()
		{
			$('#image-nav a').removeClass('active');
			$(this).addClass('active');
		
			var _url = '/images/gallery/' + selectedID + '/' + selectedID + '-' + $(this).text() + '.jpg';
					
      var img = new Image();
      
      $(img).load(function(){
        $(img).hide();
        $('#'+selectedID+' #gallery-img').append(img);
        $(img).fadeIn('slow');
      }).attr({
          src: _url,
          width: '800',
          height: '484'
        });
	
			$("#gallery-img img:lt(1)").each(
				function removePreviousImage()
				{
					$(this).fadeOut(500, function() { $(this).remove(); });
				}
			)
			
			return false;
		});      		    		
	});	
}

