﻿function setBoxImgByPID(PID) {
    var obj = $("#showPhoto");
    obj.attr({ style: "" })

    //find the hidden input by ProductID
    var pInput = $("#" + "pic_" + PID.toString());
    //  alert(pInput.attr("id"));
    var srcInput = $("#" + pInput.attr("value"));

    changeImg(srcInput.attr("value"));
    //alert(srcInput.attr("value"));
    $("#currentImg").attr({ value: srcInput.attr("id").replace("pos_", "") });
}
function changeSelectedOrder(position) {
    //  var prev = $("#pArrow");
    //  var next =$("#nArrow");
    var orderN = $("#currentImg").attr("value");
    var count = $("#countNum").attr("value");
    //  alert(orderN);
    if (position == 1) {
        orderN++;
    }
    else if (position == 0) {

        orderN--;

    }
    if (orderN > count)
        orderN = 1;
    if (orderN < 1)
        orderN = count;

    changeImg($("#pos_" + orderN.toString()).attr("value"));
    $("#currentImg").attr({ value: orderN.toString() });

}
function changeImg(val) {
    $("#showPic").empty();
    $("#showPic").append(val);
    $("#bgblack").css("opacity", 0.9);
    //	
    $("#close").click(function() {

        $("#showPhoto").add("#showPic").fadeOut(400);
    });

    $("#showPhoto").css({ "left": ($(window).width() / 2 - 300 > 20 ? $(window).width() / 2 - 300 : 20), "top": document.body.scrollTop + 40 }) 
    //	
    //	function(){
    ////		
    //		$("#showPhoto").css({
    //			
    //			"left":($(window).width()/2-300>20?$(window).width()/2-300:20),
    //			"top":($(window).height()/2-270>30?$(window).height()/2-270:30)
    //		}).add("#showPic").fadeIn(400);
    $("#showPhoto").add("#showPic").fadeIn(400);
    //		
    //		if($(this).parent().hasClass("ls"))

    //			$("#showPic").find("img").css("marginTop","70px");
    //		else if($(this).parent().hasClass("pt"))
    //			$("#showPic").find("img").css("marginTop","0px");
    //	};

    var currentSrc;
    var bMargin;



    $("#showPic").find("img").click(function() {
        $("#next").click();
    });

}
