﻿
var flash=
{
    curIndex:0,//当前图片索引
    timer:null,//定时器
    delay:2000,
    sumCount:0,     
    
    smallShow:function(index)
    {       
       var li = this.find("smallimg","IMG");
       var o = li[index]?li[index]:li[0];
       for(var i=0;i<li.length;i++)
        {  
            var temp = li[i];
            if(temp==o)
            {
                o.className="curimg";               
                o.style.width="62px";  
                o.style.height="62px";                
                o.parentNode.parentNode.style.padding="20px"; 
            }
            else
            {
                temp.className = "staticimg";
                temp.style.width="40px";  
                temp.style.height="40px"; 
                temp.parentNode.parentNode.style.width="47px";
                temp.parentNode.parentNode.style.padding="0px"; 
            }
        }   
    },   
    show:function(cur_index)
    {         
       var big = this.find("bigimgs","IMG");
       
       for(var i=0;i<big.length;i++)
       {
         if(big[i]==big[cur_index])
         {
            big[cur_index].style.display="block";
            this.curIndex=this.curIndex+1;
         }
         else
         {
            big[i].style.display="none";  
         }
       }       
       this.smallShow(cur_index);
    },
    showPre:function()
    {
        var cur = this.curIndex;        
        if(cur==0)
        {
           cur=this.sumCount;            
        }          
        this.show(cur-1)  
        this.curIndex=cur-1;
        this.start();
    },
    showNext:function()
    {
       var cur =this.curIndex;
       if( cur==this.sumCount-1)
       {
            cur=this.curIndex=-1;            
       }     
      this.show(cur+1);      
      this.start();  
    },
  
    init:function()
    {   
        
        flash.bind();
        flash.addEvent();
        flash.start();
    },
    bind:function()
    {
      this.sumCount=Commend.length;
      var content = new StringBuffer(); 
      for(var i=0;i<this.sumCount;i++)
      {    
         content.append('\<a href="/wo/?id='+Commend[i].ID+'" target="_blank">');
         content.append('\<img class="big" id="'+Commend[i].ID+'" title="'+Commend[i].Name+'" alt="'+Commend[i].Name+'"  src="'+Commend[i].Pic+'" style="display:none"/></a> ');
      }
      $("bigimgs").innerHTML = content;  
      $(Commend[0].ID).style.display = "block";     
    },
    start:function()
    {    
        this.stop();        
        var self=this;        
        self.timer= setInterval( function()
                    { 
                        toIndex = self.curIndex;                       
                        if(toIndex>=self.sumCount)
                        {                        
                            toIndex=0;
                            self.curIndex = 0;
                        } 
                        self.show(toIndex);
                    },self.delay);              
    },
    stop:function()
    {
        clearInterval(this.timer);
    },
    mouseover:function(index)
    {         
       this.show(index);
       this.stop(); 
    },
    mouseout:function(index)
    {             
        if(index==this.sumCount)
        {
            this.curIndex=0;
        }
        this.curIndex = this.curIndex-1;       
        this.start();
    } ,
    addEvent:function()
    {
        var elems = this.find("smallimg","IMG");
        var self = this;
        for(var i=0;i<elems.length;i++)
        {
           (
           function()
           {   var temp = i;
               kg.Event.add(elems[i],"mouseover",function(){self.mouseover(temp);},false);
               kg.Event.add(elems[i],"mouseout",function(){self.mouseout(temp);},false);
           })();
        }
        
        var bigs = this.find("bigimgs","IMG");        
        for(var j=0;j<bigs.length;j++)
        {          
           kg.Event.add(bigs[j],"mouseover",function(){self.stop();},false);
           kg.Event.add(bigs[j],"mouseout",function(){self.start();},false);          
        }
       
        kg.Event.add($("b_pre"),"click",function(){self.showPre();},false);
        kg.Event.add($("b_next"),"click",function(){self.showNext();},false);
        kg.Event.add($("s_pre"),"click",function(){self.showPre();},false);
        kg.Event.add($("s_next"),"click",function(){self.showNext();},false);
        
        kg.Event.add($("like"),"click",function(){
            $('HomeBtnStatistic').src='';
            $('HomeBtnStatistic').src='http://sdn.kugoo.com/link_1253.html?url=http://www.gouwo.com/images/Statistic/StatHomeLikeBtn.gif';
            var cookie = new Cookie();
            cookie.get("gouwo")==null?kg.Blank("user/speedinessreg.aspx?type=0",755,700):homeVote(bigs[self.curIndex].id,elems[self.curIndex].title,1);
            },false);
            
        kg.Event.add($("unlike"),"click",function(){
            $('HomeBtnStatistic').src='';
            $('HomeBtnStatistic').src='http://sdn.kugoo.com/link_1254.html?url=http://www.gouwo.com/images/Statistic/StatHomeUnlikeBtn.gif';
            var cookie = new Cookie();
            cookie.get("gouwo")==null?kg.Blank("user/speedinessreg.aspx?type=1",755,700):homeVote(bigs[self.curIndex].id,elems[self.curIndex].title,0);},false);
        kg.Event.add($("like"),"mouseover",function(){self.stop();},false);
        kg.Event.add($("like"),"mouseout",function(){self.start();},false);
        kg.Event.add($("unlike"),"mouseover",function(){self.stop()},false);
        kg.Event.add($("unlike"),"mouseout",function(){self.start();},false);
    },
    find:function(par,sub)
    {
        return $(par).getElementsByTagName(sub);
    } 
} 
window.onload = flash.init;

function switchTab(obj,num)
{
    $("index_msg").style.display="none";
    for(var i=0;i<6;i++)
    {
       var o = $("area_"+i);
       if(o==obj)
       {
            obj.className="left curarea";
            $("map_"+i).style.display="block";                 
       }
       else
       {
            o.className="left area";
            $("map_"+i).style.display="none";  
       }
    }
  if(num!=0){ GetCommend(num);}
}

function show(o,name)
{    
    var left = kg.Page.getRealLeft(o)-52;
    var top =  kg.Page.getRealTop(o)-105; 
    $("index_msg").style.display="block";
    $("index_msg").innerHTML = $(name).innerHTML;
    $("index_msg").style.top=top+"px";
    $("index_msg").style.left=left+"px";    
}

function GetCommend(num)
{
    var UserInfo = new StringBuffer(); 
    Http.get("MapInfo.aspx?pro="+num,
    function(result)
    {      
          var obj = JSON.parse(result);              
          var cur =1;
          var rand = RandArr(20,6,48);
          for(var row = 0;row<6;row++)
          {
                UserInfo.append('\<div style="width:100%;">');
                for(var col=0;col<8;col++)
                {
                    UserInfo.append('\<div class="index_map">');
                    if(obj.IsSuccess)
                    {    
                        var info = JSON.parse(obj.Error);                    
                        for(var cell=0;cell<info.length;cell++)   
                        {
                            if(cur == rand[[cell]])
                            {
                                UserInfo.append('\<img alt="" id=\"bj_img_'+info[cell].UserID+'\" class="pointer" onmouseover="show(this,\'bj_'+info[cell].UserID+'\')" src="'+info[cell].HeadIcon+'" />');
                                UserInfo.append('\<div id="bj_'+info[cell].UserID+'" style="display:none"><div style="float:left; padding:3px 2px;">');
                                UserInfo.append('\<a href="/wo/?id='+info[cell].UserID+'" target="_blank"><img alt="" src="'+info[cell].HeadIcon+'" style="width:60px;height:60px;"/></a></div>');
                                UserInfo.append('\<div class="textleft font10 left content">');
                                UserInfo.append('\<p>用户名：<a href="/wo/?id='+info[cell].UserID+'" target="_blank">'+info[cell].UserName+'</a></p>');
                                UserInfo.append('\<p>等级:'+info[cell].Grade+'</p>');
                                UserInfo.append('\<p>财富状态：'+info[cell].Rich+'</p><p>地址：'+info[cell].Address+'</p>');
                                UserInfo.append('\<p>状态：<img alt="" src="http://online.gouwo.com/onlineimg.aspx?id='+info[cell].UserID+'"/></p>');
                                UserInfo.append('\</div><img alt="关闭" class="right pointer" src="images/m_close.gif" onclick="$(\'index_msg\').style.display=\'none\'" /></div>');
                                
                                break;
                            }                            
                        }                         
                        cur=cur+1;
                    } 
                    UserInfo.append("</div>");
                }
              UserInfo.append("</div>");
          }             
         $('map_'+num).innerHTML = UserInfo.toString();  
    },
    function(){})
   
}

function RandArr(num,min,max)
{
        var j;
        var  b = new Array(num);
        
        for (j = 0; j < num; j++)
        {
            var i = Math.floor(Math.random()*max);
            var tmp = 0;
            for (var k = 0; k < j; k++)
            {
                if (b[k] == i)
                {
                    tmp = tmp + 1;
                }
            }
            if (tmp == 0)
            {
                if(i<6)
                {j=j-1;continue;}
                b[j] = i;
            }
            else
            {
                j = j - 1;
            }
        }
        return b;    
}

function ShowMyCommend(sex)
{
    if(sex==1)
    {
       $('HomeBtnStatistic').src='';$('HomeBtnStatistic').src='http://sdn.kugoo.com/link_1256.html?url=http://www.gouwo.com/images/Statistic/StatHomeMoreGirlBtn.gif';
    }
    if(sex==0)
    {
       $('HomeBtnStatistic').src='';$('HomeBtnStatistic').src='http://sdn.kugoo.com/link_1257.html?url=http://www.gouwo.com/images/Statistic/StatHomeMoreBoyBtn.gif';
    }
    var cookie = new Cookie();    
    cookie.get("gouwo")!=null?location.href="sort.aspx?sex="+sex:kg.Blank('sortshow.aspx?sex='+sex,750,540);
}