if(typeof($) != 'undefined')
{
    $(document).ready(function(){
        
        //don't put code in here, call functions!
    	setupPanelPortraits();
        setupExternals();
        searchTermValue();
        setupSelectDropdown();
        fixMainNavInOpera();
        bannerFades();
        gallerySetup();
        entChallegeLoginFieldLabels();
    }); 
    
    function setupPanelPortraits()
    {
    	$('.panelMemberBio').hide();
    	$('.backToTopLink').remove();
    	
    	$('#panelPortraits a').click(function(e){
    		
    		e.preventDefault();
    		$('#panelPortraits a').attr('class', '');
    		$('.panelMemberBio').hide();

    		var anchor = $(this);
    		var anchorHash = anchor.attr('href');
    		
    		$(anchorHash).show();
    		anchor.attr('class', 'currentPortrait');
    	});
    }
    
    function entChallegeLoginFieldLabels()
    {
    	if($('.entChallengeForm').length > 0)
    	{
    		$('.entChallengeForm #email').attr('value', 'Email address');
    		$('.entChallengeForm #token').attr('value', 'Enter your token');
    		
    		$('.entChallengeForm #email').focus(function(){
    			
    			if($(this).attr('value') == 'Email address')
    				$(this).attr('value','');
    			
    		});
    		$('.entChallengeForm #token').focus(function(){
    			
    			if($(this).attr('value') == 'Enter your token')
    				$(this).attr('value','');
    			
    		});
    		$('.entChallengeForm #email').blur(function(){
    			
    			if($(this).attr('value') == '')
    				$(this).attr('value','Email address');
    			
    		});
    		$('.entChallengeForm #token').blur(function(){
    			
    			if($(this).attr('value') == '')
    				$(this).attr('value','Enter your token');
    			
    		});
    	}
    }
    
    //put jquery functions here
    function setupExternals()
    {
        $('a.external').attr('target','_blank');
    }  
    
    function searchTermValue()
    {
        if($('#searchTerm'))
        {
            if($('#searchTerm').attr('value') == '')
            {
                $('#searchTerm').attr('value','Search');  
            }
            
            $('#searchTerm').click(function(){
                
                if($(this).attr('value') == 'Search')
                {
                    $(this).attr('value','');
                }
            });
            
            $('#searchTerm').blur(function(){
                
                if($(this).attr('value') == '')
                {
                    $(this).attr('value','Search');
                }
            });
        }
    }
    
    function setupSelectDropdown()
    {
        if($('.selectForm'))
        {
            $('.selectButton').hide();
            $('#selectSelect').change(function(){
                
                $('.selectForm').submit();
            });    
        }
    }
    
    function fixMainNavInOpera()
    {
        if(window.opera)
        {
            $('.navbar li.first.current').css('margin-left','0');
        }
    }
    
    function bannerFades()
    {
        if($('.slideshowBanner').length != 0 && $('.bannerPane').length != 0 && $('.bannerSlideshowNav').length != 0)
        {
            $('.mainBanner').cycle({ 
                fx:     'fade', //use the fade effect
                speed:  1000, //transition in 1 sec
                timeout: 15000, //transition after 6 secs - 0 to not auto start
                slideExpr: '.bannerPane', //only use images with a class bannerBackground for the slideshow
                pager: '.bannerSlideshowNav', //use this element to contain the page links
                cleartype: 0,
                pagerEvent: 'mouseover',
                pauseOnPagerHover: true,
                pagerAnchorBuilder: function (idx, slide) {
                    return '<li class="bannerSlideShowNav' + (idx + 1) + ' homeBannerSlideshowNav' + (idx + 1) + ' pngfix"></li>';
                }
            });

        }
    }
    
    function gallerySetup()
    {
    	$('#photos').galleryView({
    		panel_width: 630,
    		panel_height: 300,
    		frame_width: 100,
    		frame_height: 75,
    		filmstrip_size: 3,
    		overlay_height: 70,
    		overlay_font_size: '1em',
    		transition_speed: 1000,
    		transition_interval: 5000,
    		overlay_opacity: 0.6,
    		overlay_color: 'black',
    		background_color: '#592E6F',
    		overlay_text_color: 'white',
    		caption_text_color: 'white',
    		border: '1px solid #592E6F',
    		nav_theme: 'light',
    		easing: 'swing',
    		filmstrip_position: 'bottom',
    		overlay_position: 'bottom',
    		show_captions: false,
    		fade_panels: true,
    		pause_on_hover: false
    	});
    	/*$('#photos').galleryView({
			panel_width: 630,
			panel_height: 300,
			frame_width: 100,
			frame_height: 75,
			overlay_color: '#222',
			overlay_text_color: 'white',
			caption_text_color: '#222',
			background_color: 'transparent',
			border: 'none',
			nav_theme: 'light',
			easing: 'easeInOutQuad',
			pause_on_hover: true
		});*/
    }

}


