﻿function SetupCoverflow(clientID, controlID, animationSpeed,autoplay) {
    // JQuery Delay
    jQuery.fn.delay = function(time, func) {
        this.each(function() {
            setTimeout(func, time);
        });

        return this;
    };

    var coverflowControl = $('#' + controlID + "_" + clientID);
    $(coverflowControl).css("visibility", "hidden");

    $(document).ready(function() {
        // Browser compatebility fix
        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
            var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
            if (ieversion >= 8)
                $(coverflowControl).addClass("coverflowIE");
            else if (ieversion >= 7)
                $(coverflowControl).addClass("coverflowIE7");
            else
                $(coverflowControl).addClass("coverflowOther");
        }
        else {
            if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
                $(coverflowControl).addClass("coverflowChrome");
            } else {
                if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)) { //test for Opera/x.x or Opera x.x (ignoring remaining decimal places);
                    // Mirror not working curently with opera
                    $(".CFMirror").remove();
                    $(".CFMirrorGradiant").remove();
                    
                } else {
                    $(coverflowControl).addClass("coverflowOther");
                }
            }
        }

        var interval;
        $(coverflowControl).roundabout({ minScale: 0, minOpacity: 0 });

        $(this).delay(2000, function() { $(coverflowControl).css("visibility", "visible"); });
        if (autoplay == "true") {
            $(coverflowControl).hover(function() { clearInterval(interval); },
		                          function() { interval = startAutoPlay(); }
	                              );

            interval = startAutoPlay();

        }


        function startAutoPlay() {
            $(".roundabout-moveable-item").height(200);
            return setInterval(function() {
                $(coverflowControl).roundabout_animateToNextChild();
            }, animationSpeed);
        }

    });

  
}
