﻿var dif = 1, fif = 82;
var w = 0, h = 0;
$(document).ready(function () {
    resizeWindow();
});

$(window).resize(function () { resizeWindow(); });

function resizeWindow() {
    $(".mask").css("height", (document.documentElement.clientHeight - dif) + "px");
    $(".box").css("width", "100%");
    $(".prolist").css("left", "0px");

    setTimeout(function () {
        w = getWidth();
        h = getHeight();
        $(".mask").css("height", (h - dif) + "px");
        $(".prolist").css("left", "0px");

        if (w > 1024) {
            $(document.body).css("background-position", "center " + dif + "px");
        }
        else {
            $(document.body).css("background-position", "0px " + dif + "px");
        }

        if ($(".box").size() > 0) {
            var boxH = h - dif - fif;
            if (boxH > 600) {
                $(".box").css("top", (Math.floor((boxH - 600) / 2) + dif) + "px");
            }
            else {
                $(".box").css("top", dif + "px");
            }
            if (w > $(".box").get(0).offsetWidth) {
                $(".box").css("width", "1024px");
                $(".pro").css("left", "25px");
            }
            else {
                $(".box").css("width", "100%");
                $(".pro").css("left", Math.floor((w - 974) / 2) + "px");
            }
        }

        if (document.documentElement.clientWidth > 1024) {
            $(".prolist").css("left", Math.floor((w - 1024) / 2) + "px");
        }
        else {
            $(".prolist").css("left", "0px");
        }
        if (h > 600 + dif) {
            $(".prolist").css("top", (h - 82) + "px");
        }
        else {
            $(".prolist").css("top", (600 + dif) + "px");
        }
    }, 0);

}

function getWidth() {
    return (document.documentElement.clientWidth > document.documentElement.scrollWidth ? document.documentElement.clientWidth : document.documentElement.scrollWidth);
}
function getHeight() {
    return (document.documentElement.clientHeight > document.documentElement.scrollHeight ? document.documentElement.clientHeight : document.documentElement.scrollHeight);
}

///view news
function view(obj, id) {
    //obj.blur();
    $(".desc > h3").html(obj.innerHTML);

      $.get("data/news.ashx?id=" + id, { t: new Date().getTime() }, function(data)
        {
            $(".desc > .text").html(data);
            $(".desc").show();
            $(".con").hide();
            $("#NewsPager").hide();
        });
}
function closeView() {
    $(".desc").hide();
    $(".desc > h3").html("");
    $(".desc > .text").html("");
    $(".con").show();
    $("#NewsPager").show()
}

///view product
function getPhoto(v) {
    $.get("data/products.ashx?class=" + escape(type) + "&page=" + page, function (data) {
        if ($(".proli li").size() > 2) {
            $(".proli li").slice(1, $(".proli li").size() - 1).remove();
            $(".proli li").eq(0).after(data);

            if ($(".proli li").size() > 2) { 
                if (v == 1) {
                    $(".proli li").eq(1).attr("class", "ac");
                }
                else {
                    $(".proli li").eq($(".proli li").size() - 2).attr("class", "ac");
                }

                if (document.all) {
                    $(".ac").get(0).click();
                }
                else {
                    var evt = document.createEvent("MouseEvents");
                    evt.initEvent("click", true, true);
                    $(".ac").get(0).dispatchEvent(evt);
                }
            }
        }
    });
}
function change(v) {
    var cur = -1;
    if (v == 1) {
        $(".proli li").each(function (i) {
            if ($(this).attr("class") == "ac") {
                if (i < $(".proli li").size() - 2 && cur == -1) {
                    $(this).removeAttr("class");
                    $(".left").show();
                    cur = i + 1;

                    if (page * pageSize + cur == photoCount) {
                        $(".right").hide();
                    }
                }
                else if (cur == -1) {
                    page++;
                    getPhoto(1);
                }
            }
        });
    }
    else {
        $(".proli li").each(function (i) {
            if ($(this).attr("class") == "ac") {
                if (i > 1 && cur == -1) {
                    $(this).removeAttr("class");
                    $(".right").show();
                    cur = i - 1;

                    if (page == 0 && cur == 1) {
                        $(".left").hide();
                    }
                }
                else if (cur == -1) {
                    page--;
                    getPhoto(-1);
                }
            }
        });
    }
    
    pageInit();

    if (cur != -1) {
        $(".proli li").eq(cur).attr("class", "ac");

        if (document.all) {
            $(".ac").get(0).click();
        }
        else {
            var evt = document.createEvent("MouseEvents");
            evt.initEvent("click", true, true);
            $(".ac").get(0).dispatchEvent(evt);
        }
    }
}
function pageInit() {
    if (page == 0) {
        $(".backword").css("visibility", "hidden");
    }
    else if (page > 0) {
        $(".backword").css("visibility", "visible");
    }
    if (page + 1 == pageLen) {
        $(".forword").css("visibility", "hidden");
    }
    else {
        $(".forword").css("visibility", "visible");
    }
}
function viewPhoto(obj, url) {
    $(".proli > .ac").removeAttr("class");
    $(obj).attr("class", "ac");
    $("#ProPhoto").attr("src", "http://www.hzbridal.com/pic/" + url);

    $(".proli li").each(function (i) {
        if ($(this).attr("class") == "ac") {
            cur = i;

            if (page == 0 && cur == 1) {
                $(".left").hide();
            }
            else {
                $(".left").show();
            }
            if (page * pageSize + cur == photoCount) {
                $(".right").hide();
            }
            else {
                $(".right").show();
            }
        }
    });
}

//view menu
function menu(v) {
    if (v == 1) {
        $(".category").show();
    }
    else {
        $(".category").hide();
    }
}

