$(function(){

    if( !smartPhoneFlg ){
        $('#label_bhb').each(function(){
            $(this).append('<div class="drop"><div class="drop_1"></div><div class="drop_2"></div><div class="drop_3"></div></div>');
            for( i=1; i<=3; i++ ){
                $('.drop_'+i).animate({ height: (i*10)+'px'}, 1500 );
            }
        });
    };

    $('.box .image_area').each(function(){
        var boxWidth  = $(this).width();
        var imgWidth  = $(this).find('img').width();
        var imgHeight = $(this).find('img').height();
        if( boxWidth < imgWidth ){
            $(this).find('img').width(boxWidth);
            $(this).find('img').height(Number(( imgHeight * boxWidth ) / imgWidth ));
        }else{
            $(this).find('img').width(imgWidth);
            $(this).find('img').height(imgHeight);
        }
    });

    if($('body').attr('class')=='detail'){
        $('.box').css({ margin:'auto'});
        boxEffect();
    }else{
        $("#contents_area").masonry({
            columnWidth: 10,
            itemSelector: '.box'
        },function(){
            boxEffect();
        });
    }

    $('.popin_contact,.popin_purapori,.popin_sitemap').prettyPopin({width: 500});

});

/* -------------------------
    .boxにエフェクトをかける
------------------------- */
function boxEffect() {

    var boxNum = $('.box').size();

    $('.box').each(function(){
        $(this).css('z-index',(boxNum));
        boxNum--;
        if( !smartPhoneFlg ){
            var a = new Array(1,2,3,4,5);
            num = a.shuffle();
            $(this).append('<div class="drop"><div class="drop_'+num[0]+'"></div><div class="drop_'+num[1]+'"></div><div class="drop_'+num[2]+'"></div></div>');
            $(this).find('div.drop').attr('id',$(this).css('border-top-color')).find('div').css('background',$(this).css('border-top-color'));
            for( i=1; i<=5; i++ ){
                $('.drop_'+i).animate({ height: (i*10)+'px'}, 1500 );
            }
        }
    }).hover(function(){
        $(this).find('div.drop div').css('background-color','#D831AE');
    }, function(){
        $(this).find('div.drop div').css('background-color',$(this).find('div.drop').attr('id'));
    });

    $('.box, .box .drop div, .btn').css('behavior','url(/css/PIE.htc)');
    $('.loading').hide();
    $('.box').css("visibility","visible");

}

/* -------------------------
    Scroll top
------------------------- */
function slowdownScroll() {

    if(navigator.appName == "Microsoft Internet Explorer" && document.compatMode == "CSS1Compat") {
        sctop = document.body.parentNode.scrollTop;
    }else if(window.pageYOffset){
        sctop = window.pageYOffset;
    } else {
        sctop = document.body.scrollTop;
    }

    if(sctop){
        scup = Math.ceil(sctop*.2);
        scrollBy(0,-scup);
        if (sctop-scup) setTimeout("slowdownScroll()",15);
    }
}

/* -------------------------
    ランダムな数値を生成
------------------------- */
Array.prototype.shuffle = function(){
    var i = this.length;
    while(i){
        var j = Math.floor(Math.random()*i);
        var t = this[--i];
        this[i] = this[j];
        this[j] = t;
    }
    return this;
}
