﻿// JScript 文件
//----------------------浮动窗口开始--------------------------------
function ShowDetail(obj, htmlContent) {

    var conspan = 0; //插入图片的深度
    var htmlContent = htmlContent;
    var newObj = GetWH($(obj));
    newObj.left = GetLeftOrTop(obj, "left");
    newObj.top = GetLeftOrTop(obj, "top");
    var objImgWH = GetWH($("#imgICO"));

    var objDialogWH = GetWH($("#detail"));
    var left = newObj.left;

    var broderWidth = 1;
    var scrollTop = document.documentElement.scrollTop;
    var autoWidth = 0;
    objDialogWH.top = parseInt(document.documentElement.clientHeight) - (newObj.top - scrollTop) - objDialogWH.h;

    if (objDialogWH.top < 0) {
        objDialogWH.top = newObj.top + objDialogWH.top - 3;
        if (objDialogWH.top < 0) objDialogWH.top = scrollTop;
    } else {
        objDialogWH.top = newObj.top;
    }

    objImgWH.top = newObj.top + -1;

    objDialogWH.left = document.documentElement.clientWidth - left - parseInt(objDialogWH.w) - parseInt($(obj).css("width")) - conspan;
    //alert($(obj).attr("class"));
    if (left > document.documentElement.clientWidth - left - parseInt($(obj).css("width"))) {
        objDialogWH.left = left - objDialogWH.w - objImgWH.w + conspan + broderWidth + 1 + autoWidth - 3;
        objImgWH.left = left - objImgWH.w + conspan + broderWidth * 2 + autoWidth - 3;

        $("#detail").html(htmlContent);
        $("#imgICO").css("background-position", "0 25px");
    } else {
        objImgWH.left = newObj.left + parseInt($(obj).css("width")) - conspan + autoWidth;

        objDialogWH.left = objImgWH.left + objImgWH.w - broderWidth;
        $("#detail").html(htmlContent);
        $("#imgICO").css("background-position", "0 0");
    }
    $("#imgICO").css("left", objImgWH.left + "px");
    $("#imgICO").css("top", objImgWH.top + "px");

    $("#detail").css("left", objDialogWH.left + "px");

    $("#detail").css("top", objDialogWH.top + "px");

    if (objdml == null) {
        ShowDetailHide();
        return false;
    }

    $("#imgICO").show();
    $("#detail").show();
    $("#detail").bgiframe();
    if (objImgWH.top > (objDialogWH.top + objDialogWH.h - objImgWH.h))
        $("#imgICO").hide();
}
function ShowDetailHide() {
    $("#imgICO").hide(); ;
    $("#detail").hide();
}
function GetWH(obj) {
    var objwh = new ObjWH();
    objwh.w = parseInt(obj.css("width"));
    objwh.h = parseInt(obj.css("height"));
    return objwh;
}
function ObjWH() {
    this.top = 0;
    this.left = 0;
    this.w = 0;
    this.h = 0;
}
function GetLeftOrTop(obj, strName) {
    var num = 0;
    do {
        if (strName == "left") {
            num += $(obj).offset().left;
        }
        else {
            num += $(obj).offset().top;
        }

        obj = $(obj).offset().Parent;
    } while (!(obj == null || obj.tagName == "BODY"));

    return num;
}
function Point(iX, iY) {
    this.x = iX;
    this.y = iY;
}
//----------------------浮动窗口结束--------------------------------

function RegisterList() {

}
var objdml = null;
function SetObj(obj) {
    objdml = $(obj).parent();
    objdml = $(objdml).parent();
    setTimeout("ShowProductInfo()", 500);
}
function PushObj() {
    objdml = null;
    ShowDetailHide();
}
function ShowProductInfo() {

    if (objdml == null) {
        return false;
    }
    var obj = objdml;
    var productInfo = new ProductInfo();
    var productObj = "";
    var content = "";
    var imgWidth = 0;
    var imgHeight = 0;
    $($(obj).html()).each(function(i) {
        if ($(this).attr("class") == "Item_Detail") {
            productObj = $(this);
        }
    });

    if (productObj == "")
        return;
    $(productObj.html()).each(function() {
        SetProductInfo($(this), productInfo);
    });

    $("#detail").attr("class", "fc03");
    content = "<img src=\"/Resources/images/ajaxLoading/loading_2.gif\"/>";
    ShowDetail(obj, content);

    $("<img src=\"" + productInfo.ProductPic + "\">").load(function() {
        var img = new Image();
        img.src = productInfo.ProductPic;

        //        if (img.width == "337")//修改为570
        //        {
        //            $("#detail").attr("class", "fc");
        //            imgWidth = 337;
        //            imgHeight = 412;
        //        }
        //        else {
        //            $("#detail").attr("class", "fc02");
        //            imgWidth = 337;
        //            imgHeight = 412;
        //        }
        $("#detail").attr("class", "fc");
        imgWidth = 337;
        content = DetailStr(productInfo);
        ShowDetail(obj, content);

        $("#driftImg").LoadImage(true, imgWidth, 412, "<img src=\"/Resources/images/ajaxLoading/loading_2.gif\"/>");
    });
    $("<img src=\"" + productInfo.ProductPic + "\">").error(function() {
        $("#detail").attr("class", "fc02");
        content = DetailStr(productInfo);
        setTimeout(function() {
            ShowDetail(obj, '<div class="error">加载产生异常</div>');
        }, 1000);

    });
}



function ShowDiv() {
    var s = "";
}
function SetProductInfo(obj, productInfo) {
    switch (obj.attr("class")) {
        case "productid":
            productInfo.ProductCode = obj.html();
            break;
        case "name":
            productInfo.ProductName = obj.html();
            break;
        case "market_price":
            productInfo.ProductPrice = obj.html();
            break;
        case "current_price":
            productInfo.ProductSPrice = obj.html();
            break;
        case "desc":
            productInfo.ProductDesc = obj.html();
            break;
        case "pic":
            productInfo.ProductPic = obj.html();
            break;
    }
}
function ProductInfo() {
    this.ProductPic = "";
    this.ProductCode = "";
    this.ProductName = "";
    this.ProductPrice = "";
    this.ProductVPrice = "";
    this.ProductSPrice = "";
    this.ProductImgUrl = "";
    this.CommentsNumber = "";
    this.ProductDesc = "";
    this.Comments = "";
    this.SalesFlag = "0";
}
function DetailStr(productInfo) {
    var s = "<p align=\"center\" class=\"jJ\"><img src=\"" + productInfo.ProductPic + "\" id=\"driftImg\" class=\"img_l\" /></p>";
    s += "<h5 class=\"sd\">" + productInfo.ProductName + "</h5>";
    s += "<p class=\"jJ01\"><span>产品编号：</span>" + productInfo.ProductCode + "</p>";
    //s += "<p class=\"jJ01 word_basic_price\"><span>原价：</span>￥" + productInfo.ProductPrice + "(元)　</p>";
    s += "<p class=\"jJ01 word_pink\">" + productInfo.ProductSPrice + "(元)</p>";
    if (productInfo.ProductDesc.length != 0)
        s += "<p class=\"jJdesc\">" + productInfo.ProductDesc + "</p>";
    return s;
}
function IsIE() {
    if (isFirefox = navigator.userAgent.indexOf("MSIE") > 0)
        return true;
    return false;
}