/**
 * @author bdgeorge
 * Whitepixels common Javascript routines - requires jQuery
 */

jQuery(document).ready(
function(){
	(function($){
		//List decorator
		$('ul').find('> li:last').addClass('last');
		$('ul').find('> li:first').addClass('first');
		
		//Subscribe box text
		$('.replace-once').focus(function(){
			if (this.value == this.defaultValue) {
				this.value=''; 
			}
		});
		$('.replace-once').blur(function(){
			if($.trim(this.value) == ''){
				this.value = this.defaultValue;
			}
		})

		//Attach Cycle to each gallery classes, then pause them.
		$('ul.gallery').each(function(){
			$(this).cycle({ 
		    fx:      'fade', 
		    speed:    700, 
		    timeout:  3000,
			pager: jQuery('.gallery-pager', jQuery(this).parent()) 
			});
			$(this).cycle('pause');
		});
			
		//If a gallery is visible on load then resume it immediately
		$('ul.gallery:visible').cycle('resume');
		
		//Portfolio Page thumb gallery
		$('.portfolio-thumbs div').click(function(){
			target = $(this).attr('id');
			target = target.replace('thumb-','');
			
			$('#content > div.post').hide();
			//Pause any galleries that may be running
			$('ul.gallery').cycle('pause');
			
			$('#' + target).show();
			//If target has a gallery start it
			$('ul.gallery', '#' + target).cycle('resume');
			
		});		
		
		//Rollover to change opacity on Portfolio thumbs
		$('.portfolio-thumbs div').css('opacity', 0.7);
		$('.portfolio-thumbs div').hover(
			function(){
				$(this).css('opacity', 1);
			},
			function(){
				$(this).css('opacity', 0.7);
			}
			)
			
		$('.gallery-pager').hover(function(){
				$('ul.gallery').cycle('pause');
			},
			function(){
				$('ul.gallery').cycle('resume');
			}
		);
	})(jQuery)
		
});


