(function() {
    var imgs = document.getElementsByTagName('img');
    for(var i = 0, len = imgs.length; i < len; i++) {
        (function() {
            var tmp = imgs[i];
            tmp.onmousedown = function(e) {
                var src = tmp.getAttribute('rel');
                if (!src) {
                    src = tmp.getAttribute('path');
                    src = src.replace( "/image", "/image/original");
                }

                return Android.viewBigPicture(src);
            }
        })();
    }
})();


(function() {
    var links = document.getElementsByTagName('a');
    for(var i = 0, len = links.length; i < len; i++) {
        (function() {
            var tmp = links[i];
            tmp.onclick = function(e) {
                var href = tmp.getAttribute('href');
                var title = tmp.getAttribute('title');

                // 这里的方法自己定义
                Android.showTiptopDialog(href,title);
                if (e.stopPropagation) {
                    e.stopPropagation();
                }
                return e.preventDefault();
            }
        })();
    }
})();



function getOffsetTop( elem ) {
    var y = 0;
    while(elem){
        y = y + elem.offsetTop;
        elem = elem.offsetParent;
    }
    return y;
};

function jumpItems(key) {
    if (key.length) {
        var item = document.getElementById("_" + key);
        setTimeout(function() {
            window.scroll(0, getOffsetTop(item));
        }, 0);
    };
};


function saveScrollTop() {
    Android.saveScrollTop(document.body.scrollTop);
};

function scrollTo(offset) {
    if (offset > 0) {
        setTimeout(function() {
        	window.scroll(0, offset);
	}, 0);
    }
};


function copyHtml() {
    try {
        Android.copyHtml('<html>' +
            document.getElementsByTagName('html')[0].innerHTML + '</html>');
    } catch(e) {
        Android.showToast("抱歉，未能保存数据");
    }
};
