jQuery(document).ready(function() {

    var iframe01 = '<iframe src="http://scrapture.org/modules/ad_next.php" name="ad-next" width="960" height="90" border="0"frameborder="0" scrolling="no" style="border:none;display:block;"></iframe>';
    var iframe02 = '<iframe src="http://scrapture.org/modules/glam.php" name="glam" width="300" height="250" border="0"frameborder="0" scrolling="no" style="border:none;display:block;"></iframe>';

    $('#content > div.inner').infinitescroll({
        navSelector  : "div.pages",// selector for the paged navigation (it will be hidden)
        nextSelector : "div.pages a:first",// selector for the NEXT link (to page 2)
        itemSelector : "#content div.main-content",// selector for all items you'll retrieve
        loadingImg   : "http://static.scrapture.org/img/common/ajax-loader2.gif",
        loadingText  : "Loading...",
        animate      : false,
        analytics    : true,
        switcher     : true,
        bufferPx     : 200,
        donetext     : "End"
    },function() {
        $(this).prepend('<div class="ad-next">' + iframe01 + '</div>').find('div.glam').html(iframe02)
    });

    if ($.cookie('infscr-switcher') != 'off') {
        $.cookie('infscr-switcher', 'on');
        $('div.pages').hide();
        if (IE6 == false) {
            $('#infscr-control').show();
        }
    } else {
        $('#infscr-control').hide();
        $('#infscr-switcher > a').addClass('off');
    }

    //$("div.pic").hover(function() {
        //$(this).animate({marginLeft: '-8px'}, 700);
    //}, function() {
        //$(this).animate({marginLeft: '0'}, 700);
    //});

    $('#infscr-switcher').toggle(function() {
        $.cookie('infscr-switcher', 'off');
        $('div.pages:last').show();
        $('#infscr-control').hide();
        $('#infscr-switcher > a').addClass('off');
    }, function() {
        $.cookie('infscr-switcher', 'on');
        $('div.pages').hide();
        if (IE6 == false) {
            $('#infscr-control').show();
        }
        $('#infscr-switcher > a').removeClass('off');
    });

    $('#infscr-start').click(function() {
        $.scrollTo($('#header'), 800);
        $('#infscr-current').html(1);
    });

    $('#infscr-prev').click(function() {
        var prevNumber = parseInt($('#infscr-current').html(), 10) - 1;
        var prevDiv = 'infscr-page-' + prevNumber;
        if (document.getElementById(prevDiv) != null) {
            $.scrollTo($('#' + prevDiv), 800);
            $('#infscr-current').html(prevNumber);
        } else {
            $.scrollTo($('#header'), 800);
            $('#infscr-current').html(1);
        }
    });

    $('#infscr-next').click(function() {
        var nextNumber = parseInt($('#infscr-current').html(), 10) + 1;
        var nextDiv = 'infscr-page-' + nextNumber;
        if (document.getElementById(nextDiv) != null) {
            $.scrollTo($('#' + nextDiv), 800);
            $('#infscr-current').html(nextNumber);
        } else {
            $.scrollTo($('#footer'), 800);
        }
    });

    $('#infscr-end').click(function() {
        $.scrollTo($('#footer'), 800);
    });

    //$('#snap-2092').prepend('<div class="monomania-banner">monomania</div>');
    //$('#snap-2145').prepend('<div class="monomania-banner">monomania</div>');
    //$('#snap-2213').prepend('<div class="monomania-banner">monomania</div>');

    // ランダムでスナップの写真を差し替える
    var startDate = new Date(2012, 1-1, 27);
    var endDate = new Date(2012, 1-1, 31);
    var nowDate = new Date();
    if (startDate.getTime() <= nowDate.getTime() && nowDate.getTime() < endDate.getTime()) {
        var number = Math.floor(Math.random() * 12) + 3;
        $('.pic').eq(number).prepend('<a href="/temp/glam/qpt.php?gtunName=qpt" target="_blank" style="position:absolute;"><img src="http://static.scrapture.org/img/temp/qpt.jpg" /></a>');
    }

    var startDate = new Date(2012, 1-1, 31);
    var endDate = new Date(2012, 2-1, 22);
    if (startDate.getTime() <= nowDate.getTime() && nowDate.getTime() < endDate.getTime()) {
        var number = Math.floor(Math.random() * 12) + 3;
        var number2 = Math.floor(Math.random() * 2);
        if (number2 == 1) {
          $('.pic').eq(number).prepend('<a href="/temp/glam/qpt.php?gtunName=qpt" target="_blank" style="position:absolute;"><img src="http://static.scrapture.org/img/temp/qpt.jpg" /></a>');
        } else {
          var number3 = Math.floor(Math.random() * 2) + 1;
          $('.pic').eq(number).prepend('<a href="/temp/glam/maqg.php?gtunName=maqg" target="_blank" style="position:absolute;"><img src="http://static.scrapture.org/img/temp/maqg' + number3 + '.jpg" /></a>');
        }
    }

    var startDate = new Date(2012, 2-1, 22);
    var endDate = new Date(2012, 2-1, 29);
    if (startDate.getTime() <= nowDate.getTime() && nowDate.getTime() < endDate.getTime()) {
        var number = Math.floor(Math.random() * 12) + 3;
        var number2 = Math.floor(Math.random() * 2) + 1;
        $('.pic').eq(number).prepend('<a href="/temp/glam/maqg.php?gtunName=maqg" target="_blank" style="position:absolute;"><img src="http://static.scrapture.org/img/temp/maqg' + number2 + '.jpg" /></a>');
    }
});

