(function($) {

    $.fn.isIE6 = function() {
        if ($.browser.msie && $.browser.version == '6.0')
            return true;
        else return false;
    }

    $.scrollFollow = function(box, options) {
        box = $(box);

        box.css('position', options.position);
        box.css(options.approachTo, options.pixel[0] + 'px');
        box.css(options.relativeTo, options.pixel[1] + 'px');
        box.slideDown(options.speed);

        if ($().isIE6()) {
            $(window).scroll(function() { box.css(options.relativeTo, (options.pixel[1] + 1) + 'px'); box.css(options.relativeTo, options.pixel[1] + 'px'); });
        }
    };

    $.onClickFunc = function(img, box, options) {
        img = $(img);

        try {
            BoxText = $(options.container);
        } catch (e) { }

        //debugger;
        switch (img.attr('alt')) {
            case 'toMin': img.click(function() { BoxText.slideUp(options.speed) }); img.css("cursor", "pointer"); break;
            case 'toMax': img.click(function() { BoxText.slideDown(options.speed) }); img.css("cursor", "pointer"); break;
            case 'toClose': img.click(function() { box.slideUp(options.speed) }); img.css("cursor", "pointer"); break;
            default: return;
        }
    };

    $.fn.scrollFollow = function(options) {

        options = options || {};
        options.approachTo = options.approachTo || 'right';
        options.relativeTo = options.relativeTo || 'bottom';
        options.pixel = options.pixel || ['0', '0'];
        options.container = options.container || '.default';
        options.speed = options.speed || 500;
        options.offset = options.offset || 0;
        options.delay = options.delay || 0;

        if ($().isIE6()) {
            options.position = 'absolute';
            options.pixel[1] -= 6;
            //alert("123");
        }
        else {
            options.position = 'fixed';
        }
        this.each(function() {
            new $.scrollFollow(this, options);

            imgs = $(this).children('div:first').children('img');
            //debugger;
            imgs.each(function() {
                new $.onClickFunc(this, $(this).parent().parent(), options);
            });
        });
        return this;
    };
})(jQuery);



