﻿var log = function (a, b, c) { 
    if (typeof console == 'object' && typeof console.log == 'function')
        console.log(a, b, c) 
}
$(function () {

    var PageProperties = function () { }
    var PagePropertiesClass = {
        win: $(window),
        doc: $(document),
        winheight: function () { return this.win.height() },
        winwidth: function () { return this.win.width() },
        scrolltop: function () { return this.win.scrollTop() },
        docheight: function () { return this.doc.height() },
        docwidth: function () { return this.doc.width() },
        resize: function () {
            if (doc.winwidth() < doc.docwidth()) {
                $('body').css('width', doc.docwidth());
            }
            else $('body').css('width', '100%');
        },
        loadbg: function () {
            var r = Math.ceil(Math.random() * 13);
            if (window.location.hash) $('html').addClass('bg' + window.location.hash.replace('#', ''));
            else $('html').addClass('bg' + r);
        }
    }
    PageProperties.prototype = PagePropertiesClass;
    var doc = new PageProperties();
    $('#maincontent').hide().css('visibility', 'visible').fadeIn(1000);
    $('html').ad
    doc.resize();
    doc.loadbg();

    var bganimate = {
        base: (2020 - doc.winwidth()) / (doc.docheight() - doc.winheight()),
        base1: (2200 - doc.winwidth()) / (doc.docheight() - doc.winheight()),
        anim: function () {
            //var p = '-' + Math.ceil(this.base * doc.scrolltop() / 10) + 'px 0px';
            //var p = '0px -' + Math.ceil(this.base * doc.scrolltop()) + 'px';
            var p = '0px -' + doc.scrolltop() / 10 + 'px';
            //var p1 = '-' + Math.ceil(this.base1 * doc.scrolltop() / 10) + 'px 0px';
            $('html').dequeue().animate({ 'backgroundPosition': p }, 1200, 'swing')
            //$('html').dequeue().animate({'backgroundSize':x + '%'})
            //$('#texture').dequeue().animate({ 'backgroundPosition': p1 }, 1200, 'swing')
        }
    }
    doc.win.scroll(function (e) {
        bganimate.anim();
    });
    doc.win.resize(function () {
        doc.resize();
    });

    var curindex = 0;
    var change = function (index) {
        $('html').attr('class', 'bg' + index);
    }
    $('#next').click(function () { change(curindex++); return false; })
    $('#prev').click(function () { change(curindex--); return false })

});
