﻿(function($) {
    var JsBanner = window.JsBanner = function(imageContainer) {
        return new CsJsBanner(imageContainer);
    };

    function CsJsBanner(jqselector) {
        this.jqselector = jqselector;
    }

    CsJsBanner.prototype = {
        setupBannerSize: function(width, height) {
            var jqSelector = this.jqselector;
            $(function() {
                $(jqSelector + ' img').each(function() {
                    var imageWidth = $(this).get(0).width;
                    var imageHeight = $(this).get(0).height;

                    var widthCoefficient = width / imageWidth;
                    var heightCoefficient = height / imageHeight;

                    var minCoefficient = widthCoefficient < heightCoefficient ? widthCoefficient : heightCoefficient;

                    imageWidth *= minCoefficient;
                    imageHeight *= minCoefficient;

                    var imageTop = (height / 2) - (imageHeight / 2);
                    var imageLeft = (width / 2) - (imageWidth / 2);

                    $(this).attr({
                        'width': imageWidth,
                        'height': imageHeight
                    });

                    $(this).css({
                        'top': imageTop,
                        'left': imageLeft
                    });
                });
            });
        },
        effect: function(fx, timeout, delay, sync) {
            var jqSelector = this.jqselector;
            $(document).ready(function() {
                $(jqSelector).cycle({
                    fx: fx != null ? fx : $().cycle.defaults.fx,
                    timeout: timeout != null ? timeout : $().cycle.defaults.timeout,
                    delay: delay != null ? delay : $().cycle.defaults.delay,
                    sync: sync != null ? sync : $().cycle.defaults.sync
                });
            });
        },
        fade: function() { this.effect('fade'); },
        scrollUp: function() { this.effect('scrollUp'); },
        scrollLeft: function() { this.effect('scrollLeft'); },
        zoom: function() { this.effect('zoom'); },
        shuffle: function() { this.effect('shuffle'); },
        blindX: function() { this.effect('blindX'); },
        blindY: function() { this.effect('blindY'); },
        blindZ: function() { this.effect('blindZ'); },
        cover: function() { this.effect('cover'); },
        uncover: function() { this.effect('uncover'); },
        curtainX: function() { this.effect('curtainX'); },
        curtainY: function() { this.effect('curtainY'); },
        fadeZoom: function() { this.effect('fadeZoom'); },
        growX: function() { this.effect('growX'); },
        growY: function() { this.effect('growY'); },
        none: function() { this.effect('none'); },
        scrollDown: function() { this.effect('scrollDown'); },
        scrollRight: function() { this.effect('scrollRight'); },
        slideX: function() { this.effect('slideX'); },
        slideY: function() { this.effect('slideY'); },
        toss: function() { this.effect('toss'); },
        turnUp: function() { this.effect('turnUp'); },
        turnDown: function() { this.effect('turnDown'); },
        turnLeft: function() { this.effect('turnLeft'); },
        turnRight: function() { this.effect('turnRight'); },
        wipe: function() { this.effect('wipe'); },
        coverUncover: function() { this.effect('cover,uncover'); }
    }
})(jQueryCS);
