/**
 * Cadence At The Lakes JavaScript
 * @author Guillaume VanderEst <gvanderest@netshiftmedia.com>
 */

$(document).ready(function(){

    // register link
    $("#menu a").each(function(){

        if ($(this).html() == 'Register') { $(this).attr('target', '_blank'); }    
        if ($(this).html() == 'Visit Our Blog') { $(this).attr('target', '_blank'); }    
    });
	
    if ($('.gallery').length > 0)
    {
        $('.gallery').each(function ()
        {
            $this = $(this);
            $selectedContainer = $this.find('.selectedImage');
            $selectedImage = $selectedContainer.find('img');
            $thumbSectionnav = $this.find('.thumbSectionNav');
            $thumbSections = $this.find('.thumbSections');
            
            $this.find('.thumbSection a').click(function (e)
            {
                e.preventDefault();
                $this.find('.thumbSection a.active').removeClass('active');
                $(this).addClass('active');
                $selectedContainer.find('a.mediumImage').hide();
                $selectedContainer.find('a.image' + $(this).attr('imageid')).css('display','block').css('opacity',.1).animate({opacity: 1},200);
            });
            
            $thumbSectionnav.find('a').click(function ()
            {
                if($(this).is('.active'))
                {
                    return false;
                }
                
                $thumbSectionnav.find('a.active').removeClass('active');
                $(this).addClass('active');
                $thumbSections.find('ul').fadeOut("fast");
                $thumbSections.find('ul.page' + $(this).attr('page')).fadeIn("fast");
            });
            
            $thumbSectionnav.find('a[page=0]').trigger('click');
            $thumbSections.find('ul:first-child li:first-child a').trigger('click');
        });
    }
});

