﻿var iUi = null;
var isShowComm = false;
// JavaScript Document
//====================================
//功能：页面框架
//日期：2009年8月11日
//====================================
function iPowUi() {
    this.developer = "深圳市互动力科技有限公司（http://www.ipow.cn）";
}
iPowUi.prototype = {
    iInit: function (index) {
        jQuery("html,body").animate({ scrollTop: 278 }, 1);
        if (index == undefined) {
            index = 1;
        }
        this.iItem(index);
        this.iLookComm();
    },
    iRoll: function (index) {
        $("#itemListInfo").iRoll({ start: index });

    },
    iItem: function (index) {
        $('#itemListInfo').lavaLamp({
            speed: 200
        });

    },
    iLookComm: function () {
        var _this = this;
        $("#lookCommInfo")
		.unbind()
		.click(function () {
		    isShowComm = true;
		    var _self = this;
		    $("#commContainer").animate({ marginLeft: 0 }, 300, "easeInOutExpo", function () {
		        $("input[name='raSex']").cssradio({ val: "GG", name: "raSex" });
		        //显示评论面板
		        $("#submitComm")
				.unbind()
				.click(function () {
				    $("#showAddComm").show();
				});
		        //关闭评论面板
		        $("#btnCloseAddC")
				.unbind()
				.click(function () {
				    $("#showAddComm").hide();
				});
		        $("#btnResetComm")
				.unbind()
				.click(function () {
				    _this.iClearComm();
				    $("#txtUserName").focus();
				});
		        $("#txtCommContent")
				.unbind()
				.click(function () {
				    clearDefaultText(this, '请输入您的评论内容');
				});

		        $(_self).text("隐藏评论");
		        _this.iHideComm();
		    });
		})
    },
    iHideComm: function () {
        var _this = this;
        $("#lookCommInfo")
		.unbind()
		.click(function () {
		    isShowComm = false;
		    $("#showAddComm").hide()
		    var _self = this;
		    $("#commContainer").animate({ marginLeft: 671 }, 300, "easeInOutExpo", function () {
		        $(_self).text("查看评论");
		        _this.iLookComm();
		    });
		})
    },
    iLoadComm: function (page, itemid) {
        var _this = this;
        var _url = '/admin/playitemmanage/commajax.aspx?type=getItemComm&itemId=' + itemid + '&pageIndex=' + page + '&pageSize=5&temp' + Math.random();
        $.getJSON(_url, function (ResultObj) {
            _this.pageUi(page, ResultObj.PageTotal, itemid);
            var _commContent = '<ul>'
            var i = parseInt(page - 1) * 5 + 1;
            $.map(ResultObj.List, function (commjson) {
                _commContent += '<li><span class="commTopbg"></span><span class="commInfo">\
        <dl><dt><strong>来自' + commjson.VisitorAddress + '的' + commjson.VisitorName + '</strong><em>发布于：' + commjson.VisitorData + '</em><ins>' + i + '楼</ins></dt>\<dd>' + commjson.Content + '</dd></dl></span><span class="commBottombg"></span></li>';
                i++;
            });
            _commContent += '</ul>';
            $("#commContainer2").html(_commContent);
        })
    },
    pageUi: function (pcurrent, totalPages, itemid) {
        var _this = this;
        var _pagehtml = UiPage(pcurrent, totalPages);
        $("#commPages").html(_pagehtml);
        $("#commPages a")
		.unbind()
		.click(function () {
		    var aText = $(this).text();
		    var pagecurrent = pcurrent;
		    switch (aText) {
		        case "上一页":
		            pagecurrent = parseInt(pagecurrent - 1);
		            _this.iLoadComm(pagecurrent, itemid);
		            break;
		        case "下一页":
		            pagecurrent = parseInt(pagecurrent + 1);
		            _this.iLoadComm(pagecurrent, itemid);
		            break;
		        default:
		            _this.iLoadComm(parseInt($(this).text()), itemid);
		            break;
		    }
		})
    },
    iGetCount: function (itemid, type) {
        var _this = this;
        var _url = "";
        switch (type) {
            case 1:      //获取数据
                _url = '/admin/playitemmanage/commajax.aspx?type=getItemInfo&itemId=' + itemid + '&temp' + Math.random();
                $.getJSON(_url, function (result) {
                    $("#PlayCount").text(result.played);
                    $("#WantCount").text(result.wantPlay);
                });
                break;
            case 2:     //我想去
                _url = '/admin/playitemmanage/commajax.aspx?type=setWant&itemId=' + itemid + '&temp' + Math.random();
                $.getJSON(_url, function (result) {
                    if (result.Status == "OK") {
                        var _wants = $("#WantCount").text()
                        $("#WantCount").text(parseInt(_wants) + 1);
                    }
                    else {
                        alert("您已经点击过了：）");
                    }
                });
                break;
            case 3:     //我玩过
                _url = '/admin/playitemmanage/commajax.aspx?type=setPlay&itemId=' + itemid + '&temp' + Math.random();
                $.getJSON(_url, function (result) {
                    if (result.Status == "OK") {
                        var _play = $("#PlayCount").text()
                        $("#PlayCount").text(parseInt(_play) + 1);
                    }
                    else {
                        alert("您已经点击过了：）");
                    }
                });
                break;
            default:
                break;
        }
    },
    iAddComm: function (itemid) {
        var _username = $("#txtUserName").val().trim();
        var _sex = $("input[name='raSex']:checked").val().trim();
        var _from = $("#txtFrom").val().trim();
        var _commcontent = $("#txtCommContent").val().replace('请输入您的评论内容', '').trim();
        var _this = this;
        if (_username == "") {
            alert("请输入您的昵称：）");
            $("#txtUserName").focus();
            return false;
        }
        if (_from == "") {
            alert("请输入您来自哪里？\n不知道就写火星：）");
            $("#txtFrom").focus();
            return false;
        }
        if (_commcontent == "") {
            alert("请留下您的评论内容：）");
            $("#txtCommContent").focus();
            return false;
        }
        $.ajax({
            type: "POST",
            url: "/admin/playitemmanage/commajax.aspx?type=addComm",
            //contentType: "application/x-www-form-urlencoded; charset=UTF-8",
            data: 'itemId=' + itemid + '&content=' + _commcontent + '&sex=' + _sex + '&from=' + _from + '&userName=' + _username + '',
            dataType: "string",
            success: function (result) {
                if (result == "1") {
                    _this.iLoadComm(1, itemid);
                    $("#showAddComm").hide();
                } else {
                    alert("服务器繁忙，请稍后再试！");
                }
            }
        });
    },
    iRollComm: function (itemid) {
        var _html = "";
        var _url = '/admin/playitemmanage/commajax.aspx?type=getItemComm&itemId=' + itemid + '&pageIndex=1&pageSize=10&temp' + Math.random();
        $.getJSON(_url, function (ResultObj) {
            var _commContent = ''
            $.map(ResultObj.List, function (commjson) {
                _commContent += commjson.VisitorName + ":" + commjson.Content + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
            });
            $("#rollComm").html('<marquee scrollAmount="3" style="width:640px;">' + _commContent + '</marquee>');
        })
    },
    iClearComm: function () {
        $("#txtUserName").val("");
        $("#txtFrom").val("");
        $("#txtCommContent").val("");
    }
}

jQuery.extend(jQuery.easing,
{
    easeInOutExpo: function (x, t, b, c, d) {
        if (t == 0) return b;
        if (t == d) return b + c;
        if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
        return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
    },
    easeInSine: function (x, t, b, c, d) {
        return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
    },
    easeInCirc: function (x, t, b, c, d) {
        return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
    }
});

/*======================================================
功能：鼠标经过滑动效果
时间：2010年1月4日
========================================================*/
(function (jQuery) {
    jQuery.fn.lavaLamp = function (o) {
        o = jQuery.extend({ fx: 'easeInSine',
            speed: 300,
            startItem: 'no',
            setOnClick: true
        },
					o || {});

        return this.each(function () {
            var _this = this;
            var path = location.pathname + location.search + location.hash;
            var $selected = new Object;
            var delayTimer;
            var $back;
            var ce; //current_element


            var $li = jQuery('ul li[class!=noItem]', this);
            var _length = jQuery('ul li', this).size();
            var _index = 0;
            var _hash = location.hash;
            var _isHave = jQuery("#itemContainer li[rel='" + _hash + "']").length;
            var _itemID = 0;
            var _dt = 0;
            if (o.startItem == 'no' && _hash != "" && _isHave > 0) {
                var _name = "";
                $selected = jQuery('ul li a[href$="' + _hash + '"]', this).parent('li');
                _itemID = $($selected).attr("rel");
                _index = (jQuery('ul li', this).index($selected));
                _name = _hash
                o.startItem = _index;
                moveItemPhoto(_name);
                _dt = 0;
            }
            else {
                o.startItem = iArea.index;
                _index = iArea.index;
                _itemID = jQuery('ul li:eq(' + _index + ')', this).attr("rel");
                moveItemPhoto(iArea.name);
                _dt = 1;
            }
            var _dtCount = (5 - _length + _index);
            _index = _dtCount < 1 ? _index - 1 : _index - _dtCount;

            iUi.iRoll(_index - _dt);

            var current = o.startItem;
            if ($selected.length == 0 && o.startItem == 'no')
                $selected = jQuery('ul li a[href$="' + location.pathname.substring(location.pathname.lastIndexOf('/') + 1) + location.search + location.hash + '"]', this).parent('li');
            if ($selected.length == 0 || o.startItem != 'no') {
                if (o.startItem == 'no') o.startItem = 0;
                $selected = jQuery($li[o.startItem]);
            }
            ce = jQuery('ul li.selectedItem', this)[0] || jQuery($selected).addClass('selectedItem')[0];
            $back = jQuery('<ins class="backLava"></ins>').appendTo(this);
            $back.css("margin-top", parseInt(current - _length) * 101 + "px");
            $li.click(function (e) {
                jQuery(ce).removeClass('selectedItem');
                ce = this;
                current = jQuery('ul li', _this).index(ce);
                if (isShowComm) {
                    $("#commContainer").animate({ marginLeft: 671 }, 300, "easeInOutExpo", function () {
                        $("#lookCommInfo")
						.text("查看评论")
						.click(function () {
						    isShowComm = true;
						    var _self = this;
						    $("#commContainer").animate({ marginLeft: 0 }, 300, "easeInOutExpo", function () {
						        $(_self).text("隐藏评论");
						        iUi.iHideComm();
						    });
						});
                    });
                }
                if (jQuery('a', this).html() != null) {
                    var _href = jQuery('a', ce).attr("href");
                    move(current, ce, _href);
                }
                _itemID = $(ce).attr("rel");
            });

            function move(index, obj, href) {
                var _top = parseInt(index - _length) * 101;
                $back.stop()
			.animate({
			    marginTop: _top
			}, o.speed, o.fx, function () {
			    jQuery(obj).addClass('selectedItem');
			    moveItemPhoto(href);
			});
            };
            function moveItemPhoto(href) {
                var _moveObj = $("#itemContainer");
                var moveIndex = jQuery("ul li[rel='" + href + "']", _moveObj);
                moveIndex = jQuery("ul li", _moveObj).index(moveIndex)
                moveItem(moveIndex);
            }
            function moveItem(index) {
                var _ulTop = parseInt(index * 313);
                var _introTop = parseInt(index * 84)
                jQuery("#itemContainer ul").animate({ marginTop: -_ulTop }, 200, "easeInOutExpo", function () {
                    jQuery("#itemIntroInfo").css("margin-top", -_introTop + "px");
                    iUi.iRollComm(_itemID);
                    //获取数据
                    iUi.iGetCount(_itemID, 1);
                    $("#btnWant")
				.unbind()
				.click(function () {
				    iUi.iGetCount(_itemID, 2);
				});
                    $("#btnPlayed")
				.unbind()
				.click(function () {
				    iUi.iGetCount(_itemID, 3);
				});
                    //提交评论
                    $("#opAddComm")
				.unbind()
				.click(function () {
				    iUi.iAddComm(_itemID)
				});
                    //加载项目评论
                    iUi.iLoadComm(1, _itemID);
                });
            };
        });
    };
})(jQuery);


/*======================================================
功能：图片上线滚动
时间：2010年1月4日
========================================================*/
$.fn.iRoll = function (parameters) {
    parameters = $.extend({
        btnPrev: "#rollTop",
        btnNext: "#rollBottom",
        speed: 200,
        easing: "easeInOutExpo",
        visible: 4,
        start: 0,
        scroll: 1,
        beforeStart: null,
        afterEnd: null,
        height: 101
    }, parameters || {});
    return this.each(function () {
        var running = false;
        var _marginTop = 0;
        var div = $(this), tItem = $("#itemListInfo ul"), tA = $("#itemListInfo ul li"), sL = parameters.visible;
        var itemLength = tA.size(), curr = parameters.start;
        var divSize = parameters.height * parameters.visible, spanSize = parameters.height * itemLength;
        var _height = document.getElementById("ulListInfo").scrollHeight > document.getElementById("ulListInfo").offsetHeight ? document.getElementById("ulListInfo").scrollHeight : document.getElementById("ulListInfo").offsetHeight;
        var _unit = parseFloat(parseInt(_height - 402) / parseInt(445 - 49));
        if (_height <= 402) {
            $("#rollTool").hide();
            return false;
        }
        else {
            $("#rollTool").show();
        }
        var _runH = 445 - 49;
        var _runit = parseFloat(402 / (6 * _unit));

        if (parameters.btnPrev)
            $(parameters.btnPrev).click(function () {
                return goRoll(curr - parameters.scroll);
            });
        if (parameters.btnNext)
            $(parameters.btnNext).click(function () {
                return goRoll(curr + parameters.scroll);
            });
        function vis() {
            return tA.slice(curr).slice(0, parameters.visible);
        };
        if (parameters.start > 0) {
            curr = parameters.start;
            goRoll(curr + parameters.scroll);
        }
        if (curr == 0) {
            $(parameters.btnPrev).css("background-position", "left -30px");
        }
        function goRoll(to) {
            if (!running) {
                if (parameters.beforeStart)
                    parameters.beforeStart.call(this, vis());
                if (to < 0 || to > itemLength - parameters.visible) return;
                else curr = to;
                running = true;
                tItem.animate(
                    { marginTop: -(curr * parameters.height) }, parameters.speed, parameters.easing,
                    function () {
                        _marginTop = curr * 101 / _unit;
                        $("#scrSlide").animate({ marginTop: _marginTop }, 100, "easeInCirc");
                        if (parameters.afterEnd)
                            parameters.afterEnd.call(this, vis());
                        running = false;
                        iuint();
                    }
                );

            }
            return false;
        };
        function iuint() {
            $(parameters.btnPrev).css("background-position", "left top");
            $(parameters.btnNext).css("background-position", "left -30px");
            $(curr - parameters.scroll < 0 && parameters.btnPrev).css("background-position", "left -30px");
            $(curr + parameters.scroll > itemLength - parameters.visible && parameters.btnNext).css("background-position", "left top");
        }
        if ($.browser.msie) { document.execCommand("BackgroundImageCache", false, true); }
        $("#scrSlide").bind("mousedown", function (e) {
            var selef = this;
            var pageY = e.pageY, mt = parseInt($(this).css("margin-top"));
            $(document).mousemove(function (e2) {
                _marginTop = parseInt(mt + e2.pageY - pageY);
                setData();
            });
            $(document).mouseup(function () {
                $(document).unbind();
            });
            return false;
        });
        function setData() {
            if (_marginTop < _runH && _marginTop > 0)
                _marginTop = _marginTop;
            else if (_marginTop > _runH)
                _marginTop = _runH;
            else if (_marginTop < 0)
                _marginTop = 0;
            $("#scrSlide").css("margin-top", "" + _marginTop + "px");
            var _scrollCH = parseInt(_unit * _marginTop);
            $("#ulListInfo").css("margin-top", "-" + _scrollCH + "px");
            curr = Math.ceil(_scrollCH / 101);
            iuint();
        }



    });
};

/*======================================================
功能：竖向滑动条
时间：2010年1月4日
========================================================*/
jQuery.fn.Slider = function (ssettings) {
    ssettings = jQuery.extend({
        scrollh: 445,
        sliderh: 49,
        height: 402,
        scrContent: "ulListInfo"
    }, ssettings);
    return this.each(function () {
        var _self = this;
        var rtime, _marginTop = 0;
        var scrContent = ssettings.scrContent;
        var _selfId = $(this).attr("id");
        var _height = document.getElementById("" + scrContent + "").scrollHeight > document.getElementById("" + scrContent + "").offsetHeight ? document.getElementById("" + scrContent + "").scrollHeight : document.getElementById("" + scrContent + "").offsetHeight;
        var _unit = parseFloat(parseInt(_height - ssettings.height) / parseInt(ssettings.scrollh - ssettings.sliderh));
        if (_height <= ssettings.height) {
            $(_self).hide();
            return false;
        }
        else {
            $(_self).show();
        }
        var _runH = ssettings.scrollh - ssettings.sliderh;
        var _runit = parseFloat(ssettings.height / (6 * _unit));
        if ($.browser.msie) { document.execCommand("BackgroundImageCache", false, true); }
        $("#scrSlide").bind("mousedown", function (e) {
            var selef = this;
            var pageY = e.pageY, mt = parseInt($(this).css("margin-top"));
            $(document).mousemove(function (e2) {
                _marginTop = parseInt(mt + e2.pageY - pageY);
                setData();
            });
            $(document).mouseup(function () {
                $(document).unbind();
            });
            return false;
        });
        function setData() {
            if (_marginTop < _runH && _marginTop > 0)
                _marginTop = _marginTop;
            else if (_marginTop > _runH)
                _marginTop = _runH;
            else if (_marginTop < 0)
                _marginTop = 0;
            $("#scrSlide").css("margin-top", "" + _marginTop + "px");
            var _scrollCH = parseInt(_unit * _marginTop);
            $("#" + scrContent + "").css("margin-top", "-" + _scrollCH + "px");
        }
    })
}

//radio样式美化，val为单前RADIO的值，name为RADIO的name属性
jQuery.fn.cssradio = function (vpr) {
    vpr = jQuery.extend({
        val: null,
        name: "",
        over: "lblRadio2",
        out: "lblRadio1"
    }, vpr);
    return this.each(function () {
        var _this = $(this);
        if (vpr.val == _this.val()) {
            _this.next().attr("class", vpr.over);
            _this.attr("checked", "checked");
        }
        _this.next().click(function () {
            $("input[name='" + vpr.name + "']").next().attr("class", vpr.out);
            _this.next().attr("class", vpr.over);
            _this.attr("checked", "checked");
        })
    })
}

//插入FLASH
function insertFlash(ur, w, h, id) {
    var fHtml = '';
    fHtml += '<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="' + id + '" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" border="0" width="' + w + '" height="' + h + '">';
    fHtml += '<param name="movie" value="' + ur + '">';
    fHtml += '<param name="quality" value="high"> ';
    fHtml += '<param name="wmode" value="transparent">';
    fHtml += '<param name="menu" value="false">';
    fHtml += '<embed src="' + ur + '" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="' + id + '" width="' + w + '" height="' + h + '" quality="High" wmode="transparent">';
    fHtml += '</embed>';
    fHtml += '</object>';
    return fHtml;
}
function openMap(op) {
    var _width = 20;
    var _height = 20;
    if (op == "open") {
        _width = 822;
        _height = 466;
    }
    else {
        _width = 1;
        _height = 1;
    }
    $("#mapGuideCon").animate({
        width: _width + "px",
        height: _height + "px"
    }, 300, "easeInOutExpo", function () {
        if (op == "open") {
            if ($("#mapGuideCon").html() == "") {
                var mapFlash = insertFlash("/flash/playguide.swf", "100%", "100%", "mapGuideFlashG");
                var btnFlash = insertFlash("/flash/btnLookMap.swf", "100%", "100%", "btnFlashMap");
                mapFlash = '<div id="mapConF">' + mapFlash + '</div><div id="lookBigMp"><span>' + btnFlash + '</span></div>';
                $("#mapGuideCon").html(mapFlash);
            }
        }
    });
}

//分页UI
function UiPage(pcurrent, totalPages) {
    var _pagehtml = "";
    if (pcurrent < 1) {
        pcurrent = 1;
    }
    if (pcurrent > totalPages) {
        pcurrent = totalPages;
    }
    if (pcurrent <= 1) {
    }
    else {
        _pagehtml = '<a href="javascript:;" class="prev" id="turnPrev">上一页</a>' + _pagehtml;
    }
    var i;
    if (pcurrent <= 10 && totalPages <= 10) {
        for (i = 1; i <= totalPages; i++) {
            if (i == pcurrent) {
                _pagehtml = "    <span>" + i + "</span>" + _pagehtml;
            }
            else {
                _pagehtml = '<a href="javascript:;" id="bookpage' + i + '">' + i + '</a>' + _pagehtml;
            }
        }
    }
    else if (totalPages >= 10 && pcurrent <= 5) {
        for (i = 1; i <= 10; i++) {
            if (i == pcurrent) {
                _pagehtml = "    <span>" + i + "</span>" + _pagehtml;
            }
            else {
                _pagehtml = '<a href="javascript:;" id="bookpage' + i + '">' + i + ' </a>' + _pagehtml;
            }
        }
    }
    else if ((pcurrent + 5) <= totalPages) {
        for (i = (pcurrent - 4); i <= (pcurrent + 5); i++) {
            if (i == pcurrent) {
                _pagehtml = "    <span>" + i + "</span>" + _pagehtml;
            }
            else {
                _pagehtml = '<a href="javascript:;" id="bookpage' + i + '">' + i + ' </a>' + _pagehtml;
            }
        }
    }
    else {
        for (i = (pcurrent - 4); i <= totalPages; i++) {
            if (i == pcurrent) {
                _pagehtml = "    <span>" + i + "</span>" + _pagehtml;
            }
            else {
                _pagehtml = '<a href="javascript:;" id="bookpage' + i + '">' + i + ' </a>' + _pagehtml;
            }
        }
    }
    if (pcurrent >= totalPages) {
    }
    else {
        _pagehtml = '<a href="javascript:;" class="next" id="turnNext">下一页</a>' + _pagehtml;
    }
    return _pagehtml;
}
function clearDefaultText(el, message) {
    var obj = el;
    if (typeof (el) == "string")
        obj = document.getElementById(id);
    if (obj.value == message) {
        obj.value = "";
    }
    obj.onblur = function () {
        if (obj.value == "") {
            obj.value = message;
        }
    }
}
function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window["" + movieName + ""];
    } else {
        return document["" + movieName + ""];
    }
}

function showMap() {
    if (location.hash == "#show") {
        openMap("open");
        thisMovie("mapGuideFlash").callbackmap("show");
    }
    else {
        thisMovie("mapGuideFlash").callbackmap("hide");
    }
}
