﻿//流程:页面加载后，imgload一次，然后init2,然后再一次imgload

function Reader(pic_path,datas,title){
   this.tmp=0;
   this.datas=datas;
   this.pic_path=pic_path;
   this.title=title;
   
   //图片加载后界面处理
   this.loadOver=function(o)
   {
	    var v = parseInt(o.width);
	    if (v>1){ 
	      
	      document.getElementById('LayerLoading').style.display='none';	 
	      
	      this.cartoonpic.style.width="auto";
          this.cartoonpic.style.height="auto";
          this.loadpic();
    
            
       }
    
   }
    //跳转
    this.showpic=function (v)
    {
      
	   this.cartoonpic.src = pic_path + this.datas[v];	
	   document.getElementById('LayerLoading').style.display='block';	 
    }

    //选中下拉列表
    this.ch_sel=function (v)
    {
        document.getElementById('selectPager1').value = v;
        document.getElementById('selectPager2').value = v;
        return true;
    }
    
    
    //初始化下拉列表
    this.get_sel=function (v)
    {
        cur_page = this.page;

        if(cur_page<1){
            cur_page = 1;
        }else if(cur_page > (this.datas.length+1)){
            cur_page = this.datas.length;
        }

        if (v == 0)
        {
            var i,outstr = "";
	        for (i=1;i<this.datas.length;i++)
	        {
		        if(i == cur_page){
                    extra_option = ' selected ';
                }else{
                    extra_option = '';
                }
                outstr += "<option "+extra_option+" value='"+ i +"'>第"+ i +"页</option>";
	        }
	        document.write(outstr);
        }
        else
        {
	        if ((v > 0) && (v < this.datas.length+1))
	        {
		        this.page = v;
             
		        this.showpic(v);
		        this.ch_sel(v);
	        }
        }
    }
    
    
    
    this.refresh=function(){
        this.ch_sel(this.page);
		this.cartoonpic.src = pic_path + this.datas[this.page];	
		document.getElementById('LayerLoading').style.display='none';	
    }

   
    //上一页
    this.prevpage=function ()
    {
	    this.page--;
	    if (this.page <1)
	    {
		    alert('已到达首页');
		    this.page = 1;
	    }
	    else
	    {
		    this.ch_sel(this.page);
		    this.showpic(this.page);
	    }
    }

    //下一页
    this.nextpage=function ()
    {
	    this.page++;
	    if (this.page >= this.datas.length )
	    {
		    alert('已到达未页');
		    this.page = this.datas.length-1;
	    }
	    else
	    {
		    this.ch_sel(this.page);
		    this.showpic(this.page);
	    }
    }
    
    
        //按键锁定
    this.keylock=function ()
    {
	    if((event.keyCode == 78 || event.keyCode == 110) && (event.ctrlKey))
	    {
		    event.returnValue = false;
	    }
	    if((event.keyCode == 121) && (event.shiftKey))
	    {
		    event.returnValue = false;
	    }
    }

    //键盘事件
    this.keyUp=function()
    {
	    //Z
	    if (window.event.keyCode == 90)
	    {
		    this.zoom();
	    }
	    //X
	    if (window.event.keyCode == 88)
	    {
		    this.mini();
	    }
	    //C
	    if (window.event.keyCode == 67)
	    {
		    this.self();
	    }
	    //V
	    if (window.event.keyCode == 86)
	    {
		    this.wellsize();
	    }
    	
	    //两次ctrl
	    if (window.event.keyCode == 17)
	    {
		    if (this.tmp == 1)
		    {
                this.nextpage();
            }
		    this.tmp = 1;
	    }
	    //两次shift
	    if (window.event.keyCode == 16)
	    {
		    if (this.tmp == 3){
	           this.prevpage();	
	        }
            this.tmp = 3;
	    }
    }
       


// ------------------- 鼠标左键移动图片 ---------------------//
this.pX=0;
this.pY=0;
//传入被捕获的移动对象
this.MDown=function (Object)
{
	this.Obj=Object.id
	document.all(this.Obj).setCapture()
	this.pX=event.x-document.all(this.Obj).style.pixelLeft;
	this.pY=event.y-document.all(this.Obj).style.pixelTop;
	
}

this.MMove=function ()
{
	if(this.Obj!='')
	{
		document.all(this.Obj).style.left=event.x-this.pX;
		document.all(this.Obj).style.top=event.y-this.pY;
		
	}
}
this.MUp=function ()
{
	if(this.Obj!='')
	{
		document.all(this.Obj).releaseCapture();
		this.Obj='';
		
	}
}


this.loadpic=function ()
{
	this.picW = this.cartoonpic.width;
	this.picH = this.cartoonpic.height;
	this.selfW = this.picW;
	this.selfH = this.picH;
	var thisSW = document.body.clientWidth;
	this.cartoonpic.style.posLeft = (thisSW-this.picW)/2;
	this.cartoonpic.style.posTop = 1;
}

//放大
this.zoom=function ()
{
	if (this.picW > 0 && this.picH > 0)
		{
			this.picH = this.picH * 130 / 100;
			this.picW = this.picW*130/100;
			this.cartoonpic.style.height = this.picH;
			this.cartoonpic.style.width = this.picW;
		}
}
//缩小
this.mini=function ()
{
	if (this.picW > 0 && this.picH > 0)
		{
			if (this.picW > 100 || this.picH > 100)
			{
				this.picH = this.picH * 70 / 100;
				this.picW = this.picW * 70 / 100;
				this.cartoonpic.style.height = this.picH;
				this.cartoonpic.style.width = this.picW;
			}
		}
	
}

//还原原大小
this.self=function ()
{
	this.cartoonpic.style.height = "auto";
	this.cartoonpic.style.width = "auto";
	
	var thisSW = document.body.clientWidth;
	this.cartoonpic.style.posLeft = (thisSW-this.cartoonpic.width)/2;
	this.cartoonpic.style.posTop = 1;

	this.picH = this.cartoonpic.height;
	this.picW = this.cartoonpic.width;
	

}

//最佳尺寸
this.wellsize=function ()
{

	var oBody = document.body;
	var tH = oBody.clientHeight;
	var tW=900;
	if (tH > 690)
	{
		tH = 580;
		
	}
	else
	{
		tH = 480;
	}

	if (this.selfH > tH)	
	{
		this.cartoonpic.style.height = tH;
		this.cartoonpic.style.width = this.selfW*tH/this.selfH;
	}
	else if (this.selfW > tW)
	{
		this.cartoonpic.style.width = tW;
		this.cartoonpic.style.height= this.selfH*tW/this.selfW; 
	}

	var thisSW = document.body.clientWidth;

	this.cartoonpic.style.posLeft = (thisSW-this.cartoonpic.width)/2;
	this.cartoonpic.style.posTop = 1;
	
	this.picH = this.cartoonpic.height;
	this.picW = this.cartoonpic.width;

				

}




//图片鼠标滚轮缩放
this.piczoom=function (e, o)  
{
	var p = event.wheelDelta/120;
	if (p < 0)
	{
		this.mini();
	}
	else
	{
		this.zoom();
	}
}


document.onmousedown=function ()
{
    if(event.button==4) //中键 
	{
		this.self();
	}
 
}


//键盘事件
this.keydown=function ()
{
	//空格
	if ( event.keyCode== 32)
	{
		this.nextpage();
	}

	//pageup
	if (event.keyCode== 33)
	{
		this.prevpage();
	}
	//pagedown
	if (event.keyCode== 34)
	{
		this.nextpage();
	}

	//最佳尺寸:num del
	if (event.keyCode == 110)
	{
		this.wellsize();
	}
		
	//缩小:-
	if (event.keyCode== 109)
	{
		this.mini();
	}
	//放大:+
	if (event.keyCode== 107)
	{
		this.zoom();
	}
	//恢复:*
	if (event.keyCode== 106)
	{
		this.self();
	}

	

	//滚动条向下
	if (event.keyCode == 40)
		document.all.picwin.scrollTop = document.all.picwin.scrollTop + 100;
	//滚动条向上
	if (event.keyCode == 38)
		document.all.picwin.scrollTop = document.all.picwin.scrollTop - 100;

	//滚动条向左
	if (event.keyCode == 37)
		document.all.picwin.scrollLeft = 0;
	//滚动条向右
	if (event.keyCode == 39)
		document.all.picwin.scrollLeft = 9999;

}


this.rmouse=function ()
{
	if (this.selfH == this.cartoonpic.height)
	{
		this.wellsize();
	}
	else
	{
		this.self();
	}
	
	event.cancelBubble = true
	event.returnValue = false;
	return false;
}
    
    
    
   //初始化界面
this.init=function ()
{    

    this.Obj='';
    this.cartoonpic =  document.getElementById('iphoto');
  
    this.page=1;
	this.ch_sel(this.page);
	document.getElementById('title').innerText=this.title;
    this.cartoonpic.src = pic_path + datas[this.page];

    this.tmp = 0;

    this.picW = this.cartoonpic.width;
    this.picH = this.cartoonpic.height;
    this.selfW = this.picW;
    this.selfH = this.picH;
    
    
 
} 
    
    
    
    
    



}





















