
	$(function() {
				
		var onMouseOutOpacity = 0.5;
		$('#thumbs ul.thumbs li').opacityrollover({
			mouseOutOpacity:   onMouseOutOpacity,
			mouseOverOpacity:  1.0,
			fadeSpeed:         'fast',
			exemptionSelector: '.selected'
		});
		
		var gallery = $('#thumbs').galleriffic({
			delay:                     2500,
			numThumbs:                 5,
			preloadAhead:              -1,
			enableTopPager:            true,
			enableBottomPager:         true,
			maxPagesToShow:            100,
			imageContainerSel:         '#slideshow',
			controlsContainerSel:      '#controls',
			captionContainerSel:       '#caption',
			renderSSControls:          false,
			renderNavControls:         true,
			nextPageLinkText:          'N',
			prevPageLinkText:          'P',
			enableKeyboardNavigation:  false,
			enableHistory:             false,
			autoStart:                 false,
			syncTransitions:           true,
			defaultTransitionDuration: 900,
			onSlideChange:             function(prevIndex,nextIndex) {
				this.find('ul.thumbs').children().eq(prevIndex).fadeTo('fast',onMouseOutOpacity).end().eq(nextIndex).fadeTo('fast', 1.0);
				makeGallerificBehave();
			},
			onPageTransitionOut:       function(callback) {
				this.fadeTo('fast',0.0,callback);
				makeGallerificBehave();
			},
			onPageTransitionIn:        function() {
				this.fadeTo('fast',1.0);
				makeGallerificBehave();
			}
		});

		makeGallerificBehave();
		
		$('#testimonials').codaSlider({dynamicArrows: false, dynamicTabs: false});
		
		$('#get_in_touch form').ajaxForm({ target: '#alert' }); 
			
	});
	
	function makeGallerificBehave() {
		$('#thumbs .top a[title!=P]').remove();
		if($('#thumbs .top a').length == 0) $('#thumbs .top').html('<a class="disabled"></a>');
		$('#thumbs .bottom a[title!=N]').remove();
		if($('#thumbs .bottom a').length == 0) $('#thumbs .bottom').html('<a class="disabled"></a>');
	}
	
	$.fn.clearForm = function() {
  		return this.each(function() {
			var type = this.type, tag = this.tagName.toLowerCase();
			if (tag == 'form') return $(':input',this).clearForm();
			if (type == 'text' || type == 'password' || tag == 'textarea') this.value = '';
			else if (type == 'checkbox' || type == 'radio') this.checked = false;
			else if (tag == 'select') this.selectedIndex = -1;
  		});
	};
