$(function(){
    $('.polaroid').each(function(){
        var num = (Math.random()*2-1)*7;
        $(this).css('-moz-transform', 'rotate('+num+'deg)');
        $(this).css('-webkit-transform', 'rotate('+num+'deg)');
        $(this).css('-webkit-backface-visibility', 'hidden');
        $(this).css('-ms-transform', 'rotate('+num+'deg)');
        $(this).css('-o-transform', 'rotate('+num+'deg)');
        $(this).css('transform', 'rotate('+num+'deg)');
        var a = $(this).find('a');
        if (a.length) {
            $(this).click(function(){
               document.location.href = a.attr('href');
            });
        }
    });

    if ($('#main_bunny_bunny').length > 0) {
        var cover_from = $('.main_photo').next().offset();
        $(window).scroll(function() {
            if ($(window).scrollTop() > cover_from.top){
                $('#main_bunny_bunny').hide();
            }
        });
    }

    if ($('#about_gallery').length > 0) {
        $('#about_gallery').cycle({
            shuffle: true,
            timeout: 3000,
            speed: 2000
        });
    }

    if ($('#gallery_page').length > 0) {
        if ($('#gallery_page .snap').length > 6) {
            $('#gallery_page_cycle').before('<a id="gallery_prev" href="#">&nbsp;</a><a id="gallery_next" href="#">&nbsp;</a>').cycle({
                fx: 'scrollHorz',
                easing: 'easeInOutCirc',
                speed: 2000,
                prev: '#gallery_prev',
                next: '#gallery_next',
                fastOnEvent: 1000,
                timeout: 0,
                pager:  '#gallery_page_cycle_nav',
                // callback fn that creates a thumbnail to use as pager anchor 
                pagerAnchorBuilder: function(idx, slide) { 
                    return '<li><a href="#">&nbsp;</a></li>'; 
                }
            });
        }

        $("#gallery_page .group a").colorbox({
            rel:'photos',
            transition:'fade',
            opacity: 0.4,
            top: 80,
            height: 615,
            width: '90%'
        });
        
    }
});
