﻿function _gObj(id) {
    return document.getElementById(id);
}
 function copyToclipboard(ss) {
        window.clipboardData.setData("text", ss);
        alert("地址已经添加到剪贴板");
    }

    function getpos(element) {
        if (arguments.length != 1 || element == null) {
            return null;
        }
        var elmt = element;
        var offsetTop = elmt.offsetTop;
        var offsetLeft = elmt.offsetLeft;
        var offsetWidth = elmt.offsetWidth;
        var offsetHeight = elmt.offsetHeight;
        while (elmt = elmt.offsetParent) {
            // add this judge
            if (elmt.style.position == 'absolute'
            //              || elmt.style.position == 'relative'
                || (elmt.style.overflow != 'visible' && elmt.style.overflow != '')) {
                break;
            }
            offsetTop += elmt.offsetTop;
            offsetLeft += elmt.offsetLeft;
        }
        return { top: offsetTop, left: offsetLeft, right: offsetWidth + offsetLeft, bottom: offsetHeight + offsetTop };
    }

    function imageonmousemove(evnt) {
        var div_picture = getpos(_gObj("div_picture"));
        var div_pictureParent = getpos(_gObj("div_pictureParent"));
        var x = y = 1;
        if (evnt) {
            x = (parseInt(evnt.clientX) - div_picture.left - div_pictureParent.left) * 10000 / _gObj("img_productPicture").width;
            y = (parseInt(evnt.clientY) - div_picture.top - div_pictureParent.top + parseInt(document.body.scrollTop + document.documentElement.scrollTop)) * 10000 / _gObj("img_productPicture").height;
        }
//        if (mark_list[markdata]) {
//            for (var i = 0; i < mark_list[markdata].length; i++) {
//                var obj = mark_list[markdata][i];
//                if (parseInt(obj.width) / 2 + parseInt(obj.x) > x && parseInt(obj.x) - parseInt(obj.width) / 2 < x
//				&& parseInt(obj.height) / 2 + parseInt(obj.y) > y && parseInt(obj.y) - parseInt(obj.height) / 2 < y) {
//                    tagaddborder(i);
//                }
//                else {
//                    tagdelborder(i);
//                }
//            }
//        }
        if (evnt) {
            nx = (parseInt(evnt.clientX) - div_picture.left - div_pictureParent.top) / _gObj("img_productPicture").width;

            if (nx > 0.5) {
                _gObj("img_productPicture").style.cursor = "url(" + "/detail/images/picture/sign_left.gif" + "),hand";
                _gObj("img_productPicture").title = "下一张图片";
            }

            if (nx <= 0.5) {
                _gObj("img_productPicture").style.cursor = "url(" + "/detail/images/picture/sign_right.gif" + "),hand";
                _gObj("img_productPicture").title = "上一张图片";
            }
        }
    }
    function imageonclick(evnt,prevPictureUrl,nextPictureUrl) {
//        if (mark_list[markdata]) {
//            for (var i = 0; i < mark_list[markdata].length; i++) {
//                tagdelborder(i);
//            }
//        }

        var div_picture = getpos(_gObj("div_picture"));
        var div_pictureParent = getpos(_gObj("div_pictureParent"));
        //alert(evnt.clientX);
        //alert(div_picture.left);
        //alert(_gObj("img_productPicture").width);
        var x = 1;
        if (evnt) {
            x = (parseInt(evnt.clientX) - div_picture.left - div_pictureParent.left) / _gObj("img_productPicture").width;
        }

        if (x > 0.5) {
            window.location.href = nextPictureUrl;
        }

        if (x <= 0.5) {
            window.location.href = prevPictureUrl;
        }
        //imageonmousemove(evnt);
    }