function ValidateFuImage(source, args) {
    if (args.Value == null || args.Value == "") {
        var src = $('#' + $('#' + source.attributes["controltovalidate"].value).attr('imageid')).attr('src');
        if (src == "" || src == null) {
            args.IsValid = false;
        }
    }
}

function ValidateImageForType(source, args) {
    if (args.Value != null && args.Value != "") {
        if (args.Value.lastIndexOf(".jpg") > 0 || args.Value.lastIndexOf(".jpeg") > 0 || args.Value.lastIndexOf(".gif") > 0) {
            args.IsValid = true;
        }
        else {
            args.IsValid = false;
        }
    }
}

function spotlight(FadeTimeInSeconds, DelayInSeconds) {
    $('#spotlight_rotator').n4m_cycle({
        speed: FadeTimeInSeconds,
        timeout: DelayInSeconds,
        rotator_pager: $('#rotator_nav'),
        headlines_wrapper: $('#headlines_wrapper')
    });

}

function pause() {
    _this.cycle('pause');
}

function resume() {
    _this.cycle("resume");
}

function NavNext() {
    var i = parseInt($('#hdnCurrentPage')[0].value);
    _this.cycle(i < 4 ? i + 1 : 0);
}

function NavPrevious() {
    var i = parseInt($('#hdnCurrentPage')[0].value);
    _this.cycle(i > 0 ? i - 1 : 4);
}

function UpdateNav(ind) {
    $('#pnlNav a').each(function(i) {
        if (i == ind + 1) {
            $(this).addClass('activeSlide');
        }
        else {
            $(this).removeClass('activeSlide');
        }
    });
}

function ShowSpotLight(aId, cycleNo) {
    var preId = aId.substring(0, aId.length - 1);
    for (var i = 0; i < 5; i++) {
        $('#' + preId + i.toString()).removeClass();
    }
    _this.cycle(cycleNo);
    $('#' + aId).addClass("activeSlide");

}

(function(jQuery) {
    jQuery.fn.n4m_cycle = function(settings) {
        var opts = $.extend({}, jQuery.fn.n4m_cycle.defaults, settings);
        _this = $(this);
        _this.options = opts;
        start();
        return this;
    };


    function start() {
        $.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) {
            UpdateNav(currSlideIndex);
        };

        _this.cycle({
            speed: _this.options.speed,
            timeout: _this.options.timeout,
            fx: 'fade',
            pager: _this.options.rotator_pager,
            pagerEvent: 'mouseover',
            pauseOnPagerHover: true,
            pagerAnchorBuilder: function(index, slide) { return '<a href=\"' + slide.getElementsByTagName("a")[0].href + '\" target=\"' + slide.getElementsByTagName("a")[0].target + '\" title=\"' + slide.title + '\">' + slide.title + '</a>'; }
        });

        $(document).ready(function() {
            _this.show();
            $(_this.options.headlines_wrapper).show();



        });
    }
    jQuery.fn.n4m_cycle.defaults = {};

})(jQuery);




