// Note: No conflict function

// This function must be called after including the jQuery javascript file, but before including any other conflicting library, 
// and also before actually that other conflicting library gets used, in case jQuery is included last. noConflict can be called at 
// the end of the jQuery.js file to globally disable the $() jQuery alias. jQuery.noConflict returns a reference to jQuery, so it 
// can be used to override the $() alias of the jQuery object.
// Use jQuery via jQuery(...)
//jQuery.noConflict();

jQuery(document).ready(function(){
    jQuery("#banner").bannerCycle();
});

(function($){
    $.fn.bannerCycle = function(options) {
        var defaults = {
        };
        var options = $.extend(defaults, options);
        return this.each(function() {
            var obj = $(this);
            
            bannerCycleInit();
            bannerCycleCurrent();
            
            function bannerCycleInit()
            {
                var init;
                container_height = obj.height();
                if (init == undefined || init == false ) {
                    obj.find(".item:last").addClass("active");
                    init = true;
                }
            }

            function bannerCycleCurrent()
            {
                var current             = obj.find(".active");
                var img                 = current.find("img").eq(0);
                var img_height          = img.height();
                img.animate({ "top" : -(img_height - container_height) }, 7000, function(){
                    bannerCycleToNext(obj);
                });
            }

            function bannerCycleToNext()
            {
                var current     = obj.find(".active");
                var next        = bannerCycleGetNext(current);
                next.css({ "z-index" : 870, "display" : "block" });
                next.find("img").css({ "top" : 0 });
                current.css({ "z-index" : 880 }).fadeOut("slow", function(){
                    current.css({ "z-index" : 860 }).removeClass("active");
                    next.css({ "z-index" : 880 }).addClass("active");
                    bannerCycleCurrent(obj);
                });
            }

            function bannerCycleGetNext(current)
            {
                var curr_index  = obj.find(".item").index(current);
                var length      = obj.find(".item").length;
                if (curr_index >= (length - 1)) {
                    return obj.find(".item").eq(0);
                } else {
                    return obj.find(".item").eq(curr_index + 1);
                }
            }
            
        });  
    };
})(jQuery);