
(function( $ ){
    $.fn.carrousell = function() {
        if (this.length) {
            var e=null;
            var left = $('<div class="cMenu"></div>');
            var tab = 1;
            for (i=0; i < this.children().length; i++) {
                if (this.children()[i].tagName == "H3") {
                    if (e) {
                        tab+=1;
                        left.append(e);
                        e = $('<div tabindex="' + tab + '" class="cElement"></div>');
                    }
                    else {
                        e = $('<div tabindex="' + tab + '" class="cElement open"></div>');
                    }
                    
                }
                e.append($(this.children()[i]).clone());
                if ($(e).html().indexOf('<a ') > -1)
                    tab+=1;
                $(e).html($(e).html().replace('<a ','<a tabindex="' + tab + '" '));
            }
            left.append(e);
            
            this.html('').append(left);
            cHeight = this[0].getElementsByTagName('img')[0].clientHeight;
			if (cHeight>350) { cHeight=350; };
            this.css('height', cHeight + 'px');
            $('div.cElement').click( function () {
                $('div.cElement.open').removeClass('open');
                $(this).addClass('open');
            });
            
            $('div.cElement').focus( function () {
                $('div.cElement.open').removeClass('open');
                $(this).addClass('open');
            });
        }
        
    };
})( jQuery );

