$(document).ready(function() {
    $("#billboard ul").jqGalScroll({
        ease: 'easeInOutCubic',
        speed:1000,
        height: 354,
        width: 972,
        titleOpacity : .0,
        direction : 'horizontal'
    });
    
    var gallery = $('#minigallery .pics');
    var picsWrap = gallery.find('.picsWrap');
    var gal_speed = 600;
    var current_pic = 0;
    
    var picslinks = gallery.find('a');
    picslinks.filter('.popup').fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': false });

    var gal_size = picslinks.size()-1;
    function move_gal_next(){
        if (current_pic == gal_size) {
            current_pic = 0;
            picsWrap.animate({"top": "+=" + (105 * gal_size) + "px"}, gal_speed);
        } else {
            picsWrap.animate({"top": "-=105px"}, gal_speed);
            current_pic++;
        }
    }
    function move_gal_prev(){
        if (current_pic == 0) {
            current_pic = gal_size;
            picsWrap.animate({"top": "-=" + (105 * gal_size) + "px"}, gal_speed);
        } else {
            picsWrap.animate({"top": "+=105px"}, gal_speed);
            current_pic--;
        }
    }
    
    
    runGallery = function(){
      move_gal_next();
    };
    setInterval ( runGallery, 5000 );
    
    
    $('#prevGal').click(function(event){
        event.preventDefault();
        move_gal_prev();
    });
    $('#nextGal').click(function(event){
        event.preventDefault();
        move_gal_next();
    });
    if ( document.body.clientWidth < 972) {
        $('#page').width(996);
    } else { $('#page').width('100%'); }
    $(window).resize(function(){
        if ( document.body.clientWidth < 972) {
            $('#page').width('996px');
        } else { $('#page').width('100%'); }
    });
});
