$(document).ready(function () {
    $('#EnquiryForm').submit(function () {
        var _parameters = $(this).serialize();
        var _this = this;

        // Remove default values
        _parameters = _parameters.replace('tbxName=Your+Name&', '');
        _parameters = _parameters.replace('tbxEmail=Your+Email+Address&', '');
        _parameters = _parameters.replace('tbxPhone=Your+Telephone&', '');
        _parameters = _parameters.replace('tbxDetails=Details+of+Work&', '');
        _parameters += '&ajax=1';

        $.ajax({
            type: 'POST',
            url: _this.action,
            data: _parameters,
            dataType: 'json',
            success: function (_data) {
                if (_data.ok == 1) {
                    $(_this).hide();
                    $('.error_content', $(_this).closest('div')).fadeOut(0).html('<div class="info-notice border-radius-4">' + _data.response + '</div>').fadeIn('slow');
                }
                else {
                    $('.error_content', $(_this).closest('div')).fadeOut(0).html('<div class="info-error border-radius-4">' + _data.response + '</div>').fadeIn('slow');
                }
            }
        });
        return false;
    });
	
	if ($("#gallery").length > 0 )
	{
		// Gallery Stuff
		$('div.navigation').css({'width' : '300px', 'float' : 'left'});
		$('div.content').css('display', 'block');
	
		// Initially set opacity on thumbs and add
		// additional styling for hover effect on thumbs
		var onMouseOutOpacity = 0.67;
		$('#thumbs ul.thumbs li').opacityrollover({
			mouseOutOpacity:   onMouseOutOpacity,
			mouseOverOpacity:  1.0,
			fadeSpeed:         'fast',
			exemptionSelector: '.selected'
		});
		
		// Initialize Advanced Galleriffic Gallery
		var gallery = $('#thumbs').galleriffic({
			delay:                     4500,
			numThumbs:                 15,
			preloadAhead:              10,
			enableTopPager:            true,
			enableBottomPager:         false,
			maxPagesToShow:            4,
			imageContainerSel:         '#slideshow',
			controlsContainerSel:      '#controls',
			captionContainerSel:       '#caption',
			loadingContainerSel:       '#loading',
			renderSSControls:          true,
			renderNavControls:         true,
			playLinkText:              'Play Slideshow',
			pauseLinkText:             'Pause Slideshow',
			prevLinkText:              'Previous Photo',
			nextLinkText:              'Next Photo',
			nextPageLinkText:          'Next',
			prevPageLinkText:          'Prev',
			enableHistory:             false,
			autoStart:                 false,
			syncTransitions:           true,
			defaultTransitionDuration: 900,
			onSlideChange:             function(prevIndex, nextIndex) {
				// 'this' refers to the gallery, which is an extension of $('#thumbs')
				this.find('ul.thumbs').children()
					.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
					.eq(nextIndex).fadeTo('fast', 1.0);
			},
			onPageTransitionOut:       function(callback) {
				this.fadeTo('fast', 0.0, callback);
			},
			onPageTransitionIn:        function() {
				this.fadeTo('fast', 1.0);
			}
		});
	}
	
});
