﻿(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() {
                		$(this).show();	
                	
                    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(timeout) { this.effect('fade', timeout); },
        scrollUp: function(timeout) { this.effect('scrollUp', timeout); },
        scrollLeft: function(timeout) { this.effect('scrollLeft', timeout); },
        zoom: function(timeout) { this.effect('zoom', timeout); },
        shuffle: function(timeout) { this.effect('shuffle', timeout); },
        blindX: function(timeout) { this.effect('blindX', timeout); },
        blindY: function(timeout) { this.effect('blindY', timeout); },
        blindZ: function(timeout) { this.effect('blindZ', timeout); },
        cover: function(timeout) { this.effect('cover', timeout); },
        uncover: function(timeout) { this.effect('uncover', timeout); },
        curtainX: function(timeout) { this.effect('curtainX', timeout); },
        curtainY: function(timeout) { this.effect('curtainY', timeout); },
        fadeZoom: function(timeout) { this.effect('fadeZoom', timeout); },
        growX: function(timeout) { this.effect('growX', timeout); },
        growY: function(timeout) { this.effect('growY', timeout); },
        none: function(timeout) { this.effect('none', timeout); },
        scrollDown: function(timeout) { this.effect('scrollDown', timeout); },
        scrollRight: function(timeout) { this.effect('scrollRight', timeout); },
        slideX: function(timeout) { this.effect('slideX', timeout); },
        slideY: function(timeout) { this.effect('slideY', timeout); },
        toss: function(timeout) { this.effect('toss', timeout); },
        turnUp: function(timeout) { this.effect('turnUp', timeout); },
        turnDown: function(timeout) { this.effect('turnDown', timeout); },
        turnLeft: function(timeout) { this.effect('turnLeft', timeout); },
        turnRight: function(timeout) { this.effect('turnRight', timeout); },
        wipe: function(timeout) { this.effect('wipe', timeout); },
        coverUncover: function(timeout) { this.effect('cover,uncover', timeout); }
    }
})(jQueryCS);