﻿function getPhotos(uid, plid) {
    $.ajax({
        url: 'gPhotoList.asmx/getpl?uid=' + uid + '&plid=' + plid,
        type: 'GET',
        dataType: 'xml',
        timeout: 20000,
        error: function() {
            alert('Error loading XML document');
        },
        success: function(xml) {
            // do something with xml
            $("#photodesc")[0].innerHTML = xml.getElementsByTagName("photolist")[0].attributes[0].nodeValue;
            var pl = $("#Photos");
            pl[0].innerHTML = "";
            var pll = xml.getElementsByTagName("photo");
            for (var i = 0; i < pll.length; i++) {
                var im = document.createElement("img");
                var aa = document.createElement("a");
                im.src = pll[i].attributes[0].nodeValue;
                aa.href = pll[i].attributes[0].nodeValue;
                aa.appendChild(im);
                pl[0].appendChild(aa);
            }
            pl.find("a").lightBox();
            imgAutoSize("#Photos", 480);
        }
    });
}

function imgAutoSize(imgObj, w, h, isCenter) {
    if (typeof (imgObj) == 'string') {
        imgObj = $(imgObj);
        if (imgObj.find("img").length > 0)
            imgObj = imgObj.find("img");
    }
    imgObj.each(function() {
        if (w && h) {
            if (this.width / w > this.height / h) {
                this.height = this.height * w / this.width;
                this.width = w;
                if (isCenter == true) this.style.paddingTop = (h - this.height) / 2 + "px";
            } else {
                this.width = this.width * h / this.height;
                this.height = h;
                if (isCenter == true) this.style.paddingLeft = (w - this.width) / 2 + "px";
            }
            return;
        }
        if (w) {
            if (this.width > w) {
                this.height = this.height * w / this.width;
                this.width = w;
            }
        }
        if (h) {
            if (this.width > h) {
                this.width = this.width * h / this.height;
                this.height = h;
            }
        }
    });
}

$(document).ready(
    function() {
        if ($("#plist span").length > 0) {
            $("#plist span:first").trigger('click');
        }
        $("#hjjsdv a").lightBox();
        //alert($('#plist').find("div"))
        $('#plist').setScroll(
        { img: 'images/tb/sBack.jpg', width: 11 }, //background-image and width
        {img: 'images/tb/sTop.jpg', height: 10 }, //up
        {img: 'images/tb/sTop.jpg', height: 10 }, //down
        {img: 'images/tb/sBar.jpg', height: 81}//bar
        );
        //$(".menu").html("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0'" +
        //" width='950' height='435'><param name='allowScriptAccess' value='sameDomain'><param name='movie' value='images/qs/top.swf'><param name='quality' value='high'>" +
        //"<param name='menu' value='false'><param name=wmode value='transparent'>" +
        //"<embed src='images/qs/top.swf' wmode='transparent' menu='false' quality='high' width='950' height='435' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>");
        var topstr = "<div class='t1'><div class='bulletin1'><div class='B2'>公告</div>" + $(".bulletin").html() + "</div><div class='cdetail1'>" + $(".cdetail").html() + "</div></div>";
        topstr = topstr + "<div class='t2'><h3>快讯</h3>" + $("#kx .condetail").html() + "</div>";
        topstr = topstr + "<div class='t3' id='t3'></div>";
        $("#flash").html(topstr);
        $("#loginin")[0].value = "登录";
        $("#reg")[0].value = "注册";
        $("#newprice").html("<div class='newPt'></div><div class='newPhoto'>" + $("#newphoto").html() + "</div>");
        $("#newprice marquee a").lightBox();
        $("#desc .condetail").css({ "padding": "10px", "text-indent": "2em", "height": "220px" });
        $("#kx .condetail").html($("#Ticket .condetail").html());
        $("#desc .jj").html("<div></div>");
        $("#dlwz .dlwz").html("<div></div>");
        $("#kx .kx").html("<div></div>");
        $("#hjjs .wjjs").html("<div></div>");
        var mach = /\((\d+),\s?(\d+)\)/.exec($("#plist span:last").attr("onclick"));
        if (mach) {
            $.ajax({
                url: 'gPhotoList.asmx/getpl?uid=' + mach[1] + '&plid=' + mach[2],
                type: 'GET',
                dataType: 'xml',
                timeout: 20000,
                error: function() {
                    alert('Error loading XML document');
                },
                success: function(xml) {
                    // do something with xml
                    var pll = xml.getElementsByTagName("photo");
                    if (pll.length > 0) {
                        $("#t3").html("<img src='" + pll[0].attributes[0].nodeValue + "' />");
                        if (pll.length > 1) {
                            var j = pll.length, i = 0;
                            setInterval(function() { i == (j - 1) ? i = 0 : i++; $("#t3").html("<img src='" + pll[i].attributes[0].nodeValue + "' />"); }, 2000);
                        }
                    }
                }
            });
        }
    });
