            (function(){
                $.fn.infiniteCarousel = function(options){
                    var config = $.extend({
                        myInterval: 2000,
                        animationSpeed: 500,
                        autoscrolling: true
                    }, options ||
                    {});
                    
                    function repeat(str, n){
                        return new Array(n + 1).join(str);
                    }
                    
                    return this.each(function(){
                        // magic!
                        var $wrapper = $('> div', this).css('overflow', 'hidden'), $slider = $wrapper.find('> ul').width(999999), $items = $slider.find('> li'), $single = $items.filter(':first'), singleWidth = $single.outerWidth(), visible = Math.ceil($wrapper.innerWidth() / singleWidth), currentPage = 1, pages = Math.ceil($items.length / visible);
                        
                        /* TASKS */
                        
                        // 1. pad the pages with empty element if required
                        if ($items.length % visible != 0) {
                            // pad
                            $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
                            $items = $slider.find('> li');
                        }
                        
                        // 2. create the carousel padding on left and right (cloned)
                        $items.filter(':first').before($items.slice(-visible).clone().addClass('cloned'));
                        $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
                        $items = $slider.find('> li');
                        
                        // 3. reset scroll
                        $wrapper.scrollLeft(singleWidth * visible);
                        
                        // 4. paging function
                        function gotoPage(page){
                            return;
                            var dir = page < currentPage ? -1 : 1, n = Math.abs(currentPage - page), left = singleWidth * dir * visible * n;
                            
                            $wrapper.filter(':not(:animated)').animate({
                                scrollLeft: '+=' + left
                            }, config.animationSpeed, function(){
                                // if page == last page - then reset position
                                if (page > pages) {
                                    $wrapper.scrollLeft(singleWidth * visible);
                                    page = 1;
                                }
                                else 
                                    if (page == 0) {
                                        page = pages;
                                        $wrapper.scrollLeft(singleWidth * visible * pages);
                                    }
                                
                                currentPage = page;
                            });
                        }
                        
                        // 5. insert the back and forward link
                        $wrapper.after('<a href="#" class="arrow back">&lt;</a><a href="#" class="arrow forward">&gt;</a>');
                        
                        // 6. bind the back and forward links
                        $('a.back', this).click(function(){
                            gotoPage(currentPage - 1);
                            return false;
                        });
                        
                        $('a.forward', this).click(function(){
                            gotoPage(currentPage + 1);
                            return false;
                        });
                        
                        $(this).bind('goto', function(event, page){
                            gotoPage(page);
                        });
                        
                        // THIS IS NEW CODE FOR THE AUTOMATIC INFINITE CAROUSEL
                        $(this).bind('next', function(){
                            gotoPage(currentPage + 1);
                        });
                        
                        setInterval(function(){
                            if (config.autoscrolling) {
                                gotoPage(currentPage + 1);
                            }
                        }, config.myInterval);
                    });
                };
            })(jQuery);
            
            
            var highlightpoints = 5, currentPoint = 0;
            function featureHighlight(){
                if (currentPoint < highlightpoints) {
                    currentPoint = currentPoint + 1;
                }
                else {
                    currentPoint = 1;
                }
                $("#features-list li h2").removeClass("feature-highlight");
                $("#features-list li h2.feature" + currentPoint).addClass("feature-highlight");
            }
            
            var 
            /*
			featureClipImages = new Array('adapt-features0000.jpg', 'adapt-features0004.jpg', 'adapt-features0008.jpg', 'adapt-features0012.jpg', 'adapt-features0016.jpg', 'adapt-features0020.jpg', 'adapt-features0024.jpg', 'adapt-features0028.jpg', 'adapt-features0032.jpg', 'adapt-features0036.jpg', 'adapt-features0040.jpg', 'adapt-features0044.jpg', 'adapt-features0048.jpg', 'adapt-features0052.jpg', 'adapt-features0056.jpg', 'adapt-features0060.jpg', 'adapt-features0064.jpg', 'adapt-features0068.jpg', 
                                          'adapt-features0072.jpg', 'adapt-features0076.jpg', 'adapt-features0080.jpg', 'adapt-features0084.jpg', 'adapt-features0088.jpg', 'adapt-features0092.jpg', 'adapt-features0096.jpg', 'adapt-features0100.jpg', 'adapt-features0104.jpg', 'adapt-features0108.jpg', 'adapt-features0112.jpg', 'adapt-features0116.jpg', 'adapt-features0120.jpg', 'adapt-features0124.jpg', 'adapt-features0128.jpg', 'adapt-features0132.jpg', 'adapt-features0136.jpg', 'adapt-features0140.jpg', 
                                          'adapt-features0144.jpg', 'adapt-features0148.jpg', 'adapt-features0152.jpg', 'adapt-features0156.jpg', 'adapt-features0160.jpg', 'adapt-features0164.jpg', 'adapt-features0168.jpg', 'adapt-features0172.jpg', 'adapt-features0176.jpg', 'adapt-features0180.jpg', 'adapt-features0184.jpg', 'adapt-features0188.jpg', 'adapt-features0192.jpg', 'adapt-features0196.jpg', 'adapt-features0200.jpg', 'adapt-features0204.jpg', 'adapt-features0208.jpg', 'adapt-features0212.jpg', 
                                          'adapt-features0216.jpg', 'adapt-features0220.jpg', 'adapt-features0224.jpg', 'adapt-features0228.jpg', 'adapt-features0232.jpg', 'adapt-features0236.jpg', 'adapt-features0240.jpg', 'adapt-features0244.jpg', 'adapt-features0248.jpg', 'adapt-features0252.jpg', 'adapt-features0256.jpg', 'adapt-features0260.jpg', 'adapt-features0264.jpg', 'adapt-features0268.jpg', 'adapt-features0272.jpg', 'adapt-features0276.jpg', 'adapt-features0280.jpg', 'adapt-features0284.jpg',                                         
                                          'adapt-features0288.jpg', 'adapt-features0292.jpg', 'adapt-features0296.jpg', 'adapt-features0300.jpg', 'adapt-features0304.jpg', 'adapt-features0308.jpg', 'adapt-features0312.jpg', 'adapt-features0316.jpg'),
            featurePauseFrames = new Array('adapt-features0000.jpg', 'adapt-features0044.jpg', 'adapt-features0088.jpg', 'adapt-features0112.jpg', 'adapt-features0016.jpg'),
            
			//*/
			featureClipImages = new Array(
			'movie-frame0000'
,'movie-frame0003'
,'movie-frame0006'
,'movie-frame0009'
,'movie-frame0012'
,'movie-frame0015'
,'movie-frame0018'
,'movie-frame0021'
,'movie-frame0024'
,'movie-frame0027'
,'movie-frame0030'
,'movie-frame0033'
,'movie-frame0036'
,'movie-frame0039'
,'movie-frame0042'
,'movie-frame0045'
,'movie-frame0048'
,'movie-frame0051'
,'movie-frame0054'
,'movie-frame0057'
,'movie-frame0060'
,'movie-frame0063'
,'movie-frame0066'
,'movie-frame0069'
,'movie-frame0072'
,'movie-frame0075'
,'movie-frame0078'
,'movie-frame0081'
,'movie-frame0084'
,'movie-frame0087'
,'movie-frame0090'
,'movie-frame0093'
,'movie-frame0096'
,'movie-frame0099'
,'movie-frame0102'
,'movie-frame0105'
,'movie-frame0108'
,'movie-frame0111'
,'movie-frame0114'
,'movie-frame0117'
,'movie-frame0120'
,'movie-frame0123'
,'movie-frame0126'
,'movie-frame0129'
,'movie-frame0132'
,'movie-frame0135'
,'movie-frame0138'
,'movie-frame0141'
,'movie-frame0144'
,'movie-frame0147'
,'movie-frame0150'
,'movie-frame0153'
,'movie-frame0156'
,'movie-frame0159'
,'movie-frame0162'
,'movie-frame0165'
,'movie-frame0168'
,'movie-frame0171'
,'movie-frame0174'
,'movie-frame0177'
,'movie-frame0180'
,'movie-frame0183'
,'movie-frame0186'
,'movie-frame0189'
,'movie-frame0192'
,'movie-frame0195'
/*
,'movie-frame0198'
,'movie-frame0201'
,'movie-frame0204'
,'movie-frame0207'
,'movie-frame0210'
,'movie-frame0213'
,'movie-frame0216'
,'movie-frame0219'
*/
),
            featurePauseFrames = new Array('movie-frame0030', 'movie-frame0057', 'movie-frame0081', 'movie-frame0120', 'movie-frame0144', 'movie-frame0168', 'movie-frame0195'),
            featureStdDelay = 250,
            featurePauseDelay = 2000,
            featureFrame = 0,
            featureTimer;
            //now = new Date();
            //console.log(now.valueOf());
            
            function playMovie(imgElmntId, clipImagesArray, pauseFramesArray, stdDelay, pauseDelay){
            //now = new Date();
            //console.log(now.valueOf());
                var 
                    imgElmnt = document.getElementById(imgElmntId),
                    delayTime;
                
                clearInterval(featureTimer);
                
                if(!stdDelay)stdDelay=250;
                if(!pauseDelay)pauseDelay=2000;
                
                //if(imgElmnt) imgElmnt.src = 'movie-frames/'+clipImagesArray[featureFrame]+'?6';
                if(imgElmnt && $('.'+clipImagesArray[featureFrame])[0]) imgElmnt.innerHTML = $('.'+clipImagesArray[featureFrame])[0].outerHTML;//'s/'++'?6';
                if(findIndex(clipImagesArray[featureFrame], pauseFramesArray) > -1)
                {
                    delayTime = pauseDelay;
                }
                else{
                    delayTime = stdDelay;
                }
                if (featureFrame < clipImagesArray.length-1) {
                    featureFrame = featureFrame + 1;
                }
                else {
                    featureFrame = 0;
                }
                
                //var code = 'playMovie("'+imgElmntId+'", clipImagesArray, pauseFramesArray, stdDelay, pauseDelay)';
                var code = function(){
                    playMovie(imgElmntId, clipImagesArray, pauseFramesArray, stdDelay, pauseDelay);
                }
                featureTimer = setTimeout(code, delayTime);
            }
            
			function findIndex(str, arr){
				for(i = 0; i < arr.length; i++){
					if(arr[i] == str){
						return i;
					}
				}
				return -1;
			}
			
            
            $(document).ready(function(){
    
                var code = 'playMovie("feature_clip", featureClipImages, featurePauseFrames, featureStdDelay, featurePauseDelay)';
                featureTimer = setTimeout(code, featureStdDelay);
                //featureTimer = setTimeout(playMovie('feature_clip'+', '+featureClipImages+', '+featurePauseFrames+', '+featureStdDelay+', '+featurePauseDelay), featureStdDelay);
            
                /*
				// THIS IS NEW CODE FOR THE AUTOMATIC INFINITE CAROUSEL
                var autoscrolling = true;
                
                $('#infiniteCarouselBanner').infiniteCarousel({
                    myInterval: 5000,
                    animationSpeed: 0,
                    autoscrolling: true
                });
                
                $('#infiniteCarouselFeatures').infiniteCarousel({
                    myInterval: 250,
                    animationSpeed: 0,
                    autoscrolling: true
                });
                //*/
				
                setInterval('featureHighlight()', 1000);
				
				$('#form-enquiry, #form-refer').submit(function(){
					var allFieldsFilled = true;
					$(this).find('input.required, select.required').each(function(){
						if($(this).val() == '')
						{
							allFieldsFilled = false;
							$(this).addClass('input-error');
						}
					});
					if(!allFieldsFilled){
						alert('Please fill in all required fields.')
						return false;
					}
				});
            });
