﻿Ext.ns('MyP2C.ExtCore');
MyP2C.ExtCore.fly =function(bX, bY, sEscapeHtml, iWidth, iHeight, pos, iPosX, iPosY, iTime, iStep, bClose, sBdSty, sBgSty)
{
    var sId = 'myp2c_id_'+ parseInt(Math.random()*1000000);
    var time = (iTime > 50 ? iTime : "50");
    var step = (iStep > 0 ? iStep : "1");
    var pos_x = (iPosX > 0 ? iPosX : "0");
    var pos_y = (iPosY > 0 ? iPosY : "0");
    var width = (iWidth > 0 ? iWidth : "100");
    var height = (iHeight > 0 ? iHeight : "100");
    var div = "<div style='position:absolute;z-index:100;width:" + width + "px;height:" + height + "px;left:" + pos_x + "px;top:" + pos_y + "px;" + sBdSty + "'>" +
        "<iframe frameborder='0' scrolling='no' style='position:absolute;width:100%;height:100%;left:0px;top:0px;'></iframe>" +
        "<div onmouseover='Ext.TaskMgr.stop(task_" + sId + ");' onmouseout='Ext.TaskMgr.start(task_" + sId + ");' style='position:absolute;width:100%;height:100%;left:0px;top:0px;cursor:pointer;overflow:hidden;" + sBgSty + "'>" +
            (Ext.isEmpty(sEscapeHtml) ? "&nbsp;" : unescape(sEscapeHtml)) +
        "</div>" +
        (bClose ? "<div title='关闭' onmouseover='Ext.TaskMgr.stop(task_" + sId + ");' onmouseout='Ext.TaskMgr.start(task_" + sId + ");' onclick='Ext.TaskMgr.stop(task_" + sId + ");el_" + sId + ".remove();' style='position:absolute;z-index:101;width:12px;height:12px;right:0px;top:0px;font-size:12px;line-height:12px;font-weight:bold;text-align:center;cursor:pointer;background-color:#eeeeee;color:#333333;border:1px solid #999999;filter:alpha(Opacity=70);-moz-opacity:0.7;opacity:0.7;'>×</div>" : "") +
    "</div>";
    var js = "el_" + sId + "=Ext.getBody().insertHtml('beforeEnd',unescape('" + escape(div) + "'),true);" +
        "ok_x_" + sId + "=true;" +
        "ok_y_" + sId + "=true;" +
        "task_" + sId + "=Ext.TaskMgr.start({run:function(){" +
            "var pos='" + ((pos == "t" || pos == "r" || pos == "b" || pos == "l" || pos == "c" || pos == "lt" || pos == "lb" || pos == "rt" || pos == "rb") ? pos : "") + "';" +
            "var time=" + time + ";" +
            "var step=" + step + ";" +
            "var bx=" + (bX ? "true" : "false") + ";" +
            "var by=" + (bY ? "true" : "false") + ";" +
            "var s = Ext.getBody().getScroll();" +
            "var x = el_" + sId + ".getX();" +
            "var y = el_" + sId + ".getY();" +
            "var l = s.left;" +
            "var t = s.top;" +
            "var view_w = Ext.lib.Dom.getViewportWidth();" +
            "var view_h = Ext.lib.Dom.getViewportHeight();" +
            "if(bx){" +
                "if(x <= l){ok_x_" + sId + " = true;x=l;}" +
                "else if(x >= l+view_w-" + width + "){ok_x_" + sId + " = false;x=l+view_w-" + width + ";}" +
            "}else if(pos==''){x=l+" + pos_x + ";" +
            "}else if(pos=='l' || pos=='lt' || pos=='lb'){x=l+" + pos_x + ";" +
            "}else if(pos=='t' || pos=='b' || pos=='c'){x=l+view_w/2-" + width + "/2;" +
            "}else if(pos=='r' || pos=='rt' || pos=='rb'){x=l+view_w-" + width + "-" + pos_x + ";" +
            "}" +
            "if(by){" +
                "if(y < t){ok_y_" + sId + " = true;y=t;}" +
                "else if(y > t+view_h-" + height + "){ok_y_" + sId + " = false;y=t+view_h-" + height + ";}" +
            "}else if(pos==''){y=t+" + pos_y + ";" +
            "}else if(pos=='t' || pos=='lt' || pos=='rt'){y=t+" + pos_y + ";" +
            "}else if(pos=='l' || pos=='r' || pos=='c'){y=t+view_h/2-" + height + "/2;" +
            "}else if(pos=='b' || pos=='lb' || pos=='rb'){y=t+view_h-" + height + "-" + pos_y + ";" +
            "}" +
            "el_" + sId + ".setLocation((bx ? (ok_x_" + sId + " ? x+step : x-step) : x),(by ? (ok_y_" + sId + " ? y+step : y-step) : y),false);" +
        "},interval:" + time + "});";
    eval(js);
};
MyP2C.ExtCore.scroll = function (sDivId, sEscapeHtml, iWidth, iHeight, sPos, iTime, iStep, sBdSty, sBgSty) {
    var div = Ext.get(sDivId);
    if (div) {
        var sId = 'myp2c_id_' + parseInt(Math.random() * 1000000);
        var sId1 = 'e1_' + sId;
        var sId2 = 'e2_' + sId;
        var pos = ((sPos == 't' || sPos == 'r' || sPos == 'b' || sPos == 'l') ? sPos : 'l');
        var time = (iTime > 50 ? iTime : '50');
        var step = (iStep > 0 ? iStep : '1');
        // 
        var nofx = (iTime < 1000 || iStep < 20);
        //
        var sUnscapeHtml = unescape(sEscapeHtml);
        var sDiv = "<div id='" + sId1 + "'"+(nofx ? " onmouseover='Ext.TaskMgr.stop(task_" + sId + ");' onmouseout='Ext.TaskMgr.start(task_" + sId + ");'" : "")+" style='width:" + (iWidth > 0 ? iWidth : "100") + "px;height:" + (iHeight > 0 ? iHeight : "100") + "px;overflow:hidden;cursor:pointer;" + sBdSty + sBgSty + "'>" +
            "<table id='" + sId2 + "' border='0' cellspacing='0' cellpadding='0'><tr><td>" + sUnscapeHtml + "</td>" + ((pos == "l" || pos == "r") ? "" : "</tr><tr>") + "<td>" + sUnscapeHtml + "</td></tr></table>" +
        "</div>";
        div.insertHtml('beforeEnd', sDiv, false);
        //
        var js = "task_" + sId + "=Ext.TaskMgr.start({run:function(){" +
            "var e1_" + sId + " = Ext.get('" + sId1 + "');" +
            "var e2_" + sId + " = Ext.get('" + sId2 + "');" +
            "var pos='" + pos + "';var s = e1_" + sId + ".getScroll();" +
            "if(pos == 't'){if(s.top >= e2_" + sId + ".getHeight()/2){" +
                    (nofx ? "e1_" + sId + ".scrollTo('top'," + step + ");" : "e1_" + sId + ".scrollTo('top',0);e1_" + sId + ".animate({scroll:{to:[0," + step + "] }},0.5,null,'easeOut','scroll');") +
                "}else{" +
                    (nofx ? "e1_" + sId + ".scrollTo('top',s.top+" + step + ");" : "e1_" + sId + ".animate({scroll:{to:[0,s.top+" + step + "] }},0.5,null,'easeOut','scroll');") +
                "}" +
            "}else if(pos == 'b'){if(s.top <= " + step + "){" +
                    (nofx ? "e1_" + sId + ".scrollTo('top',e2_" + sId + ".getHeight()/2);" : "e1_" + sId + ".scrollTo('top',e2_" + sId + ".getHeight()/2+"+step+");e1_" + sId + ".animate({scroll:{to:[0,e2_" + sId + ".getHeight()/2] }},0.5,null,'easeOut','scroll');") +
                "}else{" +
                    (nofx ? "e1_" + sId + ".scrollTo('top',s.top-" + step + ");" : "e1_" + sId + ".animate({scroll:{to:[0,s.top-" + step + "] }},0.5,null,'easeOut','scroll');") +
                "}" +
            "}else if(pos == 'r'){if(s.left<=" + step + "){" +
                    (nofx ? "e1_" + sId + ".scrollTo('left',e2_" + sId + ".getWidth()/2);" : "e1_" + sId + ".scrollTo('left',e2_" + sId + ".getWidth()/2+"+step+");e1_" + sId + ".animate({scroll:{to:[e2_" + sId + ".getWidth()/2,0] }},0.5,null,'easeOut','scroll');") +
                "}else{" +
                    (nofx ? "e1_" + sId + ".scrollTo('left',s.left-" + step + ");" : "e1_" + sId + ".animate({scroll:{to:[s.left-" + step + ",0] }},0.5,null,'easeOut','scroll');") +
                "}" +
            "}else{if(s.left >= e2_" + sId + ".getWidth()/2){" +
                    (nofx ? "e1_" + sId + ".scrollTo('left'," + step + ");" : "e1_" + sId + ".scrollTo('left',0);e1_" + sId + ".animate({scroll:{to:["+step+",0] }},0.5,null,'easeOut','scroll');") +
                "}else{" +
                    (nofx ? "e1_" + sId + ".scrollTo('left',s.left+" + step + ");" : "e1_" + sId + ".animate({scroll:{to:[s.left+" + step + ",0] }},0.5,null,'easeOut','scroll');") +
                "}" +
            "}" +
        "},interval:" + time + "});";
        eval(js);
    }
};

var myp2c_body_scroll_pos,myp2c_body_scroll_timer; 
Ext.onReady(function(){
    /*双击滚动网页*/
    document.body.ondblclick=function(){myp2c_body_scroll_timer= setInterval(function(){myp2c_body_scroll_pos = Ext.getBody().getScroll().top +2;window.scroll(0,myp2c_body_scroll_pos);if (myp2c_body_scroll_pos != Ext.getBody().getScroll().top){clearInterval(myp2c_body_scroll_timer);}},50);};
    document.body.onclick=function(){clearInterval(myp2c_body_scroll_timer);};
});
/*
var myp2c_body_scroll_timer; 
setTimeout(function()
{
    document.body.ondblclick=function(){myp2c_body_scroll_timer= setInterval(function(){var scrollTop=(window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0);window.scrollTo(0,scrollTop +2);if ((window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0) == scrollTop){clearInterval(myp2c_body_scroll_timer);}},50);};
    document.body.onclick=function(){clearInterval(myp2c_body_scroll_timer);};
},500);
*/
