/* Must function with Prototype */
jQuery.noConflict();
var colorArr = new Array();
var x = 0;
/* Create or extend AgencyQ object */
jQuery(document).ready(function ($) {
    AgencyQ = $.extend(typeof AgencyQ == "object" ? AgencyQ : {}, {
        slideshow: function (id, pager, speed, pause, steps, colors) {
            colorArr = colors;
            $('#' + id).cycle({
                fx: 'scrollLeft',
                easing: 'easeInOutQuad',
                speed: speed,
                timeout: pause,
                next: '#' + id + ' img',
                pager: '#' + pager,
                pause: true,
                autostop: (steps == 0 ? 0 : 0),
                autostopCount: steps + 0,
                cleartype: true,
                cleartypeNoBg: true,
                before: onBefore,
                after: onAfter,
                pagerAnchorBuilder: function (idx, slide) {
                    return '<a href="#"></a>';
                }
            });
        }

    });

    function onBefore(curr, next, opts, fwd) {
        var slideid = curr.parentNode.id;
        var index = opts.nextSlide;

        // Reset index to 0 when site first loads
        if (x == 0) {
        index = 0;
        x++;
        }
        //$('#' + slideid).css({ backgroundColor: colorArr[index] }).fadeIn(2000);
        $('#' + slideid).animate({ backgroundColor: colorArr[index] }, { duration: 800, queue: false });
        //$('#' + slideid).css({ backgroundColor: colorArr[index] }).fadeIn(20000);
    }

    function onAfter(curr, next, opts, fwd) {
        var slideid = curr.parentNode.id;
        var index = opts.currSlide;

        $('#' + slideid).css({ backgroundColor: colorArr[index] }).fadeIn(2000);
    }


    $(window).resize(function () {/// <reference path="~/layouts/micrositeResources.ascx" />

        $('.slide-holder').each(function () {
            $(this).css('width', $(window).width() + 'px');
            this.cycleW = $(window).width();
        });
    });
});

