// plugin definition    
$.fn.bidAttentionHelper = function(options) {
    var defaults = {
        url: 'bid_attention_helper.php'
    };
    var bidNumber = 0;
    // Extend our default options with those provided.    
    var opts = $.extend(defaults, options);

    // Our plugin implementation code goes here.   
    var bhtml = '<div id="js_show_pop_zs" class="show_pop_zs" style="cursor:pointer;">' +
            '<div class="show_pop_zs_hd">' +
            '<strong class="title">竞投小助手</strong><span class="tex"></span><span class="show_pop" title="展开" id="js_show_pop_btn">展开</span>' +
            '</div>' +
            '</div>';
    var bhtml1 = '<div id="js_show_pop_zs_show_box"  style="z-index:999;" class="show_pop_zs_show_box radius5 show_pop_zs_show_box_h0" style="height: 0px;"></div>';
    var msg1 = '<div id="successTipa" class="dialog radius5">' +
            '<div class="hd">' +
            '<h3 class="h3">提示</h3>' +
            '<p title="关闭" class="close close-win">关闭 </p>' +
            '</div>' +
            '<div class="mod">' +
            '<div class="textMod_new" style="border:0;"><img src="http://esf.s.house365.com/zsb/images/v1.0/okBg.png" alt=""><span>已取消，还可以重新关注！</span></div>' +
            '</div>' +
            '</div>';
    var msg2 = '<div id="successTip1" class="dialog radius5">' +
            '<div class="hd">' +
            '<h3 class="h3">提示</h3>' +
            '<p title="关闭" class="close close-win">关闭 </p>' +
            '</div>' +
            '<div class="mod">' +
            '<div class="textMod_new" style="border:0;"><img src="http://esf.s.house365.com/zsb/images/v1.0/dialog.png" alt=""><span>取消失败，请稍后再试！</span></div>' +
            '</div>' +
            '</div>';
    var $this = $(this);



    $.get(opts.url, {action: 'getAttentionNumber'}, function(data) {
        if (data.length > 0 && data != '-1') {
            $this.html(bhtml + bhtml1);
            $this.after(msg1 + msg2);
            $("#js_show_pop_zs .tex").html('我已关注<strong id="attentionNumber" class="num">' + data + '</strong>项竞投');
            $("#js_show_pop_zs").click(function() {
                if ($("#js_show_pop_zs_show_box").html().length === 0) {
                    $("#js_show_pop_zs_show_box").html('<iframe id="attentionIframe" width="626" scrolling="no" height="334" frameborder="0" src="' + opts.url + '"></iframe>')
                }
                $("#js_show_pop_zs_show_box").css("height", "334px")
            })

        }
    }, 'text');



};

function scrollFixe02() {
    var st = $(document).scrollTop();
    var winh = $(window).height();
    $("#js_show_pop_zs").css("top", st + winh - 37);
    $("#js_show_pop_zs_show_box").css("top", st + winh - 334);
}

if (!window.XMLHttpRequest) {
    $(window).scroll(function() {
        scrollFixe02();
    });
    $(window).resize(function(e) {
        scrollFixe02();
    });
}