﻿function vv(){}
function homeAL(){var a={i:0,j:0,p:0,id:"",num:-1,TT:"",mvNum:0};return a;} 
var AL=new homeAL();

AL.id=setInterval("VV.moveNext()",10);
vv.prototype.moveNext=function(){
    AL.i++;
    if(AL.i>=0 && AL.i<10){
        var s=-AL.p*23;
        switch(AL.i){
          case 0:s=-1+s;break;case 1:s=-2+s;break;case 2:s=-3+s;break;case 3: s=-5+s;break;case 4:s=-7+s;break;case 5:s=-10+s;break;
          case 6:s=-13+s;break;case 7:s=-17+s;break;case 8:s=-21+s;break;case 9:s=-23+s;break;
        }
       $("#BuyShow").css("marginTop",s-3); $("#SellShow").css("marginTop",s-3);
    }
    else{ AL.j++; if(AL.j==120){AL.i=0;AL.j=0;AL.p++;} }
    if(AL.p==14){AL.p=0;}
}
vv.prototype.stop=function(){window.clearInterval(AL.id);}
vv.prototype.goOn=function(){AL.id=setInterval("VV.moveNext()",10);}
var VV=new vv();
var timernews;
$(function(){
    setMV1(0,0);
	setMV2(0,0);
	$('#children').animate({top:0},200); 
	
	$(".bottom_list li").click(function(){  // alert("sdfsd");
	    $(".bottom_list li a").removeClass("on");
	    $(this).children("a").addClass("on"); 
	    var gid=$(this).children("a").attr('alt').replace("c",""); 
        $('#children').animate({top:-(parseInt(gid)-1)*206},200);  }
    );
	 
	$(".quickbar li").hover(function(){ 
	   clearInterval(timernews);
	    }, function(){timernews=setInterval('topnews()',2500); }
    );
	  timernews= setInterval('topnews()',2500);
	  
});

function GoWhere(ac,type,pagecount){
    var b=type=="mv1",hid=b?"hidLeft":"hidRight",emID=b?"emLeft":"emRight",pv=parseInt($("#"+hid).val()),pc=parseInt(pagecount);
    if(isNaN(pv)) pv=0;
    if(ac=="left"){
       if(pv==0) return false;
       AL.mvNum=pv-1;$("#"+hid).val(pv-1);
    }
    else{
       if(pv==pc-1) return false;
       AL.mvNum=pv+1;$("#"+hid).val(pv+1);
      
    }
    $("#"+emID).html(AL.mvNum+1);
    b?setMV1(AL.mvNum,pagecount):setMV2(AL.mvNum,pagecount); 
}

function GoIndex(type,pagecount,pageindex){
	pageindex=pageindex-1;
    var b=type=="mv1",hid=b?"hidLeft":"hidRight",emID=b?"emLeft":"emRight",pv=parseInt($("#"+hid).val()),pc=parseInt(pagecount);
  
       AL.mvNum=pageindex;$("#"+hid).val(pageindex);
   
    $("#"+emID).html(AL.mvNum+1);
    b?setMV1(AL.mvNum,pagecount):setMV2(AL.mvNum,pagecount); 
}

function GoRand()
{
	  var native_random = Math.random;
      Math.random = function(min, max, exact) {
        if (arguments.length === 0) {
          return native_random();
        } else if (arguments.length === 1) {
          max = min;
          min = 0;
        }
        var range = min + (native_random()*(max - min));
        
        return exact === void(0) ? Math.round(range) : range.toFixed(exact);
      }; 
	  
	   var PCount=$("#mv1PageCount11").val();
	   var PCount2=$("#mv2PageCount11").val();
	   var now=new Date();
       var number =Math.random(1,PCount);
       var number2 =Math.random(1,PCount2);
	   GoIndex("mv1",PCount,number);	
	   GoIndex("mv2",PCount2,number2);
}
function topnews(){
$(function(){
      $('.quickbar li').eq(0).fadeOut('slow',function(){        
            $(this).clone().appendTo($(this).parent()).fadeIn('slow');
            $(this).remove();
        });
     });
}


function getID(num,ulID,leftID,rightID,pagecount){
   this.Num=num;
   this.UlID=ulID;
   this.LeftID=leftID;
   this.RigthID=rightID;
   this.PageCount=pagecount;
}
getID.prototype.MV=function(){
   $("#"+this.UlID+" ul").hide();
   $($("#"+this.UlID+" ul")[this.Num]).show();
   $("#"+this.LeftID).attr("class",this.Num=="0"?"left left_no":"left");
   $("#"+this.RigthID).attr("class",(parseInt(this.Num)+1==this.PageCount)?"right right_no":"right");
}
function setMV1(num,pagecount){
    if(isNaN($("#hidLeft").val())) $("#hidLeft").val("0");
	if(isNaN($("#emLeft").text())) $("#emLeft").text("1");
   var m=new getID(num,"ULTop","leftbtn1","rightbtn1",pagecount);
   m.MV();
   $.post("/ajax.aspx?ac=GetTopSuplyList",{PageIndex:(num+1)},function(result){  $("#ULTop").html(result); }); 
}
function setMV2(num,pagecount){
   var m=new getID(num,"PremiumUL","leftbtn2","rightbtn2",pagecount);
   m.MV();
   $.post("/ajax.aspx?ac=GetPremiumSupplyList",{PageIndex:(num+1)},function(result){ $("#PremiumUL").html(result); }); 
}


function HomeLogin()
{
 var l = new Object();
  l.init=function()
  {    
       this.showCommWater("LoginAccount");
       this.showCommWater("LoginPwd");
       $("#btLogin").click(this.SinUp);
       $("#LoginAccount").keydown(function(event){ if(comm.GetKey(event)   ==   13) {$("#LoginPwd").focus()}});
       $("#LoginPwd").keydown(function(event){ if(comm.GetKey(event)   ==   13) {homelogin.SinUp()}});
  }
  l.SinUp=function()
  {
	  layer.show(300,100,'<br><br>Please wait...');
	  var UserName=$("#LoginAccount").val();
	  var PassWord=$("#LoginPwd").val();
	  var isStay="";
	  
	  if(UserName==""||UserName=="Account")
	  {
	    layer.showWH(300,100,'<br><br>Member ID is required',-1,33);
        layer.close(1500);
        $("#LoginAccount").focus();
        return;
	  }
	 if(PassWord==""||PassWord=="******")
	  {
	    layer.showWH(300,100,'<br><br>Password is required',-1,33);
        layer.close(1500);
         $("#LoginPwd").focus();
        return;
	  }
	  
	  $.post("/ajax.aspx?ac=login",{username:UserName,password:PassWord,isstay:isStay},function(result){
	     var txt=result;
	     if(result=="1" || result=="2")  txt="Login successfully!";
         layer.showWH(300,100,'<br><br>'+txt,-1,33);
         layer.close(2000);
		 if(result!="1" && result!="2")  return;
		 var url= result == "1"? "/member/seller/default.aspx" : "/member/buyer/default.aspx";	
		 window.location.href=url;
		 
       });
   }
   l.showCommWater=function(ID)
   {
       var text_val2=$("#"+ID).val();
        if(text_val2=="Account" || text_val2=="******" ){
            $("#"+ID).css("color","#8e8e8e");
          }
         $("#"+ID).focus(function(){
            var text_val=$(this).val();
            if(text_val==this.defaultValue){
                $(this).val("");
                $(this).css("color","#000");
              }
            });
            
        $("#"+ID).blur(function(){
        var text_val=$(this).val();
        if(text_val==""){
            $(this).val(this.defaultValue);
            $(this).css("color","#8e8e8e");
          }
        }); 
    }

   return l;
}
 
   var homelogin=new HomeLogin();
  
    $(document).ready(function()
    {
       homelogin.init();
       GoRand();
    });

