/**
 * Side-Banner
 *
 * Copyright (c) 2011 Choi Jae-Young <www.miwit.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

var mw_side_banner =
{
    scroll_duration: 500,
    banner_top: 0,
    container: '#container',
    banner_move: function() {
        $('body').animate({scrollTop:0}, mw_side_banner.scroll_duration);
    },
    banner_control: function() {
        var t = 0;
        if ($(window).scrollTop() < mw_side_banner.banner_top)
            t = mw_side_banner.banner_top;
        else
            t = $(window).scrollTop() + 10;
        var m = $(mw_side_banner.container).width() ? $(mw_side_banner.container).outerHeight() : t;
        if (t >= m) t = m;

        var l = $(mw_side_banner.container).width()
                ? $(mw_side_banner.container).offset().left + $(mw_side_banner.container).outerWidth() + 10
                : $(window).width() - $('#'+mw_side_banner.banner).outerWidth() - 10;

        $('.side_banner').css('top', t).css('left', l);
        $('.side_banner').css('display', 'block');
    },
    run: function(t, c) {
        mw_side_banner.banner_top = t;
        mw_side_banner.container = c;
        $(document).ready(function () {
            banner = $(".side_banner")
                            .css('position','absolute')
                            .css('cursor', 'pointer')
                            .appendTo('body');
            mw_side_banner.banner_control()
            $(window).bind('scroll resize', function (e) { mw_side_banner.banner_control() } );
        });
    }
}
