﻿ <!--
        var homepageSid;
        var homepage = true;
        var homepagevs = null;
        var prefix = "#minyi_PageContent_";
        var showed = false;
      
        function countVote()
        {
            var lastid = currentId;
            $.ajax({
                action: "countvote",
                url: "WebSvc/SurveySvc.asmx/gtv",
                data: "{sid:'" + currentId + "'}",
                success: function(data)
                {
                    if (lastid == currentId)
                    {
                        $("#voteCount").html(data.d);
                        $("#slides b[sid=" + currentId + "]").data("s").TotalVotes = data.d;
                    }
                },
                error: function(xhr)
                {
                    // do nothing
                }
            });
        }



        function addBookmark(title, url)
        {
            if (document.all)
            {
                window.external.AddFavorite(url, title);
            }
            else if (window.sidebar)
            {                
                window.sidebar.addPanel(title, url, "");
            }
            else if (window.opera && window.print)
            {
                return true;
            }
        }

        var surveyIds = new Array();
        var currentId = null;
        var autoPlay = true; // if allow auto play
        
        var playIntervalId = 0;
        var curPos = 0;
        function initAutoplay()
        {        
            playIntervalId = setInterval("slideShow()", 6666);
        }

        function startAutoplay()
        {
            autoPlay = true;
        }

        function pauseAutoplay()
        {
            autoPlay = false;         
        }
        
        function slideShow()
        {
            if (autoPlay)
            {
                curPos = (curPos + 1) % surveyIds.length;
                changeSlide(surveyIds[curPos]);
            }
        }
                        

        function getHomePageIds()
        {
            $.ajax({
                action: "gethomepageids",
                url: "WebSvc/SurveySvc.asmx/ghids",
                data: "{}",
                success: function(data)
                {
                    for (i = 0; i < data.d.length; i++)
                    {
                        surveyIds.push(data.d[i]);
                    }
                    //by default show the top one
                    var firstItem=surveyIds[0];
                    
                    //if there're homepage survey need to display?
                    var homeSid=$(document).getUrlParam("sid");
                    
                    if(homeSid!=null && homeSid!=0)
                    {
                        $("#slideControl").removeClass("pause").addClass("play").attr("title", "自动循环已暂停，点击继续自动循环热门调查");
                        var exist=false;
                        firstItem=homeSid;
                        for(i=0;i<surveyIds.length;i++)
                        {
                            if(surveyIds[i]==homeSid) //the survey is already listed
                            {                                
                                autoPlay=false;                            
                                exist=true;
                                break;
                            }
                        }
                        if(!exist)
                        {
                            surveyIds.push(homeSid);
                            autoPlay=false;                            
                        }
                    }
                    
                    buildSlideBar(surveyIds);
                    changeSlide(firstItem);
                    setInterval("countVote()", 3000);
                    initAutoplay();
                },
                error: function(xhr)
                {
                    // do nothing
                }
            });

        }

        function buildSlideBar(ids)
        {
            html = "";

            for (i = 0; i < ids.length; i++)
            {
                html += "<b sid="+ ids[i]+ ">" + (i + 1) + "</b>";
            }
            $("#slides").html(html);
            $("#slides b").click(function()
            {
                sid = $(this).attr("sid");
                changeSlide(sid);                
            });
        }

        function changeSlide(sid)
        {
            var slideBtn = $("#slides b[sid=" + sid + "]");
            if (currentId == sid)
            {
                //do nothing
            }
            else
            {
                if (slideBtn.data("s") == null)
                {
                    getHomePageSurvey(sid);
                }
                else
                {
                    RenderSurvey(slideBtn.data("s"));
                    currentId = sid;
                }
                slideBtn.addClass("cur");
                $("#slides b[sid!=" + sid + "]").removeClass("cur");
            }
        }
        

        function getHomePageSurvey(sid)
        {
            showLoadingAni();
            $.ajax({
                action: "gethomepagesurvey",
                url: "WebSvc/SurveySvc.asmx/gjs",
                data: "{sid:" + sid + "}",
                success: function(data)
                {
                 $("#slides b[sid=" + sid + "]").data("s", data.d);
                    if(data.d!=null)
                    {                   
                        RenderSurvey(data.d);                    
                    }
                    else
                    {
                        RenderEmptySurvey(sid);
                    }
                    currentId = sid;
                    
                },
                error: function(xhr)
                {
                    // do nothing
                }
            });
        }

        function showLoadingAni()
        {
               
            $("#surveyContent").html("");
            $("#surveyContent").css("background", "url(images/loading.gif) no-repeat");
            $("#surveyContent").css("background-position", "center");
        }
        

        function resetSurveyContent()
        {
            $("#surveyContent").css("background", "none");            
            $("#surveyContent").html("<h1 class=\"homepage\" id=\"surveyTitle\"></h1>" +
            "<div id=\"describe\"></div><div style=\"clear:both\"></div>" +
            "<div id=\"provider\"></div><div id=\"options\"><div class=\"t\" id=\"optionTitle\"></div>" +
            "<div class=\"c\" id=\"optionContent\"></div></div><br>" +
             "<div id=\"numsvoted\" ><img src=\"images/already.gif\" alt=\"已经有\" /><span id=\"voteCount\" class=\"votedCount\"></span><img src=\"images/voted.gif\" alt=\"位用户发表了观点\" /><br><br></div>"
            );            
        }


        $(function()
        {
            $.ajaxSetup({
                type: "post",
                dataType: 'json',
                contentType: "application/json"
            });
            getHomePageIds();
            $("#homepageSurvey").hover(function()
            {
                pauseAutoplay();

            },
            function()
            {
                if ($("#slideControl").hasClass("pause"))
                {
                    startAutoplay();
                }
                else
                {
                    pauseAutoplay();
                }
            });

            $("#slideControl").click(function()
            {
                if ($(this).hasClass("pause"))
                {
                    $(this).removeClass("pause");
                    $(this).addClass("play");
                    $(this).attr("title", "自动循环已暂停，点击继续自动循环热门调查");
                    pauseAutoplay();
                } else
                {
                    $(this).removeClass("play");
                    $(this).addClass("pause");
                    $(this).attr("title", "正在自动循环热门调查，点击暂停");
                    startAutoplay();
                }
            });

            $("#btnrss").click(function()
            {
                if (showed)
                {
                    $("#rsslinks").slideUp();

                    showed = false;
                }
                else
                {
                    $("#rsslinks").show();
                    $("#rsslinks").height(0);
                    $("#rsslinks").animate({ height: 100 });
                    showed = true;
                }
            });
        });

        function RenderSurvey(jsonSurvey)
        {

            resetSurveyContent();
                
            $("#surveyTitle").html(jsonSurvey.Title);
            $("#describe").html(jsonSurvey.Description);
            $("#provider").html(jsonSurvey.Provider);
            $("#optionTitle").html(jsonSurvey.OptionTitle);
            $("#optionContent").html(jsonSurvey.Options);
            $("#voteCount").html(jsonSurvey.TotalVotes);

       

            $("#optionContent a[vs^='o_']").click(function()
            {
                var vs = $(this).attr("vs");
                var $divs = $("a[vs='" + vs + "']").parents(".IssueResult");
                if ($divs.length > 0)
                {
                    $divs.children().filter(".IssueOptions").hide();
                    $divs.append("<div class='Info'><img src=\"images/loading.gif\">提交中...</div>");
                }
                $(this).parent().html("<div class='Info'><img src=\"images/loading.gif\">提交中...</div>");

                vote(vs, $divs, jsonSurvey.ID);
            });  
         }  
         
         function RenderEmptySurvey(sid)
         {
            resetSurveyContent();
            $("#surveyTitle").html("该调查不存在");
            $("#optionTitle").html("对不起，您察看的调查不存在");
            $("#numsvoted").html("");
            
           
         }
    //-->         