function rotatorNav(currSlideElement, nextSlideElement, options, forwardFlag) {
    $('#nav'+$(currSlideElement).attr('id')+' a').removeClass('on');
    $('#nav'+$(nextSlideElement).attr('id')+' a').addClass('on');
}

$(document).ready( function() {
    if ( $('#rotator').length ) {
        var loaded = 0;
        
        function checkFinal(){
            loaded++;
            // if all images loaded
            if(loaded == 4){
                $('#rotator').cycle({
                    fx:     'scrollLeft',
                    easing: 'easeInOutBack',
                    startingSlide: 1,
                    delay:  -2000,
                    speed:   1000,
                    timeout: 5000,
                    after:   rotatorNav,
                    pager:  '#pager', 
                    pagerAnchorBuilder: function(idx, slide) { 
                        // return selector string for existing anchor 
                        return '<li><a href="#">' + idx + '</a></li>'; 
                    } 
                });
    //          alert('loaded');
                $('#rotator li img').show();
    
                /* give the buttons click to slide functionality */
                /*
                $('#nav1').click(function() {
                    $('#pager li:eq(0) a').trigger('click'); 
                    return false; 
                });
                $('#nav2').click(function() {
                    $('#pager li:eq(1) a').trigger('click'); 
                    return false; 
                });
                $('#nav3').click(function() {
                    $('#pager li:eq(2) a').trigger('click'); 
                    return false; 
                });
                $('#nav4').click(function() {
                    $('#pager li:eq(3) a').trigger('click'); 
                    return false; 
                });
                */
            }
        }
        
        var imgs = new Array();
        imgs[0] = 'images/RotatorWeb.jpg';
        imgs[2] = 'images/RotatorSearch.jpg';
        imgs[3] = 'images/RotatorConversion.jpg';
        imgs[4] = 'images/RotatorViral.jpg';
    
        var $img = new Image();
    
        for(var i in imgs){
            $($img).load( function () { checkFinal(); } ).attr('src', imgs[i]);
        }
    }
    
    if ( $('#secure').length ) {
        $('#secure').focus(function() { 
            if ( $(this).val() == "Type Answer Here" ) {
                $(this).val('');
                $(this).css('color','black');
            }
        });
    }
    if ( $('#captcha').length ) {
        $('#captcha').click(function() {
            var src = $(this).attr('src');
            $(this).attr('src', src);
        });
    }
    if ( $('#submit').length ) {
        $('#submit').click(function(e) {
            if ( $('#secure').val() == "Type Answer Here" || $('#secure').val() == "" ) {
                e.preventDefault();
                alert('Please enter the answer to the sum');
            }
        });
    }   
});