$(document).ready(function(){
        
    //setTimeout(showFirst, 2000);
    
    // slide down the first
    function showFirst() {
        $('#adButton').hide();
        $('#ad1').css('z-index', 3);
        $('#ad1').slideDown("slow");
        setTimeout(reset, 7000); 
    }
    
    function reset() {
        //var showFirst = showFirst;
        $('#ad1').slideUp("slow", function(){
            $('#adButton').show();
            $('#adButton').click(function(){
                showFirst();
            });
        });
    }
    
    // image gallery
    $('#home-gallery').cycle({
        before: function() {
            $('#gallery-image-title').remove();
            var parent = $(this).parent();
            if (this.title && this.alt) {
                parent.after("<div id='gallery-image-title'><a href='" + this.alt + "'>" + this.title + "</a></div>");
            } else if (this.title) {
                parent.after("<div id='gallery-image-title'>" + this.title + "</div>");
            }
        }
    });
    
    // image gallery
    //if ($('#home-gallery2').length) {
        //$('#home-gallery2').cycle();
    //}
    
    if ($('#home-gallery2').length) {
        //var images = [];
        $('#home-gallery2 div').each(function(){
            var title = decodeURI($(this).attr('title'));
            //images[i] = new Image;
            //images[i].src = "/images/home/events/images/" + title;
            if ($(this).hasClass('w-242')) {
                $('#home-gallery2').append("<img src='/images/home/events/images/" + title + "' alt='' style='margin-left: 152px' />");
            } else {
                $('#home-gallery2').append("<img src='/images/home/events/images/" + title + "' alt='' />");
            }
            $(this).remove();
        });
    
        $('#home-gallery2').cycle();
        
    }
    
    // videos
    if ($('#beVideo').length) {
        flowplayer("beVideo", "/media/flowplayer-3.1.1.swf",{
            clip:  {
                autoPlay: false,
                autoBuffering: true,
                bufferLength: 6
            }
        });
    }


});
