/*
5digistar株式会社 [ActionBrowserサービス] 
Email： support@5digistar.co.jp 
URL： http://www.5digistar.co.jp/ 

Copyright (C) 2005 5digistar Inc. All Rights Reserved.
*/

var aZoom = new Array();
var aZoomImage = new Array();
var ZoomPosition = new Array();

var aZoom3 = new Array();
var aZoomImage3 = new Array();
var ZoomPosition3 = new Array();

function zoomMainPages(argID)
{
	var pObj = getObj('lyZoomView').style;
	var Obj = getObj('lyZoomImage');
	var oLeft = getObj('lyLeftImage');
	var oRight = getObj('lyRightImage');
		
	switch(AB.FlipDirection)
	{
		case 0:
			if(argID == "lyLeftCanvas")
			{
				AB.ViewerStatus = 60;
				
				pObj.left = parseInt(getObj('lyBookBase').style.left,10);
				
				Obj.style.left = oLeft.style.left;
				Obj.style.top = oLeft.style.top;
				Obj.style.width = oLeft.style.width;
				Obj.style.height = oLeft.style.height;							
				Obj.innerHTML = createImageTag(AB.IndexCurrentPage-1,8);
			}
			else
			{
				AB.ViewerStatus = 61;
				
				pObj.left = parseInt(pObj.left,10) + parseInt(getObj('lyLeftCanvas').style.width,10);

				Obj.style.left = oRight.style.left;
				Obj.style.top = oRight.style.top;
				Obj.style.width = oRight.style.width;
				Obj.style.height = oRight.style.height;							
				Obj.innerHTML = createImageTag(AB.IndexCurrentPage,8);
			}
			break;
		case 1:
			if(argID == "lyRightCanvas")
			{
				AB.ViewerStatus = 61;
				
				pObj.left = parseInt(pObj.left,10) + parseInt(getObj('lyLeftCanvas').style.width,10);
				
				Obj.style.left = oLeft.style.left;
				Obj.style.top = oLeft.style.top;
				Obj.style.width = oLeft.style.width;
				Obj.style.height = oLeft.style.height;							
				Obj.innerHTML = createImageTag(AB.IndexCurrentPage-1,8);
			}
			else
			{
				AB.ViewerStatus = 60;
				
				pObj.left = parseInt(getObj('lyBookBase').style.left,10);
				
				Obj.style.left = oRight.style.left;
				Obj.style.top = oRight.style.top;
				Obj.style.width = oRight.style.width;
				Obj.style.height = oRight.style.height;							
				Obj.innerHTML = createImageTag(AB.IndexCurrentPage,8);
			}
			break;                                                   		
	}
}

function zoomMain3()
{
	if ( (AB.ViewerStatus!=60)&(AB.ViewerStatus!=61) ) return;
	if (AB.ZoomRatio<3)
	{ 
		AB.ViewerStatus = (AB.ViewerStatus/10);
		return;
	}	
	
	var pObj3 = getObj('lyZoomView3').style;
	var Obj3 = getObj('lyZoomImage3');
	var IdxPage = 0;

	pObj3.width = AB.ViewerMaxWidth;
	pObj3.height = AB.ViewerMaxHeight;
	pObj3.top = AB.ViewerTopBar;
	
	if( AB.WindowSizeWidth>AB.ViewerMaxWidth )
		pObj3.left = (AB.WindowSizeWidth-AB.ImageSizeWidth)/2;
	else
		pObj3.left = 0;
		
	switch(AB.FlipDirection)
	{
		case 0:
			switch(AB.ViewerStatus)
			{
			case 60:
				AB.ViewerStatus = 600;
				IdxPage = AB.IndexCurrentPage-1;
				break;
			case 61:
				AB.ViewerStatus = 610;
				IdxPage = AB.IndexCurrentPage;	
				break;
			}
			break;
		case 1:
			switch(AB.ViewerStatus)
			{
			case 61:				
				AB.ViewerStatus = 610;
				IdxPage = AB.IndexCurrentPage-1;
				break;
			case 60:
				AB.ViewerStatus = 600;
				IdxPage = AB.IndexCurrentPage;
				break;
			}
			break;                                                   		
	}

	Obj3.style.left = 0;
	Obj3.style.top = 0;
	Obj3.style.width = AB.ImageSizeWidth;
	Obj3.style.height = AB.ImageSizeHeight;
	Obj3.innerHTML = createImageTag(IdxPage,10);
}

function BeforeStretch()
{
	var beforePostionX;
	var beforePostionY;

	switch(AB.ViewerStatus)
	{
	case 60:
	case 61:		
		hideBookmarks();
		
		beforePostionX = event.clientX-parseInt(getObj('lyBookBase').style.left,10);
		beforePostionY = event.clientY-parseInt(getObj('lyBookBase').style.top,10);

		ZoomPosition = new Array(beforePostionX,beforePostionY);
		
		getObj('imgcontent').disabled = true;
		getObj('imgcontent').onmouseup = null;
		getObj('imgcontent').style.filter = "alpha(opacity=20)";
		
		getObj('imgprint').disabled = true;
		getObj('imgprint').onmouseup = null;
		getObj('imgprint').style.filter = "alpha(opacity=20)";
		
		if(AB.LinkOnOff)delLinks();

		getObj('lyScrollBottom').style.top = parseInt(getObj('lyZoomView').style.height,10)-AB.ScrollTopHeight;
		
		if(checkCurMedia())
			setTimeout(Stretch,1000);
		else
			Stretch();
			
		break;
	case 600:
	case 610:
		beforePostionX = event.clientX-parseInt(getObj('lyZoomView').style.left,10)-parseInt(getObj('lyZoom').style.left,10);
		beforePostionY = event.clientY-parseInt(getObj('lyZoomView').style.top,10)-parseInt(getObj('lyZoom').style.top,10);

		ZoomPosition3 = new Array(beforePostionX,beforePostionY);
		
		getObj('imgcontent').disabled = true;
		getObj('imgcontent').onmouseup = null;
		getObj('imgcontent').style.filter = "alpha(opacity=20)";
		
		getObj('imgprint').disabled = true;
		getObj('imgprint').onmouseup = null;
		getObj('imgprint').style.filter = "alpha(opacity=20)";
		
		if(AB.LinkOnOff)delZoomLinks();

		getObj('lyScrollRight3').style.left = parseInt(getObj('lyZoomView3').style.width,10)-AB.ScrollLeftWidth;
		getObj('lyScrollBottom3').style.top = parseInt(getObj('lyZoomView3').style.height,10)-AB.ScrollTopHeight;
	
		if(checkCurMedia())
			setTimeout(Stretch3,1000);
		else
			Stretch3();
		
		break;
	}		
}

function Stretch()
{
	var pObj = getObj('lyZoomView').style;
	var Obj = getObj('lyZoom').style;
	var ObjImg = getObj('lyZoomImage').style;
	var oLeft = getObj('lyLeftImage').style;
	var oRight = getObj('lyRightImage').style;

	Obj.left = 0;
	Obj.top = 0
	Obj.height = parseInt(getObj('lyLeftCanvas').style.height,10) * 2;
	
	if( parseInt(Obj.height,10) <= AB.ViewerMaxHeight )
	{		
		hideLayer('lyScrollTop','lyScrollBottom');		
	}
	else
	{		
		var tmpTop = -ZoomPosition[1]*2;
		tmpTop = tmpTop + parseInt(pObj.height,10)/2;
		
		if(tmpTop>=0)
			Obj.top = 0;
		else
		{			
			if( tmpTop <= (parseInt(pObj.height,10)-parseInt(Obj.height,10)) )
				Obj.top = (parseInt(pObj.height,10)-parseInt(Obj.height,10));
			else
				Obj.top = tmpTop;
		}
	}
	
	pObj.width = Obj.width = parseInt(getObj('lyLeftCanvas').style.width,10)*2;
	pObj.height = AB.ViewerMidHeight;

	switch(AB.ViewerStatus)
	{
	case 60:
		ObjImg.left = parseInt(oLeft.left,10) * 2;
		ObjImg.top = parseInt(oLeft.top,10) * 2;
		ObjImg.width = parseInt(oLeft.width,10) * 2;
		ObjImg.height = parseInt(oLeft.height,10) * 2;
		break;
	case 61:
		pObj.left = parseInt(getObj('lyBookBase').style.left,10)
					+ (parseInt(getObj('lyLeftCanvas').style.width,10) - parseInt(getObj('lyLeftCanvas').style.width,10) );
				
		ObjImg.left = parseInt(oRight.left,10) * 2;
		ObjImg.top = parseInt(oRight.top,10) * 2;
		ObjImg.width = parseInt(oRight.width,10) * 2;
		ObjImg.height = parseInt(oRight.height,10) * 2;
		break;
	}	
	EndStretch();
}

function Stretch3()
{
	var pObj3 = getObj('lyZoomView3').style;
	var Obj = getObj('lyZoom3').style;
	var ObjImg3 = getObj('lyZoomImage3').style;
	
	Obj.width = AB.ImageSizeWidth;
	Obj.height = AB.ImageSizeHeight;
	pObj3.width = AB.ViewerMaxWidth;
	pObj3.height = AB.ViewerMaxHeight;
	pObj3.top = AB.ViewerTopBar;

	if( AB.WindowSizeWidth > AB.ViewerMaxWidth )
	{
		pObj3.left = (AB.WindowSizeWidth-AB.ImageSizeWidth)/2;
		hideLayer('lyScrollLeft3','lyScrollRight3');
	}
	else
	{
		pObj3.left = 0;		
	
		var tmpLeft = -ZoomPosition3[0]*(5/3);
		tmpLeft = tmpLeft + parseInt(pObj3.width,10)/2;

		if(tmpLeft>=0)
			Obj.left = 0;
		else
		{			
			if( tmpLeft <= (parseInt(pObj3.width,10)-parseInt(Obj.width,10)) )
				Obj.left = (parseInt(pObj3.width,10)-parseInt(Obj.width,10));
			else
				Obj.left = tmpLeft;
		}				
	}

	if( parseInt(Obj.height,10) <= AB.ViewerMaxHeight )
	{
		hideLayer('lyScrollTop3','lyScrollBottom3');
	}
	else
	{
		var tmpTop = -ZoomPosition3[1]*(5/3);
		tmpTop = tmpTop + parseInt(pObj3.height,10)/2;
			
		if(tmpTop>=0)
			Obj.top = 0;
		else
		{			
			if( tmpTop <= (parseInt(pObj3.height,10)-parseInt(Obj.height,10)) )
				Obj.top = (parseInt(pObj3.height,10)-parseInt(Obj.height,10));
			else
			{
				Obj.top = tmpTop;
			}
		}
	}

	switch(AB.FlipDirection)
	{
		case 0:
			switch(AB.ViewerStatus)
			{
			case 600:
				ObjImg3.left = 0;
				ObjImg3.top = 0;
				ObjImg3.width = AB.ImageSizeWidth;
				ObjImg3.height = AB.ImageSizeHeight;
				break;
			case 610:
				ObjImg3.left = 0;
				ObjImg3.top = 0;
				ObjImg3.width = AB.ImageSizeWidth;
				ObjImg3.height = AB.ImageSizeHeight;
				break;
			}
			break;
		case 1:
			switch(AB.ViewerStatus)
			{
			case 610:				
				ObjImg3.left = 0;
				ObjImg3.top = 0;
				ObjImg3.width = AB.ImageSizeWidth;
				ObjImg3.height = AB.ImageSizeHeight;
				break;
			case 600:
				ObjImg3.left = 0;
				ObjImg3.top = 0;
				ObjImg3.width = AB.ImageSizeWidth;
				ObjImg3.height = AB.ImageSizeHeight;
				break;
			}
			break;                                                   		
	}
	EndStretch3();
}

function EndStretch()
{   	
	var oZI = getObj('lyZoomImage').style;
		
	aZoomImage = new Array(parseInt(oZI.left,10),parseInt(oZI.top,10),parseInt(oZI.width,10),parseInt(oZI.height,10));
	AB.lyZoomImage[0] = aZoomImage;
	setNaviImg();	
	setNaviPosition(ZoomPosition);	

	getObj('lyNavigation').style.top = 20;
	getObj('lyNavigation').style.left = 0;
	
	if(AB.Navigation) showLayer('lyNavigation');	
	if(AB.LinkOnOff) 
	{
		if(checkCurMedia())
			setTimeout(showZoomLinks,1000);
		else
			showZoomLinks();
	}
	AB.iFlipCount = 1;
	showLayer('lyZoomView');
	checkScroll();
}

function EndStretch3()
{   	
	var oZI = getObj('lyZoomImage3').style;

	aZoomImage3 = new Array(parseInt(oZI.left,10),parseInt(oZI.top,10),parseInt(oZI.width,10),parseInt(oZI.height,10));
	AB.lyZoomImage3[0] = aZoomImage3;
	setNaviImg();	
	setNaviPosition(ZoomPosition3);	

	getObj('lyNavigation').style.top = 20;
	getObj('lyNavigation').style.left = 0;	
	
	if(AB.Navigation) showLayer('lyNavigation');	
	if(AB.LinkOnOff) 
	{
		if(checkCurMedia())
			setTimeout(showZoomLinks3,1000);
		else
			showZoomLinks3();
	}
	AB.iFlipCount = 1;	
	showLayer('lyZoomView3');
	checkScroll3();
}

function BeforeShrink()
{
	if(AB.ActivateLink) return;

	switch(this.id)
	{
	case "lyZoom":
		switch(event.button)
		{
		case 1:
			var oZ = getObj('lyZoom').style;
			aZoom = new Array(parseInt(oZ.left,10),parseInt(oZ.top,10),parseInt(oZ.width,10),parseInt(oZ.height,10));
			if(AB.LinkOnOff)delZoomLinks();
			if(checkCurMedia())
				setTimeout(Shrink,1000);
			else
				Shrink();
			break;
		case 2:
		case 3:
			if(AB.ZoomRatio<=2) return;
			zoomMain3();
			break;
		}
		break;
	case "lyZoom3":
		switch(event.button)
		{
		case 1:
			var oZ3 = getObj('lyZoom3').style;
			aZoom3 = new Array(parseInt(oZ3.left,10),parseInt(oZ3.top,10),parseInt(oZ3.width,10),parseInt(oZ3.height,10));
			if(AB.LinkOnOff)delZoomLinks3();
			if(checkCurMedia())
				setTimeout(Shrink3,1000);
			else
				Shrink3();
			break;
		case 2:
		case 3:
		case 4:
			break;
		}
		break;
	default:
		switch(AB.ViewerStatus)
		{
			case 60:
			case 61:
			case 160:
			case 161:
			case 260:
			case 261:
			case 360:
			case 361:
			case 460:
			case 461:
			case 560:
			case 561:
			case 600:
			case 610:			
				var oZ = getObj('lyZoom').style;
				var oZ3 = getObj('lyZoom3').style;
				
				aZoom = new Array(parseInt(oZ.left,10),parseInt(oZ.top,10),parseInt(oZ.width,10),parseInt(oZ.height,10));
				aZoom3 = new Array(parseInt(oZ3.left,10),parseInt(oZ3.top,10),parseInt(oZ3.width,10),parseInt(oZ3.height,10));
			
				if(AB.LinkOnOff)delZoomLinks();
				if(AB.LinkOnOff)delZoomLinks3();
				if(checkCurMedia())
				{
					setTimeout(Shrink3,1000);
					setTimeout(Shrink,1000);
				}
				else
				{
					Shrink();
					Shrink3();
				}
				break;			
		}
		break;	
	}
}

function Shrink()
{
	var pObj = getObj('lyZoomView').style;
	var Obj = getObj('lyZoom').style;
	var ObjImg = getObj('lyZoomImage').style;;
	
	var oLeft = getObj('lyLeftImage').style;
	var oRight = getObj('lyRightImage').style;

	Obj.left = 0;
	Obj.top =  aZoom[1] - aZoom[1]/(AB.FlipSlideCount/AB.iFlipCount);
	Obj.width =  aZoom[2] - parseInt(getObj('lyLeftCanvas').style.width,10);
	Obj.height =  aZoom[3] - parseInt(getObj('lyLeftCanvas').style.height,10);
	pObj.width = Obj.width;
	
	switch(AB.ViewerStatus)
	{
	case 160:
	case 260:
	case 360:
	case 460:
	case 560:
	case 60:		
		ObjImg.left = aZoomImage[0] - parseInt(oLeft.left,10);
		ObjImg.top = aZoomImage[1] - parseInt(oLeft.top,10);
		ObjImg.width = aZoomImage[2] - parseInt(oLeft.width,10);
		ObjImg.height = aZoomImage[3] - parseInt(oLeft.height,10);
		break;
	case 161:
	case 261:
	case 361:
	case 461:
	case 561:
	case 61:
		pObj.left = parseInt(pObj.left,10)+
			(
				 parseInt(getObj('lyBookBase').style.left,10)+parseInt(getObj('lyBookBase').style.width,10)
				  - (parseInt(pObj.left,10)+parseInt(pObj.width,10))
			);

		ObjImg.left = aZoomImage[0] - parseInt(oRight.left,10);
		ObjImg.top = aZoomImage[1] - parseInt(oRight.top,10);
		ObjImg.width = aZoomImage[2] - parseInt(oRight.width,10);
		ObjImg.height = aZoomImage[3] - parseInt(oRight.height,10);
		break;
	}		
	EndShrink();
}

function Shrink3()
{
	var pObj = getObj('lyZoomView3').style;
	var Obj = getObj('lyZoom3').style;
	var ObjImg = getObj('lyZoomImage3').style;;
	var oLeft = getObj('lyLeftImage').style;
	var oRight = getObj('lyRightImage').style;

	Obj.left = 0;
	Obj.top =  aZoom3[1] - aZoom3[1]/(AB.FlipSlideCount/AB.iFlipCount);
	Obj.width =  aZoom3[2] - parseInt(getObj('lyLeftCanvas').style.width,10);
	Obj.height =  aZoom3[3] - parseInt(getObj('lyLeftCanvas').style.height,10);
	pObj.width = Obj.width;
	
	switch(AB.ViewerStatus)
	{
	case 160:
	case 260:
	case 360:
	case 460:
	case 560:
	case 60:		
		ObjImg.left = aZoomImage3[0] - parseInt(oLeft.left,10);
		ObjImg.top = aZoomImage3[1] - parseInt(oLeft.top,10);
		ObjImg.width = aZoomImage3[2] - parseInt(oLeft.width,10);
		ObjImg.height = aZoomImage3[3] - parseInt(oLeft.height,10);
		break;
	case 161:
	case 261:
	case 361:
	case 461:
	case 561:
	case 61:
		pObj.left = parseInt(pObj.left,10)+
			(
				 parseInt(getObj('lyBookBase').style.left,10)+parseInt(getObj('lyBookBase').style.width,10)
				  - (parseInt(pObj.left,10)+parseInt(pObj.width,10))
			);

		ObjImg.left = aZoomImage3[0] - parseInt(oRight.left,10);
		ObjImg.top = aZoomImage3[1] - parseInt(oRight.top,10);
		ObjImg.width = aZoomImage3[2] - parseInt(oRight.width,10);
		ObjImg.height = aZoomImage3[3] - parseInt(oRight.height,10);
		break;
	}		
	EndShrink3();
}

function EndShrink()
{
	var tmpStatus = AB.ViewerStatus;
	
	AB.iFlipCount = 1;
	
	hideLayer('lyNavigation');
	hideLayer('lyZoomView');	
	
	AB.ViewerStatus = 0;

	getObj('imgcontent').disabled = false;
	getObj('imgcontent').style.filter = "alpha(opacity=100)";
	disableContentList();
	if(AB.Printing)
	{
		getObj('imgprint').disabled = false;
		getObj('imgprint').style.filter = "alpha(opacity=100)";
	}

	switch(tmpStatus)
	{
	case 160:
	case 161:
		gotoFirstPage();
		break;
	case 260:
	case 261:
		gotoLastPage();
		break;
	case 360:
	case 361:
		gotoNextPage();
		break;
	case 460:
	case 461:
		gotoPrevPage();
		break;
	case 560:
	case 561:	
		runGoToPageNum();
		break;
	}
	
	showBookmark();
	if(AB.LinkOnOff)
	{
		setTimeout(showLinks,1000);
	}
}

function EndShrink3()
{
	var tmpStatus = AB.ViewerStatus;
	
	AB.iFlipCount = 1;
	
	hideLayer('lyZoomView3');	
	
	switch(AB.ViewerStatus)
	{
	case 600:
		AB.ViewerStatus = 60;
		break;
	case 610:
		AB.ViewerStatus = 61;
		break;
	}
	setNaviPosition(ZoomPosition);
	disableContentList();

	switch(tmpStatus)
	{
	case 160:
	case 161:
		gotoFirstPage();
		break;
	case 260:
	case 261:
		gotoLastPage();
		break;
	case 360:
	case 361:
		gotoNextPage();
		break;
	case 460:
	case 461:
		gotoPrevPage();
		break;
	case 560:
	case 561:	
		runGoToPageNum();
		break;
	}
	if(AB.LinkOnOff) 
	{
		setTimeout(showZoomLinks,1000);
	}
}

function checkCurMedia()
{
	if(AB.FlipDirection == 0)
	{
		switch(AB.ViewerStatus)
		{
		case 60:
		case 600:
			if(getCurMedia(AB.IndexCurrentPage-1))
				return true;
			break;
		case 61:
		case 610:
			if(getCurMedia(AB.IndexCurrentPage))
				return true;
			break;
		}
	}
	else
	{
		switch(AB.ViewerStatus)
		{
		case 60:
		case 600:
			if(getCurMedia(AB.IndexCurrentPage))
				return true;
			break;
		case 61:
		case 610:
			if(getCurMedia(AB.IndexCurrentPage-1))
				return true;
			break;
		}
	}
	
	return false;
}
